Professional Documents
Culture Documents
K1 A + B C K2 C + B D
dC A dt dC B dt dC C dt dC D dt
= k 1C A C B = k 1C A C B k 2 C c C B = k 1C A C B k 2 C c C B = k 2C cC B
clc clear all cA0 = 1; cB0 = 2; x0 = [cA0; cB0; 0; 0]; k1 = 1; k2 = 0.5; % set fixed parameters % tend = 10; % set end time % call ode45 to perform simulation [t x] = ode45(@batchreactor,[0 [t,x] ode45(@batchreactor [0 10] 10], x0); % plot results figure plot(t,x(:,1),'+r') hold on; plot(t,x(:,2),'Og') plot(t,x(:,3),'*b') plot(t,x(:,4),'xm') xlabel('time xlabel( time t') t) ylabel('concentration c(t)');
function f = batchreactor(t,x); % f = zeros(size(x)); f = zeros(4,1); % extract concentrations from state vector cA = x(1); cB = x(2); cC = x(3); cD = x(4); % compute rates of each reaction k1 = 1; k2 = 0.5; % set fixed parameters r1 = k1*cA*cB; r2 = k2*cC*cB; f(1) = -r1; % mole balance on A f(2) = -r1 -r2; % mole balance on B f(3) = r1 - r2; % mole balance on C f(4) = r2; % mole balance on D
dC A dt dC B dt dC c dt dC D dt dC E dt dC F dt
= k 21C A + k12 C B + k13 C C k 31C A = k 21C A k12 C B k 32 C B + k 23C c = k 43 C C + k 34 C D k13C C + k 31C A + k 32 C B k 23C c = + k 46 C F k 64 C D + k 45 C E k 54 C D + k 43C C k 34 C D = k 45 C E + k 54 C D + k 56 C F k 65 C E = k 46 C F + k 64 C D + k 65 C E k 56 C F
Initial Conditions : A0= 1.0 mol/L, B0 =0, C0 =0, D0 =0, E0= 1.0 1 0 mol/L, l/L F0 =0 0
clc clear all cA0 = 1; % Giving intial condtions cB0 = 0; cC0 = 0; cD0 D0 = 0 0; cE0 = 1; cF0 = 0; x0 = [ [cA0; ; cB0; ; cC0; ; cD0; ; cE0; ; cF0]; ]; [t,x] = ode45(@reaction,[0 20], x0);
function f = reaction(t,x); % this is to define function (which we'll call later) f = zeros(6,1); %our answer/ question has 6 components cA = x(1); cB = x(2); cC = x(3); cD = x(4); cE=x(5); cF=x(6); % allocating space for different components k12=0.1; k13=0.05; %definining constanct variable k21=0.2; k23=0.05; k31=0.1; k32=0.1; k34=0.1; k43=0.2; k45=0.1; k46=0.2; k54=0.05; k56=0.1; k64=0.2; k65=0.1; f(1) = -k21*cA + k12*cB - k31*cA + k13*cC; %since we have 6 unknown 6 efollowing equation to solve them(dcA/ct ; dcB/dt.. till dcF/dt) f(2) = -(k12+k32)*cB + k21*cA + k23*cC; f(3) = -(k13+k23+k43)*cC+ k31*cA +k32*cB +k34*cD; f(4) = -(k34+k54+k64)*cD + k43*cC+k45*cE+k46*cF; f(5) = -(k45+k65)*cE + k54*cD +k56*cF f(6) = -(k46+k56)*cF + k64*cD+ k65*cE
Consider a series of 2 tanks, where the levels interact. Assuming that the flow rate of 1st tank is linearly proportional to the difference in the tank heights,F1 = 1(h1 h2) ; the flow rate from tank 2 is proportional to the height in tank 2, 2 F2 = 2h2 ; and the tanks are of constant cross sectional area (A1,A A2), ) show that the modelling equation
Assuming g that the flow rate of 1st tank is linearly y proportional to the height in tank 1,F1 = 1h1 ; the flow rate from tank 2 is proportional to the height in tank 2, F2 = 2h2 ; and the tanks are of constant cross sectional area (A1,A2), show that the modelling equation
Assume that the steady state flow rate is 3ft3/min and the steady state tank heights of tank1 and tank 2 as h1s = 7ft, h2s = 3ft The constant cross sectional area, A1 = A2 = 5ft2 for each tank. The initial conditions for h1, h2 :h10 = 6ft, 6ft h20 = 5ft Solve for heights of tank1 and tank2 as a function of time time. Plot the tank heights as a function of time time. Write a MATLAB program and use ode45 to integrate the 2 equations shown above above.
clc clear all %using ode to solve function tankhyt hAi=6;hBi=6;%initial values declared hi=[hAi ;hBi]; t d [0 200] tend=[0 200]; %time %ti i interval t ld declared l d [t,h]=ode45(@tankhyt,tend,hi); figure; plot(t,h(:,1),'.-r'); hold on; ;
%using ode to solve function tankhyt hAi=6;hBi=6;%initial values declared hi=[hAi hBi]; t d [0 200] tend=[0 200]; %time %ti i interval t ld declared l d [t,h]=ode45(@nitankhyt,tend,hi); figure; plot(t,h(:,1),'.-r'); odo on; ; hold plot(t,h(:,2),'b'); xlabel('time t'); ylabel('height h'); title('height-time variation'); grid;
Problem statement
A chemical reaction takes place in a series of four continuous stirred tank reactors arranged d as shown h i in Fi Fig
V2 CA
2
V3 CA
3
V4 CA
4
1000 lit/hr
K1
K2
K3
K4
CA1
CA2
CA3
CA4
The chemical reaction is a first order irreversible reaction of the typeA k B The value of the rate constant ki, is different in each reactor. Also, the volume of each reactor Vi is different
Assumptions:
The system is steady state and unsteady state. The reactions are in liquid phase. There is no change in volume or density of the liquid.
Reactor
1 2 3 4
Vi(L)
1000 1500 100 500
Ki(h-1)
0.3 0.4 0.1 0.2
Solution
Running the following displays the steady state concentrations in the tanks:
clc clear all x0=[0,0,0,0]; %initial values x=fsolve(@fourcstrsteady x0) %fsolve to solve x=fsolve(@fourcstrsteady, the steadystate
Running the following code in MATLAB yields the plot depicting the variation of Concentration in each tank:
clc clear all x0=[1;0;0;0]; x0 [1;0;0;0]; %defining the initial values. [t,x]=ode45(@fourcstr, [0 0.1], x0); %ode45 to solve the unsteady state figure; plot(t,x); %plot function %labelling x and y axes xlabel('time l b l(' i t(hrs)'); (h )') ylabel('concentration c(t)');
Unsteady y state results The following variation is predicted with i h respected d to time i
Problem Description
For the reaction tanks above, heat transfer in the fluid stream takes k place l b two methods, by h d 1) Heat transfer through fluid already in the tanks, Equation for this can be written as, Q=(w/m)(Tin-Tout)where, Q = rate t of f heat h t transfer t f in i kJ/sec kJ/ W = rate of mass flow of fluid in Kg/min Tin = input p temperature p of the stream Tout = output temperature of the stream when it leaves the reaction tank 2) Other source of heat transfer is that from the coil which is provided to heat the fluid Equation used for the heat transfer in that case is Q = UA (Tsteam- T)
UA = is the final heat transfer coefficient Tsteam T = gives the temperature difference between steam used to heat and th the fl fluid id i inside id th the t tank. k Therefore total heat transferred to the liquid can be written as the sum of the above two heat transfer. Now as the heat is transferred to the fluid inside the tank its temperature rises. This rise in temperature can be expressed in terms of the rate of change of temperature or
dT/dt also l the h above b equation i h heat can b be obtained b i d lik like accumulation = input output therefore, final equation for the unsteady state can be written as,
dT/dt = (w/m)*(T0-T1)+(UA/mCp)*(Tstream-T1) dT/dt = (w/m)*(T0-T2)+(UA/mCp)*(Tstream-T2) dT/dt = (w/m) (w/m)*(T0-T3)+(UA/mCp)*(Tstream-T3) (T0 T3)+(UA/mCp) (Tstream T3)
now for the steady state rate of chane of temperature becomes 0 Therefore dT/dt = 0 Hence in matlab we use fsolve to find this temperature. To heat the fluid evenly impellers are used.
MATLAB CODE
function function f = tank (t,x) f = zeros (3,1); t1=x(1);t2=x(2);t3=x(3); t 250 ts=250;ua=10;cp=2;t0=20; 10 2 t0 20 w=100;m=10; f(1)=(w/m) (t0-t1)+(ua/m cp) (ts-t1); f(1)=(w/m)*(t0-t1)+(ua/m*cp)*(ts-t1); f(2)=(w/m)*(t1-t2)+(ua/m*cp)*(ts-t2); f(3)=(w/m)*(t2-t3)+(ua/m*cp)*(ts-t3); ( ) ( )( ) ( p) ( );
Main
clc;clf; clearall; x0=[1 1 1]; [t ] d 45(@ t [0 10] 0) [t,x]=ode45(@vmt,[0,10],x0); % [x]=fsolve(@vmt,x0); plot (t,x(:,1)); holdon; plot (t,x(:,2),'r'); plot (t,x(:,3),'b'); (t,x(:,3), b );
plot