kill(all)$

appendix1 :Control :Time dynamics  :secondorder Ode2 (serie) 
peter.vlasschaert@gmail.com, 08/07/2021

ref : →  essentials of process control , example 2.13 pg50
       →  William L.Luyben
        → McGraw-Hill

rem : overdamped system ode2 with a force term.

load packages ,option
==================

load(lrats)$ ratprint:false;

solve : second order : ode2
======================

p1:a2*'diff(x,t,2)+a1*'diff(x,t)+a0*x = b0*f(t);

→ BC : Boundary Conditions :{BC1,BC2}

p1a: x=0;               /*x(0) =0 , t=0 */
p1b:'diff(x,t) =0     /*diff(x(t),t), t=0 */;

rem : BC can one be used on the  final solution ,'see below'

example : 

parameters :{a2,a1,a0,b0}
function       :{f(t)}

a2:1;
a1:5;
a0:6;
b0:1;
f(t):=t;

p2:ev(p1);

rem : D^2+5*D+6=0

→ particular :solution

solution :
=======

n:3;/* number unknows : n+1 */

  => serie 

p3:x:sum(c[i]*t^i,i,0,n);

rem : four unknowns  → need four equations

→ subst

p3a:ev(p2);

→ ev : diff

p3b:expand(ev(p3a,diff));

→ rhs=lhs

rem : coef. lhs t^0

p3c:coeff(lhs(p3b),t,0);

p3c1:makelist(coeff(lhs(p3b),t,i)=coeff(rhs(p3b),t,i),i,0,n);

→ solve equations

 => list of variable

p3d1:listofvars(p3);

p3d2:sort(p3d1);

p3d3:makelist(p3d2[i],i,1,n+1);

 => list of equations

p3d1a:p3c1;

 => result solution

p3d1b:setify(p3d3);

→ solution : equations.

 => solve

p3d2b:flatten(solve(p3d1a,p3d3));

 => see above serie 'p3'

p3d2c:expand(lratsubst(p3d2b,p3));/*particular solution*/

→ Homogeneous solution

use :p2,p1a,p1b

 => init

remvalue(x);

  => Homegeneous ode2

p4d1a:lhs(p2)=0;

rem : quadratic equation :D^2+5*D+6=0, solve =(-2,-3)
                                             x= c1*exp(-2*t)+c2*exp(-3*t)

p4d1b:ode2(p4d1a,x,t);

→ final :x(t),use rhs(p41b) + p3d2c

p4d1c:rhs(p4d1b)+p3d2c;

→ use BC , 'p1a,p1b ' for {%k1,%k2}

=> p1a

p4d1da:subst([t=0],p4d1c)=0;

 => p1b

p4d1b:diff(p4d1c,t);

p4d1b1:subst([t=0],p4d1b)=0;

→ find :

p5a1:listofvars(p4d1b1);

p5b1:setify(p5a1);

→ solution : homogeneous,' use :p4d1c '

p5c1:flatten(solve([p4d1da,p4d1b1],p5a1));

final solution : ode2 with BC
======================
x(t) = particular solution +homogeneous solution

p6:x(t)=subst(p5c1,p4d1c);