2
//chemical process (stiff)
5
titlepage(['Integration of ODE:';...
6
'dy1/dt=-0.04*y1 + 1d4*y2*y3';...
7
'dy3/dt= 3d7*y2*y2';...
8
'dy2/dt= -dy1/dt - dy3/dt';...
9
'finding points such that';...
10
'y1=1.e-4 or y3=1.e-2'])
12
// Equations definition
13
deff('[yd]=chem(t,y)',[
14
'yd(1)=-0.04*y(1) + 1d4*y(2)*y(3);';
15
'yd(3)= 3d7*y(2)*y(2);';
16
'yd(2)= -yd(1) - yd(3);'])
19
t=[1.d-5:0.02:.4 0.41:.1:4 40 400 4000 40000 4d5 4d6 4d7 4d8 4d9 4d10];
20
rtol=1.d-4;atol=[1.d-6;1.d-10;1.d-6];
21
y=ode([1;0;0],0,t,rtol,atol,chem);
24
rect=[1.d-5,-0.1,1d11,1.1];
25
plot2d1("oln",t',(diag([1 10000 1])*y)',(1:3),"111",' y1@10000 y2@y3',rect)
27
// Add surface condition
29
deff('[y]=surf(t,x)','y=[x(1)-1.e-4;x(3)-1.e-2]')
32
[y,rd,w,iw]=ode('root',[1;0;0],0,t,rtol,atol,chem,2,surf);rd
36
k=find(rd(1)>t(1:nt-1)&rd(1)<t(2:nt));
38
write(%io(2),[rd(1);y(:,ny)]','(''t='',e10.3,'' y='',3(e10.3,'',''))')
39
plot2d1("oln",rd(1)',(diag([1 10000 1])*y(:,ny))',[-3,-3,-3],"000");
41
[y,rd,w,iw]=ode('root',[1;0;0],rd(1),t(k+1:nt),rtol,atol,chem,2,surf,w,iw);