4 To do this problem you should first go through the code fo

4. To do this problem, you should first go through the code for the GaussianElimina- a function that solves the system o , and understand it. Then write a funo tion function, and understand it. Then write f equations for the case where the equation matrix is upper-triangular. The function header is given as: function x = Solv(Upper (U,b) where the input U iS an upper-triangular matrix, and b iS a column vector; the output x is the solution to Ur = b. (Hint: if the system begins with a matrix U which is already in an upper-triangular form, we do not need to do elimination at all; hence only the back-substitute part fro needed m the GaussianElimination function is

Solution

Code of the function:

function [ x ] = SolveUpper(U,b)
% Based on the back-substitute part from the Gaussian Elimination function
% All we have to do is find each variable once the previous ones are already
%defined
for i=length(U):-1:1 %length() throws the matrix length
sum=0;
for j=i+1:length(U)
sum=sum+U(i,j)*x(j); % to do the summatory of the terms
end
x(i)=(b(i)-sum)/U(i,i); % finding each variable
end
x=x\'; % just to generate a column vector
end

Testing for the following case:

A=[5 1 1;0 2 1; 0 0 4]; b=[7 3 4];

x=solveupper(A,b)

x =

1
1
1

 4. To do this problem, you should first go through the code for the GaussianElimina- a function that solves the system o , and understand it. Then write a funo

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site