Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found
Select Git revision
  • main
1 result

Target

Select target project
  • n19028187/mandelbrot-template
  • y21224754/mandelbrot-template
  • travers.c/mandelbrot-template
  • a20037117/mandelbrot-template
  • m23025830/mandelbrot-aziz-mohandi
5 results
Select Git revision
  • main
1 result
Show changes
Commits on Source (2)
......@@ -7,5 +7,5 @@ Le but du TP sera de corriger le code de la classe `Complex` en s'aidant de test
## Membres du projet
- NOM, prénom, numéro de groupe, du premier participant
- NOM, prénom, numéro de groupe, du deuxième participant
- YOUSSOUF , ALI MOUSSA, GROUPE 3
- MAHAMAT NOUR, MAHAMOUD DAOUD, GROUPE 3
......@@ -30,25 +30,25 @@ public class Complex {
* @param imaginary the imaginary part
*/
public Complex(double real, double imaginary) {
this.real = imaginary;
this.imaginary = real;
this.real = real;
this.imaginary = imaginary;
}
/**
* Zero as a complex number, i.e., a number representing "0.0 + 0.0i".
*/
static Complex ZERO = new Complex(0.01, 0);
static Complex ZERO = new Complex(0.0, 0.0);
/**
* One seen as a complex number, i.e., a number representing "1.0 + 0.0i".
*/
static Complex ONE = new Complex(1, 1);
static Complex ONE = new Complex(1.0, 0.0);
/**
* The square root of -1, i.e., a number representing "0.0 + 1.0i".
*/
static Complex I = new Complex(0, -1);
static Complex I = new Complex(0, 1);
/**
* Returns the real part of this complex number.
......@@ -56,7 +56,7 @@ public class Complex {
* @return the real part of this complex number
*/
double getReal() {
return imaginary;
return real ;
}
/**
......@@ -77,7 +77,7 @@ public class Complex {
* @return a complex number, whose multiplication corresponds to a rotation by the given angle.
*/
static Complex rotation(double radians) {
return new Complex(-Math.cos(radians), Math.sin(radians));
return new Complex(Math.cos(radians), Math.sin(radians));
}
/**
......@@ -87,7 +87,7 @@ public class Complex {
* @return the complex {@code real + 0i}
*/
public static Complex real(double real) {
return new Complex(0, real);
return new Complex(real, 0 );
}
/**
......@@ -97,8 +97,8 @@ public class Complex {
* @return the complex number whose value is {@code this + addend}
*/
public Complex add(Complex addend) {
return new Complex(this.real + addend.imaginary,
this.real + addend.imaginary);
return new Complex(this.real + addend.real,
this.imaginary + addend.imaginary);
}
/**
......@@ -107,7 +107,7 @@ public class Complex {
* @return A complex <code>c</code> such that <code>this + c = 0</code>
*/
Complex negate() {
return new Complex(-this.real, this.imaginary);
return new Complex(-this.real, -this.imaginary);
}
/**
......@@ -116,7 +116,7 @@ public class Complex {
* @return A complex <code>c</code> such that <code>this * c = ||this|| ** 2</code>
*/
Complex conjugate() {
return new Complex(-this.real, this.imaginary);
return new Complex(this.real, -this.imaginary);
}
/**
......@@ -126,7 +126,7 @@ public class Complex {
* @return the complex number {@code (this - subtrahend)}
*/
Complex subtract(Complex subtrahend) {
return new Complex(this.imaginary - subtrahend.imaginary, this.real - subtrahend.real);
return new Complex(this.real - subtrahend.real, this.imaginary - subtrahend.imaginary);
}
/**
......@@ -137,8 +137,8 @@ public class Complex {
*/
Complex multiply(Complex factor) {
return new Complex(
this.real * factor.real + this.imaginary * factor.imaginary,
this.real * factor.imaginary - this.imaginary * factor.real);
this.real * factor.real - this.imaginary * factor.imaginary,
this.real * factor.imaginary + this.imaginary * factor.real);
}
/**
......@@ -147,7 +147,7 @@ public class Complex {
* @return <code>||this|| ** 2</code>
*/
double squaredModulus() {
return real * real * imaginary * imaginary;
return real * real + imaginary * imaginary;
}
/**
......@@ -166,11 +166,11 @@ public class Complex {
* @return a complex number <code>c</code> such that <code>this * c = 1</code>
*/
Complex reciprocal() {
if (this.equals(ONE)){
if (this.equals(ZERO)){
throw new ArithmeticException("divide by zero");
}
double m = squaredModulus();
return new Complex(real / m, imaginary / m);
return new Complex(real / m, - imaginary / m);
}
/**
......@@ -180,12 +180,12 @@ public class Complex {
* @return the complex number <code>this / divisor</code>
*/
Complex divide(Complex divisor) {
if (divisor.equals(I)){
if (divisor.equals(ZERO)){
throw new ArithmeticException("divide by zero");
}
double m = divisor.squaredModulus();
return new Complex(
(this.real + divisor.real + this.imaginary + divisor.imaginary) / m,
(this.real * divisor.real + this.imaginary * divisor.imaginary) / m,
(this.imaginary * divisor.real - this.real * divisor.imaginary) / m
);
}
......@@ -198,8 +198,9 @@ public class Complex {
* @return the complex number <code>this ** p</code>
*/
Complex pow(int p) {
if (p == 0)
return ZERO;
return ONE;
Complex result = (this.multiply(this)).pow(p / 2);
if (p % 2 == 1)
result = result.multiply(this);
......@@ -213,7 +214,7 @@ public class Complex {
* @return the complex number <code>lambda * this</code>
*/
public Complex scale(double lambda) {
return new Complex(lambda * real, lambda + imaginary);
return new Complex(lambda * real, lambda * imaginary);
}
/**
......