GaussPivot

# GaussPivot - If the values along the first non-singleton...

This preview shows page 1. Sign up to view the full content.

function x=GaussPivot(A,b) %{ Problem 9.7 check GaussPivot: Gauss elimination Pivoting x=GaussPivot(A,b): Gauss elimination with pivoting. input: A=coefficient matrix b=right hand side vector output: x=solution vector %} [m,n]=size(A); if m~=n, error('matrix A must be squared'); end nb=n+1; Aug=[A b]; %forward elimination for k=1:n-1 %Partial Pivoting [big,i]=max(abs(Aug(k:n,k))); %{ [Y,I] = MAX(X) returns the indices of the maximum values in vector I.
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: If the values along the first non-singleton dimension contain more than one maximal element, the index of the first one is returned. %} ipr=i+k-1; if ipr~=k Aug([k,ipr],:)=Aug([ipr,k],:); end for i=k+1:n factor=Aug(i,k)/Aug(k,k); Aug(i,k:nb)=Aug(i,k:nb)-factor*Aug(k,k:nb); end end %back substitution x=zeros(n,1); x(n)=Aug(n,nb)/Aug(n,n); for i=n-1:-1:1 x(i)=(Aug(i,nb)-Aug(i,i+1:n)*x(i+1:n))/Aug(i,i); end...
View Full Document

{[ snackBarMessage ]}

Ask a homework question - tutors are online