MATLAB Write a function that will accept a matrix and return a matrix. The funct
ID: 3691904 • Letter: M
Question
MATLAB
Write a function that will accept a matrix and return a matrix. The function should take the passed matrix and using Gauss Elimination put zeros in the first column of the matrix. The first step is to put the row with the largest absolute value in the first row by swapping using two functions you wrote in a previous homework. Then calculate the factor necessary to multiply the first row by so that when it is added to the second row, the element in row 2 column 1 becomes zero. Use your linear combination function to accomplish this task. Then move down to the next row. Keep looping through the rows until all the elements in column 1, except row 1, are zero.
For example, if the matrix
is passed to the function, the function would return
Explanation / Answer
Answer for Question:
This below matlab code will compute the given matrix with gaussian elemination method and will produce the result.
See the code:
function [x,U]=gausselim(A,b)
% function to perform gauss eliminination
%FORWARD ELIMINATION
n=length(b);
m=zeros(n,1);
x=zeros(n,1);
for k =1:n-1;
end
U= triu(A);
%BACKWARD ELIMINATION
x(n)=b(n)/A(n,n);
for k =n-1:-1:1;
end
end
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.