Advanced Linear Algebra - Matrix Write MATLAB code (using loops) for tri-diagona
ID: 3111746 • Letter: A
Question
Advanced Linear Algebra - Matrix
Write MATLAB code (using loops) for tri-diagonal Gaussian elimination with Input should as a random strictly diagonally dominant matrix of size n (generated from MATLAB code), and a random right-hand side vector. Note the simulation run time for n = 10, 20, 50, 100, 150, 200. Compare them with the run time of the standard solver in Matlab.
Note: Complete Matlab code is required which includes tri-diagonal Gaussian elimination; random strictly diagonally dominant matrix; standard solver in Matlab. Appreciate if the way to compare the run time is also provided. Weightage of question is very high
Explanation / Answer
DEFINITION:
a matrix is said to be diagonally dominant if for every row of the matrix, the magnitude of the diagonal entry in a row is larger than or equal to the sum of the magnitudes of all the other (non-diagonal) entries in that row.
Start with row 1, generate all the random numbers for this row. Now check if the diagonal element is greater than the sum of rest of the row elements. If it is, proceed to row 2 otherwise, generate row 1 ... Keep doing, until diagonal element is greater than sum of other element of the rows (i.e. diagonally dominant row)
function y = tridiag( a, b, c, f )
Solve the n x n tridiagonal system for y:
f must be a vector (row or column) of length n
a, b, c must be vectors of length n (note that b(1) and c(n) are not used)
simulation run time for n = 10, 20, 50, 100, 150, 200
MATLAB CODE:
n = length(f);
v = zeros(n,1);
y = v;
w = a(1);
y(1) = f(1)/w;
for i=2:n
v(i-1) = c(i-1)/w;
w = a(i) - b(i)*v(i-1);
y(i) = ( f(i) - b(i)*y(i-1) )/w;
end
for j=n-1:-1:1
y(j) = y(j) - v(j)*y(j+1);
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.