Solve using Gauss Jordan. Input: (copy and paste the MATLAB or Scilab command in
ID: 3109647 • Letter: S
Question
Solve using Gauss Jordan.
Input: (copy and paste the MATLAB or Scilab command in the following box)
Output: (copy and paste the output in the following box)
• Solve using Cramer’s Rule.
Input: (copy and paste the MATLAB or Scilab command in the following box)
Output: (copy and paste the output in the following box)
3) Given the following set of linear equations x, 2x, X. x, 2x 2x, 5x 10 X, X Solve using x A b Input: copy and paste the MATLAB or Scilab command in the following box a [1 2-1 1; -1 -2 -3 2, 2 1 -1 -5, 1 1 1 1], b [5 7-1 10) X-inv(a) b output copy and paste the output in the following box) 11.604651 -5.2790698 -0.1395349 3.8139535Explanation / Answer
Using Gauss Jordan:
Note: You can interchange the first row and fourth row to get the pivot elements in the top.
Matlab Code:
function C = gauss_elimination(A,B) % defining the function
A= [ 1 1 1 1;-1 -2 -3 2;2 1 -1 -5;1 2 -1 1]; % Inputting the value of coefficient matrix
B = [10;7;-1;5]; % % Inputting the value of coefficient matrix
i = 1; % loop variable
X = [ A B ];
[ nX mX ] = size( X); % determining the size of matrix
while i <= nX % start of loop
if X(i,i) == 0 % checking if the diagonal elements are zero or not
disp('Diagonal element zero') % displaying the result if there exists zero
return
end
X = elimination(X,i,i); % proceeding forward if diagonal elements are non-zero
i = i +1;
end
C = X(:,mX);
function X = elimination(X,i,j)
% Pivoting (i,j) element of matrix X and eliminating other column
% elements to zero
[ nX mX ] = size( X);
a = X(i,j);
X(i,:) = X(i,:)/a;
for k = 1:nX % loop to find triangular form
if k == i
continue
end
X(k,:) = X(k,:) - X(i,:)*X(k,j); % final result
end