当前位置: 首页 > news >正文

wordpress网站做app网站搭建平台

wordpress网站做app,网站搭建平台,wordpress不支持php7,佛山做网站公司有哪些复数在数学、科学或者工程领域是很常用的,可以通过调用Apache Commons Math库来完成,也可以自己手撸。 一、使用Apache Commons Math库 这个库有多个版本,在写这篇文章时,它的最新版是2022年12月19日的4.0-beta1,构建…

复数在数学、科学或者工程领域是很常用的,可以通过调用Apache Commons Math库来完成,也可以自己手撸。

一、使用Apache Commons Math库

这个库有多个版本,在写这篇文章时,它的最新版是2022年12月19日的4.0-beta1,构建坐标是org.apache.commons:commons-math4-core:4.0-beta1,考虑到程序稳定性,我们可以使用目前开发者用得最多的版本3.6.1(2016年3月17日发布),Maven依赖如下:

<!-- https://mvnrepository.com/artifact/org.apache.commons/commons-math3 -->
<dependency><groupId>org.apache.commons</groupId><artifactId>commons-math3</artifactId><version>3.6.1</version>
</dependency>

示例代码如下:

import org.apache.commons.math3.complex.Complex;
public class ACMComplexDemo {public static void main(String[] args) {Complex c = new Complex(3, 5);Complex d = new Complex(2, -2);System.out.println(c);System.out.println("c = " + c.getReal() + " + " + c.getImaginary() + "i");System.out.println(c + " * " + d + " = " + c.multiply(d));System.out.println(c + " / " + d + " = " + c.divide(d));}
}

二、自己开发一个复数类

public class SimpleComplex {private double real;private double imaginary;// 无参构造public SimpleComplex() {this(0.0, 0.0);}// 双参构造,用于表示虚数public SimpleComplex(double real, double imaginary) {this.real = real;this.imaginary = imaginary;}// 单参构造,适用于实数范围public SimpleComplex(double real) {this(real, 0.0);}// 加法public SimpleComplex add(SimpleComplex other) {double real = this.real + other.real;double imaginary = this.real + other.imaginary;return new SimpleComplex(real, imaginary);}// 减法public SimpleComplex sub(SimpleComplex other) {return this.add(opposite(other));}// 乘法public SimpleComplex mul(SimpleComplex other) {double real = this.real * other.real - this.imaginary * other.imaginary;double imaginary = this.real * other.imaginary + this.imaginary * other.real;return new SimpleComplex(real, imaginary);}// 除法public SimpleComplex div(SimpleComplex other) {double real = (this.real * other.real + this.imaginary * other.imaginary)/ (other.real * other.real + other.imaginary * other.imaginary);double imaginary = (this.imaginary * other.real - this.real * other.imaginary)/ (other.real * other.real + other.imaginary * other.imaginary);return new SimpleComplex(real, imaginary);}// 获取实部public double getReal() {return real;}// 获取虚部public double getImaginary() {return imaginary;}@Overridepublic String toString() {if (this.real == 0.0) {return this.imaginary + "i";} else if (this.imaginary == 0.0) {return this.real + "";} else if (this.imaginary < 0.0 && this.real != 0.0) {return this.real + "" + this.imaginary + "i";} else if (this.imaginary == 0.0 && this.real == 0.0) {return "0.0";}return this.real + "+" + this.imaginary + "i";}// 判断两个复数是否相等@Overridepublic boolean equals(Object obj) {if (obj == this) {return true;} else if (obj == null || !(obj instanceof SimpleComplex)) {return false;}SimpleComplex tmp = (SimpleComplex) obj;return Math.abs(this.real - tmp.real) < 1e-6&& Math.abs(this.imaginary - tmp.imaginary) < 1e-6;}// 返回相反数private static SimpleComplex opposite(SimpleComplex one) {return new SimpleComplex(-one.real, -one.imaginary);}public static void main(String[] args) {// 示例用法SimpleComplex c1 = new SimpleComplex(3, 5); // 3 + 5iSimpleComplex c2 = new SimpleComplex(2, -2); // 2 - 2iSystem.out.println("c1 + c2 = " + c1.add(c2));System.out.println("c1 - c2 = " + c1.sub(c2));System.out.println("c1 * c2 = " + c1.mul(c2));System.out.println("c1 / c2 = " + c1.div(c2));}
}

显然,自己开发一个并不如Apache Commons Math做得好了,毕竟Apache的库提供了大量的运算方法,且逻辑严谨,是应用开发的首选。但执行一些简单的运算,譬如复数除法,在一定量的基础上,简单实现有一点点的性能优势。

http://www.hengruixuexiao.com/news/38089.html

相关文章:

  • 祥云平台做网站好不好网站域名购买
  • 网络营销是什么基础类型河南网站推广优化
  • 服装网站建设目的电脑全自动挂机赚钱
  • 网站建设费属于研发费用吗网站设计公司报价
  • 企业做网站一般多少钱百度云搜索引擎官网
  • 企业微信会话内容存档seo zac
  • 高端建设网站公司哪家好广州seo招聘信息
  • 旅游景区网站建设方案搜索引擎优化涉及的内容
  • 旅游网站开发毕业设计找客户的软件有哪些
  • 做网站的大骗子福建百度seo排名点击软件
  • 网站谁建设的软文营销经典案例
  • 手机如何创网站北京seo服务商
  • 微信扫一扫登录网站如何做网络推广的优势
  • 小企业做网站有没有用湖南企业竞价优化
  • 自动做微网站宁波网站seo哪家好
  • 织梦网站中的对话框怎摸做全球十大网站排名
  • 做网站的安全证书app地推接单平台
  • 商业空间设计案例网站最好的优化公司
  • 深圳网站建设公司招聘电商平台怎么注册
  • 郑州网站开发汉狮网络营销的优势和劣势
  • 安平县哪个做网站的好网址seo优化排名
  • ios开发网站app企业宣传册模板
  • 渭南做网站博创互联上海百度公司地址
  • 做网站编辑有人带吗关键词工具
  • 动态网站开发工程师试题百度竞价代运营托管
  • 房产网站电商怎么做中国站长
  • 网站制作流程的组成部分包括网络营销策划内容
  • 旅游wordpressseo公司系统
  • 网站开发如何设置视频教程产品如何推广
  • 网站运营需要什么行业技术广州推广系统