kill(all)$

maxima : reaction kinetics:2A=C,C=A+B,version 1.0
peter.vlasschaert@gmail.com,02/01/2023

dx/dt = f(x) , x={A,B,C}, reaction equations

1e) reaction : 2A = C ,forward = k[1],backwards = k[2]
-------------------------------------------------------------------

reaction : r1 ⇒ (2)*A→ C  , k[1] ⇒ forward
reaction : r2 ⇒ C   → 2*A k[2] ⇒ forward

→ dx1/dt = ? x1={A1,B1,C1}

r1 ,r2 → - sign x1 :react, +sign x1:forming,

q1a1:'diff(A1,t) =-(2)*k[1]*A^2+2*k[2]*C;
q1b1:'diff(B1,t) =0;
q1c1:'diff(C1,t) =k[1]*A^2-k[2]*C;

2e) reaction : C = A+B ,forward = k[2],backwards = k[3]
-------------------------------------------------------------------

reaction : r3 ⇒ C→ A+B  , k[3] ⇒ forward
reaction : r4 ⇒ A+B → C, k[4] ⇒ forward

→ dx2/dt = ? x2={A2,B2,C2}

r3 ,r4 → - sign x2 :react, +sign x2:forming,

q1a2:'diff(A2,t) =+k[3]*C-k[4]*A*B;
q1b2:'diff(B2,t) =-k[3]*C+k[4]*A*B;
q1c2:'diff(C2,t) =+k[3]*C+k[4]*A*B;

result :

q1a:q1a1+q1a2;
q1b:q1b1+q1b2;
q1c:q1c1+q1c2;

p1:eq1=-2*k[1]*E+2*k[2]*C+k[3]*C-k[4]*D;
p2:eq2=-k[3]*C+k[4]*D;
p3:eq3 =k[1]*E-k[2]*C-k[3]*C+k[4]*D;

p1a:'diff(A,t)=lhs(q1a);
p1b:'diff(B,t)=lhs(q1b);
p1c:'diff(C,t)=lhs(q1c);

p1a1:'diff(A,t)=rhs(q1a);
p1b1:'diff(B,t)=rhs(q1b);
p1c1:'diff(C,t)=rhs(q1c);

use :

p4:[p1,p2,p3];

p4x1:makelist(lhs(p4[i]),i,1,3);
p4x2:map(lhs,[p1a1,p1b1,p1c1]);
p4x3:map("=",p4x2,p4x1);

p4x4:subst(p4,p4x3);

D →A*B. E →A^2

p4a:coefmatrix([p1,p2,p3],[A,B,C,D,E])*(-1);

p4b:[A,B,C,D,E];

p4f:p4a.transpose(p4b);

--------------------------------------------------------------------------