Please write the code in either Matlab or Octave \"2. Consider the system 2.Cons
ID: 3666318 • Letter: P
Question
Please write the code in either Matlab or Octave
"2. Consider the system 2.Consider the system 0.4096 0.1234 0.3678 0.29431[ 1 0.4043 0.2246 0.3872 0.4015 0.11290.1550 0.4240 0.3645 0.1920 0.378 0.0643 0.1784 0.4002 0.2786 0.3927 x 02557 0.2557 Solve it by Gaussian elimination with scaled partial pivoting using procedures Gauss "3. (Continuation) Assume that an error was made when the coefficient matrix in Computer Problem 7.2.2 was typed and that a single digit was mistyped-namely, 0.3645 became 0.3345. Solve this system, and notice the effect of this small change. Explain.Explanation / Answer
Save it as Gauss.m
function G = Gauss(n,a,l)
s(1:n) = 0;
for i = 1 : n
l(i) = i;
smax = 0;
for j = 1 : n
smax = max(smax,det(a));
end
s(i) = smax;
end
for k = 1:n-1
rmax = 0;
for i = k:n
r = det(a(l(i),k)/s(l(i)));
if(r > rmax)
rmax = r;
j = i;
end
end
t = l(j);
l(j) = l(k);
l(k) = t;
for i = k+1 : n
xmult = a(l(i),k)/a(l(k),k);
a(l(i),k) = xmult;
for j = k + 1 : n
a(l(i),j) = a(l(i),j) - xmult * a(l(k),j);
end
end
end
G = s ;
%#########################################################################################
Save it as Solve.m
function S = Solve(n,a,l,b,x)
for k = 1 : n-1
for i = k + 1 : n
b(l(i)) = b(l(i)) - a(l(i),k)*b(l(k));
end
end
x(n) = b(l(n))/a(l(n),n);
for i = n - 1 : -1 : 1
sum = b(l(i));
for j = i + 1 : n
sum = sum - a(l(i),j)*x(j);
end
x(i) = sum/a(l(i),i);
end
S = x;