0% found this document useful (0 votes)
41 views

Adrian Lawrenz F-Matlab

This document contains a MATLAB code to solve a system of 3 linear equations with 3 unknowns (a, b, c) using Gaussian elimination. The code defines the coefficient matrix a with the equations, performs Gaussian elimination on the matrix, then back-substitutes to solve for the variables x' = [1 2 3].

Uploaded by

Penny Delfin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
41 views

Adrian Lawrenz F-Matlab

This document contains a MATLAB code to solve a system of 3 linear equations with 3 unknowns (a, b, c) using Gaussian elimination. The code defines the coefficient matrix a with the equations, performs Gaussian elimination on the matrix, then back-substitutes to solve for the variables x' = [1 2 3].

Uploaded by

Penny Delfin
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Adrian Lawrenz F.

Pesebre

Meeting No. 1

MATLAB CODE:

%solve the system of linear equations:


%2a+4b+6c = 28
%3a+5b+7c = 34
%6a+1b+5c= 23

a= [ 2 4 6 28
3 5 7 34
6 1 5 23 ];

%gauss elimination
[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
disp('Gauss elimination method:');
a
x'

display:
a=

2 4 6 28
0 -1 -2 -8
0 0 9 27

ans =
1
2
3

You might also like