版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、secondComplex.javapackage secondComplex;public class secondComplex private double real;private double vir;public secondComplex()this(0.0,0.0);public secondComplex(double real, double vir) this.real = real;this.vir = vir;public secondComplex(secondComplex c)this.real = c.real;this.vir = c.vir;/求共轭复数p
2、ublic static secondComplex Conjugate(secondComplex a)return new secondComplex(a.real, -a.vir);/求复数的相反数public secondComplex oppositeComplex(secondComplex a)return new secondComplex(-a.real, -a.vir);/求复数的倒数public static secondComplex Reciprocal(secondComplex a)secondComplex b = secondComplex.Conjugate
3、(a);b.Multiplication(a);b.real = b.real +b.vir;a = secondComplex.Conjugate(a);if(Math.abs(b.real) 1e-6)b.real = 0;return null;return new secondComplex(a.real/b.real, a.vir/b.real);/* * this+=a * return * */public void Add(secondComplex a)this.real += a.real;this.vir += a.vir;/* * this-=a; */public v
4、oid Sub(secondComplex a)a = a.oppositeComplex(a);this.Add(a);/* * this*=a; */public void Multiplication(secondComplex a)double tmp;tmp = this.real;this.real = this.real * a.real - this.vir * a.vir;this.vir = tmp * a.vir + this.vir * a.real; /* *this /= b * return */public void Division(secondComplex
5、 a)secondComplex b = Multiplication(this, secondComplex.Reciprocal(a);if(b = null)return;this.real = b.real;this.vir = b.vir;/* * * c = this + a * return */public secondComplex Add(secondComplex a, int type) return Add(this, a);/* * c = this - a */public secondComplex Sub(secondComplex a, int type)a
6、 = a.oppositeComplex(a);return Add(this, a);/* * c = this * a */public secondComplex Multiplication(secondComplex a, int type)return Multiplication(this, a);/* *c = this / b * return */public secondComplex Division(secondComplex a,int type)return Division(this,a);/* * c = a + b * param a * param b *
7、 return */public static secondComplex Add(secondComplex a, secondComplex b)return new secondComplex(a.real + b.real, a.vir + b.vir);/* * c = a - b * return */public secondComplex Sub(secondComplex a, secondComplex b)b = b.oppositeComplex(b);return Add(a, b);/* * c = a * b * return */public static se
8、condComplex Multiplication(secondComplex a, secondComplex b)if(b = null)return null;return new secondComplex(a.real * b.real - a.vir * b.vir, a.real * b.vir + a.vir * b.real);/* *c = a / b * return */public secondComplex Division(secondComplex a, secondComplex b)if(secondComplex.Reciprocal(b) = null
9、)return null;return Multiplication(a, secondComplex.Reciprocal(b);public double getReal() if(Math.abs(real) 1e-6)real = 0;return real;public void setReal(double real) this.real = real;public double getVir() if(Math.abs(vir) 1e-6)vir = 0;return vir;public void setVir(double vir) this.vir = vir;public
10、 String toString()if(Math.abs(this.getReal() 1e-6 & Math.abs(this.getVir() 1e-6)System.out.println(0);else if(Math.abs(this.getReal() 1e-6)if(Math.abs(this.getVir() 0)System.out.println(i);elseSystem.out.println(-i);elseSystem.out.println(this.getVir()+i);else if(Math.abs(this.getVir() 0)System.out.
11、println(+ i);elseSystem.out.println(- i);else if(Math.abs(this.getVir() 1e-6)System.out.println( + this.getVir()+i);elseif(this.getVir() 0)System.out.println(this.getReal() + + + this.getVir() + i);elseSystem.out.println(this.getReal() + - + Math.abs(this.getVir() + i);return ;Complex.javapackage se
12、condComplex;public class Complex extends secondComplex private double mo;private double jiao;public Complex()this(1.0,Math.PI/4);public Complex(double mo, double jiao)super(Complex.returnX(mo, jiao), Complex.returnY(mo, jiao);public static double returnX(double mo, double jiao)return mo * Math.cos(j
13、iao);public static double returnY(double mo, double jiao)return mo * Math.sin(jiao);public static double returnMo(double x, double y)x = Math.abs(x);y = Math.abs(y);if(x 1e-6)x = 0;if(y 1e-6)y = 0;return Math.sqrt(x*x + y*y);public static double returnJiao(double x, double y)double tmp1;int st1;int
14、st2;double tmp2;/横轴正向:1;反向:-1;原点:0/纵轴正向:1;反向:-1;原点:0if(Math.abs(x) 0)tmp1 = x;st1 = 1;elsetmp1 = x;st1 = -1;if(Math.abs(y) 0)tmp2 = y;st2 = 1;elsetmp2 = y;st2 = -1;if(0 = st1 & 0 = st2)System.out.println(复数无辐角);return -1000;else if(0 = st1 & 0 != st2)if(st2 0)return Math.PI/2;elsereturn -Math.PI/2;e
15、lse if(st1 0 & tmp2 != 0.0)return Math.atan(tmp2/tmp1);else if(st1 0 & tmp2 != 0.0)return Math.atan(tmp2/tmp1)-Math.PI;return -1000;public String toString()if(Complex.returnJiao(this.getReal(), this.getVir() = -900)return ;return 计算结果模值为: + (double)(int)(Complex.returnMo(this.getReal(), this.getVir(
16、)*1000)/1000 + 角度为: + (double)(int)(Complex.returnJiao(this.getReal(), this.getVir()*1000)/1000;public double getMo() return mo;public void setMo(double mo) this.mo = mo;public double getJiao() return jiao;public void setJiao(double jiao) this.jiao = jiao;/* * this+=a */public void Add(Complex a) th
17、is.setReal(this.getReal() + a.getReal(); this.setVir(this.getVir() + a.getVir();public void Sub(Complex a)secondComplex tmp = a.oppositeComplex(new secondComplex(a.getReal(), a.getVir();Complex d = new Complex();d.setReal(tmp.getReal();d.setVir(tmp.getVir();this.Add(d);public void Multiplication(Com
18、plex a)this.setReal(this.getReal() * a.getReal() - this.getVir() * a.getVir();this.setVir( this.getReal() * a.getVir() + this.getVir() * a.getReal(); public void Division(Complex a)secondComplex tmp = new secondComplex(a.getReal(), a.getVir();/Complex b = Multiplication(this, secondComplex.Reciproca
19、l(tmp);secondComplex b = secondComplex.Reciprocal(tmp);if(b = null)return;Complex c = new Complex(Complex.returnMo(b.getReal(), b.getVir(),Complex.returnJiao(b.getReal(), b.getVir();Complex d = Multiplication(this, c);this.setReal(d.getReal();this.setVir(d.getVir();/* * c = this + a * return */publi
20、c Complex Add(Complex a, int type) return Add(this, a);public Complex Sub(Complex c, int type)secondComplex a = new secondComplex(c.getReal(),c.getVir();a = a.oppositeComplex(a);Complex d = new Complex(Complex.returnMo(a.getReal(), a.getVir(),Complex.returnJiao(a.getReal(), a.getVir();return Add(thi
21、s, d);public Complex Multiplication(Complex a, int type)return Multiplication(this, a);public Complex Division(Complex a,int type)return Division(this,a);/* * c = a + b * return */public static Complex Add(Complex a, Complex b)secondComplex c = new secondComplex(a.getReal() + b.getReal(), a.getVir()
22、 + b.getVir();Complex d = new Complex(Complex.returnMo(c.getReal(), c.getVir(),Complex.returnJiao(c.getReal(), c.getVir();return d;public Complex Sub(Complex a, Complex d)secondComplex b = new secondComplex(d.getReal(),d.getVir();b = b.oppositeComplex(b);Complex c = new Complex(Complex.returnMo(b.ge
23、tReal(), b.getVir(),Complex.returnJiao(b.getReal(), b.getVir();return Add(a, c);public static Complex Multiplication(Complex a, Complex b)if(b = null)return null;secondComplex bb = new secondComplex(a.getReal() * b.getReal() - a.getVir() * b.getVir(), a.getReal() * b.getVir() + a.getVir() * b.getRea
24、l();Complex c = new Complex(Complex.returnMo(bb.getReal(), bb.getVir(),Complex.returnJiao(bb.getReal(), bb.getVir();return c;public Complex Division(Complex a, Complex c)secondComplex b = new secondComplex(c.getReal(), c.getVir();secondComplex f = secondComplex.Reciprocal(b);if(f = null)return null;
25、Complex d = new Complex(Complex.returnMo(f.getReal(), f.getVir(),Complex.returnJiao(f.getReal(), f.getVir();return Multiplication(a, d);demoSecondComplex.javapackage secondComplex;public class demoSecondComplex public static void main(String args) System.out.println(-mo jiao-);Complex a = new Comple
26、x(1.0, 0.5*Math.PI);Complex b = new Complex(2.0, 0.5*Math.PI);a.Add(b);System.out.println(a);a = b.Add(a, 0);System.out.println(a);Complex d = a.Add(b, a);System.out.println(d);a.Sub(b);System.out.println(a);a = a.Sub(b, 0);System.out.println(a);a = a.Sub(a, b);System.out.println(a);a.Multiplication
27、(b);System.out.println(a);a = a.Multiplication(b, 0);System.out.println(a);a = a.Multiplication(a, b);System.out.println(a);trya.Division(b);System.out.println(a);a = a.Division(b, 0);System.out.println(a);a = a.Division(a, b);System.out.println(a);catch(Exception e)System.out.println(除0错);System.out.println(-real vir-);secondComplex a1 = new secondComplex(1.0, 1);secondComplex b1 = new secondComplex(2.0, 5);a1.Add(b1);System.out.println(a1);a1 = b1.Add(a1, 0);System.out.println(a1);secondComplex d1 = a1.Add(b1, a1);System
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 印染洗涤工操作管理强化考核试卷含答案
- 环境地质调查员安全强化模拟考核试卷含答案
- 家用电子产品维修工安全知识强化考核试卷含答案
- 输蔗破碎工岗位合规化技术规程
- 2025-2026学年冀教版(新教材)二年级上册数学第六单元达标试卷(附参考答案)
- 2025年述职报告范例
- 公差累积效应及应对策略探讨
- 解析数学思维
- 节气新闻的创新报道
- 硕士研究全解析
- 高一历史上学期期末冲刺模拟卷02-统编版高一《历史》上学期期末考点大串讲
- 2025年信用报告征信报告详版个人版模板样板(可编辑)
- 物业法律法规培训
- 2025年化危为安考试题库及答案
- 矿山施工安全风险分级管理方案
- 2025年贵州省基层法律服务工作者执业核准考试卷附答案
- GB/T 31439.1-2025波形梁钢护栏第1部分:两波形梁钢护栏
- 雅马哈电子琴KB-200说明书
- 2026届新高考语文背诵篇目60篇(注音版)
- 企业政府补贴申请书
- 2025年领导干部任前廉政知识测试题库(附答案)
评论
0/150
提交评论