ComplexAnalysis LAB 9

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 83

Complex Analysis Using Python

Name: Aayush
Class: 6CMS
Registration Number: 21215419
LAB 1 : Revision
AIM: To revise the basic concepts of Python

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2023-12-12

QUES 1: Write a program to enter two real number and convert them into complex number.
Also find the real and imaginary part of the complex number.

real_part1 = float(input("Enter the first real number: "))


imaginary_part1 = float(input("Enter the imaginary part for the first
number: "))

real_part2 = float(input("Enter the second real number: "))


imaginary_part2 = float(input("Enter the imaginary part for the second
number: "))

complex_number1 = complex(real_part1, imaginary_part1)


complex_number2 = complex(real_part2, imaginary_part2)

print("Complex Number 1:", complex_number1)


print("Real Part of Complex Number 1:", complex_number1.real)
print("Imaginary Part of Complex Number 1:", complex_number1.imag)

print("\nComplex Number 2:", complex_number2)


print("Real Part of Complex Number 2:", complex_number2.real)
print("Imaginary Part of Complex Number 2:", complex_number2.imag)

Enter the first real number: 1


Enter the imaginary part for the first number: 2
Enter the second real number: 8
Enter the imaginary part for the second number: 4
Complex Number 1: (1+2j)
Real Part of Complex Number 1: 1.0
Imaginary Part of Complex Number 1: 2.0

Complex Number 2: (8+4j)


Real Part of Complex Number 2: 8.0
Imaginary Part of Complex Number 2: 4.0

QUES 2: Display the current date.

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2023-12-12

QUES 3: Write a python program which accepts the user's first and last name and print it with a
space between them.

first_name = input("Enter your first name: ")


last_name = input("Enter your last name: ")

full_name = f"{first_name} {last_name}"


print("Full Name:", full_name)

Enter your first name: Kriti


Enter your last name: Tandon
Full Name: Kriti Tandon

QUES 4: Write a python program which accepts a number from the user and predicts whether it
is even or odd.

number = int(input("Enter a number: "))


if number % 2 == 0:
print("The number is even.")
else:
print("The number is odd.")

Enter a number: 19
The number is odd.

QUES 5: Write a python program which gives the reverse of a number given by the user and
tells whether the reverse is same as the orginal number.

number=int(input("Enter a number"))
reverse_number = int(str(number)[::-1])
if number == reverse_number:
print("The number is a palindrome.")
else:
print("The number is not a palindrome.")

Enter a number15
The number is not a palindrome.

QUES 6: Write a program to divide two no.s only if denominator is non-zero.

numerator = float(input("Enter the numerator: "))


denominator = float(input("Enter the denominator: "))

if denominator != 0:
result = numerator / denominator
print("Result of division:", result)
else:
print("Cannot divide by zero.")

Enter the numerator: 8


Enter the denominator: 5
Result of division: 1.6

QUES 7: Write a program to identify the largest of the given 3 numbers.

num1 = float(input("Enter the first number: "))


num2 = float(input("Enter the second number: "))
num3 = float(input("Enter the third number: "))

largest_number = max(num1, num2, num3)


print("The largest number is:", largest_number)

Enter the first number: 18


Enter the second number: 2
Enter the third number: 4
The largest number is: 18.0

QUES 8: Plot a scatter plot, 2D, 3D, and subplot with four 2D plots.

import matplotlib.pyplot as plt


x = [1, 2, 3, 4, 5]
y = [2, 3, 5, 7, 11]
plt.scatter(x, y)
plt.title("2D Scatter Plot")
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.show()
ax=axes(projection='3d')
x=linspace(0,15,1000) #axis on which it is formed
z=sin(x)
y=cos(x)
ax.plot3D(x,y,z)
show()
from matplotlib.pylab import *
figure(figsize=(10,8))
suptitle('SUBPLOTS OF VARIOUS FUNCTIONS')

subplot(221) #2 tall, 2 wide, plot number 1


x=linspace(-20,20,100)
plot(x,exp(x),color='Orange')
xlabel('x')
ylabel('exp(X)')

subplot(222) #2 tall, 2 wide, plot number 2


x=linspace(-20,20,100)
plot(x,x**2,color='Green')
xlabel('x')
ylabel('x^2')

subplot(223) #2 tall, 2 wide, plot number 3


x=linspace(-20,20,100)
plot(x,cos(x),color='Brown')
xlabel('x')
ylabel('cos(x)')

subplot(224) #2 tall, 2 wide, plot number 4


x=linspace(-20,20,100)
plot(x,tan(x),color='Red')
xlabel('x')
ylabel('tan(x)')
None

CONCLUSION: Basic concepts of python are revised

LAB 2: Complex Numbers


AIM: To perform the concepts of Complex Numbers in Python

'cmath' module:
The 'cmath' module defines functions that take a complex number as argument and return a
complex number as a result.
from cmath import *
from math import *

Absolute value of a complex number


The modulus (absolute value) of a complex number x can be computed using the built-in abs()
function.

a= 4+7j
abs(a)

8.06225774829855

import math
abs_a= sqrt(a.real**2+a.imag**2)
abs_a

8.06225774829855

Calculate phase of a complex number


The phase of a complex number is defined as the angle between the real axis and the vector
representing the complex number. Using cmath module, we can find the phase of a complex
number using the phase() method. The phase method takes a complex number as input and
returns a floating point number representing the phase of the complex number as follows.

phase(a)

1.0516502125483738

import math
phase_a= atan(a.imag/a.real)
phase_a

1.0516502125483738

Polar coordinates of a complex number


In polar coordinates, a complex number is defined as a tuple consisting of the modulus of the
complex number as the first element and phaseof the complex number as the second element.
We can find the polar coordinates of a complex number using polar() method in python. Polar
coordinates of Z= ( r , θ ) . The polar() method takes a complex number as input and returns a tuple
representing the polar coordinates as follows.

polar(a)

(8.06225774829855, 1.0516502125483738)
polar_a=(abs(a),phase(a))
polar_a

(8.06225774829855, 1.0516502125483738)

Rectangular Form of a complex number


If we know the modulus and phase of a complex number i.e. if we know the polar coordinates of
a complex number, we can obtain the complex number using the rect() method.

The form z=a+b i or z=( r c o s θ , r s i nθ ) is called the rectangular coordinate form of a complex
number.

The rect() method takes the modulus as the first argument and phase of the complex number as
the second argument and returns the corresponding complex number as follows.

rect(polar_a[0],polar_a[1])

(3.999999999999999+7j)

rect_a= (polar_a[0]*cos(polar_a[1]),polar_a[0]*sin(polar_a[1]))
rect_a

(3.999999999999999, 7.0)

Constants in cmath module


The cmath module also provides certain mathematical constants like infinity,NaN and pi which
are useful in mathematical calculations. Some of the constants are given below.

print("Given below are some of the constants defined in cmath


module.")
print("e:",e)
print("Infinity (real axis):",inf)
print("Infinity (Imaginary axis):",infj)
print("NaN (real):",nan)
print("NaN (imaginary):",nanj)
print("Pi:",pi)
print("Tau:",tau)

Given below are some of the constants defined in cmath module.


e: 2.718281828459045
Infinity (real axis): inf
Infinity (Imaginary axis): infj
NaN (real): nan
NaN (imaginary): nanj
Pi: 3.141592653589793
Tau: 6.283185307179586
Trigonometric functions in cmath module
For mathematical calculations on complex numbers, the cmath module provides a set of
trigonometric functions.

All of the trigonometric functions take the complex number as input and also return a complex
number which represents the corresponding output for the trigonometric functions.

Examples are discussed below.

import cmath as cm
a= 4+7j
print("Complex number is:",a)
print("Sine of the complex number is:",cm.sin(a))
print("Cosine of the complex number is:",cm.cos(a))
print("Tangent of the complex number is:",cm.tan(a))
print("Inverse Sine of the complex number is:",cm.asin(a))
print("Inverse Cosine of the complex number is:",cm.acos(a))
print("Inverse Tangent of the complex number is:",cm.atan(a))

Complex number is: (4+7j)


Sine of the complex number is: (-414.96770042530954-
358.4033361942234j)
Cosine of the complex number is: (-
358.4039322400533+414.96701031076253j)
Tangent of the complex number is: (1.645359989233288e-
06+1.0000002419735892j)
Inverse Sine of the complex number is:
(0.5158519091936864+2.782304040344133j)
Inverse Cosine of the complex number is: (1.0549444176012102-
2.782304040344133j)
Inverse Tangent of the complex number is:
(1.508618829521516+0.10769572902311356j)

CONCLUSION: We have successfully performed the concepts of Complex Numbers in Python.

Lab2- Assignment
Q1. Write a Python program that accepts three complex numbers from the user and verifies the
following property. " Any three set complex numbers 𝑧 1 , 𝑧 2 , a n d 𝑧 3 satisfies the commutative,
associative and distributive laws. "

Solution: Prove the following

(i) 𝑧1+𝑧2=𝑧2+𝑧1 (Commutative law for addition).

(ii) 𝑧1∙𝑧2=𝑧2∙𝑧1 (Commutative law for multiplication).

(iii) (𝑧1+𝑧2)+𝑧3=𝑧1+(𝑧2+𝑧3) (Associative law for addition)

(iv) (𝑧1𝑧2)𝑧3=𝑧1(𝑧2𝑧3) (Associative law for multiplication)


(v) 𝑧1(𝑧1+𝑧3)=𝑧1𝑧2+𝑧1𝑧3 (Distributive law).

def verify_properties(z1, z2, z3):


# Commutative law for addition
commutative_addition = (z1 + z2) == (z2 + z1)

# Commutative law for multiplication


commutative_multiplication = (z1 * z2) == (z2 * z1)

# Associative law for addition


assoc_addition = (z1 + z2) + z3 == z1 + (z2 + z3)

# Associative law for multiplication


assoc_multiplication = (z1 * z2) * z3 == z1 * (z2 * z3)

# Distributive law
distributive_law = z1 * (z2 + z3) == (z1 * z2) + (z1 * z3)

return commutative_addition, commutative_multiplication,


assoc_addition, assoc_multiplication, distributive_law

def main():
# Accept three complex numbers from the user
z1 = complex(input("Enter the first complex number (in the form
a+bj): "))
z2 = complex(input("Enter the second complex number (in the form
a+bj): "))
z3 = complex(input("Enter the third complex number (in the form
a+bj): "))

# Verify properties
results = verify_properties(z1, z2, z3)

# Display results
print("\nResults:")
print(f"(i) Commutative law for addition: {results[0]}")
print(f"(ii) Commutative law for multiplication: {results[1]}")
print(f"(iii) Associative law for addition: {results[2]}")
print(f"(iv) Associative law for multiplication: {results[3]}")
print(f"(v) Distributive law: {results[4]}")

if __name__ == "__main__":
main()

Enter the first complex number (in the form a+bj): 7+8j
Enter the second complex number (in the form a+bj): 8+9j
Enter the third complex number (in the form a+bj): 9+2j

Results:
(i) Commutative law for addition: True
(ii) Commutative law for multiplication: True
(iii) Associative law for addition: True
(iv) Associative law for multiplication: True
(v) Distributive law: True

Q2. Write a Python program to input a complex number from the user and prove the following. "
The sum of two conjugate complex numbers is real. "

def complex_number():
real = float(input("Enter the real part: "))
imag = float(input("Enter the imaginary part: "))
return complex(real, imag)
# Get three complex numbers
z1 = complex_number()
z2 = complex_number()
# Display the entered complex numbers
print("\nYou entered the following complex numbers:")
print("z1:", z1)
print("z2:", z2)
conjugate_z1 = z1.conjugate()
print("conj_z1:",conjugate_z1)
print()
conjugate_z2 = z2.conjugate()
print("conj_z2:",conjugate_z2)
print()
# The sum of two conjugate complex numbers is real.
Sum = conjugate_z1 + conjugate_z2
if Sum.imag == 0:
print("The sum is a real number.")
else:
print("The sum is not a real number.")

Enter the real part: 3


Enter the imaginary part: 6
Enter the real part: 3
Enter the imaginary part: -6

You entered the following complex numbers:


z1: (3+6j)
z2: (3-6j)
conj_z1: (3-6j)

conj_z2: (3+6j)

The sum is a real number.

Q3. Write a Python program to input a complex number from the user and prove the following. "
The product of two conjugate complex numbers is real. "
def is_product_of_conjugates_real(z):
# Conjugate of complex number
conjugate_z = z.conjugate()

# Product of conjugates
product_of_conjugates = z * conjugate_z

# Check if the product is real


is_real = product_of_conjugates.imag == 0

return product_of_conjugates, is_real

def main():
# Accept a complex number from the user
z = complex(input("Enter a complex number (in the form a+bj): "))

# Verify the statement


result, is_real = is_product_of_conjugates_real(z)

# Display results
print("\nResults:")
print(f"The conjugate of {z} is {z.conjugate()}")
print(f"The product of conjugates is: {result}")
print(f"The product of conjugates is real: {is_real}")

if __name__ == "__main__":
main()

Enter a complex number (in the form a+bj): 2+4j

Results:
The conjugate of (2+4j) is (2-4j)
The product of conjugates is: (20+0j)
The product of conjugates is real: True

Q4. Prove that for any two complex numbers |𝑧1+𝑧2|≤|𝑧1|+|𝑧2|, for two complex numbers 𝑧1
and 𝑧2.

def triangle_inequality(z1, z2):


# Calculate the left-hand side of the inequality: |z1 + z2|
lhs = abs(z1 + z2)

# Calculate the right-hand side of the inequality: |z1| + |z2|


rhs = abs(z1) + abs(z2)

# Check if the inequality holds


is_triangle_inequality_satisfied = lhs <= rhs

return lhs, rhs, is_triangle_inequality_satisfied


def main():
# Accept two complex numbers from the user
z1 = complex(input("Enter the first complex number (in the form
a+bj): "))
z2 = complex(input("Enter the second complex number (in the form
a+bj): "))

# Verify the triangle inequality


result_lhs, result_rhs, is_satisfied = triangle_inequality(z1, z2)

# Display results
print("\nResults:")
print(f"|z1 + z2| = {result_lhs}")
print(f"|z1| + |z2| = {result_rhs}")
print(f"The triangle inequality is satisfied: {is_satisfied}")

if __name__ == "__main__":
main()

Enter the first complex number (in the form a+bj): 6+7j
Enter the second complex number (in the form a+bj): 5+9j

Results:
|z1 + z2| = 19.4164878389476
|z1| + |z2| = 19.515174598279888
The triangle inequality is satisfied: True

Q5. Write a Python program that shows that the following statement is true. " When the sum of
two complex numbers is real and the product of two complex numbers is also real then the
complex numbers are conjugate. "

def are_complex_numbers_conjugate(z1, z2):


# Check if the sum of two complex numbers is real
is_sum_real = (z1 + z2).imag == 0

# Check if the product of two complex numbers is real


is_product_real = (z1 * z2).imag == 0

# If both conditions are met, check if the complex numbers are


conjugate
if is_sum_real and is_product_real:
are_conjugate = z1.conjugate() == z2 and z2.conjugate() == z1
else:
are_conjugate = False

return are_conjugate

def main():
# Accept two complex numbers from the user
z1 = complex(input("Enter the first complex number (in the form
a+bj): "))
z2 = complex(input("Enter the second complex number (in the form
a+bj): "))

# Verify the statement


are_conjugate = are_complex_numbers_conjugate(z1, z2)

# Display results
print("\nResults:")
print(f"The sum of the complex numbers is real: {(z1 + z2).imag ==
0}")
print(f"The product of the complex numbers is real: {(z1 *
z2).imag == 0}")
print(f"The complex numbers are conjugate: {are_conjugate}")

if __name__ == "__main__":
main()

Enter the first complex number (in the form a+bj): 8+7j
Enter the second complex number (in the form a+bj): 8-7j

Results:
The sum of the complex numbers is real: True
The product of the complex numbers is real: True
The complex numbers are conjugate: True

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2023-12-28

import cmath as cmath


from math import *
import numpy as np
import matplotlib.pyplot as plt
from sympy import *

Verification of Euler's Formula


Euler's formula named after Leonhard Euler, is a mathematical formula in complex analysis that
establishes the fundamental relationship between the trigonometric functions and the complex
exponential function. Euler's formula states that for any real number x: $ e^{ix}= cosx+ isinx$
where e is the base of natural logarithm, i is the imaginary unit and cos and sin are the
trigonometric functions.

import cmath
z=complex(90,4)
print("The complex number is",z)
s=cmath.exp(z)
print("LHS= e^z=",s)
d=(cmath.exp(z.real))*(cmath.cos(z.imag)+1j*cmath.sin(z.imag))
print("RHS= ",d)
if(d==s):
print("Eulers law verified")
else:
print("Eulers law not verified")

The complex number is (90+4j)


LHS= e^z= (-7.977088282117938e+38-9.236042584217578e+38j)
RHS= (-7.977088282117938e+38-9.236042584217578e+38j)
Eulers law verified

Plotting a given set of complex numbers


n=int(input("Enter the number of points to be plotted: "))
x=[]
y=[]
for i in range (0,n):
re= float(input("Enter the real part: "))
ig=float(input("Enter the imaginary part: "))
x.append(re)
y.append(ig)
plt.scatter(x,y,marker='*',color='green')
for j in range (len(x)):
plt.text(x[j],y[j],x[j]+j*y[j]) #try giving j instead of 1j and
tell the diff
plt.xlabel("Real Axis -->")
plt.ylabel("Imaginary Axis -->")
plt.suptitle("Plotting the given numbers of complex numbers")
plt.show()

Enter the number of points to be plotted: 2


Enter the real part: 6
Enter the imaginary part: 3
Enter the real part: 2.5
Enter the imaginary part: 8.6
Ques: Out of the three points, z 1=2.5+1.9 j , z 2=1.5− 2.9 j and z 3=− 2+ 2.2 j find the point
which is farthest away from the origin.

z1= complex(2.5,1.9)
z2= complex(1.5,2.9)
z3= complex(-2,2.2)
w1= abs(z1)
w2= abs(z2)
w3=abs(z3)
c=max(w1,w2,w3)
if c==w1:
print("z1=",z1,"is the farthest from the origion")
elif c ==w2:
print("z2=",z2,"is the farthest from the origin")
elif c== w3:
print("z3=",z3,"is the farthest from the origion")
print("The distance from the origin is: ",c)

z2= (1.5+2.9j) is the farthest from the origin


The distance from the origin is: 3.2649655434629015
Plotting complex numbers on a polar plane
from matplotlib.pylab import *
figure(figsize=(6,5))
b=complex(4,3)
polar(angle(b),abs(b),marker= '*')
show()

Plotting the Cube roots of Unity


import numpy as np
import matplotlib.pyplot as plt
from sympy import *
x= Symbol('x')
s= x**3-1
t=solve(s)
print(t)
for i in range(len(t)):
z=complex(t[i])
plt.scatter(z.real,z.imag)
plt.text(z.real,z.imag,z)
[1, -1/2 - sqrt(3)*I/2, -1/2 + sqrt(3)*I/2]

Practice Questions
Ques 1: Write a python program to plot the fourth roots of unity

import numpy as np
import matplotlib.pyplot as plt
from sympy import *
x= Symbol('x')
s= x**4-1
t=solve(s)
print(t)
for i in range(len(t)):
z=complex(t[i])
plt.scatter(z.real,z.imag)
plt.text(z.real,z.imag,z)

[-1, 1, -I, I]
Ques 2: Write a python program to plot the nth roots of unity

import numpy as np
import matplotlib.pyplot as plt
from sympy import *
n=int(input("Enter the value of n:"))
x= Symbol('x')
s= x**n-1
t=solve(s)
print(t)
for i in range(len(t)):
z=complex(t[i])
plt.scatter(z.real,z.imag)
plt.text(z.real,z.imag,z)

Enter the value of n:5


[1, -1/4 + sqrt(5)/4 - I*sqrt(sqrt(5)/8 + 5/8), -1/4 + sqrt(5)/4 +
I*sqrt(sqrt(5)/8 + 5/8), -sqrt(5)/4 - 1/4 - I*sqrt(5/8 - sqrt(5)/8), -
sqrt(5)/4 - 1/4 + I*sqrt(5/8 - sqrt(5)/8)]
Form a complex number calculator containing : 1.Addition 2.Subtraction 3.Multiplication
4.Division 5.Argument of number 6.Absolute value of the number 7.Conversion to polar form
8.Conversion to rectangular form 9.Plot c1 and c2 in polar plane

import cmath
#Addition
def add(num1,num2):
return num1 +num2

#subtraction
def subtract(num1,num2):
return num1-num2

#multiplication
def multiply(num1,num2):
return num1*num2

#function to divide to numbers


def divide(num1,num2):
return num1/num2

print("Please select the operation -\n" \


"1.Add\n" \
"2.Subtract\n"\
"3.Multiply\n" \
"4.Divide\n" \
"5.Argument\n" \
"6.Absolute values\n" \
"7.Polar conversion\n" \
"8.Rectangular conversion\n" \
"9.Plotting\n")

#user input
select = int(input("Select operations from 1,2,3,4,5,6,7,8,9:"))
c1= complex(input("Enter first complex number (a+jb): "))
c2= complex(input("Enter second complex number (c+jd):"))

if select == 1:
print(c1, "+",c2,"=", add(c1,c2))

elif select == 2:
print(c1, "-",c2,"=",subtract(c1,c2))

elif select == 3:
print(c1, "*",c2,"=",multiply(c1,c2))

elif select == 4:
print(c1, "/",c2,"=",divide(c1,c2))

elif select == 5:
print('Argument of c1 is', cmath.phase(c1))
print('Argument of c2 is', cmath.phase(c2))

elif select ==6:


print('Absolute value of c1 is', abs(c1))
print('Absolute value of c2 is', abs(c2))

elif select ==7:


print('Polar form of c1 is', cmath.polar(c1))
print('Polar form of c2 is', cmath.polar(c2))

elif select ==8:


print('Rectangular form of c1 is',cmath.rect(cmath.polar(c1)
[0],cmath.polar(c1)[1]) )
print('Rectangular form of c2 is',cmath.rect(cmath.polar(c2)
[0],cmath.polar(c2)[1]))

elif select ==9:


from matplotlib.pylab import *
figure(figsize=(6,5))
polar(angle(c1),abs(c1),marker='*')
polar(angle(c2),abs(c2),marker='o')
show()

else:
print("Invalid input")
Please select the operation -
1.Add
2.Subtract
3.Multiply
4.Divide
5.Argument
6.Absolute values
7.Polar conversion
8.Rectangular conversion
9.Plotting

Select operations from 1,2,3,4,5,6,7,8,9:1


Enter first complex number (a+jb): 5+6j
Enter second complex number (c+jd):8+9j
(5+6j) + (8+9j) = (13+15j)

CONCLUSION: Concepts of complex numbers are implemented successfully using Python


Language.

Lab 3
AIM: To find the limit of the given complex sequence in Python.

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2024-01-09

Finding the limit of a given complex sequence


A sequence in C is a function f : N → C . We let z n :=f ( n ) and call it the $n-th $ term of the
sequence. As is the practice, we shall use z n to denote the sequence f . We say a sequence ( z n )
converges to z ∈ C if given $ \epsilon >0$ there exists N ′ ∈ N such that for all n ≥ N ′ , we have $
|z_n -z| < \epsilon $ for all but finitely mant n . If a sequence converges, then we say it is
converegent.

Find the limit of the complex sequence $ z_n = 1/n + i((n-1)/n)$


import matplotlib.pyplot as plt
from cmath import *
from math import *
from sympy import *
Finding the limit of a complex sequence
z= Symbol('z')
real_z=eval(input('Enter real part of function in terms of z='))
#eval=evaluating the string
img_z=eval(input('Enter imaginary part of the function in terms of
z='))

limit_real_z=limit(real_z,z, inf)
limit_img_z=limit(img_z,z,inf)

limit_z=complex(limit_real_z, limit_img_z) #evaluating the limit of


the sequence
print('Limit of', real_z + 1j*img_z, 'is', limit_z)

Enter real part of function in terms of z=1/z


Enter imaginary part of the function in terms of z=(z-1)/z
Limit of 1.0*I*(z - 1)/z + 1/z is 1j

Plotting limit of a sequence in Cartesian Plane


from matplotlib.pylab import *
z= Symbol('z')
a= complex(limit((1)/z,z,inf), limit((z-1)/z,z,inf))
print(a)

x= []
y= []
l= int(input("Enter the lower limit of the range:"))
u= int(input("Enter the upper limit of the range:"))

b=1
figure(figsize=(6,5))
for i in range(0,u-1):
re= 1/b
im= (b-1)/b

x.append(re)
y.append(im)
b+=1

plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g')

show()

1j
Enter the lower limit of the range:50
Enter the upper limit of the range:100
Find the limit of the following complex sequences:
2
n
1) i (
n +1 )
2

import matplotlib.pyplot as plt

from cmath import*


from math import *
from sympy import *

z=Symbol('z')
a= complex(limit(0,z,inf),limit((z**2)/(z**2+1),z,inf)) #evaluating
the limit of the sequence
print(a)

x=[]
y=[]

l=int(input("Enter the lower limit of the range:"))


u=int(input("Enter the upper limit of the range:"))
b=l

for i in range (0, u-1):


re=0
im=(b**2)/(b**2 +1)

x.append(re)
y.append(im)
b=b+1

plt.figure(figsize=(8,8))
plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g')

plt.show()

1j
Enter the lower limit of the range:50
Enter the upper limit of the range:100
n 7n
2) ( 1+4 n ) +i ( n+ 4 )
import matplotlib.pyplot as plt

from cmath import*


from math import *
from sympy import *

z=Symbol('z')
a=complex(limit(((1+4/z)**z),z,np.inf),
limit((7*z/(z+4)),z,np.inf))#evaluating the limit of the sequence
print(a)

x=[]
y=[]

l=int(input("Enter the lower limit of the range:"))


u=int(input("Enter the upper limit of the range:"))
b=l

for i in range (0, u-1):


re=(1+4/b)**b
im=(7*b/(b+4))

x.append(re)
y.append(im)
b=b+1

plt.figure(figsize=(8,8))
plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g') #plotting the limit of the
sequence

plt.show()

(54.598150033144236+7j)
Enter the lower limit of the range:150
Enter the upper limit of the range:350
3) √(¿ n+ 1)−i ¿ ¿
import matplotlib.pyplot as plt

from cmath import*


from math import *
from sympy import *

z=Symbol('z')
a=complex(limit((sqrt(z+1)),z,np.inf),limit(sqrt(z)
+3,z,np.inf))#evaluating the limit of the sequence
print(a)

x=[]
y=[]

l=int(input("Enter the lower limit of the range:"))


u=int(input("Enter the upper limit of the range:"))
b=l

for i in range (0, u-1):


re=(sqrt(b+1))
im=sqrt(b)+3
x.append(re)
y.append(im)
b=b+1

plt.figure(figsize=(8,8))
plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g') #plotting the limit of the
sequence

plt.show()

(inf+infj)
Enter the lower limit of the range:75
Enter the upper limit of the range:300
4) () ( )
1 n
2
+n
1 −i
2
import matplotlib.pyplot as plt

from cmath import*


from math import *
from sympy import *

z=Symbol('z')
a=complex(limit((1/2)**z+z/2,z,inf),limit((-z/2),z,inf))#evaluating
the limit of the sequence
print(a)
x=[]
y=[]

l=int(input("Enter the lower limit of the range:"))


u=int(input("Enter the upper limit of the range:"))
b=l

for i in range (0, u-1):


re=(1/2)**b+b/2
im=(b/2)
x.append(re)
y.append(im)
b=b+1

plt.figure(figsize=(8,8))
plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g') #plotting the limit of the
sequence

plt.show()

(inf-infj)
Enter the lower limit of the range:100
Enter the upper limit of the range:150
(
( 3+ 4 i )2
5) n 5 )
import matplotlib.pyplot as plt

from cmath import*


from math import *
from sympy import *
no= (3+4*1j)**2/5
real_part=no.real
imag_part=no.imag

z=Symbol('z')
a=complex(limit(z*real_part,z,inf),limit(z*imag_part,z,inf))#evaluatin
g the limit of the sequence
print(a)

x=[]
y=[]

l=int(input("Enter the lower limit of the range:"))


u=int(input("Enter the upper limit of the range:"))
b=l

for i in range (0, u-1):


re=b*real_part
im=b*imag_part
x.append(re)
y.append(im)
b=b+1

plt.figure(figsize=(8,8))
plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g') #plotting the limit of the
sequence

plt.show()

(-inf+infj)
Enter the lower limit of the range:50
Enter the upper limit of the range:100
( ) ( )
n
5 5+ n
6) 3+
n
+i
n
import matplotlib.pyplot as plt

from cmath import*


from math import *
from sympy import *

z=Symbol('z')
a=complex(limit((3+ 5/z)**z,z,inf),limit(((5+z)/z),z,inf))#evaluating
the limit of the sequence
print(a)
x=[]
y=[]

l=int(input("Enter the lower limit of the range:"))


u=int(input("Enter the upper limit of the range:"))
b=l

for i in range (0, u-1):


re=(3+5/b)**b
im=(5+b)/b
x.append(re)
y.append(im)
b=b+1

plt.figure(figsize=(8,8))
plt.scatter(x,y,color='r')
plt.scatter(a.real,a.imag,color='g') #plotting the limit of the
sequence

plt.show()

(inf+1j)
Enter the lower limit of the range:50
Enter the upper limit of the range:100
from datetime import date
today= date.today()
print("Today's date:", today)

Today's date: 2024-01-16

Lab 4: Analytic Function


Aim: To check the necessary and sufficient conditions for analyticity of complex functions . A
function f ( z ) is said to be analytical at a point a ∈ C if it differentiable at every point of some
neighborhood of a
Cauchy-Riemann Equations
If f ( z )=u ( x , y )+ i v ( x , y ) , then the CR equations are given by : $ 1. \dfrac{\partial u}{\partial x} = \
dfrac{\partial v}{\partial y} \

1. \dfrac{\partial u}{\partial y}= - \dfrac{\partial v}{\partial x} $

Necessary and Sufficient conditions for analyticity of


complex functions.
Necessary Condition for analyticity:
If a function f , is said to be analytic at a point z 0, if it satisfy the Cauchy Riemann
Equations.

Sufficiency Condition for analyticity:


For a function f ,if the Cauchy Riemann Equations are satisfied and the first order
partial derivatives are continous, then the function is analytic.

Question : Write a python program to check whether f ( z )=x 2 − y 2 +2 x y i satisfies the CR


equations

from sympy import *


x,y,i= symbols("x,y,i")

u=x**2-y**2
v=2*x*y
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Given expression f(z): x**2 - y**2 +i 2*x*y

Derivative of u wrt x: 2*x

Derivative of u wrt y: -2*y

Derivative of v wrt x: 2*y


Derivative of v wrt y: 2*x

f(z) satisfies CR equations.

Question : Write a python program to check whether f ( z )=2 x y+ 2 x i satisfies the CR equations

from math import *


x,y,i=symbols("x,y,i")
u=2*x*y
v=2*x
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Given expression f(z): 2*x*y +i 2*x

Derivative of u wrt x: 2*y

Derivative of u wrt y: 2*x

Derivative of v wrt x: 2

Derivative of v wrt y: 0

f(z) does not satisfy CR equations.

( x −i y )
Question : Write a python program to check whether f ( z )= satisfies the CR equations
( x2+ y2)

from math import *


x,y,i=symbols("x,y,i")
u=(x)/(x**2+y**2)
v=(-y)/(x**2+y**2)
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Given expression f(z): x/(x**2 + y**2) +i -y/(x**2 + y**2)

Derivative of u wrt x: -2*x**2/(x**2 + y**2)**2 + 1/(x**2 + y**2)

Derivative of u wrt y: -2*x*y/(x**2 + y**2)**2

Derivative of v wrt x: 2*x*y/(x**2 + y**2)**2

Derivative of v wrt y: 2*y**2/(x**2 + y**2)**2 - 1/(x**2 + y**2)

f(z) does not satisfy CR equations.

Question : Write a python program to check whether f ( z )=2 x +i x y 2 satisfies the CR equations

from math import *


x,y,i=symbols("x,y,i")
u=2*x
v=x*y**2
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Given expression f(z): 2*x +i x*y**2

Derivative of u wrt x: 2

Derivative of u wrt y: 0

Derivative of v wrt x: y**2

Derivative of v wrt y: 2*x*y


f(z) does not satisfy CR equations.

Question : Write a python program to check whether f ( z )=x y +i y satisfies the CR equations

from math import *


x,y,i=symbols("x,y,i")
u=x*y
v=y
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Given expression f(z): x*y +i y

Derivative of u wrt x: y

Derivative of u wrt y: x

Derivative of v wrt x: 0

Derivative of v wrt y: 1

f(z) does not satisfy CR equations.

Question : Write a python program to check whether $f(z)=x^3 -3ix^2y-3xy^2 +iy^3 $ satisfies
the CR equations

from math import *


x,y,i=symbols("x,y,i")
u=x**3-3*x*y**2
v=-3*x**2*y+y**3
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Given expression f(z): x**3 - 3*x*y**2 +i -3*x**2*y + y**3

Derivative of u wrt x: 3*x**2 - 3*y**2

Derivative of u wrt y: -6*x*y

Derivative of v wrt x: -6*x*y

Derivative of v wrt y: -3*x**2 + 3*y**2

f(z) does not satisfy CR equations.

Question : Write a python program to accept any complex function from the user and check
whether it satisfies the CR equations.

from sympy import *


x,y,i=symbols("x,y,i")
u=input("Enter u :")
v=input("Enter v:")
print("Given expression f(z):",u,"+i",v)
diff_ux=diff(u,x,1)
print("\n Derivative of u wrt x:",diff_ux)
diff_uy=diff(u,y,1)
print("\n Derivative of u wrt y:",diff_uy)
diff_vx=diff(v,x,1)
print("\n Derivative of v wrt x:",diff_vx)
diff_vy=diff(v,y,1)
print("\n Derivative of v wrt y:",diff_vy)
if (diff_ux==diff_vy and diff_uy==-diff_vx):
print("\n f(z) satisfies CR equations.")
else:
print("\n f(z) does not satisfy CR equations.")

Enter u :x**y+2*x*y
Enter v:x*y
Given expression f(z): x**y+2*x*y +i x*y

Derivative of u wrt x: 2*y + x**y*y/x

Derivative of u wrt y: 2*x + x**y*log(x)

Derivative of v wrt x: y
Derivative of v wrt y: x

f(z) does not satisfy CR equations.

Question : Write a python program to check whether $f(z)=(x+iy)^3 $ satisfies the CR equations

from sympy import *

x,y,i = symbols("x y i")

f=(x+i*y)**3

u= re(f)
v= im(f)

diff_ux = diff(u, x, 1)
diff_uy = diff(u, y, 1)
diff_vx = diff(v, x, 1)
diff_vy = diff(v, y, 1)

if(diff_ux==diff_vy and diff_uy == -diff_vx):


print("\n f(z) is anlalytic.")
else:
print("f(z) is not analytic ")

f(z) is not analytic

Conclusion: The necessary and sufficient conditions are verified

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2024-01-23

Lab 5: Harmonic Functions


Aim: To understand the basics of Harmonic Functions and execute codes related to it in Python
A function u ( x , y ) is called harmonic, if it is twice continously differentiable and satisfies the
following partial equation u x x + u y y =0

Write a general program to check whether a given function is


harmonic.
from sympy import *
init_printing(use_latex=True)
x,y=symbols('x,y')
def harmonic (q):
print("The function is :",q)
dqdx=diff(q,x,2)
dqdy=diff(q,y,2)
if dqdx+dqdy ==0:
print("This is a harmonic function")
else:
print("This is not a harmonic function")

Example: Check whether x 3 − 3 x y 2 is Harmonic


harmonic (x**3-3*x*y**2)

The function is : x**3 - 3*x*y**2


This is a harmonic function

Ques 1: Check whether x 2 − y 2+ x +1 is Harmonic


harmonic(x**2-y**2+x+1)

The function is : x**2 + x - y**2 + 1


This is a harmonic function

Ques2: Check whether x 2 y − y 2 x is Harmonic


harmonic(x**2*y-y**2*x)

The function is : x**2*y - x*y**2


This is not a harmonic function

Ques 3:Check whether real and imaginary parts of


x − y + x+1+i ( x −3 x y + 2 x ) is harmonic
3 3 3 2

harmonic(x**3-y**3+x+1)
harmonic(x**3-3*x*y**2+2*x)

The function is : x**3 + x - y**3 + 1


This is not a harmonic function
The function is : x**3 - 3*x*y**2 + 2*x
This is a harmonic function

Harmonic Conjugates
Let u ( x , y ) be a harmonic function, then a function v ( x , y ) is said to be harmonic conjugate of
u ( x , y ) if 1. v ( x , y ) is harmonic 2.u and v satisfies CR Equations
Write a general program to check whether v is harmonic conjugate of u
from sympy import *
x,y=symbols('x,y')
def verify(u,v):
dv_dx2=diff(v,x,2)
dv_dy2=diff(v,y,2)
du_dx=diff(u,x)
du_dy=diff(u,y)
dv_dx=diff(v,x)
dv_dy=diff(v,y)
if dv_dx2 +dv_dy2==0:
if du_dx==dv_dy and du_dy==-dv_dx:
print("v is a harmonic conjugate of u ")
else:
print("CR Equations are not satisfied")
else:
print("v itself is not a harmonic function")

Example: Check whether c o s ( x ) s in h ( y ) is the harmonic conjugate of


s in ( x ) c o s h ( y )
verify(sin(x)*cosh(y),cos(x)*sinh(y))

v is a harmonic conjugate of u

2 2
−x y
Ques 1: Check if 2
+
2
is the harmonic conjugate of x 2 − y 2+ x +1
verify(x**2-y**2+x+1,-x**2/2 + y**2/2)

CR Equations are not satisfied

2 2
−x y
Ques 2: Check if 2
+
2
is the harmonic conjugate of x y
verify(x*y,-x**2/2+y**2/2)

v is a harmonic conjugate of u

Ques 3: Check if x 2 − y 2 is the harmonic conjugate of ( 2 x y +3 )


verify(2*x*y+3,x**2-y**2)

CR Equations are not satisfied


Note : If v is the harmonic conjugate of u, it is not necessary that v is the
harmonic conjugate of u
Ques: Check whether x 2 − y 2and 2 x y are harmonic conjugate to each
other
verify(2*x*y,x**2-y**2)

CR Equations are not satisfied

verify(x**2-y**2,2*x*y)

v is a harmonic conjugate of u

Finding the Harmonic Conjugate v of a


Harmonic Function u
The harmonic conjugate to a given harmonic function u ( x , y ) is a harmonic function v ( x , y ) such
that : f ( x , y )=u ( x , y ) +i v ( x , y ) is complex differentiable (ie. satisfies the Cauchy-Reimann
equation.)

Write a general program to find the harmonic conjugate v of a


harmonic function u
from sympy import *
import math

def conjugate():
init_printing(use_latex=True)
x,y,c=symbols("x,y,c")
u=input("Enter the function u:")
print("")
dx2=diff(u,x,2)
dy2=diff(u,y,2)
if dx2+dy2==0:
print("The function",u,"is harmonic.")
dux=diff(u,x)
duy=diff(u,y)
iv=integrate(-duy,x)
vy=diff(iv,y)
gy= dux-vy
ig=integrate(gy,y)
v=iv+ig
print("The harmonic conjugate of u is:")
display(v)
else:
print("The function",u,"is not harmonic.")

Conclusion: The concept Harmonic Functions in Complex analysis in Python is implemented


successfully.

Lab 6

Orthogonal Family of Curves


AIM: To plot the curves of Orthogonal Family using python

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2024-01-30

ORTHOGONAL FAMILIES OF CURVE


Suppose the function f ( z )=u ( x , y )+ i v ( x , y ) is analytical in some domain D . Then the real and
imaginary parts of f can be used to define two families of curves in D . The equations u ( x , y )=c 1
and v ( x , y ) =c 2 where c 1 a n d c2 are arbitrary real constants, are called level curves of u and v ,
respectively. The level curves (2) are orthogonal families.

Ques 1: Suppose the function f ( z )=e x c o s y +i e y c o s x is analytic in some


domain D . Write a python program to find the orthogonal family of
curves corresponding to real and imaginary parts of the function. Also
plot the curves.
import numpy as np
def ortho_family(x,y):
u=np.exp(x)*np.cos(y)
v=np.exp(y)*np.cos(x)
return u,v

ortho_family(2,4)

(-4.829809383269385, -22.720847417619233)

#Plotting implicit functions u and v

#Plotting u
from numpy import *
from sympy import *
x,y=symbols('x y')
p1=plot_implicit(Eq(exp(x)*cos(y),5),line_color='blue',line_width=2)
None

#Plotting v
from numpy import *
from sympy import *
x,y=symbols('x y')
p2=plot_implicit(Eq(exp(y)*sin(x),10))
None
#Plotting u and v together
from numpy import *
from sympy import *
import matplotlib.pyplot as plt
x,y=symbols('x y')
p1=plot_implicit(Eq(exp(x)*cos(y),10))
p2=plot_implicit(Eq(exp(y)*sin(x),10))
None
p1.extend(p2)
p1
p1.show()
Ques 2: x 3 y −i x y 3=C
import numpy as np
def ortho_family(x,y):
u=x**3*y
v=x*y**3
return u,v

ortho_family(2,4)

(32, 128)

from numpy import *


from sympy import *
import matplotlib.pyplot as plt
x,y=symbols('x y')
p1=plot_implicit(Eq(y*x**3,5),(x,-10,10),(y,-10,10),line_color='red')
p2=plot_implicit(Eq(x*y**3,5),(x,-10,10),(y,-10,10),line_color='blue')
None
p1.extend(p2)
p1
p1.show()
## Practice Questions ### For the following problems find the corresponding conjugate and
plot the orthogonal families ### Ques 3: e x s i n ( y )=C ### Ques 4: e (− x ) c o s ( y )+ x y=C ###
Ques 5: s in ( x ) c o s h ( y )=C ### Ques 6: 2 x y=C

from numpy import *


from sympy import *
import math

def conjugate ():


init_printing(use_latex=True)
x,y,c=symbols("x,y,c")
u=input("Enter the function u:")
print("")
dx2=diff(u,x,2)
dy2=diff(u,y,2)
if dx2+dy2==0:
print("The function",u,"is harmonic.")
dux=diff(u,x)
duy=diff(u,y)
iv=integrate(-duy,x)
vy=diff(iv,y)
gy= dux-vy
ig=integrate(gy,y)
v=iv+ig
print("The harmonic conjugate of u is:")
display(v)
else:
print("The function",u,"is not harmonic.")

#Question 3
conjugate()

Enter the function u:exp(x)*sin(y)

The function exp(x)*sin(y) is harmonic.


The harmonic conjugate of u is:

from numpy import *


from sympy import *
import matplotlib.pyplot as plt
x,y=symbols('x y')
p1=plot_implicit(Eq(exp(x)*sin(y),5),(x,-10,10),(y,-
10,10),line_color='red')
p2=plot_implicit(Eq(-exp(x)*cos(y),5),(x,-10,10),(y,-
10,10),line_color='blue')
None
p1.extend(p2)
p1
p1.show()
#QUESTION 4
conjugate()

Enter the function u:exp(-x)*cos(y)+x*y

The function exp(-x)*cos(y)+x*y is harmonic.


The harmonic conjugate of u is:

from numpy import *


from sympy import *
import matplotlib.pyplot as plt
x,y=symbols('x y')
p1=plot_implicit(Eq(exp(-x)*cos(y)+x*y,5),(x,-10,10),(y,-
10,10),line_color='red')
p2=plot_implicit(Eq(-(x**2/2)+(y**2/2)-exp(-x)*sin(y),5),(x,-10,10),
(y,-10,10),line_color='blue')
None
p1.extend(p2)
p1
p1.show()
#QUESTION 5
conjugate()

Enter the function u:sin(x)*cosh(y)

The function sin(x)*cosh(y) is harmonic.


The harmonic conjugate of u is:

from numpy import *


from sympy import *
import matplotlib.pyplot as plt
x,y=symbols('x y')
p1=plot_implicit(Eq(sin(x)*cosh(y),5),(x,-10,10),(y,-
10,10),line_color='red')
p2=plot_implicit(Eq(cos(x)*sinh(y),5),(x,-10,10),(y,-
10,10),line_color='blue')
None
p1.extend(p2)
p1
p1.show()
#Question6
conjugate()

Enter the function u:2*x*y

The function 2*x*y is harmonic.


The harmonic conjugate of u is:

from numpy import *


from sympy import *
import matplotlib.pyplot as plt
x,y=symbols('x y')
p1=plot_implicit(Eq(2*x*y,5),(x,-10,10),(y,-10,10),line_color='red')
p2=plot_implicit(Eq(-x**2+y**2,5),(x,-10,10),(y,-
10,10),line_color='blue')
None
p1.extend(p2)
p1
p1.show()
Conclusion: Curves for the Orthogonal Family are executed successfully using Python

from datetime import date


today= date.today()
print("Today's date:", today)

Today's date: 2024-03-12

LAB 7

Milne Thomson's Method


Aim: To find analytic functions using Milne Thomson's Method in python
It is a method of finding a holomorphuc function whose real and imaginary part is given Let f be
a complex variable function given by f ( z )=u ( x , y )+ i v ( x , y ) , where z=x +i y then f ( z ) can be
constructed if either u o r v is given
∂u ∂u
$\textbf{Case I: When u is given}$ Step 1: Find and equate it to u x. Step 2: Find and
∂x ∂y
equate it to u y . Step 3: Find f ′ ( x , y ) by the formula f ′ ( x , y )=u x − iu y Step 4: Replace $ x$ by z
and y by 0 in f ′ ( x , y ) to get f ′ ( z , 0 ) . Step 5: Find f ( z ) by the formula f ( z )= ∫ f ′ ( z , 0 ) d z +c

∂v ∂v
$\textbf{Case II: When v is given}$ Step 1: Find and equate it to u x. Step 2: Find and
∂x ∂y
equate it to u y . Step 3: Find f ′ ( x , y ) by the formula f ′ ( x , y )=v y + i v x Step 4: Replace $ x$ by z
and y by 0 in f ′ ( x , y ) to get f ′ ( z , 0 ) . Step 5: Find f ( z ) by the formula f ( z )= ∫ f ′ ( z , 0 ) d z +c

Example: Considering e x ( x c o s ( y ) + y s i n ( y ) ) as (i)the real part (ii)the imaginary part of the


corresponding function , find the analytic functions for the same.

import pprint
import sympy as sp
x,y,z=sp.symbols("x,y,z")
def u_giv(u):
ux=sp.diff(u,x)
print("ux=",ux)
uy=sp.diff(u,y)
print("uy=",uy)
fp=sp.simplify(ux-1j*uy)
print("f'(x,y)=",str(fp))
g=fp.subs({x:z,y:0})
print("f'(z,0)=",g)
f=sp.integrate(g,z)
return ("f="+str(f))
def v_giv(v):
vx=sp.diff(v,x)
print("vx=",vx)
vy=sp.diff(v,y)
print("vy=",vy)
fp=sp.simplify(vy+1j*vx)
print("f'(x,y)=",str(fp))
g=fp.subs({x:z,y:0})
print("f'(z,0)=",g)
f=sp.integrate(g,z)
return ("f="+str(f))
sp.pprint(u_giv(sp.exp(x)*(x*sp.cos(y)-y*sp.sin(y))))
print()
sp.pprint(v_giv(1j*sp.exp(x)*(x*sp.cos(y)-y*sp.sin(y))))

ux= (x*cos(y) - y*sin(y))*exp(x) + exp(x)*cos(y)


uy= (-x*sin(y) - y*cos(y) - sin(y))*exp(x)
f'(x,y)= (x*cos(y) - y*sin(y) + 1.0*I*(x*sin(y) + y*cos(y) + sin(y)) +
cos(y))*exp(x)
f'(z,0)= (z + 1)*exp(z)
f=z*exp(z)

vx= 1.0*I*(x*cos(y) - y*sin(y))*exp(x) + 1.0*I*exp(x)*cos(y)


vy= 1.0*I*(-x*sin(y) - y*cos(y) - sin(y))*exp(x)
f'(x,y)= 1.0*(-x*cos(y) + y*sin(y) - I*(x*sin(y) + y*cos(y) + sin(y))
- cos(y))*exp(x)
f'(z,0)= 1.0*(-z - 1)*exp(z)
f=-1.0*z*exp(z)

Problem 1: If u=x2 − y 2, find the corresponding analytic function

import sympy as sp
x,y,z=sp.symbols("x,y,z")
def u_giv(u):
ux=sp.diff(u,x)
print("ux=",ux)
uy=sp.diff(u,y)
print("uy=",uy)
fp=sp.simplify(ux-1j*uy)
print("f'(x,y)=",str(fp))
g=fp.subs({x:z,y:0})
print("f'(z,0)=",g)
f=sp.integrate(g,z)
return ("f="+str(f))
F=u_giv(x**2-y**2)
sp.pprint(F)

ux= 2*x
uy= -2*y
f'(x,y)= 2.0*x + 2.0*I*y
f'(z,0)= 2.0*z
f=1.0*z**2

Problem 2: Construct analytic function f ( z ) of which the imaginary part is


v=( x , y )=−2 s i n x ( e x −e − y )

import sympy as sp
x,y,z=sp.symbols("x,y,z")
def v_giv(v):
vx=sp.diff(v,x)
print("vx=",vx)
vy=sp.diff(v,y)
print("vy=",vy)
fp=sp.simplify(vy+1j*vx)
print("f'(x,y)=",str(fp))
g=fp.subs({x:z,y:0})
print("f'(z,0)=",g)
f=sp.integrate(g,z)
return ("f="+str(f))
F=v_giv(-2*sp.sin(x)*(e**x-e**-y))

vx= -2.0*2.71828182845905**x*sin(x) + (-2*2.71828182845905**x +


2/2.71828182845905**y)*cos(x)
vy= -2.0*sin(x)/2.71828182845905**y
f'(x,y)= 2.0*0.367879441171442**y*(I*(-2.71828182845905**(x +
y)*sin(x) + (1 - 2.71828182845905**(x + y))*cos(x)) - sin(x))
f'(z,0)= 2.0*I*(-2.71828182845905**z*sin(z) + (1 -
2.71828182845905**z)*cos(z)) - 2.0*sin(z)

