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

Combinepdf

1. The document discusses solving partial differential equations (PDEs) including the Laplace equation, Poisson equation, and potential distribution problems using finite difference methods. 2. It provides 6 problems involving computing temperature distributions, potential distributions, and electric potentials using Laplace's equation, Poisson's equation and the boundary conditions specified. 3. The solutions include writing Python code to set up finite difference equations, solve the systems numerically, and plot the results as matrices and contour plots.

Uploaded by

kattarhindu1011
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)
35 views

Combinepdf

1. The document discusses solving partial differential equations (PDEs) including the Laplace equation, Poisson equation, and potential distribution problems using finite difference methods. 2. It provides 6 problems involving computing temperature distributions, potential distributions, and electric potentials using Laplace's equation, Poisson's equation and the boundary conditions specified. 3. The solutions include writing Python code to set up finite difference equations, solve the systems numerically, and plot the results as matrices and contour plots.

Uploaded by

kattarhindu1011
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/ 8

Experiment-2

Partial Differential Equations I


Laplace and Poisson Equations

LAPLACE EQUATION

)
24
3-
02
(2
ge
lle
Co
u
nd
Hi
ics

1. Consider a 40 cm × 40 cm metallic square plate with its edges kept at constant temper-
s
hy

atures as shown in the figure above:


fP

(a) Compute the temperature distribution across the plates taking ∆x = ∆y = 10 cm


to

and display your results as a matrix as shown in the figure above.


en

(b) Take ∆x = ∆y = 1 cm and depict the temperature distribution across the plate
m

using contour plot.


rt

(c) Repeat both the above parts if the lower edge of the given plate is insulated. Display
pa

your results as a matrix as shown in the figure below.


De

1
2. Solve the following for potential distribution in the given region:

∇2 V (x, y) = 0, 0 ≤ x, y ≤ 1

with the boundary conditions V (x, 1) = 45x(1 − x), V (x, 0) = V (0, y) = V (1, y) = 0.
Make a contour plot of the computed potential distribution.
Employ ∆x = ∆y = 0.1

3. A steel plate is of size 15 cm × 15 cm with two of its adjacent sides kept at 100o C and
the other two sides held at 0o C.

(a) Compute the temperature distribution in the interior of the plate at 16 equally
spaced points. Display your result as a matrix.
(b) Repeat the above problem if one of the edges of the plate at 0o C is insulated.
(c) Make a contour plot of the temperature distributions in the above cases.

)
24
POISSON EQUATION

