Gauss_piv

# Gauss_piv - %defines temporary var for pivot line ab(j,:) =...

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

%%Gauss Elimination % This function solves a system of linear equations [a][x] = [b] using the % Gauss Elimination method %%Input Variables %a = matrix coefficients %b = Right-hend-side column vector of constants %x = column vector with the solution % function x = Gauss_piv(a,b) f ab = [a,b]; %append colum [b] to matrix [a] [R,C] = size(ab); %determine size of ab %%Gauss Elimination for j = 1:(R-1) %loop over elements of matrix %%pivoting section begins if ab(j,j)==0 for k = (j+1):R %defines lower triangle if ab(k,j) ~= 0 %selects very small numbers in pivot position abTemp = ab(j,:);
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: %defines temporary var for pivot line ab(j,:) = ab(k,:); %renames another line to be the pivot line ab(k,:) = abTemp; %sets the temp line to position of moved line break end end end for i = j+1:R %subtracts lines times multiple of Pivot equation ab(i,j:C) = ab(i,j:C) - ab(i,j)/ab(j,j)*ab(j,j:C); end end %%Back Substitution x = zeros(R,1); x(R)=ab(R,C)/ab(R,R); %Calculates last element of x for i = R - 1:-1:1 %loop that runs backwards %substitutes values of x and [a'] and [b'] x(i) = (ab(i,C) - ab(i,i + 1:R)*x(i+1:R))/ab(i,i); end...
View Full Document

## This note was uploaded on 04/01/2011 for the course ECM 006 taught by Professor Higgins during the Spring '07 term at UC Davis.

Ask a homework question - tutors are online