複素数コードの乗算法に苦労しています。この行が私に最も問題を引き起こしているようです:
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
}
}