kill(all)$

ode : part1,intro: ricatti 
peter.vlasschaert@gmail.co,03/02/2017

# Theory Ricatti : ODE (reaction kinetics)

(dy/dx) = p(x)*y^2+q(x)*y+r(x)
Why: Consective 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)$

example: (1) n=1,2
y = CA,x = t
n=1 => p(x) = 0,r(x)=0,q(x)<>0
n=2 => q(x) = 0,r(x)=0,p(x)<>0

n=1,equation (1),initial value CA = CA0

eq1:'diff(CA,t) = - k1*CA^1;
assume(CA>0)$
eq2:contrib_ode(eq1,CA,t)[1]$
method;
eq3:subst(CA0,%c,eq2);

n=2,equation (1),initial value CA = CA0

first method :

eq4:'diff(CA,t) = - k1*CA^2;
assume(CA>0)$
eq5:contrib_ode(eq4,CA,t)[1]$
method;
eq6:subst(CA0,%c,eq5);
eq7:factor(solve(eq6,CA)[1]);
eq8:factor(ratsubst(rhs(eq7),CA,eq4));
eq81:part(eq8,1);

check solution for: n=2

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

appendix: command: ev,nouns,part

ev('diff(1/(k1*(t+CA0)),t,1), nouns);

eqa1:'diff(CA,t,1) = - k1*CA^2;

part(eqa1,1,2);

second method : use ode2

ode2('diff(CA,t,1)=-CA^2*k1, CA, t);
subst(CA0,%c,%);
factor(solve(%,CA))[1];

third method :manual:separable

eq12:integrate(CA^(-2), CA);
eq13:-integrate(k1,t);
eq14:eq12=eq13;
eq15:ratsubst(-1/CA,-1/CA,lhs(eq14));
eq16:ratsubst(-1/CA0,-1/CA,lhs(eq14));
eq17:eq15-eq16=eq13;
eq18:solve(eq17,CA)[1];