Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write a program to solve the linear system Ax = b by Gaussian elimination and ba

ID: 3111638 • Letter: W

Question

Write a program to solve the linear system Ax = b by Gaussian elimination and back substitution, without any pivoting, run it as follows: A = [3 2 -4: -4 5 -1: 2 -3 5] b = [-5: 3: 11] x = gauss_elim(A, b) Try also A = [3 2 -4: 2 -3 5: -4 5 -1] b = [-5: 11: 3] x = gauss_elim(A, b) which is the first system, but with the equations are written in a different order (in this case, it is clear from the output that the program does not do interchange the rows of the augmented matrix since pivoting is not used). In the case A = [1 2 3: 4 5 6;7 8 9] b = [-5: 3: 11] x = gauss_elim(A, b) explain what went wrong.

Explanation / Answer

MATLAB program and output

Problem 1:

clear all
clc
A = [3 2 -4; 2 -3 5; -4 5 -1];
b= [-5; 11; 3];
Det_A=det(A)
if det(A)==0
disp('Gauss elimination method is not applicable')
else
a=[A b]
%Gauss elimination method [m,n)=size(a);
[m,n]=size(a);
for j=1:m-1
for z=2:m
if a(j,j)==0
t=a(j,:);a(j,:)=a(z,:);
a(z,:)=t;
end
end
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s);
end
end
a
disp('Solution by Gauss elimination method:')
x=x'

Output:Solution by Gauss elimination method:

x= 1.0000
2.0000
3.0000

Problem 2:

clear all
clc
A = [3 2 -4; -4 5 -1;2 -3 5 ];
b= [-5; 3; 11];
det(A)
if det(A)==0
disp('Gauss elimination method is not applicable')
else
a=[A b]
%Gauss elimination method [m,n)=size(a);
[m,n]=size(a);
for j=1:m-1
for z=2:m
if a(j,j)==0
t=a(j,:);a(j,:)=a(z,:);
a(z,:)=t;
end
end
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s);
end
end
a
disp('Solution by Gauss elimination method:')
x=x'

Output:Solution by Gauss elimination method:

x= 1.0000
2.0000
3.0000

Problem 3:

clear all
clc
A = [1 2 3; 4 5 6;7 8 9];
b= [-5; 3; 11];
Det_A=det(A)
if det(A)==0
disp('Gauss elimination method is not applicable')
else
a=[A b]
%Gauss elimination method [m,n)=size(a);
[m,n]=size(a);
for j=1:m-1
for z=2:m
if a(j,j)==0
t=a(j,:);a(j,:)=a(z,:);
a(z,:)=t;
end
end
for i=j+1:m
a(i,:)=a(i,:)-a(j,:)*(a(i,j)/a(j,j));
end
end
x=zeros(1,m);
for s=m:-1:1
c=0;
for k=2:m
c=c+a(s,k)*x(k);
end
x(s)=(a(s,n)-c)/a(s,s);
end

a
disp('Solution by Gauss elimination method:')
x=x'
end

Output:

Det_A = 0

Gauss elimination method is not applicable

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote