Chapter 23: Revision of complex numbers

Example 1, page no. 418

In [1]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
Z1  =  5  -  3j;
Z2  =  4  +  7j;
Z3  =  3.9  -  6.7j;

 #calculation:
ZT  =  (Z1*Z2/(Z1  +  Z2))+  Z3
y  =  ZT.imag
x  =  ZT.real


#Results
print  "\n\n  Result  \n\n"
print  "\n  ZT  is  ",round(x,2),"  +  (",round(y,2),")i"

  Result  



  ZT  is   8.65   +  ( -6.26 )i

Example 2, page no. 418

In [2]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
Z1  =  3  +  4j;
Z2  =  2  -  5j;

#calculation:
za  =  1/Z1
zb  =  1/Z2
zc  =  za  +  zb
zd  =  1/zc
zax  =  za.real
zay  =  za.imag
zbx  =  zb.real
zby  =  zb.imag
zcx  =  zc.real
zcy  =  zc.imag
zdx  =  zd.real
zdy  =  zd.imag


#Results
print  "\n\n  Result  \n\n"
print  "\n  (a)1/Z1  is  ",round(  zax,2),"  +  (",round(zay,2),")i"
print  "\n  (b)1/Z2  is  ",round(  zbx,2),"  +  (",round(zby,2),")i"
print  "\n  (c)1/Z1  +  1/Z2  is  ",round(  zcx,2),"  +  (",round(zcy,2),")i"
print  "\n  (d)1/(1/Z1  +  1/Z2)  is  ",round(  zdx,2),"  +  (",round(zdy,2),")i"

  Result  



  (a)1/Z1  is   0.12   +  ( -0.16 )i

  (b)1/Z2  is   0.07   +  ( 0.17 )i

  (c)1/Z1  +  1/Z2  is   0.19   +  ( 0.01 )i

  (d)1/(1/Z1  +  1/Z2)  is   5.27   +  ( -0.35 )i

Example 3, page no. 419

In [4]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
Z1  =  9  -  2j;
Z2  =  2  +  1j;
Z3  =  -2  +  1j;
Z4  =  5  +  2j;

#calculation:
za  =  Z1/3
zb  =  Z2*Z3
zca  =  (2*Z4.real  +  Z4.imag)/-1
zcb  =  Z4.real  -  zca
zaa  =  za.real
zab  =  za.imag
zbx  =  zb.real
zby  =  zb.imag


#Results
print  "\n\n  Result  \n\n"
print  "\n  (a)a  and  b  are  ",  zaa,"  and  ",round(zab,2),"  resp."
print  "\n  (b)x  and  y  are  ",  zbx,"  and  ",zby,"  resp."
print  "\n  (c)a  and  b  are  ",  zca,"  and  ",zcb,"  resp."

  Result  



  (a)a  and  b  are   3.0   and   -0.67   resp.

  (b)x  and  y  are   -5.0   and   0.0   resp.

  (c)a  and  b  are   -12.0   and   17.0   resp.

Example 5, page no. 422

In [6]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
r  =  5;#  magnitude
theta  =  -132;#  in  degree

#calculation:
x  =  r*math.sin(theta*math.pi/180)
y  =  r*math.cos(theta*math.pi/180)
z  =  x + y*1j


#Results
print  "\n\n  Result  \n\n"
print  "\n  Z  is  ",round(x,2),"  +  (",round(y,2),")i"

  Result  



  Z  is   -3.72   +  ( -3.35 )i

Example 6, page no. 422

In [7]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
r1  =  4.76;#  magnitude
theta1  =  35;#  in  degree
r2  =  7.36;#  magnitude
theta2  =  -48;#  in  degree

#calculation:
x1  =  r1*cmath.cos(theta1*math.pi/180)
y1  =  r1*cmath.sin(theta1*math.pi/180)
z1  =  x1 + y1*1j
x2  =  r2*cmath.cos(theta2*math.pi/180)
y2  =  r2*cmath.sin(theta2*math.pi/180)
z2  =  x2 + y2*1j
z3  =  z1*z2/(z1  +  z2)
x3  =  z3.real
y3  =  z3.imag
r3  =  (x3**2  +  y3**2)**0.5
theta3  =  cmath.phase(complex(x3,y3))*180/math.pi


#Results
print  "\n\n  Result  \n\n"
print  "\n  ZT  is  (",round( r3,2),",round(/_",round(theta3,2),"deg)"

  Result  



  ZT  is  ( 3.79 ,round(/_ 4.25 deg)

Example 7, page no. 423

In [8]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
z  =  -2  +  3j;

#calculation:
zc  =  z**5
x  =  zc.real
y  =  zc.imag
r  =  (x**2  +  y**2)**0.5
theta  =  cmath.phase(complex(x,y))*180/math.pi

#Results
print  "\n\n  Result  \n\n"
print  "\n  Z  is  ",round(  x,2),"  +  (",round(y,2),")i"
print  "\n  ZT  is  (",round(  r,2),"round/_",round(theta,2),"deg)"

  Result  



  Z  is   -122.0   +  ( -597.0 )i

  ZT  is  ( 609.34 round/_ -101.55 deg)

Example 8, page no. 423

In [1]:
from __future__ import division
import math
import cmath
#initializing  the  variables:
z  =  12  +  5j;

#calculation:
x  =  z.real
y  =  z.imag
r  =  (x**2  +  y**2)**0.5
theta1  =  cmath.atan(y/x)*180/math.pi
'''
if  ((x<0)&(y<0))
         theta1  =  theta1  -180;
elif  ((x<0)&(y>0))
         theta1  =  theta1  +180;
'''
theta2  =  theta1  +  360
rtheta1  =  theta1/2
rtheta2  =  theta2/2
'''
if  (rtheta2  >  180)
         rtheta2  =  rtheta2  -360;
elif  ((x<0)&(y>0))
         rtheta2  =  rtheta2  +360;
'''
rr  =  r**0.5
x1  =  rr*cmath.cos(rtheta1*math.pi/180)
y1  =  rr*cmath.sin(rtheta1*math.pi/180)
z1  =  x1  +  y1*1j

x2  =  rr*cmath.cos(rtheta2*math.pi/180)
y2  =  rr*cmath.sin(rtheta2*math.pi/180)
z2  =  x2  +  y2*1j


#Results
print  "\n\n  Result  \n\n"
print  "\n  two  roots  are  (",round(z1.real,2),"  +  (",round(z1.imag,2),")i) "
print   " and  (",round(z2.real,2),"  +  (",round(z2.imag,2),")i)"
print  "\n  two  roots  are  (",round(  rr,2),"/_",round((cmath.phase(complex(z1.real,z1.imag)))*180/math.pi,2),"deg) "
print   " and  (",round(  rr,2),"/_",round((cmath.phase(complex(z2.real,z2.imag)))*180/math.pi,2),"deg)"

  Result  



  two  roots  are  ( 3.54   +  ( 0.71 )i) 
 and  ( -3.54   +  ( -0.71 )i)

  two  roots  are  ( 3.61 /_ 11.31 deg) 
 and  ( 3.61 /_ -168.69 deg)