Problem 3: Find the analytic function f ( z )=u+i v such that u+ v=e x ( c o s y + s i n y )

from math import *


import sympy as sp
x,y,z=sp.symbols("x,y,z")
f=sp.exp(x)*(sp.cos(y)+sp.sin(y))
U= sp.diff(f,x)
V=sp.diff(f,y)
dudx=(U+V)/2
dvdx=(U-V)/2
Z= dudx-1j*dvdx
Z1= Z.subs({x:z,y:0})
F=sp.integrate(Z1,z)
sp.pprint(F)

z

Problem 4: Find the analytic function f ( z )=u+i v such that u+ v=e y ( c o s x +s in x )

from math import *


import sympy as sp
x,y,z=sp.symbols("x,y,z")
f=sp.exp(y)*(sp.cos(x)+sp.sin(x))
U= sp.diff(f,x)
V=sp.diff(f,y)
dudx=(U+V)/2
dvdx=(U-V)/2
Z= dudx-1j*dvdx
Z1= Z.subs({x:z,y:0})
F=sp.integrate(Z1,z)
sp.pprint(F)

ⅈ⋅z
-1.0⋅ⅈ⋅ℯ

Problem 5: Find the analytic function f ( z )=u+i v such that u+ v=x 3 +3 x 2 y − 3 x y 2 − y 2+ 4 x +5


