Java 格点与复数
我对复数代码的乘法方法很难理解。这句话似乎给我带来了最大的麻烦:Java 格点与复数,java,Java,我对复数代码的乘法方法很难理解。这句话似乎给我带来了最大的麻烦: public IntegerComplex multiply(IntegerComplex a){ return new IntegerComplex((this.c*a.c - this.d*a.d)+(this.c*a.c + this.d*a.d)); } 我一辈子也弄不明白;现在,我以前从未为复数编码过 public class LatticePoint { private int x;
public IntegerComplex multiply(IntegerComplex a){
return new IntegerComplex((this.c*a.c - this.d*a.d)+(this.c*a.c + this.d*a.d));
}
我一辈子也弄不明白;现在,我以前从未为复数编码过
public class LatticePoint {
private int x;
private int y;
protected double distance;
public LatticePoint()
{
x = 0;
y = 0;
}
public LatticePoint(int x, int y){
setX(x);
setY(y);
}
public void setX(int x){
this.x = x;
}
public int getX()
{
return this.x;
}
public void setY(int y){
this.y = y;
}
public int getY()
{
return this.y;
}
public double distance(LatticePoint p){
LatticePoint q = new LatticePoint(p.x - this.y, p.y - this.x);
return q.distance();
}
public double distance()
{
return Math.sqrt((x*x)+(y*y));
}
public LatticePoint add(LatticePoint p){
return new LatticePoint(this.x + p.x, this.y + p.y);
}
//returns this - p
public LatticePoint sub(LatticePoint p){
return new LatticePoint(this.x - p.x, this.y - p.y);
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
public class IntegerComplex extends LatticePoint {
private int c;
private int d;
public IntegerComplex()
{
super();
}
public IntegerComplex(int c, int d)
{
super.setX(c);
super.setY(d);
}
public int getC(){
return this.c;
}
public int getD(){
return this.d;
}
public IntegerComplex add(IntegerComplex a){
super.add(a);
return a;
}
public double distance(IntegerComplex a){
super.distance(a);
return a.distance();
}
public IntegerComplex multiply(IntegerComplex a){
return new IntegerComplex((this.c*a.c - this.d*a.d)+(this.c*a.c +this.d*a.d));
}
public static void main(String[] args) {
// TODO Auto-generated method stub
}
}
没有IntegerComplex构造函数将单个int作为参数,因此无法编译
编辑:
如果您想要实现公式ac-bd+bc+ad*i,那么该方法应该这样编写:
public IntegerComplex multiply(IntegerComplex a){
return new IntegerComplex(this.c*a.c - this.d*a.d, this.d*a.c + this.c*a.d);
}
但要注意,你的数学似乎是假的,而且一道题有太多的东西需要修正。请看一看关于复杂数学或数学的基础课程。你的问题到底是什么?你有错误吗?我能做些什么来修正它呢?要回答这个问题,你需要告诉我们你想要这个方法做什么,因为现在它没有意义。试图找到两个晶格点之间的距离,这是我试图用来解ac-bd+bc+adi的方法,我代表-1的sqrt,这个虚数看起来你对数学很困惑。不管怎样,如果你的公式是ac-bd+bc+ad,那么我现在修改我的答案,考虑到这一点,但我必须告诉你,这个公式也没有任何意义,这不是计算2D点之间距离的方法,或者你使用的是我不知道的距离定义。我需要计算两个点之间距离的数学公式,比如x-yi和x+yi。我的书给我的公式毫无意义。这本书本身很旧
public IntegerComplex multiply(IntegerComplex a){
return new IntegerComplex(this.c*a.c - this.d*a.d, this.d*a.c + this.c*a.d);
}