Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.lang.Math;
- class Complex{
- private double Re;
- private double Im;
- Complex(){
- this.Re=0.;
- this.Im=0.;
- }
- Complex(double Re,double Im){
- this.Re=Re;
- this.Im=Im;
- }
- Complex(Complex x){
- this.Re=x.Re;
- this.Im=x.Im;
- }
- static Complex add(Complex a,Complex b){
- return new Complex(a.Re+b.Re,a.Im+b.Im);
- }
- static Complex sub(Complex a,Complex b){
- return new Complex(a.Re-b.Re,a.Im-b.Im);
- }
- static Complex mult(Complex a,Complex b){
- return new Complex(a.Re*b.Re-a.Im*b.Im,a.Im*b.Re+a.Re*b.Im);
- }
- static Complex div(Complex a,Complex b){
- return new Complex((a.Re*b.Re+a.Im*b.Im)/(b.Re*b.Re+b.Im*b.Im),(a.Im*b.Re-a.Re*b.Im)/(b.Re*b.Re+b.Im*b.Im));
- }
- static Complex conj(Complex a){
- return new Complex(a.Re,-a.Im);
- }
- static Complex pow(Complex a,int n){
- Complex b=new Complex(a);
- for(int i=1;i<n;i++)
- b=mult(b,a);
- return b;
- }
- static double abs(Complex a){
- return Math.sqrt(a.Re*a.Re+a.Im*a.Im);
- }
- static double getRe(Complex a){
- return a.Re;
- }
- static double getIm(Complex a){
- return a.Im;
- }
- public String toString(){
- return this.Re+"+"+this.Im+"i";
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment