0% found this document useful (0 votes)
15 views

Complex Analysis - Jupyter Notebook

Uploaded by

230383
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views

Complex Analysis - Jupyter Notebook

Uploaded by

230383
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

COMPLEX ANALYSIS

REAL AND IMAGINARY PART OF A COMPLEX FUNCTION

In [1]: import sympy as sp


z = sp.symbols('z')
f_z = z**2 + z
real_part = sp.re(f_z)
imag_part = sp.im(f_z)
print('Real part of f(z) is ')
display(real_part)
print('Imaginary part of f(z) is ')
display(imag_part)

Real part of f(z) is

(re (𝑧))2 + re (𝑧) − (im (𝑧))2


Imaginary part of f(z) is

2 re (𝑧) im (𝑧) + im (𝑧)

In [2]: import sympy as sp


z = sp.symbols('z')
f_z = z**2
real_part = sp.re(f_z)
imag_part = sp.im(f_z)
print('Real part of f(z) is ')
display(real_part)
print('Imaginary part of f(z) is ')
display(imag_part)

Real part of f(z) is

(re (𝑧))2 − (im (𝑧))2


Imaginary part of f(z) is

2 re (𝑧) im (𝑧)
VERIFY CAUCHY-RIEMANN EQUATIONS

In [3]: import sympy as sp


def verify_CR_equation(u,v,x,y):
u_x = sp.diff(u, x)
u_y = sp.diff(u, y)
v_x = sp.diff(v, x)
v_y = sp.diff(v, y)

cr_eqn1 = sp.simplify(u_x - v_y)


cr_eqn2 = sp.simplify(u_y + v_x)

if cr_eqn1 == 0 and cr_eqn2 == 0:


return True, cr_eqn1, cr_eqn2
else:
return False,cr_eqn1, cr_eqn2

x, y = sp.symbols('x y')
u = x**3 - 3*x*y**2
v = 3*x**2*y - y**3

is_analytic, eqn1, eqn2 = verify_CR_equation(u, v, x, y)
print('u_x = ',sp.diff(u, x))
print('u_y = ',sp.diff(u, y))
print('v_x = ',sp.diff(v, x))
print('v_y = ',sp.diff(v, y))

if is_analytic:
print('The function satisfies the CR equations and is analytic')
else:
print('The function does not satisfies the CR equations and is not analytic')
print(f"CR equation 1 : {eqn1}")
print(f"CR equation 2 : {eqn2}")

u_x = 3*x**2 - 3*y**2


u_y = -6*x*y
v_x = 6*x*y
v_y = 3*x**2 - 3*y**2
The function satisfies the CR equations and is analytic
CR equation 1 : 0
CR equation 2 : 0
In [4]: import sympy as sp
x, y = sp.symbols('x y')
u = x**2 - y**2
v = 2*x*y
u_x = sp.diff(u, x)
u_y = sp.diff(u, y)
v_x = sp.diff(v, x)
v_y = sp.diff(v, y)

cr1 = sp.simplify(u_x - v_y)
cr2 = sp.simplify(u_y + v_x)

print("Partial derivatives:")
print("u_x : ", u_x)
print("u_y : ", u_y)
print("v_x : ", v_x)
print("v_y : ", v_y)
print("\nCauchy-Riemann equations:")
print("u_x - v_y = ", cr1)
print("u_y + v_x = ", cr2)

if cr1 == 0 and cr2 == 0:
print("\nThe function satisfies the Cauchy-Riemann equations and is analytic.")
else:
print("\nThe function does not satisfy the Cauchy-Riemann equations and is not analytic.")

Partial derivatives:
u_x : 2*x
u_y : -2*y
v_x : 2*y
v_y : 2*x

Cauchy-Riemann equations:
u_x - v_y = 0
u_y + v_x = 0

The function satisfies the Cauchy-Riemann equations and is analytic.


In [5]: import sympy as sp
x, y = sp.symbols('x y')
u = x**3 - 3*x*y**2
v = 3*x**2*y - y

u_x = sp.diff(u, x)
u_y = sp.diff(u, y)
v_x = sp.diff(v, x)
v_y = sp.diff(v, y)

cr1 = sp.simplify(u_x - v_y)
cr2 = sp.simplify(u_y + v_x)

print("Partial derivatives:")
print("u_x : ", u_x)
print("u_y : ", u_y)
print("v_x : ", v_x)
print("v_y : ", v_y)
print("\nCauchy-Riemann equations:")
print("u_x - v_y = ", cr1)
print("u_y + v_x = ", cr2)

if cr1 == 0 and cr2 == 0:
print("\nThe function satisfies the Cauchy-Riemann equations and is analytic.")
else:
print("\nThe function does not satisfy the Cauchy-Riemann equations and is not analytic.")

Partial derivatives:
u_x : 3*x**2 - 3*y**2
u_y : -6*x*y
v_x : 6*x*y
v_y : 3*x**2 - 1

Cauchy-Riemann equations:
u_x - v_y = 1 - 3*y**2
u_y + v_x = 0

The function does not satisfy the Cauchy-Riemann equations and is not analytic.

HARMONIC FUNCTION

In [6]: import sympy as sp


x, y = sp.symbols('x y')
u = x**2 - y**2

u_xx = sp.diff(u,x,x)
u_yy = sp.diff(u,y,y)

Laplacian = u_xx + u_yy
print('u_xx = ', u_xx)
print('u_yy = ', u_yy)
print('u_xx + u_yy = ', Laplacian)
if Laplacian == 0:
print('The function is harmonic')
else:
print('The function is not harmonic')

u_xx = 2
u_yy = -2
u_xx + u_yy = 0
The function is harmonic
In [7]: import sympy as sp
x, y = sp.symbols('x y')
u = x**2 - y**3

u_xx = sp.diff(u,x,x)
u_yy = sp.diff(u,y,y)

Laplacian = u_xx + u_yy
print('u_xx = ', u_xx)
print('u_yy = ', u_yy)
print('u_xx + u_yy = ', Laplacian)
if Laplacian == 0:
print('The function is harmonic')
else:
print('The function is not harmonic')

u_xx = 2
u_yy = -6*y
u_xx + u_yy = 2 - 6*y
The function is not harmonic

In [8]: import sympy as sp


def find_harmonic_conjugate(u,x,y):
u_x = sp.diff(u,x)
u_y = sp.diff(u,y)

v_y = u_x
v_x = -u_y
v1 = sp.integrate(v_y,y)

g = sp.integrate(sp.diff(v1,x)-v_x, x)
print('g(x) = ',g)
v=v1+g
v = sp.symbols('c')+v
return v
x, y = sp.symbols('x y')
u = x**2 - y**2
v = find_harmonic_conjugate(u,x,y)
print("The harmonic conjugate of u(x,y) is :")
display(v)

g(x) = 0
The harmonic conjugate of u(x,y) is :

𝑐 + 2𝑥𝑦

In [9]: import sympy as sp


def find_harmonic_conjugate(u,x,y):
u_x = sp.diff(u,x)
u_y = sp.diff(u,y)

v_y = u_x
v_x = -u_y
v1 = sp.integrate(v_y,y)

c = sp.integrate(sp.diff(v1,x)-v_x, x)
v=v1+c
v = v + sp.symbols('c')
return v
x, y = sp.symbols('x y')
u = x**3-3*x*y**2
v = find_harmonic_conjugate(u,x,y)
print("The harmonic conjugate of u(x,y) is :")
display(v)

The harmonic conjugate of u(x,y) is :

𝑐 + 3𝑥2 𝑦 − 𝑦3

You might also like