from math import *
import sympy as sp
x,y,z=sp.symbols("x,y,z")
f= x**3+3*x**2*y-3*x*y**2-y**2+4*x+5
U= sp.diff(f,x)
V=sp.diff(f,y)
dudx=(U+V)/2
dvdx=(U-V)/2
Z= dudx-1j*dvdx
Z1= Z.subs({x:z,y:0})
F=sp.integrate(Z1,z)
sp.pprint(F)

3
1.0⋅z + z⋅(2.0 - 2.0⋅ⅈ)

Problem 6: Find the analytic function f ( z )=u+i v such that u+ v=e y ( c o s y − s in y )

from math import *


import sympy as sp
x,y,z=sp.symbols("x,y,z")
f=sp.exp(y)*(sp.cos(y)-sp.sin(y))
U= sp.diff(f,x)
V=sp.diff(f,y)
dudx=(U+V)/2
dvdx=(U-V)/2
Z= dudx-1j*dvdx
Z1= Z.subs({x:z,y:0})
F=sp.integrate(Z1,z)
sp.pprint(F)

Problem 7: Find the analytic function f ( z )=u+i v such that u+ v=e y ( c o s x − s in x )

from math import *


import sympy as sp
x,y,z=sp.symbols("x,y,z")
f=sp.exp(y)*(sp.cos(x)-sp.sin(x))
U= sp.diff(f,x)
V=sp.diff(f,y)
dudx=(U+V)/2
dvdx=(U-V)/2
Z= dudx-1j*dvdx
Z1= Z.subs({x:z,y:0})
F=sp.integrate(Z1,z)
sp.pprint(F)
ⅈ⋅z

$\textbf{Conclusion:} $Analytics functions are found out easily in python using the Milne
Thomson Method

TOPIC: Conformal Transformations


from datetime import date
today= date.today()
print("Today's date:", today)

Today's date: 2024-03-19

A transformation is conformal when T ( z ) is analytic and T ′ ( z ) is not equal to 0 Algorithm Step


1: Define x,y and x as symbols Step 2:Define function in terms of z and real and imaginary part
sepeartely Step 3: Check whether the given function satisfies Cr equation or not, if yes set a=1.
Step 4: Check whether the given function have any critical points or not, if no set b=1. Step 5: If
a=1 and b=1, the function is conformal.

import math
import cmath
import sympy as sp

Question: Check if the following are conformal.


z x
1. e =e ( c o s y +i s i n y )

x,y,z=sp.symbols('x,y,z')
f=sp.exp(z)
r=sp.exp(x)*sp.cos(y)
i=sp.exp(x)*sp.sin(y)
du_dx=sp.diff(r,x)
dv_dy=sp.diff(i,y)
du_dy=sp.diff(r,y)
dv_dx=sp.diff(i,x)
if du_dx==sp.simplify(dv_dy) and du_dy==sp.simplify(-dv_dx):
a=1
else:
a=0
print('a=',a)

d=sp.diff(f)
print('derivative=',d)
s=sp.solve(d,z)
print('critical points=',s)
if len(s)==0:
b=1
else:
b=0
print('b=',b)
if a==1 and b==1:
print("This is a conformal transformation")
else:
print("This is not a conformal transformation")

a= 1
derivative= exp(z)
critical points= []
b= 1
This is a conformal transformation

2 2 2
2. z =x +2 x y i− y

x,y,z=sp.symbols('x,y,z')
f=z**2
r=x**2-y**2
i=2*x*y
du_dx=sp.diff(r,x)
dv_dy=sp.diff(i,y)
du_dy=sp.diff(r,y)
dv_dx=sp.diff(i,x)
if du_dx==sp.simplify(dv_dy) and du_dy==sp.simplify(-dv_dx):
a=1
else:
a=0
print('a=',a)

d=sp.diff(f)
print('derivative=',d)
s=sp.solve(d,z)
print('critical points=',s)
if len(s)==0:
b=1
else:
b=0
print('b=',b)
if a==1 and b==1:
print("This is a conformal transformation")
else:
print("This is not a conformal transformation")

a= 1
derivative= 2*z
critical points= [0]
b= 0
This is not a conformal transformation

3. s i n ( z )=c o s h (− y ) c o s ( x ) +i s i nh ( − y ) s i n ( x )

x,y,z=sp.symbols('x,y,z')
f=sp.sin(z)
r=sp.cosh(-y)*sp.cos(x)
i=sp.sinh(-y)*sp.sin(x)
du_dx=sp.diff(r,x)
dv_dy=sp.diff(i,y)
du_dy=sp.diff(r,y)
dv_dx=sp.diff(i,x)
if du_dx==sp.simplify(dv_dy) and du_dy==sp.simplify(-dv_dx):
a=1
else:
a=0
print('a=',a)

d=sp.diff(f)
print('derivative=',d)
s=sp.solve(d,z)
print('critical points=',s)
if len(s)==0:
b=1
else:
b=0
print('b=',b)
if a==1 and b==1:
print("This is a conformal transformation")
else:
print("This is not a conformal transformation")

a= 1
derivative= cos(z)
critical points= [pi/2, 3*pi/2]
b= 0
This is not a conformal transformation

Lab 8: Linear and Bilinear Transformations


from datetime import date
today= date.today()
print("Today's date:", today)

Today's date: 2024-04-02


The basic elementary transformations of complex numbers are reflection, translation, rotation
and dilation. Reflection: Reflection of a point (5,6) with respect to the x axis and the reflection
of point with respect to y axis is (-5,6)

import matplotlib.pyplot as plt


x=int(input("Enter the value of x coordinate:"))
y=int(input("Enter the value of y coordinate:"))
axis=input("Reflection with respect to which axis:")

if axis=="y":
xref=-x
yref=y
elif axis=="x":
xref=x
yref=-y

x=[x,xref]
y=[y,yref]

plt.scatter(x,y,color=["red","black"])
plt.axhline(0,color="black")
plt.axvline(0,color='blue')

Enter the value of x coordinate:5


Enter the value of y coordinate:6
Reflection with respect to which axis:x

