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

wordpress网站做app南宁百度seo排名优化

wordpress网站做app,南宁百度seo排名优化,旅游景点网站建设规划书,社区网站源码复数在数学、科学或者工程领域是很常用的,可以通过调用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.khdw.cn/news/18083.html

相关文章:

  • 宁夏网站建设多少钱网络竞价推广托管公司
  • 地推接单在哪个平台找宁波seo营销平台
  • 个人建什么网站比较好什么是全网营销推广
  • 网站建设unohacha做企业推广
  • 网站接入服务 公司扬州网站推广公司
  • 怎么做网站上翻译泰剧百度收录平台
  • 三级 做爰免费网站天津网站排名提升
  • 平台网站如何优化湖南网站制作公司
  • 北京低价做网站绍兴seo计费管理
  • 茶叶价格网站建设橙子建站官网
  • 淮安高端网站制作阿里指数数据分析平台官网
  • 深圳网站建设ppchsj广州seo推广服务
  • 呼市网站建设企业域名查询
  • 免费icp备案服务码seo搜索引擎优化工资薪酬
  • 食品网站开发毕业设计影视网站怎么优化关键词排名
  • 内江做网站哪里便宜如何搜索关键词热度
  • 用yii框架做的网站如何搭建网络互联网推广
  • 重庆网站制作服务百度推广话术全流程
  • 四川省人民政府名单福建百度seo排名点击软件
  • 手把手网站开发百度搜索引擎排行榜
  • 广州做鞋的网站中国网站排名100
  • 怎么做关于狗的网站惠州关键词排名优化
  • 上海响应式网站建设费用学做网站需要学什么
  • 网站改版方案购物网站如何推广
  • 创办一个网站能够做那些事seo薪资水平
  • 合肥网站建设合肥网站制作软件开发培训中心
  • 设计一个网站的首页步骤房产网站模板
  • 专做童车批发的网站优质网站
  • 学做网站需要学那些程序搜狗推广登录平台
  • 网站建设服务条款网页广告