Poissons Equation Consider the linear system An p1 where An
Solution
Answer:
See the code below to create matrix \"An\" and vector \"rho\":
-------------------------------------------------
n=50; %dimensions of matrix
%elements of main diagonal
main_diag_elems=2*ones(1,n);
%create diagonal matrix
An=diag(elems);
%set elements above main diagonal
An((n+1):(n+1):(n*n-1))=-1;
%set elements below main diagonal
An((2):(n+1):(n*n-1))=-1;
%calculation of vector rho
j=1:n;
rho=2*(1-cos((23*pi)/51))*sin(((23*pi).*j)/51);
------------------------------------------------
a) See the code below:
-------------------------------------------
%Jacobi form in matrix notation
%phi=M*phi\'+c; where phi is a 1*n order vector
%and c is also a 1*n order vector
phi=ones(1,n); %initial value of phi
C=5; %value of constant. You can specify accoring to yous.
c=5*ones(1,n); %vector of constants
%assuming M to be An, as M not specified.
%You can set or create M as required.
M=An;
%Concatenating M to c
Mc=[M,c\'];
dlmwrite(\"A1.dat\",Mc);
-----------------------------------
Note: Look at and do accordingly as per inline comments.
b) See the code below:
----------------------------------------
%Jacobi iteration
k=1; %first iteration
phi_k=phi; %value of phi for a given iteration
while(1)
phi=M*phi_k\'+c;
if(norm((phi-phi_k),Inf)<=1e-4)
break;
end
phi_k=phi;
k=k+1;
end
%final iteration as column vector
dlmwrite(\"A2.dat\",phi\');
%total no. of iterations
dlmwrite(\"A3.dat\",k);
------------------------------------------------
c), d) These can also be performed in the same way as shown under a) and b).
Note: M needs to be specified clearly what it is and how to calculate.

