a+bi
的数,
其中
a,
b
i^2
=
-1.
实数可以用一条直线(数轴)上的点表示,
类似地,
复数可以用一个平面(称为复平面)上的点表示.
在复平面上,a+bi
用点Z(a,b)
表示。Z与原点的距离r称为Z的模|Z|=√(a^2+b^2)
复数a+bi,b=0为实数,b不等于0为虚数,
a=0且b不等于0时为纯虚数。
复数的三角形式是
Z=r(cosx+isinx)
中x,r是实数,rcosx称为实部,rsinx称为虚部,i是虚数单位。Z与原点的距离r称为Z的模,x称为辐角。
package tablepublic class Complex
{
double real
double imaginary
public static final Complex ZERO = new Complex (0, 0)
public static final Complex ONE = new Complex (1, 0)
public static final Complex I = new Complex (0, 1)
public Complex ( double real, double imaginary )
{
this.real = real
this.imaginary = imaginary
}
public double magnitude ()
{
return Math.sqrt (this.real * this.real + this.imaginary * this.imaginary)
}
public Complex negative ()
{
return new Complex (-real, -imaginary)
}
public double valueOf ()
{
return this.real
}
public Complex add ( Complex a, Complex b )
{
return new Complex (a.real + b.real, a.imaginary + b.imaginary)
}
public Complex subtract ( Complex a, Complex b )
{
return new Complex (a.real - b.real, a.imaginary - b.imaginary)
}
public Complex multiply ( Complex a, Complex b )
{
return new Complex (a.real * b.real - a.imaginary * b.imaginary, a.real * b.imaginary + a.imaginary * b.real)
}
@Override
public String toString ()
{
StringBuilder builder = new StringBuilder ()
builder.append ("Complex [real=").append (real).append (", imaginary=").append (imaginary).append ("]")
return builder.toString ()
}
}
1、首先Java中的数都是有符号的2、所以,负数的话只需直接在数字前面加个负号(-)即可,如-5。
3、要开平方的话,请直接调用Math.sqrt(数值)方法即可。
4、当然,由于要开平方的数都必须是正数,所以,你可以直接调用Math.abs(d)方法求绝对值最为正确与简便,而不用写成-(-5),代码里也不提倡此写法。
有问题请继续提问,欢迎采纳,谢谢!