<matplotlib.lines.Line2D at 0x24ef8d1eca0>
Question:Plot the reflection of the points (3,2) and (5,1) with respect to both the x-axis and y-axis
in the same place.

import matplotlib.pyplot as plt


import cmath
print("The reflection of the points (3,2) and (5,1)")
A=[-3,3,3]
B=[2,2,-2]
plt.plot(A,B,marker='o')
C=[-5,5,5]
D=[1,1,-1]
plt.axhline(0,linewidth=1,color='black')
plt.axvline(0,linewidth=1,color="black")
plt.plot(C,D,marker='o')

The reflection of the points (3,2) and (5,1)

[<matplotlib.lines.Line2D at 0x24ef94226d0>]
The reflection of a complex number z about the real is its conjugate ź and the
reflection about the imaginary axis is − ź
Question: Plot the reflection of the points -2+j,1+4j,3+2j,-2+1j with respect to imaginary axis in
plane.

from pylab import *


z=[-2+1j,1+4j,3+2j,-2+1j]
w=[-conjugate(x) for x in z]
print(w)
X1=[x.real for x in z]
Y1=[x.imag for x in z]
X2=[x.real for x in w]
Y2=[x.imag for x in w]
plt.axhline(0,linewidth=1,color="black")
plt.axvline(0,linewidth=1,color="black")
plot(X1,Y1,color="red",label="Original ponts",marker='*')
plot(X2,Y2,color='blue',label="Reflections")
xlabel("Real axis")
ylabel("Imaginary axis")
title("Plotting reflection against y-axis")
legend();

[(2+1j), (-1+4j), (-3+2j), (2+1j)]


Translation: A complex translation is a map of the form z → z +a, where a is a fixed complex
number, which corresponds to translation (shifting) of points the complex plane by complex
number a

import matplotlib.pyplot as plt


import numpy as np
def translation(x,y,p,q):
u=complex(x,y)
v=complex(p,q)
w=u+v
print(w)

plt.polar([np.angle(v),np.angle(w)],
[np.abs(v),np.abs(w)],marker='o',label="Translation Point")

translation (3,2,2,3)

(5+5j)
Rotation: w=z∗ei θ is the rotation of the complex number z about an angle θ to obtain a
complex number w of the same magnitude.

import math
import cmath
from matplotlib.pylab import *
from numpy import *
a=complex(3,2)
b=complex(2,3)
alpha=angle(b)
w=a*exp(alpha*1j)
polar([0,angle(a)],[0,abs(a)],marker='o',color='red')

[<matplotlib.lines.Line2D at 0x24ef967fc40>]
Bilinear Transformation
Transformation of the form
a z +b
w=T ( z ) =
c z+ d
are called Bilinear Transformation, where a , b , c , d are complex or real constants. To find the
bilinear transformation that takes the ordered triple ( z 1 , z 2 , z 3 ) to the ordered triple ( w1 , w2 , w3 )
we use the formula

( w − w1 ) ( w 2 − w3 ) ( z − z 1 )( z 2 − z 3 )
=
( w1 − w2 ) ( w 3 − w ) ( z 1 − z2 ) ( z 3 − z )

from sympy import *


def BT(z1,z2,z3,w1,w2,w3):
z=Symbol("z")
w=Symbol("w")
Z=((z-z1)*(z2-z3))/((z1-z2)*(z3-z))
W=((w-w1)*(w2-w3))/((w1-w2)*(w3-w))
eq=Z-W
print("The Bilinear Transformation is :")
print((solve(eq,w)))
Question 1: Find the bilinear transformation that takes (1,i,-1) onto (1,0,-1).

BT(1,1j,-1,1,0,-1)

The Bilinear Transformation is :


[(I*z + 1.0)/(z + I)]

Question 2: Find the bilinear transformation that takes (2,1,i) onto (i,1,2).

BT(2,1,1j,1j,1,2)

The Bilinear Transformation is :


[(z*(2.0 + I) - 3.0 - 2.0*I)/(z - 2.0 - I)]

Question 3: Find the bilinear transformation that takes (1,i,20) onto (2,9,-1).

BT(1,1j,20,2,9,-1)

The Bilinear Transformation is :


[(z*(-160.0 + 27.0*I) + 540.0 - 407.0*I)/(z*(130.0 + 3.0*I) + 60.0 -
193.0*I)]

Question 4: Find the bilinear transformation that takes (5,-1,-3) onto (1,i,-1).

BT(5,-1,-3,1,1j,-1)

The Bilinear Transformation is :


[(z*(2.0 + I) + 2.0 + 7.0*I)/(z*(1.0 + 2.0*I) + 7.0 + 2.0*I)]

Conclusion
In this class we learnt how to solve bilinear transformation using python.

Lab-9

MACLAURIN SERIES
Aim: To learn about the maclaurin series in python
from datetime import datetime
current_date = datetime.now()
print("Current Date:", current_date.date())
Current Date: 2024-04-09

Expand $ f(x) =1/(1-x) $ in a maclaurin series

import numpy as np
from sympy import *
import math
def factorial(n):
fact=1
for i in range(1,n+1):
fact=fact*i
return fact
x,z,z0=symbols('x,z,z0')
z0=0
fun=1/(1-x)
series=0
dif=fun
for i in range(8):#the upper range will be the highest number needed
to your expamsion
if(i!=0):
dif=diff(dif)
exp=dif.subs(x,0)*(z)**i/factorial(i)
series=series+exp
else:
exp=dif.subs(x,0)*(z)**i/factorial(i)
series=series+exp
pprint(series)

7 6 5 4 3 2
z + z + z + z + z + z + z + 1

TAYLOR SERIES ABOUT A PARTICULAR POINT


Expand the $ f(z)= 1/(1-z) $ in a taylor seies with center $ z_0=2t $

import numpy as np
from sympy import *
import math
def factorial(n):
fact=1
for i in range(1,n+1):
fact=fact*i
return fact

x,z,z0=symbols('x,z,z0')
z0=2*I
fun=1/(1-x)
series=0
dif=fun
for i in range(4):#the upper range will be the highest number needed
to your expamsion
if(i!=0):
dif=diff(dif)
exp=dif.subs(x,z0)*(z-z0)**i/factorial(i)
series=series+exp
else:
exp=dif.subs(x,z0)*(z-z0)**i/factorial(i)
series=series+exp
print("The taylor series expansion of",fun,"is",)
pprint(series)

The taylor series expansion of 1/(1 - x) is


3 2
(z - 2⋅ⅈ) (z - 2⋅ⅈ) z - 2⋅ⅈ 1 + 2⋅ⅈ
────────── + ────────── + ────────── + ───────
4 3 2 5
(1 - 2⋅ⅈ) (1 - 2⋅ⅈ) (1 - 2⋅ⅈ)

GRAPHICAL APPROXIMATION OF TAYLOR


SERIES OF VARIOUS ORDERS
import numpy as np
import matplotlib.pyplot as plt

x=np.linspace(-np.pi,np.pi,200)
y=np.zeros(len(x))

labels=['First Order','Third Order','Fifth Order','Seventh Order']

for n, label in zip(range(7),labels):


y=y+((-1)**n*(x)**(2*n+1))/ math.factorial(2*n+1)
plt.plot(x,y,label=label)

plt.plot(x,np.sin(x),'k',label='Analytic')
plt.grid()
plt.title('Taylor eries approximation of various orders')
plt.xlabel('x')
plt.ylabel('y')
plt.legend()
plt.show()
Conclusion
In this class we learnt how to solve maclaurin series and learnt how to plot the series.

You might also like