kill(all)$

ode : part5,intro: ricatti 
peter.vlasschaert@gmail.com,05/02/2017

# Theory Ricatti : ODE (reaction kinetics)

(dy/dx) = p(x)*y^2+q(x)*y+r(x)
Why: Consecutive Reactions and Ricatti
                      k1   k2
reaction kinetics : A -> B -> C
dCA/dt = - k1*CA^n          (1)
dCB/dt = k1*CA^n-k2*CB^m    (2)
dCC/dt = k2*CC^l            (3)
                                              
integer values :  n,m,l 
concentration  : CA,CB,CC

load('contrib_ode)$
assume(t>0,CA>0,CB>0)$

equation (2) n=1,m=2, by 't=0 -> CA=CA0'

eq1: CA = CA0*%e^(-k1*t);
eq2:'diff(CB,t)=k1*CA^1-k2*CB^2;

method1:

eq3:subst(rhs(eq1),CA,eq2);
eq4:part(eq3,2,2);
eq5: lhs(eq3)-eq4=rhs(eq3)-eq4;

eq6:contrib_ode(eq5,CB,t)[1];
method;

check : solution n=1,m=2

eq7:part(eq6,1);
eq8:part(eq6,2);

eq7 : What subst. to use -> linear second order
      equation with nonconstant coefficients.

depends([%u],[t]);

dependencies;

eq9:subst(eq7,eq5);

eq10:ev(part(eq9,1),nouns)=ev(part(eq9,2),nouns);

eq11:part(eq10,1,2);

eq12:eq10*eq11;

dependencies;

eq13:lhs(eq12)-rhs(eq12)=0;

eq14:ratsubst(lhs(eq1),rhs(eq1),eq13);

try to solve:eq12:  d/dt(d%u/dt)=f(t)*%u

eq14:part(eq12,1,1);
eq15:part(eq12,1,2);
eq16:part(eq12,1,3);

convert : 'two' first order ODE's
 Numerical Solution find with 4th Order Runge-Kutta.

eq17:'diff(%u,eq15,eq16-1)=h;
eq18:'diff(rhs(eq17),eq15,eq16-1)=rhs(eq12);