3-
02
(2
ge
lle
Co
u
nd
Hi
s ics
hy
fP

4. Solve: uxx + uyy = −10(x2 + y 2 + 10) in the domain shown in the figure above and display
to

your result as a matrix.


en

5. Solve ∇2 V (x, y) = x(y − 1), 0 ≤ x, y ≤ 1 with the boundary conditions V (x, 0) =


m

0 V, V (x, 1) = 20 V, V (0, y) = −10 V, V (1, y) = 10 V .


rt
pa

Make a contour plot of the potential distribution using ∆x = ∆y = 0.1


De

6. Use Poisson’s equation to compute the electric potential over a unit square (1 × 1)
plate with zero voltage at the edges and point charge sources of ρv / (0.7, 0.7) = 1
and ρv / (0.3, 0.3) = 1.
Employ ∆x = ∆y = 0.1 cm.
Display your results as a matrix and also as a contour plot.

2
MP ASSIGNMENT - 2
SOURCE CODES
import numpy as np
import matplotlib.pyplot as plt
def laplace(Lx,Ly,dx,dy,lower_boundary,left_boundary,right_boundary,upper_boundary):
x = np.arange(0, Lx+dx, dx)
y = np.arange(0, Ly+dy, dy)
m,n = np.meshgrid(x,y)
nx = len(x)
ny = len(y)
A = np.zeros([nx*ny,ny*nx])
B = np.zeros(nx*ny)
X = np.zeros(nx*ny)
B[0:nx] = lower_boundary
B[nx:nx*ny-nx:nx] = left_boundary
B[2*nx-1:nx*ny:nx] = right_boundary
B[-1:-nx-1:-1] = upper_boundary
for i in range(0,nx*ny):
A[i,i] = 1
for k in range(nx+1,nx*ny-nx-1):
A[k,k] = -4
A[k,k+1] = 1
A[k,k-1] = 1
A[k,k+nx] = 1
A[k,k-nx] = 1
for j in range(nx,nx*ny-nx,nx):
A[j,:] = 0
A[j-1,:] = 0
A[j,j] = 1
A[j-1,j-1] = 1
Xr = np.linalg.solve(A,B)
X = Xr.reshape(ny,nx)
return m,n,X
def laplace_derivative(Lx,Ly,dx,dy,lower_boundary,left_boundary,right_boundary,upper_boundary):
x = np.arange(0, Lx+dx, dx)
y = np.arange(0, Ly+dy, dy)
m,n = np.meshgrid(x,y)
nx = len(x)
ny = len(y)
A = np.zeros([nx*ny,ny*nx])
B = np.zeros(nx*ny)
B[nx-1:nx*ny-nx:nx] = right_boundary
B[0:nx*ny:nx] = left_boundary
B[-1:-nx-1:-1] = upper_boundary
for i in range(0,nx*ny):
A[i,i] = 1
for i in range(1,nx-1):
A[i,i] = -4
A[i,i+1] = 1
A[i,i-1] = 1
A[i,i+nx] = 2
for k in range(nx+1,nx*ny-nx-1):
A[k,k] = -4
A[k,k+1] = 1
A[k,k-1] = 1
A[k,k+nx] = 1
A[k,k-nx] = 1
for j in range(nx,nx*ny-2,nx):
A[j,:] = 0
A[j-1,:] = 0
A[j,j] = 1
A[j-1,j-1] = 1
X = np.linalg.solve(A,B)
X = np.reshape(X,(ny,nx))
return m,n,X
def poisson(f,Lx,Ly,dx,dy,lower,left,right,upper):
x = np.arange(0,Lx+dx,dx)
y = np.arange(0,Ly+dy,dy)
nx = len(x)
ny = len(y)
B = np.zeros(nx*ny)
A = np.zeros([nx*ny,nx*ny])
X,Y = np.meshgrid(x,y)
for i in range(1,nx):
for j in range(1,ny):
k = nx*j + i
B[k] = dx**2*f(np.round(X[i,j],5),np.round(Y[i,j],5))
B[0:nx] = lower
B[nx:nx*ny-nx:nx] = right
B[2*nx-1:nx*ny:nx] = left
B[-1:-nx-1:-1] = upper
# print(B.reshape(ny,nx))
for i in range(0 , nx*ny):
A[i,i] = 1
for i in range(nx+1,nx*ny-nx-1,1):
A[i,i] = -4
A[i,i+1] = 1
A[i,i-1] = 1
A[i,i+nx] = 1
A[i,i-nx] = 1
for i in range(nx,nx*ny-nx,nx):
A[i,:] = 0
A[i,i] = 1
A[i-1,:] = 0
A[i-1,i-1] = 1
Xs = np.linalg.solve(A,B)
return X,Y,Xs.reshape(ny,nx)
SOLUTION 1
from pde_MP import laplace,laplace_derivative
import matplotlib.pyplot as plt

fig = plt.figure()
fig.subplots_adjust(hspace=0.4, top=0.85)
fig. suptitle("Temperature Distribution", fontsize=15)

# for dx = dy = 10
x,y,X = laplace(40, 40, 10, 10,0,75,50,100)
plt.subplot(2,2,1)
plt.contourf(x,y,X,cmap="YlOrRd")
plt.xlabel('Along x-axis')
plt.ylabel("Along y-axis")
plt.title("dx=dy=10cm")

# for dx = dy = 1
x,y,X= laplace(40,40,1,1,0,75,50,100)
plt.subplot(2,2,2)
plt.contourf(x,y,X,cmap = 'YlOrRd')
plt.title("dx=dy=1cm")
plt.xlabel('Along x-axis')
plt.ylabel("Along y-axis")

# for insulated lower plate(dx = dy = 10 cm)


x,y,X = laplace_derivative(40, 40, 10, 10,0,75,50,100)
plt.subplot(2,2,3)
plt.contourf(x,y,X,cmap = 'YlOrRd')
plt.title("Insulated(dx=dy=10cm)")
plt.xlabel('Along x-axis')
plt.ylabel("Along y-axis")

# for insulated plate(dx = dy = 1 cm)


x,y,X = laplace_derivative(40, 40, 1, 1,0,75,50,100)
plt.subplot(2,2,4)
plt.contourf(x,y,X,cmap = 'YlOrRd')
plt.title("Insulated(dx=dy=1cm)")
plt.xlabel('Along x-axis')
plt.ylabel("Along y-axis")
plt.tight_layout()
PLOT

SOLUTION 2 PLOT
import numpy as np
from pde_MP import laplace
import matplotlib.pyplot as plt
x = np.arange(0,1.1,0.1)
f = np.empty(len(x))
for i in range(len(x)):
f[i] = 45*x[i]*(1-x[i])
x,y,X = laplace(1,1,0.1,0.1,0,0,0,f)
plt.contourf(x,y,X,cmap = "Blues")
plt.colorbar()
plt.xlabel("X-axis")
plt.ylabel("Y-axis")
plt.title("Potential distribution")

SOLUTION 3
from pde_MP import laplace,laplace_derivative
import matplotlib.pyplot as plt
import numpy as np
fig = plt.figure()
fig.subplots_adjust(hspace=0.4, top=0.85)
fig. suptitle("Temperature Distribution", fontsize=12)

x,y,X = laplace(15,15,1,1,0,100,0,100)
np.set_printoptions(linewidth = 200,precision=3)
print("X = \n",X)
PLOTS
plt.subplot(1,2,1)
plt.contourf(x,y,X,cmap = "YlOrRd")
plt.colorbar()
plt.xlabel('Along x-axis')
plt.ylabel("Along y-axis")
plt.title('')

x,y,X = laplace_derivative(15, 15, 1, 1,


0, 100, 0, 100)
plt.subplot(1,2,2)
plt.contourf(x,y,X,cmap='YlOrRd')
plt.colorbar()
plt.xlabel('Along x-axis')
plt.ylabel("Along y-axis")
plt.tight_layout()
CONSOLE OUTPUT

SOLUTION 4
from pde_MP import poisson

def f(x,y):
return (-10*(x**2+y**2+10)) CONSOLE OUTPUT
x,y,X = poisson(f, 3, 3, 1, 1, 0, 0, 0, 0)
print("X = ",X)
SOLUTION 5 PLOT
from pde_MP import poisson
import matplotlib.pyplot as plt

def f(x,y):
return (x*(y-1))

x,y,X = poisson(f, 1, 1, 0.1, 0.1, 0, -10, 10, 20)


plt.contourf(x,y,X,cmap = "Blues")
plt.xlabel("x-axis")
plt.ylabel('y-axis')
plt.title("Potential distribution")
plt.colorbar()

SOLUTION 6 PLOT
from pde_MP import poisson
import numpy as np
import matplotlib.pyplot as plt
def f(x,y):
if (x,y) in [(0.3,0.3) ,(0.7,0.7)]:
return 1
else:
return 0

x,y,X = poisson(f,1,1,0.1,0.1,0,0,0,0)
plt.contourf(x,y,X,cmap = "winter")
plt.colorbar()

You might also like