This repository has been archived on 2021-09-27. You can view files and clone it, but cannot push or open issues or pull requests.
NC/mp2/Project_2_Maggioni_Claudio/ex2.m

27 lines
350 B
Mathematica
Raw Normal View History

2020-10-21 13:21:51 +00:00
A = createA(5);
spy(A);
matlab2tikz('../ex2_2_spy.tex');
A = createA(100);
figure;
subplot(1,2,1)
spy(A);
subplot(1,2,2)
spy(chol(A));
matlab2tikz('../ex2_3_spy.tex');
function A = createA(n)
2020-10-07 13:39:10 +00:00
A = sparse(n, n);
A(1,:) = 1;
A(end,:) = 1;
A(:,1) = 1;
A(:,end) = 1;
% make sure diagonal is 0
A(1,1) = 0;
2020-10-21 13:21:51 +00:00
A(end,end) = 0;
2020-10-07 13:39:10 +00:00
A = A + diag(n:(2*n-1));
2020-10-21 13:21:51 +00:00
end