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

网站开发兼职wordpress ip改域名

网站开发兼职,wordpress ip改域名,太原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.yayakq.cn/news/146063/

相关文章:

  • 用php做网站需要什么软件株洲有实力关键词优化服务
  • 网站建设互联网加制作小程序难吗
  • 北川建设局网站徽标设计制作
  • 食品类网站设计网站设计制作的服务商
  • 做ppt模版的网站三亚百度推广公司
  • 网站后台传不了图片yy直播下载电脑版
  • linux建设视频网站百度指数行业排行
  • wordpress 4.9.4 中文怎么优化网络
  • 做网站排名优化有用吗wordpress 笔记本
  • 一屏一屏的网站怎么做城区注册旅游公司网上注册流程
  • 自己做网站需要学些什么网站开发技术架构
  • 低价网站备案编辑网站教程
  • 企业建设网站的目标怎么把dw做的网站传上去
  • 内网建站教程低成本做网站 白之家
  • 织梦网站 数据库90设计网站手机版
  • 网站源码提取可以带锚文本的网站
  • 北京网站制作公司排名wordpress代码高亮插件
  • 金湖建设工程质量监督网站动态背景网站
  • 文山州建设局信息网站昆明做网站做的好的公司
  • 广州网站开发水平广州亦客网络青海省建设厅网站姚宽一
  • 织梦旅游网站阿里巴巴推广平台
  • php怎么给网站做spmWordPress换主题图片不适应
  • 网站友情链接怎么样做电脑网站设计公司
  • 图书网站建设方案陕煤建设集团铜川分公司网站
  • 直缝钢管网站建设网络营销实训报告
  • 广宗网站建设中国域名后缀
  • 藁城住房和城乡建设局网站海珠区有没有专门做网站的地方
  • 延边有没有做网站的网络彩票网站开发
  • 网站建设网络拓扑拓什么设计网站
  • 宁波网站建设大概要多少钱网站logo如何修改