Class7 - Ode - Matlab
Class7 - Ode - Matlab
Outline:
1. 2. 3. 4. 5. ODEs Solution Using MATLAB Mixing Process Example Level Process Example Multiple Reactions Process Example Reaction Process with input disturbance
M(t,y)dy/dt = f(t,y)
Step 2: Write an m-file to compute the state derivative
Stiff equations
ode23s: implicit, onestep modified Rosenbrock solver of order 2 ode15s: implicit, multistep numerical differentiation solver of varying order. Solver to try if ode45 fails or is too inefficient
Example 1: Solution
Applying the conservation of mass,
Accumulation = +
You get the differential equation as;
=
identify the independent variable, t, the dependent variable, c and initial value, then we can rewrite the ODE as in explicit form as;
1 = = (, ) 0 = 10
% display solution of C(t) plot(t,C,'r','LineWidth',2) xlabel('time') ylabel('Concentration, C [molg/m^3]') title('Concentration profile, C(t) in CSTR')
Parameter C_in C (t = 0) Q V
Value 50 10 5 100
Example 2: Solution
Thus; ()
() =4
Example 2: Solution (cont.) Q: Derive and solve the differential equation for this process over a 100 second.
%File Name: myODE2.m function dVdt = myODE2(t,V) dVdt = 4;
The initial condition (at t = 0) of volume inside tank is 0 liter %File Name: Example2_Solution.m timeSpan = [0 100]; V_0 = 0; %initial value [t,V] = ode45(@myODE2,timeSpan,V_0) ;%call Matlab solver plot(t,V,b','LineWidth',2) xlabel('time') ylabel(Tank Volume, V *liter+') title(Volume profile, V(t) in infinity tank')
Where k1=1 hr-1 and k2=2 hr-1 and at time t=0, Ca=5mol and Cb=Cc=0mol. Solve the system of equations and plot the change in concentration of each species over time. Select an appropriate time interval for the integration.
Q: Solve the differential mole balance in the CSTR.
Example 3: Solution
The following function file and run file are created to obtain the solution:
%File Name: myODE3.m function dCdt=myODE3(t,C) Ca=C(1), Cb=C(2), Cc=C(3) ; global k1 k2 ; dCdt=[-k1*Ca; k1*Ca - k2*Cb; k2*Cb]
Optional : Ca, Cb and Cc variable must be defined within the same matrix, and so by calling Ca =C(1), Cb = C(2) and Cc = C(3), they are listed as common to matrix c.
A CSTR initially filled with 10mol/L of A is to be started up at specific conditions of inlet concentration, inlet flow rate and outlet flow rate. The CSTR suffer with a disturbance at inlet volumetric flow rate, while the outlet volumetric flow rate is kept constant.
Q: Solve the differential equations in the CSTR and plot the CA(t) and V(t) profile in same Figure.
Example 4: Solution
Identify the dependent and independent variables = , ; = ( ) Differential equations mole balance of A:
d v C i n A (A A k CC C ) A 0 d V t
Differential equation mass balance in CSTR:
d V in o t v vu d t
%display profile subplot(2,1,1);plot(t,X(:,1),'b','LineWidth',2) ylabel('Volume, [liter]') xlabel('time, s') title('Volume profiles, V(t) in CSTR') subplot(2,1,2); plot(t,X(:,2),'r','LineWidth',2) xlabel('time, s') ylabel('Concentration,C_A [mols/liter]') title('Concentration profiles, C(t) in CSTR')