1.1 1. Complex Arithmetic in Python
1.1 1. Complex Arithmetic in Python
January 8, 2021
1 Complex Arithmetic
1.1 1. Complex Arithmetic in python
1.1.1 1.1 Defining of Complex number
EXAMPLE 1:
[2]: u=3j+5
[3]: u
[3]: (5+3j)
EXAMPLE 2:
[4]: v=2+3j
[5]: v
[5]: (2+3j)
EXAMPLE 3:
[6]: p=3
q=5
r=p+1j*q
[7]: r
[7]: (3+5j)
EXAMPLE 4:
[8]: s=2
t=6
z=complex(s,t)
[9]: z
[9]: (2+6j)
1
w=m+n
[11]: w
[11]: (6+8j)
EXAMPLE 2:
[12]: a=2+3j
b=5+6j
a+b
[12]: (7+9j)
EXAMPLE 3:
[13]: a-b
[13]: (-3-3j)
1.1.4 1.4 Extracting real and Imaginery part from a complex number
EXAMPLE 1:
[23]: w.real
2
[23]: 6.0
[24]: w.imag
[24]: 8.0
EXAMPLE 2:
[21]: z.real
[21]: 2.0
[25]: z.imag
[25]: 6.0
EXAMPLE 3:
[26]: r.real
[26]: 3.0
[28]: r.imag
[28]: 5.0
EXAMPLE 4:
[29]: h=9-5j
h.real
[29]: 9.0
[30]: h.imag
[30]: -5.0
3
EXAMPLE 1:
[37]: r1=sin(8j)
[38]: r1
[38]: 1490.4788257895502j
EXAMPLE 2:
[39]: r2=cos(4j)
[40]: r2
[40]: (27.308232836016487-0j)
Note: eˆ(i) = cos + i sin
EXAMPLE 1:
[41]: f1=3
exp(1j*f1)
[41]: (-0.9899924966004454+0.1411200080598672j)
[42]: cos(f1)+1j*sin(f1)
[42]: (-0.9899924966004454+0.1411200080598672j)
EXAMPLE 2:
[43]: f2=8
exp(1j*f2)
[43]: (-0.14550003380861354+0.9893582466233818j)
[44]: cos(f2)+1j*sin(f2)
[44]: (-0.14550003380861354+0.9893582466233818j)
EXAMPLE 3: Find 1
[45]: sqrt(-1)
[45]: 1j
[[1 2]
[3 4]]
EXAMPLE 2:
4
[50]: B=np.array([[12,10],[-13,-4]])
print(B)
[[ 12 10]
[-13 -4]]
[[ 13 12]
[-10 0]]
2.2.2 Subtraction of two matrices subtract() : This funtion is used to perform elementwise matrix
subtraction
EXAMPLE :
[52]: print(np.subtract(A,B))
[[-11 -8]
[ 16 8]]
2.2.3 Multiplication of two matrices multiply() : This function is used to perform elementwise
matrix multiplication.
EXAMPLE :
[53]: print(np.multiply(A,B))
[[ 12 20]
[-39 -16]]
[[-14 2]
[-16 14]]
2.2.4 Division of two matrices divide() : This command performs elementwise matrix division.
EXAMPLE :
[55]: print(np.divide(A,B))
[[ 0.08333333 0.2 ]
[-0.23076923 -1. ]]
5
[56]: print(A.transpose())
[[1 3]
[2 4]]
EXAMPLE 2:
[57]: print(B.transpose())
[[ 12 -13]
[ 10 -4]]
N[0]= 1
N[1]= 2
N[2]= 20
N[3]= 30
[ 2 10]
[ ]: