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
to solve an upper triangular system Hint: Loops can be run
backwards, say, from down to by typing in MATLAB: for :
: Remember also that the diagonal entries in are not necessarily Use this starting code in MATLAB:
Gaussian elimination without pivoting
for solving linear systems Axb
A ; ; ; b ;
A ; ; ; ; b ; another example
n sizeA;
This is Step of Gaussian Elimination
for i:n Loop over rows below row
mult AiA; Subtract this multiple of row from
row i to make Ai
Ai: Ai:multA:; this line is equivalent to the "for loop:
for k:n Aik AikmultAk; end;
bi bi multb;
end
U A display U
All steps of Gaussian elimination
A ; ; ; b ;
A ; ; ; ; b ; another example
n sizeA;
for j:n Loop over columns.
for ij:n Loop over rows below j
mult AijAjj; Subtract this multiple of row j from
row i to make Aij
Ai: Ai: multAj:; This does more work than necessary! WHY?
bi bi multbj;
end
end the resulting A is an upper triangular matrix
U A display U
Modified Gaussian elimination
to avoid recomputing zeros
A ; ; b ; ;
A ; ; ; b ;
A ; ; ; ; b ; another example
n sizeA;
for j:n Loop over columns.
for ij:n Loop over rows below j
mult AijAjj; Subtract this multiple of row j from
row i to make Aij
Aij:n Aij:n multAjj:n; modified! no more recomputing of
of zeros in columns to j and rows j to n
bi bi multbj;
end
end the resulting A is an upper triangular matrix
U A display U
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
