|
|
EDA365欢迎您登录!
您需要 登录 才可以下载或查看,没有帐号?注册
x
代码如下;/ o- j% S! s8 D, P5 v: H
function Kinetics4, V; _0 W. w; E6 O2 \; p+ A
clear all, a9 ]3 c3 z3 h4 q1 Y3 |6 j
clc9 z% [" {9 Y y5 Q( b- H+ ~
k0 = [2.159*10^8 4.734*10^6 174686 149892 0.99 0.7 0.5 0.78];%参数初值,其实是不知道的
, A U* e- d; x; Plb = [-inf -inf -inf -inf -inf -inf -inf -inf]; % 参数下限/ N0 t# |% O) Z: I/ G
ub = [inf inf inf inf inf inf inf inf]; % 参数上限
" L0 e& v# w, [7 }$ {u0 = [0,0]; %y初值6 l- |. ~7 j6 @5 J R( }
a=[0;0.06680583;0.192617534;0.301693824;0.419783943;0.527041818;0.598345407;0.65055108;0.6876854;0;0.0295189820000000;0.0760025420000000;0.143652564000000;0.303435528000000;0.419715167000000;0.525496977000000;0.565069320000000;0.743536298000000;0;0.0411725930000000;0.0608472370000000;0.0986899250000000;0.241132264000000;0.324760943000000;0.466871464000000;0.531688237000000;0.683614442000000];/ d) K! w$ q" L5 z; W; A0 d* a; e
b=[0;0.2378;0.3288;0.3556;0.39;0.3877;0.3766;0.3580;0.3384;0;0.1373;0.2123;0.2755;0.3561;0.3549;0.3475;0.3486;0.2518;0;0.115879961000000;0.178182567000000;0.219982937000000;0.315058656000000;0.339244190000000;0.348664305000000;0.351963292000000;0.313743618000000];; `4 A* S; D1 ^( B5 o3 b
yexp=[a,b];
A6 ?. Y T) |% }% 使用函数lsqnonlin()进行参数估计
; O3 Z8 @, y6 k. y7 u5 P. ]2 c V
[k,resnorm,residual,exitflag,output,lambda,jacobian] = ...
* }- a3 }" l) T% E. C" t/ c lsqnonlin(@ObjFunc4LNL,k0,lb,ub,[],u0,yexp);
# L% Z0 B5 f$ X( Uci = nlparci(k,residual,jacobian); }% e9 Q8 Y" {$ @0 Z5 A
fprintf('\tk1 = %.4f ± %.4f\n',k(1),ci(1,2)-k(1))1 o+ X/ N2 @2 K: n, k
fprintf('\tk2 = %.4f ± %.4f\n',k(2),ci(2,2)-k(2))
/ W$ z% H7 K7 T% q; _1 Z: U% Rfprintf('\tk3 = %.4f ± %.4f\n',k(3),ci(3,2)-k(3)) & h$ T- A3 y! c$ D( B0 H B
fprintf('\tk4 = %.4f ± %.4f\n',k(4),ci(4,2)-k(4))
! \. M$ y9 k7 ?- c, S% _# dfprintf('\tk5 = %.4f ± %.4f\n',k(5),ci(5,2)-k(5))
; k" p! F4 w) L/ Dfprintf('\tk6 = %.4f ± %.4f\n',k(6),ci(6,2)-k(6))2 Y* k' a# B \/ J
fprintf('\tk7 = %.4f ± %.4f\n',k(7),ci(7,2)-k(7))8 F9 y9 v# ], N) {* P. A
fprintf('\tk8 = %.4f ± %.4f\n',k(8),ci(8,2)-k(8))
/ e: }9 A0 K- i2 Zfprintf(' The sum of the squares is: %.1e\n\n',resnorm)
; N) E% z4 i( pfprintf('\n\n使用函数lsqnonlin()估计得到的参数值为:\n')6 d' g6 u+ B" x2 [4 `5 D
%目标函数
# h1 l6 _% e2 ]6 F; h1 ufunction f =ObjFunc4LNL(k,u0,yexp)
6 d, C0 y% V% h* A- D: c+ }' B; Qglobal theta Pt Ac R T Fa02 a2 a0 l o2 D4 f
theta=zeros(5,1);
9 F7 i% e7 b, V9 l: R- |" ^; cr0= 1.24*10^-3; % Outer diameter of the membrane, [m]( d0 C) m. C4 `* W5 ^9 ?4 w/ y
ri= 9.4*10^-4;% Inner diameter of the membrane, [m]
7 d% S# b5 Q7 `4 f- E* {5 w& _r=(r0-ri)/log(r0/ri);% equivalent diameter ,[m]
# C/ H# K9 ^0 r* O) kPi=3.14159;1 J) \* M! S" ]$ L1 a+ U! M1 e
L=0.05;% membrane length,[m]8 _. T4 P9 L; r. X
Ac=Pi*r*L;% membrane area [m^2] F: z3 b6 g5 g6 J% ?% F
R=8.314; % [J/K.mol]- S; M6 Z" U x9 m3 ~. Z# p
Pt=101.325;
* n! L* s7 w+ M3 s( T5 R, VFtot=[2.678*10^-2;2.678*10^-2*1.5;2.678*10^-2*2];
* y/ O* S1 L- \: p4 s- QKmax=length(Ftot);
8 t9 o. c; ^% \: r
; j! j' h8 o! Z& X2 aT0=600+273;% Inlet temperature [K]. r, U8 H4 H- N$ k
nmax=9;
+ M& }$ W) l* @6 `( `! b( V$ IX1=zeros(nmax,Kmax);X2=zeros(nmax,Kmax);
. p' R& _4 C5 B% P7 P7 y! sfor K=1:Kmax
' t8 r# ]$ W1 [" a1 ]( f9 O9 |Fa0=Ftot(K); % If Pt is the parameter/Matrix/ z! B& l8 t# z* K' ?, V
%Pt=Pt0+(k-1)*1; % If Pt is an axis1 u: K% k3 c/ v2 g
%L=Lsize(k); % If L is the parameter/Matrix
0 }" ^& }) Q; w% {8 Y7 c8 `%theta(2)=H2Oratio+(k-1)*1; % If m is the parameter/Matrix
" _/ Z5 c* C b, k1 {theta(2)=3; % F0(H2O)/F0(CH4)
( |" O- `' D$ R* ~1 z5 `theta(3)=0; % F0(CO)/F0(CH4)
( g) \ ^5 j; K |& C' etheta(4)=0; % F0(CO2)/F0(CH4)2 ]& \7 d {5 E$ X
theta(5)=0; % F0(H2)/F0(CH4)
2 p# y8 z5 H: |2 ~* i# gfor n=1:nmax y' f5 Y& e% Q$ \1 o
%delta=delta0+(n-1)*1e-6; % If delta is the parameter/Matrix
* r3 h- j' V6 R/ k%rit=r0+delta; % inner tube radius [m]
! g& q6 ]1 ]$ U. P) X$ [%sweep=s0+(n-1); % If sweep is the parameter/Matrix5 P9 {1 v" C4 M( h$ v4 E
%T=T0; % If T is a constant' O7 [+ i/ O f* b8 P, k
T=T0+(n-1)*50; Z( L7 B9 K* I% p1 M
ksispan=(0:0.1:1); % precision
2 q R6 v( L. W: J6 C0 n0 X[ksi,S1]=ode23s(@KineticEqs,ksispan,u0,[],k); % PBR reactor: P1 H' N Y) l7 Y8 w% l6 d# U
X1(n,Kmax)=real(S1(end,1)); % methane finale conversion
, |) \: ^$ x2 b5 x8 SX2(n,Kmax)=real(S1(end,2)); % carbon dioxide finale conversion
8 L& h1 L) W; q3 aend
9 [# y0 I' @. \& S; ^) g) ?0 Nend
% }7 i1 s/ l; o0 Lf1=X1(n,Kmax)-yexp(:,1);1 F( {4 [6 x# t Q* F
f2=X2(n,Kmax)-yexp(:,2);# X! a! ~; x; u q
f=[f1;f2];
8 H" V/ Z* x) A: j) \( W* L. u% V%T0=T0-273.15;T=T-273.15; % Temperature expressed in Celsius
4 A' Z1 r0 y8 B) y2 t0 ^- G%Tspan=(T0:1:T);( G" V$ t# R* w, L
%Pspan=(Pt0:1 t);" n5 {$ @- M7 U0 ]( R+ S2 K( U
%DSPan=(delta0*1e6:1:delta*1e6);
( N& [4 t1 T2 @; L0 A1 A4 ]( a%Sspan=(s0:1:sweep);$ F& e, j* e$ ~ l; Z
%D(:, =X3(:, -X1(:, ; % Delta = XCH4(MR) - XCH4(PBR)
7 {6 [# s, B7 C _3 n) a/ `% s8 I/ X5 L, k0 Q& q: ~: g. H" Z4 a
function diff=KineticEqs(ksi,u,k)
: P$ f( M5 r) T# a% j4 K# [) P4 Bglobal theta Pt Ac Fa0 T R
2 T2 K, @0 V J# R# H# _: ]S=Pt/(1+theta(2)+theta(3)+theta(4)+theta(5)+2*(u(1)+u(2)));
5 S8 M7 q/ N. E7 P+ x F8 TP(1)=(1-u(1)-u(2))*S;
7 B3 y4 N# T5 Q a2 NP(2)=(theta(2)-u(1)-2*u(2))*S;
7 D' C: B% K/ {; }* F/ }1 C) G8 G) ~P(3)=(theta(3)+u(1))*S;" r4 w' O! }, ^- r* }
P(4)=(theta(4)+u(2))*S;
# S- O- ~& y8 Z- D; j4 aP(5)=(theta(5)+3*(u(1)+u(2))+u(2))*S;# I0 b! ]% S0 u1 `6 O+ y, w
% Differential System
/ _: G8 a% u1 Q8 o1 S' Sdiff1=Ac/Fa0*k(1)*exp(-k(3)/R/T)*P(1)^k(5)*P(2)^k(7);
1 v/ @$ O! m" w4 i3 B( adiff2=Ac/Fa0*k(2)*exp(-k(4)/R/T)*P(1)^k(6)*P(2)^k(8);" s; y$ R) S; ?9 T- F
diff=[diff1 diff2]';: b& s8 K3 ~# G2 s9 a7 r
: S. J+ } w, u5 C- W1 T运行结果:: e, I% T0 e K" P" x
In nlparci (line 104)9 W% }, [$ H9 _
In Kinetics4 (line 15)1 j3 m6 b8 t; C* e6 T. T3 f
警告: 矩阵为奇异工作精度。8 M- \0 C( I0 V" \: |3 d" `
k1 = 215900000.0000 ± NaN" m( t0 T6 Y/ W2 d
k2 = 4734000.0000 ± NaN
, ^+ i$ @4 X6 D& ?$ i k3 = 174686.0000 ± NaN
/ `! ~/ o& V. w( e2 e k4 = 149892.0000 ± NaN; W' N; K* p5 P4 L
k5 = 1.2381 ± NaN
! @6 T x" Q/ ~7 v2 l- g9 B3 {: j k6 = 0.5426 ± NaN6 j9 K3 Q" [7 R: H$ Y# R# Q& N" d& L
k7 = -0.3426 ± NaN
4 D/ t$ C2 R, ]- `1 y& U k8 = 0.4455 ± NaN
8 e2 _8 L3 \; N: y The sum of the squares is: 2.0e+00: O7 O g4 p& b! K2 j* v- P
|
|