HW2 - Part1 functionx=mygehw2_soln(a,b)...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Part 1 function x = mygehw2_soln(a,b) % Made by the ChBE 2120 Fall 2010 class n = length(b); % Forward elimination step of Gauss elimination % Eliminate each variable from x_1 to x_n 1 for k = 1:n 1 if (abs(a(k,k)) < 1e 12) error('Divide by zero error in forward elimination.') end % Eliminate our variable in each row below our current variable number for i = k+1:n % Find our pivot factor = a(i,k)/a(k,k); % For each column in the row being eliminated, subtract the initial % value times the pivot for j = k+1:n a(i,j) = a(i,j) factor*a(k,j); end % Don't forget to do that for the b vector as well b(i) = b(i) factor*b(k);
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
end end % Backward substitution step if (abs(a(n,n)) < 1e 12) error('Divide by zero error in back substitution.') end % Do first back substitution to get x_n x(n) = b(n)/a(n,n); % Go back up each row for i = n 1: 1:1 sum = b(i); % Use all previously found x's to subtract constants from the b value for j = i+1:n sum = sum a(i,j)*x(j); end
Background image of page 2
Image of page 3
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 05/01/2011 for the course CHBE 2120 taught by Professor Gallivan during the Spring '07 term at Georgia Institute of Technology.

Page1 / 4

HW2 - Part1 functionx=mygehw2_soln(a,b)...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online