Argh. Well, you did make an effort. But this is for what appears to be a basic numerical linear algebra class. So you need to start thinking about linear algebra.
To start ... Why do you think you need to add diagonal matrices to a zeros array? Just add them to each other.
A = diag(6*ones(1,18),0) + diag(3*ones(1,17),1) + diag(3*ones(1,17),-1);
Next, learn to use semi-colons on the end of your lines, unless there is some reason to inspect the result. Otherwise, you see tons of useless crap on the command line.
So, A is a tridiagonal matrix. Is it full rank? Are the eigenvalues positive? Is it symmetric? Yes. Yes. Yes.
rank(A)
ans =
18
isequal(A,A.')
ans =
logical
1
eig(A)
ans =
0.081832
0.3251
0.72316
1.2652
1.9363
2.7183
3.5898
4.5271
5.5045
6.4955
7.4729
8.4102
9.2817
10.064
10.735
11.277
11.675
11.918
So A is SPD (symmetric, positive, definite.)
Next, why would you possibly think that triu(A) and tril(A) are factorizations of A? Or, even that b\tril(A) is how you solve the indicated linear system? That is close, but the wrong use of backslash. So you need to read the help for slash again. Read what it says about backslash carefully.
What does the characterization of A (above) tell you will be the most efficient factorization of A?
Best Answer