Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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
image text in transcribed

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Nested Relations And Complex Objects In Databases Lncs 361

Authors: Serge Abiteboul ,Patrick C. Fischer ,Hans-Jorg Schek

1st Edition

ISBN: 3540511717, 978-3540511717

Students also viewed these Databases questions