Write a function in MATLAB that takes as input a symmetric tridiagonal matrix re
ID: 3111149 • Letter: W
Question
Write a function in MATLAB that takes as input a symmetric tridiagonal matrix represented as two vectors: an n times 1 vector u representing the main diagonal and an (n - 1) times 1 vector w representing the upper (and lower) diagonal. Have this function output the Cholesky factor of the matrix as a vector for the main diagonal and a vector for the upper diagonal. Only submit the code, but to make sure your code works, if you input v = [4, 4, 4, 4, 4, 4] and w = [1, 1, 1, 1, 1], your program should output the vectors [2, 1.94, 1.93, 1.93, 1.93, 1.93] and [.5, 516, 518, 518, 518]. For big matrices, this algorithm is more efficient than the standard Cholesky method. For a 100 times 100 matrix, what percentage of the memory do we need to store our matrix, compared to the naive method? About what percentage of flops do we compute, compared to the naive method? (Use the approximations for flops we gave in class.)Explanation / Answer
MATLAB CODE:
prompt = ('Enter the size of the matrix');
n = input(prompt);
prompt = sprintf('Enter the diagonal vector v with %d elements',n);
disp(prompt);
for i = 1:n
v(i) = input(' ');
end
prompt = sprintf('Enter the upper diagonal vector w with %d elements',n-1);
disp(prompt);
for i = 1:n-1
w(i) = disp(' ');
end
M = zeros(n,n);
for i=1:n
M(i,i) = v(i);%Entering the main diagonal
end
for i=1:n-1
M(i+1,i) = w(i); % entering the lower diagonal
M(i,i+1) = w(i); % entering the upper diagonal
end
R = chol(M); % Cholesky factorization of matrix M
for i = 1:n
vc(i) = R(i,i);
end
for i = 1:n-1
wc(i) = R(i,i+1);
end
disp('The required vectors of Cholesky factorization are:');
disp('vc = ');
disp(vc);
disp('wc = ');
disp(wc);
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.