Gauss - for j = 1(R-1%loop over elements of matrix for i...

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

View Full Document Right Arrow Icon
%%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(a,b) ab = [a,b]; %append colum [b] to matrix [a] [R,C] = size(ab); %determine size of ab if R ~= C-1 fprintf('[A] and [B] matrisies do not match in size'); return end %%Gauss Elimination
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: for j = 1:(R-1) %loop over elements of matrix for i = (j+1):R %defines lower triangle %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

{[ snackBarMessage ]}

Ask a homework question - tutors are online