diff options
Diffstat (limited to '527/CH9/EX9.20/9_20exam.sce')
-rwxr-xr-x | 527/CH9/EX9.20/9_20exam.sce | 111 |
1 files changed, 111 insertions, 0 deletions
diff --git a/527/CH9/EX9.20/9_20exam.sce b/527/CH9/EX9.20/9_20exam.sce new file mode 100755 index 000000000..9d9d89912 --- /dev/null +++ b/527/CH9/EX9.20/9_20exam.sce @@ -0,0 +1,111 @@ +//Engineering and Chemical Thermodynamics
+//Example 9.20
+//Page no :476
+
+clear ; clc
+//Given
+del_g_0_f_CH4 = -2.057 ; //[J/mol]
+del_g_0_f_H2O = -192.713 ; //[J/mol]
+del_g_0_f_CO = -182.494 ; //[J/mol]
+del_g_0_f_CO2 = -203.595 ; //[J/mol]
+del_g_0_f_H2 = 0 ; //[J/mol]
+R = 8.314 ;
+T = 800 ; //[K]
+w = 1 / (R * T) ;
+function Z920 = F920(R)
+ m = R(1) ,
+ n = R(2) ,
+ o = R(3) ,
+ a = R(4), // n_CH4
+ b = R(5), // n_H2O
+ c = R(6), // n_H2
+ d = R(7), // n_CO
+ e = R(8), // n_CO2
+
+Z920(1) = a + d + e - 1 ;
+Z920(2) = 4 * a + 2 * b + 2 * c - 12 ;
+Z920(3) = b + d + 2 * e - 4 ;
+Z920(4) = del_g_0_f_CH4 * w + log(a) - log(a + b + c + d + e) + m + 4 * o ;
+Z920(5) = del_g_0_f_H2O * w + log(b) - log(a + b + c + d + e) + 2 * o + n ;
+Z920(6) = del_g_0_f_H2 * w + log(c)- log(a + b + c + d + e) + 2 * o ;
+Z920(7) = del_g_0_f_CO * w + log(d) - log(a + b + c + d + e) + m + n ;
+Z920(8) = del_g_0_f_CO2 * w + log(e) - log(a + b + c + d + e) + m + 2 * n ;
+
+endfunction ;
+
+
+function [J] = jacob(X)
+
+ m = X(1) ,
+ n = X(2) ,
+ o = X(3) ,
+ a = X(4), // n_CH4
+ b = X(5), // n_H2O
+ c = X(6), // n_H2
+ d = X(7), // n_CO
+ e = X(8), // n_CO
+
+ J(1,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+b+c+d+e) ;
+ J(8,5) = -1/(a+b+c+d+e) ; J(8,6) = -1/(a+b+c+d+e) ;
+ J(8,7) = -1/(a+b+c+d+e) ; J(8,8) = (a+b+c+d)/(e*(a+b+c+d+e)) ;
+endfunction
+
+// We will use newton Raphson Method to solve the set of equations.
+// Reference : www.infoclearinghouse.com/files/scilab/scilab6a.pdf
+
+function [x] = newtonm(x0,f,J)
+ N = 1000 ;
+ epsilon = 1*10^-10 ;
+ maxval = 1000 ;
+ xx = x0 ;
+
+ while(N>0)
+ JJ = J(xx)
+ // disp(abs(det(JJ)))
+ if abs(det(JJ))<epsilon then
+ error('newtonm-Jacobian is singular- try new x0')
+ abort ;
+ end ;
+ xn = xx -inv(JJ) * f(xx) ;
+ // disp(abs(f(xn)))
+ if abs(f(xn))<epsilon then
+ x = xn ;
+ // disp(100-N) ;
+ // disp((x))
+ return(x) ;
+ end ;
+
+ if abs(f(xn))>maxval then
+ disp(1000-N) ;
+ error('Solution diverges') ;
+ abrot ;
+ end ;
+ N = N -1 ;
+ xx = xn ;
+ end ;
+endfunction ;
+
+x1 = [1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ; 1 ] ; // Initial guess .
+
+[z] = newtonm(x1,F920,jacob) ;
+
+disp("Example 9.20 Page no:476") ;
+printf("\n\n L_c/RT = %f ,\n L_o/RT = %f ,\n L_h/RT = %f ,\n n_CH4 = %f ,\n n_H2O = %f ,\n n_H2 = %f ,\n n_CO = %f ,\n n_CO2 = %f",z(1),z(2),z(3),z(4),z(5),z(6),z(7),z(8)) ;
+//The solutions given in the text book does not satisfy E9.20D, E9.20E,
+// E9.20F and so on .
\ No newline at end of file |