hw11_p09 - % 'wt' means "write...

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

View Full Document Right Arrow Icon
clc clear c %We'll order the variables to solve for with gas first, then liquid, %counting upward, so x will be [ g1; g2; g3; g4; g5; l1; l2; l3; l4; l5 ] % Qg = 2; Ql = 1; D = 0.8; Cg0 = 100; Cl6 = 10; C for i=1:5 %gas equation if (i > 1) A(i,i-1) = Qg; end A(i,i) = -Qg - D; A(i,i+5) = D; %liquid equation A(i+5,i) = D; A(i+5,i+5) = -Ql - D; if (i < 5) A(i+5,i+6) = Ql; end end e for i=1:10 b(i,1)=0; end e b(1,1) = -Qg*Cg0; b(10,1) = -Ql*Cl6; b x=A\b; x fid4 = fopen('hw11_p09_answer.txt','a');
Background image of page 1
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: % 'wt' means &quot;write text&quot; if (fid4 &lt; 0) error('could not open file &quot;hw11_p09_answer.txt&quot;'); end; e fprintf(fid4, '\ng1 = %10.5f\ng2 = %10.5f\ng3 = %10.5f\ng4 = %10.5f\ng4 = %10.5f\n',. .. x(1), x(2), x(3), x(4),x(5)); fprintf(fid4, '\nl1 = %10.5f\nl2 = %10.5f\nl3 = %10.5f\nl4 = %10.5f\nl4 = %10.5f\n',. .. x(6), x(7), x(8), x(9),x(10)); fclose(fid4);...
View Full Document

Ask a homework question - tutors are online