Question

using matlab Write your own routine for Gaussian elimination without any pivoting. Input for the routine...

using matlab Write your own routine for Gaussian elimination without any pivoting. Input for the routine should consist of the number (n) of equations and the augmented matrix. Output should be the vector solution of the system. Test your code by using it to solve the following two problems: a) x + y + w + z = 10, 2x + 3y + w + 5z = 31, −x + y − 5w + 3z = −2, 3x + y + 7w − 2z = 18

Homework Answers

Answer #1

MATLAB Code:

close all
clear
clc

% x + y + w + z = 10
% 2x + 3y + w + 5z = 31
% −x + y − 5w + 3z = −2
% 3x + y + 7w − 2z = 18

A = [ 1 1 1 1;
2 3 1 5;
-1 1 -5 3;
3 1 7 -2];
b = [10 31 -2 18]';
Ag = [A b];
n = size(A, 1);
x = gauss_elim(n, Ag)

function x = gauss_elim(n, Ag)
A = Ag(:,1:end-1);
b = Ag(:,end);
nb = length(b);
x = zeros(1,n);
  
% Gaussian elimination
for i = 1:n-1
if A(i,i) == 0
t = min(find(A(i+1:n,i) ~= 0) + i);
if isempty(t)
disp ('Error: A matrix is singular');
return
end
temp = A(i,:); tb = b(i);
A(i,:) = A(t,:); b(i) = b(t);
A(t,:) = temp; b(t) = tb;
end
for j = i+1:n
m = -A(j,i) / A(i,i);
A(j,i) = 0;
A(j,i+1:n) = A(j,i+1:n) + m*A(i,i+1:n);
b(j) = b(j) + m*b(i);
end
end
  
% Back substitution
x(n) = b(n) / A(n,n);
for i = n-1:-1:1
x(i) = (b(i) - sum(x(i+1:n) .* A(i,i+1:n))) / A(i,i);
end
end

Output:

x =
1 2 3 4

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
Solve the following system of equations using Gaussian elimination. Write the anwser as ordered triples and...
Solve the following system of equations using Gaussian elimination. Write the anwser as ordered triples and please show steps. 2x+y+2z=18 x-y+2z=9 x+2y-z=6
Use Gaussian elimination to find the complete solution to the following system of​ equations, or show...
Use Gaussian elimination to find the complete solution to the following system of​ equations, or show that none exists. {5x + 17y + 7z = 14 {2x + 7y -5z = -3 { x + 3y - 3z = 8 Find the​ row-echelon form of the matrix for the given system of equations. ​(Do not include the vertical bar in the augmented​matrix.) Select the correct choice below​ and, if​ necessary, fill in the answer boxes to complete your choice. A....
Use Gaussian Elimination to solve and show all steps: 1. (x+4y=6) (1/2x+1/3y=1/2) 2. (x-2y+3z=7) (-3x+y+2z=-5) (2x+2y+z=3)
Use Gaussian Elimination to solve and show all steps: 1. (x+4y=6) (1/2x+1/3y=1/2) 2. (x-2y+3z=7) (-3x+y+2z=-5) (2x+2y+z=3)
Solve the system using either Gaussian elimination with back-substitution or Gauss-Jordan elimination.If the system has an...
Solve the system using either Gaussian elimination with back-substitution or Gauss-Jordan elimination.If the system has an infinite number of solutions, express x, y, and z in terms of the parameter t.) 3x + 3y + 9z = 6 x + y + 3z = 2 2x + 5y + 15z = 10 -x + 2y + 6z = 4 (x, y, z) = ?
Solve system of equations using matrices. Make a 4x4 matrix and get the diagonal to be...
Solve system of equations using matrices. Make a 4x4 matrix and get the diagonal to be ones and the rest of the numbers to be zeros 2x -3y + z + w = - 4 -x + y + 2z + w = 3 y -3z + 2w = - 5 2x + 2y -z -w = - 4
1)Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution,...
1)Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, express your answer in terms of the parameters t and/or s.) x1 + 2x2 + 8x3 = 6 x1 + x2 + 4x3 = 3 (x1, x2, x3) = 2)Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION. If there are infinitely many solutions, express...
4. Solve the system of linear equations by using the Gauss-Jordan (Matrix) Elimination Method. No credit...
4. Solve the system of linear equations by using the Gauss-Jordan (Matrix) Elimination Method. No credit in use any other method. Use exactly the notation we used in class and in the text. Indicate whether the system has a unique solution, no solution, or infinitely many solutions. In the latter case, present the solutions in parametric form. 3x + 6y + 3z = -6 -2x -3y -z = 1 x +2y + z = -2
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT