Exploration 3.2.11 USING MATLAB - Modify your function gausselim from Exploratio
ID: 2260428 • Letter: E
Question
Exploration 3.2.11 USING MATLAB - Modify your function gausselim from Exploration 3.1.7 so that it is called as follows: LU=gausselim(A). That is, it no longer takes a vector b as an input argument, nor does it return it as an output argument. The entries of the output argument LU are set as follows: for i > j, the (i,j) entry is equal to the multiplier mij from Algorithm 3.1.6, and for i j, the (i,j) entry is equal to uij, where U is the upper triangular matrix that is the nal result of Gaussian Elimination.
Please use my previous code from 3.1.7:
function [A,b] = gausselim(A,b)
n = size(A,1);
m = zeros(n-1);
for j =1:n-1
for i=j+1:n
m(i,j)=A(i,j)/A(j,j);
for k=j:n
A(i,k) = A(j,k) - m(i,j)*A(j,k);
end
b(i)=b(i)-m(i,j)*b(j);
end
end
end
Explanation / Answer
MATLAB code
close all
clear
clc
A = [1 2 3;
4 5 6;
7 8 9];
b = [3 2 1];
LU = gausselim(A)
function LU = gausselim(A)
n = size(A,1);
m = zeros(n-1);
for j=1:n-1
for i=j+1:n
m(i,j)=A(i,j)/A(j,j);
for k=j:n
A(i,k) = A(i,k) - m(i,j)*A(j,k);
end
end
end
LU = zeros(n);
for i=1:n
for j=1:n
if i>j
LU(i,j) = m(i,j);
else
LU(i,j) = A(i,j);
end
end
end
end
output
LU =
1 2 3
4 -3 -6
7 2 0
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.