kill(all)$

maxima : nonlinear tank height(=elementary principles),version 1,0
peter.vlasschaert@gmail.com, 23/02/2022

load packages : 

load(lrats)$ /* see code below how to use*/

book:

ref : process dynamics ,modeling,analysis and simulation
       (B.Wayne Bequette, Prentice Hall)

Nonlinear Tank Height
==================

→ principles

first principle : elementary mechanics
-----------------------------------------------
v = velocity [m/s]
a = acceleration ( = constant : gravitation , g =9.81m/s^2)
s = distance ( = height of tank ( =reservoir) ) [m]
t = time [s]

→ dependencies: variables

depends([v,s],t);

reason : a "no dependencies in this problem"7
rem : v = ds/dt =[m/s] ,a = dv/dt = [m/s^2] 

p1:diff(v,t) = a;

intial condition : @t = 0 {v=v0, s=s0}

→ step 1 : integration ( variables , separable)
dv/dt =a→ dv = a*dt

p2: v-v0 = a*(t-0);

p2a:solve(p2,v);

→ step 2: integration ( variables , separable)
v = ds/dt → ds = v*dt

listofvars(p2a);

p3: s-s0 ='integrate(rhs(p2a[1]),t,0,t);

p3a:expand(ev(p3,integrate));

p3b:expand(solve(p3a,s)[1]);

p3b : "result : elementary mechanics , highschool level"

also : suppose  v0=0,s0=0 ,@t=0 into p3b

p3c:subst([v0=0,s0=0],p3b);

second principles: mass balance (= system)
--------------------------------------------------------------
IN          = input
OUT       = output
ACCUM  = accumulation (= differential part )
__________________________________________ 
no : chemical reaction
__________________________________________
dM/dt =[mass/time] =[kg/s]
dM/dt =[density*flowrate]  =[kg/m^3*m^3/s]          (1)
dM/dt =[density*area*velocity]=[kg/m^3*m^2*m/s] (2)
V = volume = A*h = area*height =[m^2*m] 
M = ρ*V ( = problem ρ =constant) =[kg/m^3*m^3]
__________________________________________
M = mass, ρ =density

p4: IN = OUT +ACCUM;
p4b:solve(p4,ACCUM)[1];

solve : problem

→ first step : nonlinear term into differential eaquation

use ; first principle ,p3c , s= h (= height of the Tank)

p5:subst ([s=h],p3c);

solve : p5 for t , t>0 , absolute value : time

p5a:lhs(solve(p5,t)[1])=abs(rhs(solve(p5,t)[1]));

assume(h>0,a>0);

subst : p5a into p2a

p5b:expand(subst(p5a,p2a)[1]);

subst :v0 =0 ,see : above

p5c:subst([v0=0],p5b);

find : coef sqr(h)→ maxima : sqrt, set =β

p5c1:β =coeff(rhs(p5c),sqrt(h));

p5c2:reverse(p5c1);

find : expression : velocity =v ,p5c use p5c2

p5d: lratsubst([p5c2],p5c);/*[m/s]*/

use packages : lratsubst , l =list ,rat = rational

second step : lhs ( = differential equation)

use : p4b, lhs

p6: lhs(p4b) ='diff(M,t);

' diff protect against evaluation

see above : equations 

p6a:M=ρ*V;

p6b:subst([p6a],p6);

p6c:V=A*h;

p6d:subst([p6c],p6b);

third step : rhs(differential equation)

a) IN = input 

rem : flow rate F[i] , i = input, use (1)

use : p4b

p7:part(rhs(p4b),1)= F[i]*ρ;

b) Out = output 

use : rhs(p5d), use (2)

p7a:part(rhs(p4b),2,1)=v*A*ρ;

p7b:subst([p5d],p7a);

fourth step : final differential equation 

use : {p6d,p7,p7b} into p4b

p8:subst([p6d,p7,p7b],p4b);

h : depends , h =h(t)

depends(h,t);

p8a:ev(p8,nouns);

use : p8a /A*ρ

p8b:expand(p8a/(A*ρ));

ref : book , dh/dt = F[i]/A-β/A√(h)
reason : other definition for β

solve : ode2,nonlinear differential equation,full

use : p8b , h = h(t) ? no solution, when in flow :F[i]≠ 0

p9:ode2(p8b,h,t);

use : p8b , h = h(t) ? solution, when in flow :F[i]= 0

p9a: subst([F[i]=0],p8b);

p9b:ode2(p9a,h,t);

p9c1:sort(listofvars(p9b));

find %c @t=0, h =h0, IC condition
IC = initial condition

p9c: subst([h=h0,t=0],p9b);

p9c1:reverse(p9c);

subst: p9c into p9b

p9d:subst([p9c1],p9b);

find : h=h(t), when no input in the Tank

assume(h0>0);

→ solve : sqrt(h)

p9e: solve(p9d,sqrt(h));

→ both sides : power 2

p9f:(p9e)^2;

final : result , F[i] =0 , into p8b

p9g:p9f[1];

reason : different ,definition of β, in the book.
β = parameter