Question

In: Computer Science

Write a MATLAB function function = pivGauss(.....) to solve linear equations using Gaussian Elimination with Partial...

Write a MATLAB function function = pivGauss(.....) to solve linear equations using Gaussian Elimination with Partial Pivoting.

You'll need to employ Nested Loops.

Thank you !

Solutions

Expert Solution

The algorithm to solves a linear system Ax=b using the Gaussian elimination method with Partial pivoting is as following :


1) Initialize a permutation vector r = [1, 2,...,n] where r(i) corresponds to row i in A.
2) For k = 1,...,n-1 find the largest (in absolute value) element among a(r(k),k),a(r(k+1),k),...,a(r(n),k).
3) Assume r(j,k) is the largest element. Switch r(j) and r(k).
4) For i=1,...,k-1,k+1,...,n calculates:
zeta = a(r(i),k) / a(r(k),k)
5) For j=k,...,n calculate:
a(r(i),j)=a(r(i),j)-a(r(k),j)*zeta
b(r(i)) = b(r(i))-b(r(k))*zeta
6) Steps 1 through 6 has effectively diagonalized A.
7) Each element in the solution vector is:
x(r(i)) = b(i)/a(i,i);

MATLAB code :-

function x = GAUSS_ELIM(A, b)

%% Create permutation vector

n = size(A, 1); % Size of input matrix

r = zeros(n, 1); % Initialize permutation vector

for i = 1 : 1 : n

r(i) = i;

end

%% Apply Gaussian elimination and rearrange permutation vector

x = zeros(n, 1); % Initialize solution vector

for k = 1 : 1 : n % Go through each element in permutation vector

% Compare each element in r(k)th column for the max

max = abs(A(r(k), r(k)));

max_pos = k;

for l = k : 1 : n

if abs(A(r(l), r(k))) > max

max = abs(A(r(l), r(k)));

max_pos = l;

end

end

% Switch the kth r-vector element with max r-vector element

temp_r = r;

r(k) = temp_r(max_pos);

r(max_pos) = temp_r(k);

% Eliminate A-vector elements in r(k)th column below r(k)th row

for i = 1 : 1 : n

if i ~= k

zeta = A(r(i), k) / A(r(k), k);

for j = k : 1 : n

A(r(i), j) = A(r(i), j) - A(r(k), j) * zeta;

end

b(r(i)) = b(r(i)) - b(r(k)) * zeta;

end

end

end

% Compute the solution frpm the diagonalized A-matrix

for i = 1 : 1 : n

x(i) = b(r(i)) / A(r(i), i);

end

end


Related Solutions

When using Gaussian elimination to solve a system of linear equations, how can you recognize that...
When using Gaussian elimination to solve a system of linear equations, how can you recognize that the system has no solution?
Write a function in Python that solves the linear system ??=? using Gaussian Elimination, taking ?,?...
Write a function in Python that solves the linear system ??=? using Gaussian Elimination, taking ?,? as input. The function should have two phases: the elimination phase, and the back substitution phase. You can use numpy library.
in parts a and b use gaussian elimination to solve the system of linear equations. show...
in parts a and b use gaussian elimination to solve the system of linear equations. show all algebraic steps. a. x1 + x2 + x3 = 2 x1 - x3 = -2 2x2 + x3 = -1 b. x1 + x2 + x3 = 3 3x1 + 4x2 + 2x3 = 4 4x1 + 5x2 + 3x3 = 7 2x1 + 3x2 + x3 = 1
Using Matlab's FUNCTION FILE Solve this system of equations using Gauss Elimination in MATLAB by writing...
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!
Solve the following system of equations using Gaussian or​ Gauss-Jordan elimination. w + x + y...
Solve the following system of equations using Gaussian or​ Gauss-Jordan elimination. w + x + y + z = -2 2w +2x - 2y - 2z = -12 3w - 2x + 2y + z = 4 w - x + 7y + 3z = 4
1. Solve linear system using Gaussian elimination a) x1 + 2x2 + x3 = 2 -x1...
1. Solve linear system using Gaussian elimination a) x1 + 2x2 + x3 = 2 -x1 − 3x2 + 2x3 = -3   x1 − 6x2 + 3x3 = -6 b) -2b + 2c = 10 3a + 12b -3c = -6 6a + 18b + 0c = 19 c) 4x - 1y + 4z + 3t = 5 1x - 4z + 6t = 7 5x - 5y + 1z + 2t = -5 4x + 1y + 3z +...
Write a function to solve a system of linear equations of the form Ax= b using...
Write a function to solve a system of linear equations of the form Ax= b using the iterative Gauss-Seidel method. You are free to use any basic MATLAB operation to implement the algorithm (i.e. you may use any combination of loops, indexing, math, etc.), but avoid “built-in” solution methods — you would not be allowed to use the GaussSeidel function if such a function existed. The function must also test for a number of possible issues. If an issue is...
1) Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no...
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.) 3y + 2z = 1 2x − y − 3z = 4 2x + 2y − z = 5 (x, y, z) = 2) Solve the system of linear equations, using the Gauss-Jordan elimination method. (If there is no solution, enter NO SOLUTION....
Solve the system using either Gaussian elimination with back-substitution or Gauss-Jordan elimination. (If there is no...
Solve the system using either Gaussian elimination with back-substitution or Gauss-Jordan elimination. (If there is no solution, enter NO SOLUTION. If the system has an infinite number of solutions, express x, y, z, and w in terms of the parameters t and s.) 4x + 12y − 7z − 20w = 20 3x + 9y − 5z − 28w = 36 (x, y, z, w) = ( ) *Last person who solved this got it wrong
Implement Gaussian elimination(with partial pivoting) and backward substitu- tion in MATLAB. You need to submit your...
Implement Gaussian elimination(with partial pivoting) and backward substitu- tion in MATLAB. You need to submit your code on moodle page.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT