Hello, any hint on these for coding in MATLAB would be helpful. Mostly confused
ID: 3599676 • Letter: H
Question
Hello, any hint on these for coding in MATLAB would be helpful. Mostly confused on what questions are asking.
Exercise 1: Poisson's Equation Consider the linear system A. = p, where A, is an xn matrix with 2's on the main diagonal, -1's directly above and below the main diagonal and O's everywhere else. For instance, As is 21 00 0 12 1 00 As-0-1 20 This is a discretized version of Poisson's equation: This equation appears very often in physics. We'll learn about discretizations of differeni eqations later this quarter Construct the matrix Aso in Matlab. Try readg the documentation for diag() to find a simple way to do this. Make the vector such that the jth entry in p, Pj, is defined according to the formula Pi = 2 ( 1-cos (23r/51 )) sin (23zj/51 ) (a) Write down the matrix form of the Jacobi iteration /k+1 - M#x + c. Con- catenate the matrix M and the vector c and save the resulting 50 x 51 matrix as Al.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 tern in the vector is within 10 of the previous iteration. Le norm(phic.k+1) . phi(:.k), Inf) 104. Save the final iteration as a column vectorin A2.dat and save the total umber of iterations as A3.dat. (c) Now write down the matrix form of the Gauss-Seidel iteration Mpk+c. Note that these are not the same M and c as in part (a). Concate- nate the matrix M and the vector c and save the resulting 50 × 51 matrix as A4.dat. (d) Use Gauss-Seidel iteration to solve for given an initial guess of a column very terin in of ones. Contimue to iterate the Gauss-Seidel method until e the vector is within 10-4 of the previous iteration (as in part (b). Save the final iteration as a column vector in A5.dat and save the total number of itcrations as A6.datExplanation / Answer
Hi
The images are not very clear but I will still try to give some insight. The matrix asked is A50. It is supposed to be a diagonal matrix with values 2 in the diagonal.
Matlab code: To create a matrix using diag(). D = diag(v,k) places the elements of vector v on the kth diagonal. k=0 represents the main diagonal, k>0 is above the main diagonal, and k<0 is below the main diagonal .Let us assume a vector v of of length 50 since matrix size is 50X50. So ,
v = [2 2 2 2 2 2 2 2 2 2 2.............................2 2 2 2 2 ];
u = [-1 -1 -1 -1 -1 -1 -1 -1 ...................-1 -1 -1 -1 -1 -1 ];
D = diag (v);
D = diag (u , -1);
D = diag (u,1);
Part a) Jacobi iterative method in Matlab:
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.