Let A and T be two nonsingular, n x n real matrices. Furthermore, suppose we are
ID: 3698911 • Letter: L
Question
Let A and T be two nonsingular, n x n real matrices. Furthermore, suppose we are given two matrices L and U such that L is unit lower triangular, U is upper triangular, and T A = LU Write an algorithm that will solve the problem Ax b for any given vector b in (n2) complexity. First explain briefly yet clearly why your algo- rithm requires only O(n*) flops (you may assume without proof that solving an upper trian gular or a lower triangular system requires only O(n2) flops). Then specify your algorithm in detail (including the details for lower and upper triangular systems) using pseudocode ora MATLAB script.Explanation / Answer
Solutoin:
code:
U=[3 5 2; %upper triangular matrix
0 8 2;
0 0 6];
L=[1 0 0; %lower triangular matrix
0 1 0;
2 -1 1];
b=[8 -7 26]';
n=length(b);
%%% solving the system Ax=b, where A=LU
% forward substitution for Ly=b , where y=Ux
y=zeros(1,n); % initializing solution
for i=1:n % for every unknown in y
y(i)=b(i);
if i>=2
for j=1:i-1 % subtract with other known
y(i)=y(i)-L(i,j)*y(j);
end
end
end
% backward substitution for y=Ux
x=zeros(1,n); % initializing solution
for i=n:-1:1 % for every unknown in x
x(i)=y(i);
if i<n
for j=n:-1:i+1 % subtract with other known
x(i)=x(i)-U(i,j)*x(j);
end
end
x(i)=x(i)/U(i,i);
end
x' % display solution vector
Output:
ans =
4.0000
-1.0000
0.5000
>>
I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.