Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hello, need help with MATLAB coding. If anyone could please even tell me what qu

ID: 3600138 • Letter: H

Question

Hello, need help with MATLAB coding. If anyone could please even tell me what questions are asking, or any hints on coding, that would be great. Thank you

Exercise 1: Poisson's Equation Consider the linear system An = p, where An is an nx n matrix with 2's on the main diagonal, -1's directly above and below the main diagonal and 0's everywhere else. For instance, A5 is 21 00 0 -1 21 0 0 A5-0 2-1 0 0 0 1 21 0 0 0-1 2 This is a discretized version of Poisson's equation This equation appears very often in physics. We'll learn about discretizations of differential equations later this quarter. Construct the matrix Aso in Matlab. Try reading the documentation for diag() to find a simple way to do this. Make the vector such that the jth entry in , pj, is defined according to the formula pj- 2(1- cos (23T/51)) sin (23Tj/51) (a) Write down the matrix form of the Jacobi iteration +1 = M#x + c, Con- catenate the matrix M and the vector c and save the resulting 50 x 51 matrix as A1.dat. (b) Use Jacobi iteration to solve for given an initial guess of a column of ones. Continue to iterate the Jacobi method until every term in the vector is within 10- of the previous iteration. L.e., norm(phi(.k+1)-phi(:,k), Inf)

Explanation / Answer

ANSWER::


nx=80;
ny=80;   
niter=1000;   
dx=2/(nx-1);   
dy=2/(ny-1);
x=0:dx:2;   
y=0:dy:2;   
b=zeros(nx,ny);
pn=zeros(nx,ny);

p=zeros(nx,ny);

p(:,1)=0;
p(:,ny)=0;
p(1,:)=0;   
p(nx,:)=0;


b(round(ny/4),round(nx/4))=3000;
b(round(ny*3/4),round(nx*3/4))=-3000;


i=2:nx-1;
j=2:ny-1;
%Explicit iterative scheme with C.D in space (5-point difference)
for it=1:niter
pn=p;
p(i,j)=((dy^2*(pn(i+1,j)+pn(i-1,j)))+(dx^2*(pn(i,j+1)+pn(i,j-1)))-(b(i,j)*dx^2*dy*2))/(2*(dx^2+dy^2));
%Boundary conditions
p(:,1)=0;
p(:,ny)=0;
p(1,:)=0;   
p(nx,:)=0;
end
h=surf(x,y,p','EdgeColor','none');
shading interp
axis([-0.5 2.5 -0.5 2.5 -100 100])
title({'2-D Poisson equation';['{itNumber of iterations} = ',num2str(it)]})
xlabel('Spatial co-ordinate (x) ightarrow')
ylabel('{leftarrow} Spatial co-ordinate (y)')
zlabel('Solution profile (P) ightarrow')