Question
  1. Write a program in Matlab that solves linear systems of equations using Gauss elimination with partial pivoting. Make sure that you use variables that are explicit, and make sure to include comment lines (each subroutine should have at least a sentence stating what it does). Make sure that your program checks for valid inputs in matrix and vectors dimensionality.

    • Using your code, solve the systems of equations in problems 9.11, 9.12, and 9.13

2x1-6x2-X3 =-38 9.11

9.12

6x1 + 2x2 + 2x3 = 2 3x1 + 4x2 + x3 = 1 9.13

2x1-6x2-X3 =-38

6x1 + 2x2 + 2x3 = 2 3x1 + 4x2 + x3 = 1
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Consider the following system of linear equations:

A1x + B1y + C1z = D1 . . . . . . . ( 1 )
A2x + B2y + C2z = D2 . . . . . . . . ( 2 )
A3x + B3y + C3z = D3 . . . . . . . . . . ( 3)

In order to apply Gauss elimination method, we need to express the above three linear equations in matrix form as given below:

A = | A1    B1    C1 |
         |A2   B2   C2   |
         | A3 B3   C3 |

B=    D1
         D2
         D3    
Arrange matrices A and B in the following form (augmented matrix):

         | A1    B1    C1 D1|
         |A2   B2   C2    D2|
         | A3 B3   C3   D3|


As per that given matrix is

9.11)
   2    -6     -1
-3     -1     7
-8     1      -2

-38
-34
-20

9.12)
2         1         -1
5        2          2
3       1         1


1
-4
5

9.13)

1           1         -1
6           2          2
-3         4          1

-3
2
1

program:

function C = gauss_elimination(A,B) % defining the function
A= [ 2 -6 -1; -3 -1 7; -8 1 -2] % Inputting the value of coefficient matrix 9.11
B = [-38; -34; -20] % % Inputting the value of coefficient matrix 9.11
    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

Add a comment
Know the answer?
Add Answer to:
Write a program in Matlab that solves linear systems of equations using Gauss elimination with pa...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT