Matlab Gaussian elimination with partial pivoting

In summary, the conversation is about a person trying to write a program to solve a system of linear algebraic equations using Gaussian elimination. They are having trouble with the pivot and are seeking help on how to find the max_row in the forward elimination step. The code they have provided is based on their professor's pseudo code but they are having trouble translating it. They later share some resources they found that may help with the discussion.
  • #1
NewAlias
2
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
  • #2

1. What is Gaussian elimination with partial pivoting?

Gaussian elimination with partial pivoting is a numerical method used to solve systems of linear equations. It involves transforming a matrix into an upper triangular form by performing row operations, and using pivoting to avoid division by small numbers and reduce rounding errors.

2. How does partial pivoting differ from complete pivoting?

In partial pivoting, only the rows are interchanged during the pivoting process, whereas in complete pivoting, both rows and columns are interchanged. Partial pivoting is simpler and more efficient, but can still lead to some inaccuracies in the final solution.

3. When is Matlab Gaussian elimination with partial pivoting useful?

Matlab Gaussian elimination with partial pivoting is useful when solving systems of linear equations with large matrices, as it can reduce the number of operations needed and minimize round-off errors. It is also helpful when dealing with ill-conditioned matrices, which can cause significant errors when using other methods.

4. What are the advantages of using Matlab for Gaussian elimination with partial pivoting?

Matlab has built-in functions for performing Gaussian elimination with partial pivoting, making it easier and faster to implement. It also allows for efficient handling of large matrices and provides tools for visualizing and analyzing the results.

5. Are there any limitations to using Matlab Gaussian elimination with partial pivoting?

One limitation of using Matlab Gaussian elimination with partial pivoting is that it may not be suitable for systems of equations with a high level of sparsity. In these cases, other methods such as sparse matrix algorithms may be more efficient. Additionally, round-off errors may still occur, especially for ill-conditioned matrices.

Similar threads

  • Calculus and Beyond Homework Help
Replies
1
Views
642
  • Engineering and Comp Sci Homework Help
Replies
3
Views
809
  • Engineering and Comp Sci Homework Help
Replies
1
Views
958
  • Engineering and Comp Sci Homework Help
Replies
6
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
3
Views
942
  • Engineering and Comp Sci Homework Help
Replies
6
Views
3K
  • Engineering and Comp Sci Homework Help
Replies
2
Views
1K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
1K
Back
Top