matlab exercise

8
Process Simulation Computer Exersice 1 3UREOHP0L[LQJ7DQN (material balances and MATLAB) A stirred mixing tank has one inlets and one outlet. A model of the tank is developed in Example 1.1 to 1.5 in the lecture note. a) Put up the total material balance over the tank. Assume that the outlet flow is proportional to the volume (total mass) in the tank, 9 N T = . Assume the following data set: T P VT P VρNJP N b) Solve the dynamic problem numerically using ode23. Start the simulation with an empty tank and stop at t=100. Write the equation on VWDWHVSDFHIRUP in a M- file in the following way seen below. Let us call this kind of M-file that contains the model description a 0RGHOILOH. The command will be [tsol,msol]=ode23(’mixtankdyn’,[0 100],0); and the plot commad will be plot(tsol,msol) function dm = mixtank(t,m) dm = … c) Solve the steady-state problem numerically using fzero. Write the equation on UHVLGXDOIRUP in a M-file in the following way seen below. This kind of M-file is also a 0RGHOILOH. Note the similarities between the two model files. Guess a initial value on the mass variable. Assume that we guess mguess=2000. The command will be msol=fzero('mixtankstat',2000) function res = mixtank(m) res = … 3UREOHP0L[LQJ7DQN (material balances and MATLAB) A stirred mixing tank has two inlets and one outlet. The volume is assumed to be constant (controlled). The first inlet is a fresh feed with high composition of a component A. The second inlet is a recycle stream with low composition of A. a) Develop a component mass balance and list our assumptions. Rewrite the component mass balance as a composition equation. Express it also as a concentration change equation. Assume the following data: 9P T P V[ NTNJT P V[ NJNJρNJP At the beginning (time zero) the mixing tank is full of recycled liquid. b) Solve the dynamic problem numerically using ode23. Write the composition equation in an M-file (0RGHOILOH) in the following way.

Upload: abvib

Post on 13-Apr-2015

12 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Matlab Exercise

Process Simulation Computer Exersice 1

����������� � ������� (material balances and MATLAB) A stirred mixing tank has one inlets and one outlet. A model of the tank is developed in Example 1.1 to 1.5 in the lecture note.

a) Put up the total material balance over the tank. Assume that the outlet flow is proportional to the volume (total mass) in the tank, ���

RXWRXW= . Assume the

following data set: ���������������� �

��������������RXW�����

b) Solve the dynamic problem numerically using ode23. Start the simulation with an empty tank and stop at t=100. Write the equation on ���������������� in a M-file in the following way seen below. Let us call this kind of M-file that contains the model description a ����������. The command will be [tsol,msol]=ode23(’mixtankdyn’,[0 100],0); and the plot commad will be plot(tsol,msol) function dm = mixtank(t,m) … dm = …

c) Solve the steady-state problem numerically using fzero. Write the equation on ��� ��������� in a M-file in the following way seen below. This kind of M-file is also a ����������. Note the similarities between the two model files. Guess a initial value on the mass variable. Assume that we guess mguess=2000. The command will be msol=fzero('mixtankstat',2000) function res = mixtank(m) … res = …

������������� � ������� (material balances and MATLAB) A stirred mixing tank has two inlets and one outlet. The volume is assumed to be constant (controlled). The first inlet is a fresh feed with high composition of a component A. The second inlet is a recycle stream with low composition of A.

a) Develop a component mass balance and list our assumptions. Rewrite the

component mass balance as a composition equation. Express it also as a concentration change equation. Assume the following data: ��������������

���������������������� �������������������������� �

At the beginning (time zero) the mixing tank is full of recycled liquid. b) Solve the dynamic problem numerically using ode23. Write the composition

equation in an M-file (����������) in the following way.

Page 2: Matlab Exercise

function dx = mixtank(t,x) … dx = …

������������ � ������� (energy balance) Assume that the mixing tank in Problem 2 is heated with steam in a jacket. The heat transfer of the jacket can be described as �����K�K��V�����. Assume the following data:���S������ ��!������������������"������F��"�����K���"��#���and��K���$"�

��

a) Develop an energy balance over the mixing tank and list our assumptions. b) Assume constant density and heat capacity and rewrite the energy balance into a

temperature change equation. c) Solve the dynamic temperature equation for an initial value of ����.

������������������������ �!�"��� �� (balance equations and MATLAB) The buffer tank similar to the tank form Problem 1.1 to 1.3 has two inlets and one outlet. The tank is open and has cylindrical geometry, �����WDQN�%. The height in the tank changes and the cross section area is �WDQN���&�

�� The heating model and parameters are identical to Problem 3. The flow rates, compositions and temperatures are as follows; �������

��������������������������� '��(�)�*���

�����������������"������RXW������������S������ �

�!����and�������� a) Develop mass balance component balance and energy balance over the buffer tank.

Express the equation system in the states: height, composition and temperature. b) Write a ���������� for the equation system in a). Simulate the dynamic tank

behaviour. Assume that )������". Plot the height, composition and temperature. c) Simulate the tank with one larger ) and one lower ). Discuss the result.

Page 3: Matlab Exercise

Computer Exersice 1 - ��+��,*��(

�������� a) Assumptions: • Well-mixed vessel means the same density in the whole tank and in outlet

( )RXWRXWRXW

����*�

���)))�*��

�*� −+=⇒−+=−+== 212121 ρρρρρ

b) An example of a dynamic (state space) model file. function dm=mixtankdyn(t,m)

% MIXTANK is a well-stirred tank model % with two inlets and one outlet. % Constant density. % parameters rho=1000; q1=0.1; q2=0.3; kout=0.1; % equations V=m/rho; w1=rho*q1; w2=rho*q2; wout=rho*kout*V; % mass balance on dynamic state space form dm = w1 + w2 – wout;

�������������� �������������������������� ����������������

Aofncompositiois;flowmassis

)(

AccOutIn

�)

�))

�)

�)

�*��

�*�

�)�)�) 5)

5

5

)

)$

0055))

+−+=⇒+=+

+=

( )

( ) W

P

ZZW

P

ZZ

5)

55))EWEW

EW

EWEWEWEWEWEWEW

5)

5

5

)

)

5)5)

���))

�)�)���

-.

*�

-.

����-.

*���-.

*�

��-.

��.�*����.��-��*��

))

-�)

�)

..-��*��

)(

0

)(

0

01011

1

1)(

)(1)(

)0()(

)(andwhere

+−+−−−

+

++=+−=

−=⇒=+==⇒+=

+=⇒=⇒=+

+=+==+

∫ ∫

Page 4: Matlab Exercise

0 10 20 30 40 50 60 70 80 90 1000

500

1000

1500

2000

2500

3000

3500

4000

c) An example of a steady-state (residual) model file. function res=mixtankstat(m) % MIXTANK is a well-stirred tank model % with two inlets and one outlet. % Constant density. % parameters rho=1000; q1=0.1; q2=0.3; kout=0.1; % equations V=m/rho; w1=rho*q1; w2=rho*q2; wout=rho*kout*V; % mass balance on residual form res = w1 + w2 – wout;

������������������������������ msol = 4.0000e+003�

( )

( ) W

P

ZZW

P

ZZ

5)

55))EWEW

EW

EWEWEWEWEWEWEW

5)

5

5

)

)

5)5)

���))

�)�)���

-.

*�

-.

����-.

*���-.

*�

��-.

��.�*����.��-��*��

))

-�)

�)

..-��*��

)(

0

)(

0

01011

1

1)(

)(1)(

)0()(

)(andwhere

+−+−−−

+

++=+−=

−=⇒=+==⇒+=

+=⇒=⇒=+

+=+==+

∫ ∫

Page 5: Matlab Exercise

��������� a) Assumptions: b) The component balance is written in mixtank M-file. The model is solved using ode23. type mixtank function dx=mixtank(t,x) % MIXTANK is a well-stirred tank model % with two inlets and one outlet. % Constant volume and density. % parameters V=4; rho=1000; q1=0.1; q2=0.3; x1=0.9; x2=0.1; % equations m=rho*V; w1=rho*q1; w2=rho*q2; % component balance dx = (w1*x1+w2*x2)/m -(w1+w2)/m*x; �������� ������������������� ��������������

0 5 10 15 20 25 30 35 40 45 500.1

0.15

0.2

0.25

0.3

0.35

����������a and b)Assumptions:

Page 6: Matlab Exercise

• Constant volume and density means constant mass and that outlet mass flow is equal to the sum of the inflows

• Well-mixed vessel means the same enthalpy in the whole tank and in outlet • Constant heat capacity (Note that the temperature differential equation is mathematically idential with the component balance in Problem 1. It can be written as ���*�'�.�����-! c) heated tank model is as follows. �����!�������� function dTemp=heattank(t,Temp) % HEATTANK is a well-stirred heated tank model % with two inlets and one outlet. % Constant heat capacity, volume and density. % (pressure-volume work neglected) % parameters V=4; rho=1000; q1=0.1; q2=0.3; T1=10; T2=50; Ts=95; kh=5; Ah=75; Cp=4.18; % equations m=rho*V; w1=rho*q1; w2=rho*q2; % component balance dTemp = (w1*T1+w2*T2)/m +(kh*Ah)/(m*Cp)*(Ts-Temp)-(w1+w2)/m*Temp;�

����������� ��!������������������������������������

( )

( )

( )

( ) �))

�����

�)

�)

�*��

��))

��)

��)

��))

����

��)

��)

�*��

���))

����

���)

���)

�*

����

���%

%)

%))

����

%)

%)

�*�%

�*%�

%)�%)%)

5)V

S

KK5

5)

)

UHS5)

UHIS5

UHIS)

S5)

VKK

5S5

)S)

S

UHIS5)

VKK

UHI5S5

UHI)S)UHIS

UHIS

5)V

KK5

5)

)0055))

)(

)()(

)()(

)()()(

)(

enthalpyis;flowmassis

)()(

AccOutIn

+−−++=

+−+−+−−++=

−+−−+−+−=−

⇒−=

+−−++=⇒+=++

+=

Page 7: Matlab Exercise

0 5 10 15 20 25 30 35 40 45 5010

15

20

25

30

35

40

45

50

� �����������See the solution in the lecture notes or in the Process Simulation compendium. �����"#��������� function dy=buffertank(t,y) % BUFFERTANK is a well-stirred open tank model % with two inlets and one outlet. % Constant heat capacity and density. % states z=y(1); %level x=y(2); %composition Temp=y(3);%temperature % parameters w=0.05; rho=1000; q1=0.1; q2=0.3+0.05*sin(w*t); qout=0.4; x1=0.9; x2=0.1; T1=10; T2=50; Ts=95; kh=5; Ah=75; Cp=4.18; Atank=6; % equations m=Atank*z*rho; w1=rho*q1; w2=rho*q2; wout=rho*qout; Q=kh*Ah*(Ts-Temp);

Page 8: Matlab Exercise

% balances dz = (w1+w2-wout)/(rho*Atank); dx = (w1*x1+w2*x2)/m -(w1+w2)/m*x; dTemp = (w1*T1+w2*T2)/m +Q/(m*Cp)-(w1+w2)/m*Temp; dy=[dz;dx;dTemp]; �������� ��"#���������������������� �����������������$�����

0 20 40 60 80 100 120 140 160 180 2001

1.05

1.1

1.15

1.2

1.25

1.3

1.35

1.4