Create a function gaussian elimination that performs the gaussian elimination of
ID: 3147659 • Letter: C
Question
Create a function gaussian elimination that performs the gaussian elimination of linear system of the form Ax = b. The function should return the associated upper triangular matrix U and the modified right-hand side f. The function header should look something like:
function [U,f] = gaussian_elimination (A,b)
How would you write the following pseudocode shown below in MATLAB?
Gaussian Elimination with Backward Substitution To solve the n × n linear system INPUT number of unknowns and equations n; au i Sn and 1 sj sn+1 ed matrix A = [aij], where 1 OUTPUT solution x1, x2, xn or message that the linear system has no unique solu- tion. Step 1 For i = 1, . . . , n-1 do Steps 2-4. (Elimination process.) Step 2 Let p be the smallest integer with 1Explanation / Answer
function [U,f] = gaussian_elimination (A,b)
n = length(b); x = zeros(n,1);
for k=1:n-1 % forward elimination
for i=k+1:n
xmult = A(i,k)/A(k,k);
for j=k+1:n
A(i,j) = A(i,j)-xmult*A(k,j);
end
b(i) = b(i)-xmult*b(k);
end
end
% back substitution
x(n) = b(n)/A(n,n);
for i=n-1:-1:1
sum = b(i);
for j=i+1:n
sum = sum-A(i,j)*x(j);
end
x(i) = sum/A(i,i);
end
f = x;
end
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.