0% found this document useful (0 votes)
29 views3 pages

""" Created On Sun Oct 23 21:05:24 2022 @author: 92322 """: Print

The document demonstrates various operations on complex numbers in Python including: defining and printing a complex number in rectangular form, mathematical operations on complex numbers, converting between rectangular and polar forms, solving linear equations with complex coefficients, finding polynomial roots, and plotting a sine wave. Functions from libraries like NumPy, matplotlib, cmath and math are used.

Uploaded by

Rehan Naeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

""" Created On Sun Oct 23 21:05:24 2022 @author: 92322 """: Print

The document demonstrates various operations on complex numbers in Python including: defining and printing a complex number in rectangular form, mathematical operations on complex numbers, converting between rectangular and polar forms, solving linear equations with complex coefficients, finding polynomial roots, and plotting a sine wave. Functions from libraries like NumPy, matplotlib, cmath and math are used.

Uploaded by

Rehan Naeem
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

# -*- coding: utf-8 -*-

"""
Created on Sun Oct 23 21:05:24 2022

@author: 92322
"""
# Defining and printing a complex no. in rectangular form
z = 5 - 3j
print(z)
#%%

# Mathematical Operations on complex nos.


z1 = 5 - 3j
z2 = 2 + 1j
print(z1+z2)
print(z1/z2)

#%%

import math
theeta = 15 #theeta is in degrees
theeta_1 = theeta * (math.pi/180)
z = math.tan(theeta_1)
print(z)

theeta_2 = math.asin(0.707) #theeta_2 is in radians


print(theeta_2 * (180/math.pi)) #print theeta_2 in degrees

#%%

#Rectangular to polar form

import cmath
import math # To use math.pi function
z = 5 - 3j
print(cmath.polar(z)) # Both Magnitude and angle displayed
print(cmath.polar(z)[0]) # Only magnitude is displayed
print(cmath.polar(z)[1]) # Only angle is displayed in radians
print(cmath.polar(z)[1] * (180/math.pi)) # Only angle is displayed in degrees

#%%

#Polar to rectangular form and calculations in polar form

1
import cmath
import math # To use math.pi function

print(cmath.rect(5,1)) # Magnitude is 5 and angle is 1 rad


print(cmath.rect(5,1*(math.pi/180))) # Now 1 is in degrees

z1 = cmath.rect(10 , 45 * (math.pi / 180) )


z2 = cmath.rect(5 , 25 * (math.pi / 180) )
z3 = z1+z2
print(z3) # z3 is in rectangular form
print(cmath.polar(z3)) # z3 is in polar form

#%%

# Solving linear equations

import numpy as np

a = np.array( [ [600+1250j,100j] , [100j,60-150j] ] )


b = np.array( [25,0] )
x = np.linalg.solve(a, b)
print(x)

#%%

# Polynomial Coeffecients to roots


import numpy as np

a = [5, 3, 2] #A list of coefficients of the polynomial


r = np.roots(a)
print(r)

#%%

# Polynomial roots to Coeffecients

import numpy as np

coeff = np.poly( (0,-50, -250, -1000) )


print(coeff)

#%%

#Plotting a sine wave


2
import matplotlib.pyplot as plt
import numpy as np

PhaseShift = 90 * (np.pi/180)
t = np.linspace(0,1,41000)
f = 5
v1 = 5 * np.sin(2*np.pi*f*t)
v2 = 1 * np.sin( (2*np.pi*f*t) + PhaseShift)
v3 = np.exp(-10*t)
plt.figure(1)
plt.plot(t,v1,color='red')
plt.plot(t,v2,color='blue')
plt.plot(t,v3,color='orange')
plt.grid()
plt.xlabel('Time')
plt.ylabel('Voltage')

You might also like