I'm working on a numerical analysis question and need support to help me learn.
Laplace & Poisson Problems
1. Find the electric potential for all points inside the charge-free square shown on
the left of Figure 5.2. The bottom and sides of the square are grounded, while
the wire at the top is kept at 100 V. Listing 5.2 is our code LaplaceLine.py that
solves Laplace’s equation within the square of Figure 5.2.
a. Create a surface plot of the potential V (x, y).
b. Run 10-1000 iterations, and note when convergence occurs.
c. Modify the code so that it quits iterating once the sum of the diagonal elements P|Vi,i| converges to some measure of precision such as 10−4
d. Investigate the effect of varying the step size ∆. Draw conclusions regarding
the stability and accuracy of the solution for various ∆’s.
e. Investigate the effect of using Gauss-Seidel versus Jacobi relaxation. Which
converges faster? Do the answers agree?
# LaplaceLine.py: Solve Laplace's eqtn, 3D matplot, close shell to quit
import matplotlib.pylab as p;
from mpl_toolkits.mplot3d import Axes3D
from numpy import *;
Nmax = 100; Niter = 70; V = zeros((Nmax, Nmax), float)
print ("Working hard, wait for the figure while I count to 60")
for k in range(0, Nmax-1): V[k,0] = 100.0 # Line at 100V
for iter in range(Niter):
if iter%10 == 0: print(iter)
for i in range(1, Nmax-2):
for j in range(1,Nmax-2):
V[i,j] = 0.25*(V[i+1,j]+V[i-1,j]+V[i,j+1]+V[i,j-1])
x = range(0, Nmax-1, 2); y = range(0, 50, 2)
X, Y = p.meshgrid(x,y)
def functz(V): # V(x, y)
z = V[X,Y]
Z = functz(V)
fig = p.figure() # Create figure
ax = Axes3D(fig) # Plot axes
ax.plot_wireframe(X, Y, Z, color = 'r') # Red wireframe
p.show() # Show fig