2023-05-18 23:45:24 +02:00
|
|
|
package fr.alnotz;
|
|
|
|
|
|
|
|
public class Dual implements IsDual{
|
|
|
|
private double r;
|
|
|
|
private double d;
|
2023-05-19 00:57:23 +02:00
|
|
|
public Dual(){
|
|
|
|
this.r = 0;
|
|
|
|
this.d = 0;
|
|
|
|
}
|
2023-05-18 23:45:24 +02:00
|
|
|
public Dual(double r, double d){
|
|
|
|
this.r = r;
|
|
|
|
this.d = d;
|
|
|
|
}
|
|
|
|
public static Dual plus(IsDual dual0, IsDual dual1){
|
|
|
|
return new Dual(dual0.getR() + dual1.getR(), dual0.getD() + dual1.getD());
|
|
|
|
}
|
2023-05-19 00:57:23 +02:00
|
|
|
public static Dual times(IsDual dual0, IsDual dual1){
|
|
|
|
return new Dual(dual0.getR() * dual1.getR(), dual0.getR() * dual1.getD() + dual1.getR() * dual0.getD());
|
|
|
|
}
|
|
|
|
public static Dual conjugate(IsDual dual){
|
|
|
|
return new Dual(dual.getR(), -1 * dual.getD());
|
|
|
|
}
|
|
|
|
public static boolean equals(IsDual dual0, IsDual dual1){
|
|
|
|
return dual0.getR() == dual1.getR() && dual0.getD() == dual1.getD();
|
|
|
|
}
|
2023-05-18 23:45:24 +02:00
|
|
|
@Override
|
|
|
|
public double getR() {
|
|
|
|
return this.r;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public double getD() {
|
|
|
|
return this.d;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setR(double r) {
|
|
|
|
this.r = r;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void setD(double d) {
|
|
|
|
this.d = d;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2023-05-19 02:11:21 +02:00
|
|
|
public Dual plus(IsDual dual) {
|
|
|
|
return new Dual(this.r + dual.getR(),
|
|
|
|
this.d + dual.getD());
|
2023-05-18 23:45:24 +02:00
|
|
|
}
|
|
|
|
@Override
|
2023-05-19 02:11:21 +02:00
|
|
|
public Dual times(IsDual dual) {
|
|
|
|
return new Dual(this.r * dual.getR(),
|
|
|
|
this.r * dual.getD() + this.d * dual.getR());
|
2023-05-19 00:57:23 +02:00
|
|
|
}
|
|
|
|
@Override
|
2023-05-19 02:11:21 +02:00
|
|
|
public Dual conjugate(){
|
|
|
|
return new Dual(this.r, this.d * -1);
|
2023-05-18 23:45:24 +02:00
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public boolean equals(IsDual dual) {
|
2023-05-19 00:57:23 +02:00
|
|
|
return this.r == dual.getR() && this.d == dual.getD();
|
|
|
|
}
|
|
|
|
@Override
|
|
|
|
public String toString(){
|
|
|
|
return String.format("%+f %+fε\n", this.r, this.d);
|
2023-05-18 23:45:24 +02:00
|
|
|
}
|
|
|
|
}
|