In: Computer Science
Using Matlab's FUNCTION FILE
Solve this system of equations using Gauss Elimination in MATLAB by writing a Function file.
10y + z = 2
x + 3y – z = 6
2x + 4y + z = 5
Could you also provide me with a copiable function file of Matlab and the associated screenshot. Thank you!
function C = gauss_elimination(A,B)
A= [ 0 1 2; 10 3 4; 1 -1 1]
B = [-2; 6; 5]
i = 1;
X = [ A B ];
[ nX mX ] = size( X);
while i <= nX
if X(i,i) == 0
disp('Diagonal element zero')
return
end
X = elimination(X,i,i);
i = i +1;
end
C = X(:,mX);
function X = elimination(X,i,j)
[ nX mX ] = size( X);
a = X(i,j);
X(i,:) = X(i,:)/a;
for k = 1:nX
if k == i
continue
end
X(k,:) = X(k,:) - X(i,:)*X(k,j);
end
As per the matrix a1,a2,a3 ; b1,b2,b3 you can change the values of matrix A(coefficient matrix) and matrix B(result matrix) and get any equation solved.