Matlab Gaussian elimination with partial pivoting

Click For Summary
SUMMARY

This discussion focuses on implementing Gaussian elimination with partial pivoting in MATLAB. The user seeks assistance in determining the maximum row for pivoting during the forward elimination process. The provided MATLAB function, Lab7gauss, outlines the steps for solving a system of linear equations represented as Ax=b. Key resources shared include a tutorial from Delft Stack and a MATLAB Central file exchange link for Gaussian elimination with partial pivoting.

PREREQUISITES
  • Understanding of Gaussian elimination
  • Familiarity with MATLAB programming
  • Knowledge of linear algebra concepts
  • Experience with matrix operations in MATLAB
NEXT STEPS
  • Study the implementation of partial pivoting in MATLAB
  • Learn about the max function in MATLAB for row selection
  • Explore back substitution techniques in Gaussian elimination
  • Review the provided resources on MATLAB Central for additional examples
USEFUL FOR

Students and educators in mathematics or engineering fields, MATLAB programmers, and anyone looking to implement Gaussian elimination with partial pivoting in their projects.

NewAlias
Messages
1
Reaction score
0

Homework Statement


Hi all, I'm writing a program to solve a system of linear algebraic equations using the method of Gaussian elimination. The only thing I can't figure out is how to perform the actual pivot.
In the %Forward elimination nest, I can't figure out how I am supposed to find the max_row. Is it just any row that has the maximum value or is it specific to the pivot row? Most of the function is translated from pseudo code posted by my professor and the only part I can't translate is how to get the max_row. Any help would be greatly appreciated!

Homework Equations


Matlab:
function x=Lab7gauss(A,b)
%Solves a given system of linear equations Ax=b using the Gauss Elimination
%method. Equations in format Ax=b.%Function code
A=input('Enter the coefficient matrix: ');
b=input('Enter the right hand side vector b: ');
[m,n]=size(A);
if m~=n
    error('Coefficient matrix A must be square')
end
Ab=[A,b];
nc=n+1;

%Forward elimination

for p=1:n-1     %p is current pivot row
    %partial pivoting
    max_row=max(A);
    if max_row~=p
        p=max_row;
        max_row=p;
    end
    for i=p+1:n     %operate on all rows below pivot
        factor = Ab(i,p)/Ab(p,p);
        for c=p:nc
        Ab(i,c)=Ab(i,c)-factor*Ab(p,c);
        end
    end
end

%back substitution
x(n)=Ab(n,nc)/Ab(n,n);
for k=n-1:-1:1
    x(k)=Ab(k,nc);
    for j=k+1:n
        x(k)=x(k)-Ab(k,j)*x(j);
    end
    x(k)=x(k)/Ab(k,k);
end
[C,I]=max(A)
 
Last edited by a moderator:
Physics news on Phys.org

Similar threads

  • · Replies 2 ·
Replies
2
Views
2K
Replies
1
Views
2K
  • · Replies 3 ·
Replies
3
Views
2K
Replies
2
Views
2K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 6 ·
Replies
6
Views
3K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 1 ·
Replies
1
Views
3K
Replies
14
Views
2K
  • · Replies 1 ·
Replies
1
Views
4K