Design a Gaussian elimination algorithm for matrices with the structure a1 di 0
ID: 3167362 • Letter: D
Question
Design a Gaussian elimination algorithm for matrices with the structure a1 di 0 0 0 c2 as ds 0 0 0 0 0 0... an-2 dn-20 0 0 0 0... cn-2 an-1 dn-1 0 Cn-1 an Namely, only the diagonals and the off-diagonals that are next to the diagonals are nonzero. These entries are given by three arrays, a, d and c. The algorithm should make use of this special pattern of the matrix. Test your algorithm on the following linear system: Az = b, where 1 1 1 1T 2'3'4'5' a=[2, 2, 2, 2, 2j,d=|-1,-1,-1,-1,c=|-1,-1,-1,-1,b=11,Explanation / Answer
clc;
clear all;
d=[-1 -1 -1 -1 -1];
a=[2 2 2 2 2];
c=[-1 -1 -1 -1 -1];
b=[1 1/2 1/3 1/4 1/5];
n=length(b);
b1(1)=a(1);
f1(1)=b(1);
for i=1:n
c1(i)=c(i);
end
for i=2:n
b1(i)=a(i)-(c1(i-1)*(d(i)/b1(i-1)));
end
for i=2:n
f1(i)=b(i)-(f1(i-1)*(d(i)/b1(i-1)));
end
% Back substution
u(n)=f1(n)/b1(n);
for i=n-1:-1:1
u(i)=(f1(i)-c1(i)*u(i+1))/b1(i);
end
u
Answer
u =
1.4500 1.9000 1.8500 1.4667 0.8333