SOLUTIONS+TO+HW3+revised

# SOLUTIONS+TO+HW3+revised - SOLUTIONS TO HW3 Part 1 1 n1...

This preview shows pages 1–2. Sign up to view the full content.

SOLUTIONS TO HW3 Part 1 1. n1 + nc2H4 = 75 n2 + n0 = 25 * for mixing point 2n1+ 2n3+2n4 = 150 2n2+n3+2n4+n5=50 4n1+4n3+2n5=300 n 1 = 75(0.8) = 60 n 3 – 4.5n4 = 0 2.A = [1 0 0 0 0 1 0;0 1 0 0 0 0 1;2 0 2 2 0 0 0;0 2 1 2 1 0 0 ;4 0 4 0 2 0 0 ;1 0 0 0 0 0 0;0 0 1 -4.5 0 0 0] b=[75;25;150;50;300;60;0]; x =[n1,n2,n3,n4,n5,n6,n7] 3) Matlab code for Gaussian Elimination function x = mygehw3_nita3(a,b) n = length(b); x = zeros(size(b)); % Forward elimination step of Gauss elimination for k = 1:n-1 if (abs(a(k,k)) < 1e-12) [val, index] = max(abs(a(k+1:n,k))); tmpA = a(k,:); tmpB = b(k); a(k,:) = a(index+k,:); b(k) = b(index+k); a(index+k,:) = tmpA; b(index+k) = tmpB; end % Eliminate our variable in each row for i = k+1:n % Find pivot fctr = 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) - fctr*a(k,j); end % Don't forget to do that for the b vector as well b(i) = b(i) - fctr*b(k); end end % Backward substitution step if (abs(a(n,n)) < 1e-12) error('Divide by zero error in back substitution.') end % Do back substitution to get x_n x(n) = b(n)/a(n,n); for i = n-1:-1:1 sum = b(i);

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern