-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathComplexarithmetic.java
53 lines (47 loc) · 1.48 KB
/
Complexarithmetic.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package assignment2cop;
/**
*
* @author kunal
*/
public class Complexarithmetic extends LinearEqusolve
{
public static double[] addcomplex(double a ,double b ,double c ,double d)
{
double[] ans = new double[2];
ans[0] = (a+c);
ans[1] = (b+d);
// a + b i + c + d i = (a+c)+(b+d)j
return ans;
}
public static double[] minuscomplex(double a ,double b ,double c ,double d)
{
double[] ans = new double[2];
ans[0] = (a-c);
ans[1] = (b-d);
// a + b i - (c + d i) = (a-c)+(b-d)j
return ans;
}
public static double[] mutliplycomplex(double a ,double b ,double c ,double d)
{
double[] ans = new double[2];
double sqrtval = Math.sqrt(c*c + d*d);
ans[0] = (a*c - b*d)/sqrtval ;
ans[1] = (b*c + a*d)/sqrtval ;
// a + b i / c + d i = (ac + bd ) + (bc - ad ) / sqrt(c*c + d*d)
return ans;
}
public static double[] dividecomplex(double a ,double b ,double c ,double d)
{
double[] ans = new double[2];
double sqrtval = Math.sqrt(c*c + d*d);
ans[0] = (a*c + b*d)/sqrtval ;
ans[1] = (b*c - a*d)/sqrtval ;
// a + b i / c + d i = (ac + bd ) + (bc - ad ) / sqrt(c*c + d*d)
return ans;
}
}