Please show code, table (made in MATLAB), and explain all steps. Thank you. The
ID: 2967524 • Letter: P
Question
Please show code, table (made in MATLAB), and explain all steps. Thank you.
The matrix A = gallery(poisson , n) (in Matlab) arises in the numerical solution of elliptic partial differential equations using finite difference methods. The resulting n^2 x n^2 matrix A is sparse, banded, and SPD. (a) For n E {10,20,30,40,50,60, 70, 80}, compute [L,U] = lu(A). Make a table with n, the number of elements of A, the number of nonzeros in A (using nnz), and the number of nonzeros in L. In the case n = 10, use subplot to make side -by -side spy plots of A and L. (b) Repeat part (a) using [L, U, P, Q]= lu(A), which uses a better sparse algorithm, and add the number of nonzeros in this version of L to your table. Also make a spy plot for n = 10.Explanation / Answer
part 1:
n=10:10:80;
table=zeros(length(n),4);
table(:,1)=n';
for i=1:length(n)
A=gallery('poisson',n(i));
[L U]=lu(A);
table(i,2)=length(A);
table(i,3)=nnz(A);
table(i,4)=nnz(L);
if n(i)==10
subplot(2,1,1)
spy(A)
title('spy plot of A')
subplot(2,1,2)
spy(L)
title('spy plot of L')
end
end
disp(' n elements in A non zero in A non zero in L')
disp(table)
part 2:
n=10:10:80;
table=zeros(length(n),4);
table(:,1)=n';
for i=1:length(n)
A=gallery('poisson',n(i));
[L U P Q]=lu(A);
table(i,2)=length(A);
table(i,3)=nnz(A);
table(i,4)=nnz(L);
if n(i)==10
subplot(2,1,1)
spy(A)
title('spy plot of A')
subplot(2,1,2)
spy(L)
title('spy plot of L')
end
end
disp(' n elements in A non zero in A non zero in L')
disp(table)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.