Question: Write a function usolve, analogous to function lsolve in section 7 . 2 . 2 , to solve an upper triangular system U x =

Write a function usolve, analogous to function lsolve in section 7.2.2,
to solve an upper triangular system Ux=y.[Hint: Loops can be run
backwards, say, from n down to 1, by typing in MATLAB: for i=n :-
1:1. Remember also that the diagonal entries in U are not necessarily 1. Use this starting code in MATLAB:
% Gaussian elimination without pivoting
% for solving linear systems Ax=b
%
%A =[123; 456; 780]; b =[102]';
%A =[2110; 4331; 8795; 6798]; b =[2345]'; % another example
n = size(A,1);
%
%---------------------------------------------%
% This is Step 1 of Gaussian Elimination
%----------------------------------------------%
%
for i=2:n % Loop over rows below row 1
mult = A(i,1)/A(1,1); % Subtract this multiple of row 1 from
% row i to make A(i,1)=0.
A(i,:)= A(i,:)-mult*A(1,:); %(this line is equivalent to the "for loop:
% for k=1:n, A(i,k)= A(i,k)-mult*A(1,k); end; ")
b(i)= b(i)- mult*b(1);
end
U = A % display U
%
%
%----------------------------------------------%
% All steps of Gaussian elimination
%----------------------------------------------%
%
A =[123; 456; 780]; b =[102]';
%A =[2110; 4331; 8795; 6798]; b =[2345]'; % another example
n = size(A,1);
for j=1:n-1% Loop over columns.
for i=j+1:n % Loop over rows below j.
mult = A(i,j)/A(j,j); % Subtract this multiple of row j from
% row i to make A(i,j)=0.
A(i,:)= A(i,:)- mult*A(j,:); % This does more work than necessary! WHY?
b(i)= b(i)- mult*b(j);
end
end % the resulting A is an upper triangular matrix
U = A % display U
%
%
%----------------------------------------------%
% Modified Gaussian elimination
%(to avoid recomputing zeros)
%----------------------------------------------%
%
A =[10^-161; 11]; b =[2; 3];
%A =[123; 456; 780]; b =[102]';
%A =[2110; 4331; 8795; 6798]; b =[2345]'; % another example
n = size(A,1);
for j=1:n-1% Loop over columns.
for i=j+1:n % Loop over rows below j.
mult = A(i,j)/A(j,j); % Subtract this multiple of row j from
% row i to make A(i,j)=0.
A(i,j:n)= A(i,j:n)- mult*A(j,j:n); % modified! no more recomputing of
% of zeros in columns 1 to j-1 and rows j to n.
b(i)= b(i)- mult*b(j);
end
end % the resulting A is an upper triangular matrix
U = A % display U
 Write a function usolve, analogous to function lsolve in section 7.2.2,

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!