che310hw3 - Ch E 310 Fall 2008 - Homework 3 Solutions...

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

View Full Document Right Arrow Icon

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

View Full DocumentRight Arrow Icon

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

View Full DocumentRight Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Ch E 310 Fall 2008 - Homework 3 Solutions Problem 1 gauss_pivot.m function [x] = gauss_pivot(A,b) % test for a square matrix A input [rowA,colA] = size(A); rowb = length(b); if rowA ~= colA error( 'the matrix A must be square' ) end % test for size agreement between A and b if rowb ~= colA error( 'the matrix inner dimensions must agree' ) end % initialize solution vector x and augmented matrix A|b x = ones(rowb,1); Ab = A; Ab(:,colA+1) = b; Ud = Ab; % forward elimination: A|b -> U|d for j = 1:colA-1 % loop over necessary columns in A [maxval,k] = max(abs(Ud(j:rowA,j))); % test for max value pr = k+j-1; % identify row with max value if pr ~= j % if the max isn't in the current row, swap rows Ud([j,pr],:) = Ud([pr,j],:); end for i = j+1:rowA % loop over rows > current column Ud(i,:) = Ud(i,:)-(Ud(i,j)/Ud(j,j))*Ud(j,:); % eliminate end end % back substitute the last value directly x(rowA) = Ud(rowA,colA+1)/Ud(rowA,colA); % loop to find the rest of the values from the bottom up for i = rowA-1:-1:1 x(i) = (Ud(i,colA+1)-Ud(i,i+1:colA)*x(i+1:colA))/Ud(i,i); end hw3_1.m A = diag(-6*ones(10,1))+2*ones(10); b = [1 10 2 9 3 8 4 7 5 6]'; x = gauss_pivot(A,b) Output: >> hw3_1 x = 1.1429 -0.3571 0.9762 -0.1905 0.8095 -0.0238 0.6429 0.1429 0.4762 0.3095 Compare this with MATLABs left divide operator: >> A\b ans = 1.1429 -0.3571 0.9762 -0.1905 0.8095 -0.0238 0.6429 0.1429 0.4762 0.3095 The results are the same. Note that using Nave Gauss Elimination would produce divide by zero errors. Pivoting is required to eliminate these errors. (For reference, Cramers Rule does not suffer from these problems.) Problem 2 Matrix A and vector b were generated solving the mass balance equations around each of the eight process units for each of the three species ( A , B , and C ). In addition, there are 12 process specifications, one stoichiometric reaction, and one conversion as additional information. The total number of unknowns will vary depending on how you define the system, however the method I chose was to introduce a reaction extent and use an equation to define the inlet flow of A in stream n 1 . This resulted in a 38 equation, 38 unknown system (see the next page for a typical spreadsheet layout of the coefficient matrix A and constant vector b )....
View Full Document

Page1 / 8

che310hw3 - Ch E 310 Fall 2008 - Homework 3 Solutions...

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

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