Vous êtes sur la page 1sur 23

TECHNOLOGICAL INSTITUTE OF THE PHILIPPINES

363 P.CASAL ST., QUIAPO, MANILA

CHEP 530D1
COMPUTER APPLICATION FOR CHEMICAL ENGINEERING
COMPILATION

SUBMITTED BY:
FRENUZA S. RAMIRO

SUBMITTED TO:
ENGR. CRISPULO MARANAN

DATE OF SUBMISSION:
MARCH 25, 2013

Laboratory Exercise No.2


Steady-State Material Balances on a Separation Train
Objective:

1. To solve simultaneous linear equations using material balances of a steady-state process with no
recycle.
Material Used:
Microsoft Excel software
Discussion:
A mass balance (also called a material balance) is an application of conservation of mass to the analysis of
physical systems. By accounting for material entering and leaving a system, mass flows can be identified
which might have been unknown, or difficult to measure without this technique. The exact conservation
law used in the analysis of the system depends on the context of the problem but all revolve around mass
conservation, i.e. that matter cannot disappear or be created spontaneously.[1]
Therefore, mass balances are used widely in engineering and environmental analyses. For example mass
balance theory is used to design chemical reactors, analyse alternative processes to produce chemicals as
well as in pollution dispersion models and other models of physical systems. Closely related and
complementary analysis techniques include the population balance,energy balance and the somewhat more
complex entropy balance. These techniques are required for thorough design and analysis of systems such as
the refrigeration cycle.
Procedure:
1. To solve the three equations three unknowns, which is:
x + y + 4z = 5
2x + 3y + z = 4
3x + y + 2z = 3
The coefficient matrix is
1
1
4
2
3
1
3
1
2
The unknown matrix is
x
y
z
The right hand side vector is
5
4
3
2. The equation in matrix form is (coefficient matrix) x [unknown vector]=right hand side vector.
[A][x]=[b]
And the solution is
[x] =inv[A]*[b]
3. Indicate the numerical coefficients on the corresponding cells as indicated on the table as shown below:
A
1
B1
1
C1
4
1
A
2
B2
3
C2
1
2
A
3
B3
1
C3
2
3
4. Highlight cell range A5 to C7 and enter the formula =MINVERSE(A1:C3) and hold shift, control and
enter.
5. For the right hand side vector, indicate the numerical coefficients on the corresponding shell on the
table as shown below:
F1
5
F2
4
F3
3

6. Highlight cell range D1:D3 and enter the formula =MMULT(A5:A7,F1:F3) and hold shift, control and
enter. The resulting values are the values of x, y and z.
7. Solve 10 equations in 10 unknowns.

Data and Results:


1. Three equations in three unknowns.
2. Ten equations in ten unknowns.
Problems:
1. In this problem, we are separating paraxylene, styrene, toluene and benzene viacontinuous distillation in
three columns. Continuous distillation is typically a steady-state process as the lighter components (lower
boiling temperatures at the operating pressure) will collect overhead and the heavier will collect in the
bottoms. Depending on what your purity specifications are will then determine how you want to operate your
equipment. A schematic with the problem details is shown below:

Initial set of material balances use a basis of 1 minute of operation:


Xylene: 0.07*D_1 + 0.18*B_1 + 0.15*D_2 + 0.24*B_2 = 0.15*70 kg-mol
Styrene: 0.04*D_1 + 0.24*B_1 + 0.10*D_2 + 0.65*B_2 = 0.25*70 kg-mol
Toluene: 0.54*D_1 + 0.42*B_1 + 0.54*D_2 + 0.10*B_2 = 0.40*70 kg-mol
Benzene: 0.35*D_1 + 0.16*B_1 + 0.21*D_2 + 0.01*B_2 = 0.20*70 kg-mol
Calculate the molar flow rates of D_1, D_2, B_1 and B_2?

Reduce the original feed flow rate to the first column by first 1% and then 2% and calculate the corresponding
flow rates of D_1, D_2, B_1 and _2. Explain your results. We wont do all four, after all this is a blog and
brevity is the soul of wit.
Determine the molar flow rates and compositions of B and D for part 1.
Xylene, styrene, toluene and benzene are to be separated with the array of distillation columns that is
shown below where F, D, B, D1, B1, D2 and B2 are the molar flow rates in mol/min.

Material balances on individual components on the overall separation train yield the equation set
Xylene: 0.07D1 + 0.18B1 + 0.15D2 + 0.24B2= 0.15 70
Styrene: 0.04D1 + 0.24B1 + 0.10D2 + 0.65B2= 0.25 70
Toluene: 0.54D1 + 0.42B1 + 0.54D2 + 0.10B2= 0.40 70
Benzene: 0.35D1 + 0.16B1 + 0.21D2 + 0.01B2= 0.20 70
Overall balances and individual component balances on column #2 can be used to determine the
molar flow rate and mole fractions from the equation of stream D from
Molar Flow Rates: D = D1 + B1
Xylene: XDxD = 0.07D1 + 0.18B1
Styrene: XDsD = 0.04D1 + 0.24B1
Toluene: XDtD = 0.54D1 + 0.42B1
Benzene: XDbD = 0.35D1 + 0.16B1
where XDx = mole fraction of Xylene, XDs = mole fraction of Styrene, XDt = mole fraction of Toluene,
and XDb = mole fraction of Benzene.
Similarly, overall balances and individual component balances on column #3 can be used to
determine the molar flow rate and mole fractions of stream B from the equation set
Molar Flow Rates: B = D2 + B2
Xylene: XBxB = 0.15D2 + 0.24B2
Styrene: XBsB = 0.10D2 + 0.65B2
Toluene: XBtB = 0.54D2 + 0.10B2
Benzene: XBbB = 0.21D2 + 0.01B2
(a) Calculate the molar flow rates of streams D1, D2, B1 and B2.
(b) Determine the molar flow rates and compositions of streams B and D.
Laboratory Exercise No.2
Steady-State Material Balances on a Separation Train

USING MATLAB:
CREATE A M-FILE:
clc;
disp('FRENUZA S. RAMIRO');
disp('LAB EXERCISE NO.2');
disp('STEADY-STATE MATERIAL BALANCES ON A SEPARATION TRAIN');
disp('The Matrix will display the material balances on individual components');
disp('GIVEN:')
disp('Row Values :');
disp('[0.07 0.18 0.15 0.24;0.04 0.24 0.10 0.65;0.54 0.42 0.54 0.10;0.35 0.16 0.21 0.01]');
disp('Column Values :');
disp('[0.15*70;0.25*70;0.40*70;0.20*70]');
A = input ('Enter the row values inside a bracket : ');
b = input ('Enter the column values inside a bracket : ');
matri=[A b]
disp('x = The Molar Flow Rates for D1, D2, B1, B2 : ');
x = A\b
D1 = x(1);
B1 = x(2);
disp ('
ANSWERS
');
disp ('Solving for the compositions at D')
D=D1+B1
disp ('% mole fraction of xylene at D : ');
X_xD=(0.07*D1+0.18*B1)/D
disp ('% mole fraction of styrene at D: ');
X_sD=(0.04*D1+0.24*B1)/D
disp ('% mole fraction of toluene at D : ');
X_tD=(0.54*D1+0.42*B1)/D
disp ('% mole fraction of benzene at D : ');
X_bD=(0.35*D1+0.16*B1)/D
D2 =x(3);
B2 =x(4);
disp ('Solving for the compositions at B')
B=D2+B2
disp ('% mole fraction of xylene at B : ');
X_xB=(0.15*D2+0.24*B2)/B
disp ('% mole fraction of styrene at B: ');
X_sB=(0.10*D2+0.65*B2)/B
disp ('% mole fraction of toluene at B : ');
X_tB=(0.54*D2+0.10*B2)/B
disp ('% mole fraction of benzene at B : ');
X_bB=(0.21*D2+0.01*B2)/B
FRENUZA S. RAMIRO
LAB EXERCISE NO.2
STEADY-STATE MATERIAL BALANCES ON A SEPARATION TRAIN
The Matrix will display the material balances on individual components
GIVEN:
Row Values :
[0.07 0.18 0.15 0.24;0.04 0.24 0.10 0.65;0.54 0.42 0.54 0.10;0.35 0.16 0.21 0.01]
Column Values :
[0.15*70;0.25*70;0.40*70;0.20*70]

Enter the row values inside a bracket : [0.07 0.18 0.15 0.24;0.04 0.24 0.10 0.65;0.54 0.42 0.54 0.10;0.35 0.16
0.21 0.01]
Enter the column values inside a bracket : [0.15*70;0.25*70;0.40*70;0.20*70]
matri =
0.0700 0.1800 0.1500 0.2400 10.5000
0.0400 0.2400 0.1000 0.6500 17.5000
0.5400 0.4200 0.5400 0.1000 28.0000
0.3500 0.1600 0.2100 0.0100 14.0000
x = The Molar Flow Rates for D1, D2, B1, B2 :
x=
26.2500
17.5000
8.7500
17.5000
ANSWERS
Solving for the compositions at D
D=
43.7500
% mole fraction of xylene at D :
X_xD =
0.1140
% mole fraction of styrene at D:
X_sD =
0.1200
% mole fraction of toluene at D :
X_tD =
0.4920
% mole fraction of benzene at D :
X_bD =
0.2740
Solving for the compositions at B
B=
26.2500
% mole fraction of xylene at B :
X_xB =
0.2100
% mole fraction of styrene at B:
X_sB =
0.4667
% mole fraction of toluene at B :
X_tB =
0.2467
% mole fraction of benzene at B :
X_bB =
0.0767
RAMIRO, FRENUZA S.
CHEP530D1

PROBLEM NO.1
clc;
disp('1.Molar Volume')
disp('2.compressibilty factor')

choose= input ('Enter your choice:');


switch(choose)
case 1;
Pc = input('enter the Critical Pressure: ');
Tc = input('enter the Critical Temperature: ');

P = input('enter the Pressure: ');


T = input('enter the Temperature: ');
R = 0.08206;
V = 0.57;
Pr = P/Pc;
a = 27*(R^2*Tc^2/Pc)/64;
b = R*Tc/(8*Pc);
Z = P*V/(R*T);
f = (P+a/(V^2))*(V-b)-R*T;
fprintf('the Molar Volume is %.2f.\n',f);
break;
case 2;
V = input('enter the Volume: ');
P = input('enter the Pressure: ');
T = input('enter the Temperature: ');
R = 0.08206;
Z = P*V/(R*T);
fprintf('the compressibility factor is %.2f.\n',Z);
break;
end;

ANSWER:
1.Molar Volume
2.compressibilty factor
Enter your choice:1
enter the Critical Pressure: 111.3
enter the Critical Temperature: 405.5
enter the Pressure: 56
enter the Temperature: 140
the Molar Volume is 25.44.
1.Molar Volume
2.compressibilty factor
Enter your choice:2

enter the Volume: .57


enter the Pressure: 56
enter the Temperature: 450
the compressibility factor is 0.86.

Laboratory Exercise No.3


Vapor Pressure Data Representation by Polynomials and Equations
Problem 3a
>> %To solve part a, insert the data:
>> vp = [ 1 5 10 20 40 60 100 200 400 760]
vp =
1 5 10 20 40 60 100 200 400 760
>> T = [-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1 42.2 60.6 80.1]
T=
Columns 1 through 7
-36.7000 -19.6000 -11.5000 -2.6000 7.6000 15.4000 26.1000
Columns 8 through 10
42.2000 60.6000 80.1000
>> %set the degree of polynomial: p(1) = a(n),...p(n+1) = a(0)
>> m = 4
m=
4
>> % m here is one less than n in the problem statement
>> %fit the polynomial
>> p=polyfit(T,vp,m)
p=
0.0000 0.0004 0.0360 1.6062 24.6788
>> %evaluate the polynomial for every T (if desired)
>> z=polyval(p,T)
z=
Columns 1 through 7
1.0477 4.5184 10.4154 20.7392 39.1623 59.6942 100.3384
Columns 8 through 10
200.2647 399.7679 760.0518
>> %z = 1.0477e+00 4.5184e+00 1.0415e+01 2.0739e+01 3.9162e+01
>> % 5.9694e+01 1.0034e+02 2.0026e+02 3.9977e+02 7.6005e+02
>> %calculate tne norm of the error
>> norm(vp-polyval(p,T))
ans =
1.4105
>> %plot results
>> plot(T,z,'or',T,vp,'b')
>> xlabel('T (C)')
>> ylabel('vp (mm Hg)')

Problem 3b
>> % file Prob_3b.m
>> %To solve part b, insert the data:
>> vp = [ 1 5 10 20 40 60 100 200 400 760]
vp =
1 5 10 20 40 60 100 200 400 760
>> T = [-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1 42.2 60.6 80.1]
T=
Columns 1 through 7
-36.7000 -19.6000 -11.5000 -2.6000 7.6000 15.4000 26.1000
Columns 8 through 10
42.2000 60.6000 80.1000
>> % create the new variables
>> y = log10(vp);
>> x = 1./(T+273.15);
>> % fit the polynomial
>> p = polyfit(x,y,1)
p=
1.0e+003 *
-2.0353 0.0088
>> %To compute the norm based on the logarithm of the vapor pressure
>> norm(y - polyval(p,x))
ans =
0.2464

>> %To compute the norm based on the vapor pressure


>> norm(vp-10.^(polyval(p,x)))
ans =
224.2934
Problem 3c
>> %filename Prob_3c.m
>> %To solve part c, insert the data:
>> vp = [ 1 5 10 20 40 60 100 200 400 760]
vp =
1 5 10 20 40 60 100 200 400 760
>> T = [-36.7 -19.6 -11.5 -2.6 7.6 15.4 26.1 42.2 60.6 80.1]
T=
Columns 1 through 7
-36.7000 -19.6000 -11.5000 -2.6000
Columns 8 through 10
42.2000 60.6000 80.1000

7.6000 15.4000 26.1000

>> % Make vp and T available in fit2


>> global vp T
Warning: The value of local variables may have been changed to match the
globals. Future versions of MATLAB will require that you
declare
a variable to be global before you use that variable.
Warning: The value of local variables may have been changed to match the
globals. Future versions of MATLAB will require that you
declare
a variable to be global before you use that variable.
>> % set initial guesses of parameters
>> p0(1) = 10;
>> p0(2) = 2000;
>> p0(3) = 273;
>> % call least squares minimization
ls = fmins(fit_c,p0)
ls = 5.7673 677.09 153.8
% To compute the sum of squares of errors:
vpfit1=(vp - 10.^(ls(1) - ls(2)./(T+ls(3))));
norm(vpfit1)
%To compute the norm based on the logarithm of the vapor pressure
vpfit2 = log10(vp) - (ls(1) - ls(2)./(T+ls(3)));
norm(vpfit2)

Laboratory Exercise 4
Reaction Equilibrium for Multiple Gas-Phase Reactions
PROBLEM NO. 4

%filename Prob_4.m
global Cao CboKciKciiKciiicvector
% define constants
Cao = 1.5; Cbo=1.5; Kci= 1.06; Kcii= 2.63; Kciii= 5;
%set initial conditions
% Initial guess and set tolerance
% remove the % in front of the desired initial guess
cvector=[1.5 1.5 0 0 0 0 0]; %initial guess, part a
%cvector=[-.5 -1.5 -1 1 1 2 1]; %initial guess, part b
%cvector=[-18.5 -28.5 -10 10 10 20 10]; %initial guess, part c
guess=cvector;
%call fsolve
y = fsolve('prob4',guess)
%filename Prob_4NR.m
clear all
clc
global Cao CboKciKciiKciiicvector
% define constants
Cao = 1.5; Cbo=1.5; Kci= 1.06; Kcii= 2.63; Kciii= 5;
% Initial guess and set tolerance
err=1;
iter=0;
% remove the % in front of the desired initial guess
cvector=[1.5 1.5 0 0 0 0 0]; %initial guess, part a
%cvector=[-.5 -1.5 -1 1 1 2 1]; %initial guess, part b
%cvector=[-18.5 -28.5 -10 10 10 20 10]; %initial guess, part c
guess=cvector;
while err > 1e-4 &&iter< 200
x= prob4(cvector);
J= jac4(cvector);
errr= -J\x';
cvector=cvector+errr';
errr=abs(errr);
err= sqrt(sum(errr));
iter=iter+1;
end
disp('guess')
disp(guess)
disp('error')
disp(err)
disp(' A

Z');

disp(cvector);
disp('iter')
disp(iter)
y = Columns 1 through 5
4.2069e-001 2.4290e-001 1.5357e-001 7.0533e-001 1.7779e-001
Columns 6 through 7
5.5177e-001 3.7398e-001
guess
Columns 1 through 5
1.5000e+000 1.5000e+000
0
0
0
Columns 6 through 7
0
0
error 1.4094e-006
A
B
C
D
X
Y
Z
Columns 1 through 5
4.2069e-001 2.4290e-001 1.5357e-001 7.0533e-001 1.7779e-001
Columns 6 through 7
5.5177e-001 3.7398e-001
iter 7

Laboratory Exercise 5
Terminal Velocity of Falling Particles
PROBLEM NO. 5
clc;
disp('Computation for Terminal Velocity');

g = input('Enter the value of g (in m/s^2)');


y = input('Enter the Density of the Particle (in kg/m^3)');
z = input('Enter the Mean Velocity of the Object Relative to the Fluid (in m/s)');
v = input('Enter the Viscosity of the Fluid (in kg/(m*s))');
d = input('Enter the Diameter of the Spherical Particle (in m)');
Re = ((z*d*y)/v);
fprintf('The Value of Reynolds Number is %0.4f', R);
disp(Computation of Drag Coefficient(CD));
if Re<0.1
CD=24/Re;
elseif Re<1000
CD=24*(1+0.14*Re^0.7)/Re;
elseif Re<350000
CD=0.44;
else
CD=0.19-80000/Re;
End
%Calculate v_t (Terminal Velocity)
v_t=sqrt((4*g*(rho_p-rho)*D_p)/(3*C_D*rho));
if (v_t == v_t_g)
tae = 1;
else
v_t_g=v_t;ML-14
end

Laboratory Exercise 6
Heat Exchange In a Series of Tanks
PROBLEM NO.6
function P2_16A
clear, clc, format short g, format compact
tspan = [0 200.]; % Range for the independent variable
T0 = [20.; 20.; 20.]; % Initial values for the dependent variables
disp(' Variable values at the initial point ');
disp([' t = ' num2str(tspan(1))]);
disp('
T
dT/dt
');
disp([T0 ODEfun(tspan(1),T0)]);
[t,T]=ode45(@ODEfun,tspan,T0);

for i=[1 2 3]:size(T,2)


disp([' temperature T' int2str(i)]);
disp(['
t
T' int2str(i)]);
disp([t T(:,i)]);
plot(t,T(:,i));
title([' Temperature in Stirred Tanks' int2str(i)]);
xlabel(' Independent variable (t)');
ylabel([' Dependent variable T' int2str(i)]);
pause
end
%- - - - - - - - - - - - - - - - - - - - - function dYfuncvecdt = ODEfun(~,Yfuncvec)
T1 = Yfuncvec(1);
T2 = Yfuncvec(2);
T3 = Yfuncvec(3);
W = 100;
Cp = 2;
T0 = 20;
UA = 10;
Tsteam = 250;
M = 1000;
dT1dt = (W * Cp * (T0 - T1) + UA * (Tsteam - T1)) / (M * Cp);
dT2dt = (W * Cp * (T1 - T2) + UA * (Tsteam - T2)) / (M * Cp);
dT3dt = (W * Cp * (T2 - T3) + UA * (Tsteam - T3)) / (M * Cp);
dYfuncvecdt = [dT1dt; dT2dt; dT3dt];

Laboratory Exercise 7
Diffusion with Chemical Reaction in a One-Dimensional Slab
PROBLEM 7
clc;
display ['Diffusion with Chemical Reaction in a One-Dimensional Slab'];
Cao= input('enter the value Ca0:');
K= input('enter the value of K:');
L= input('enter the value of L:');
Dab= input ('enter the value of Dab:');
display ('z=0');
display ('z=L');
switch(choose)
case 1;
a =input('enter the value of z:');

z = 0;
Ca=(Dab/(K*z))*(1/Cao);
fprintf('the value of Ca is %0.2f.\n',Ca);
break;
case 2;
a = input('enter the value of z: ');
z = L;
Ca=(Dab/(K*z))*(1/Cao);
fprintf('the value of Ca is %0.2f.\n',Ca);
break;
end

Laboratory Exercise 9
Reversible, Exothermic, Gas-Phase Reaction In a Catalytic Reactor
%filename Prob_9.m
global Ta delH CPA FA0
%set parameters
Ta = 500;
delH = -40000;
CPA = 40;
FA0=5;
%set initial conditions
var0(1) = 0.;
var0(2) = 450;
var0(3) = 1.0;
Wspan = [0 20];
%integrate equations
[W var]=ode45('react',Wspan,var0)

% For version 4.0 use


%[W var]=ode45('react',0,20,var0)
%plot results
tt = var(:,2)/1000;
plot(W,var(:,1),'r',W,var(:,3),'g',W,tt,'b')
title ('Reactor Model')
xlabel ('W')
legend('Conversion of A','Normalized Pressure','T/1000')
% To plot concentration, issue command conc

W=
0
0.0068
0.0137
0.0205
0.0274
0.0616
0.0958
0.1300
0.1642
0.3352
0.5062
0.6772
0.8482
1.3482
1.8482
2.3482
2.8482
3.3482
3.8482
4.3482
4.8482
5.3482
5.8482
6.3482
6.8482
7.3482
7.8482
8.3482
8.8482
9.3482
9.8482
10.3482
var =
1.0e+003 *
0 0.4500 0.0010
0.0000 0.4501 0.0010
0.0000 0.4501 0.0010
0.0000 0.4502 0.0010
0.0000 0.4502 0.0010
0.0000 0.4505 0.0010
0.0000 0.4507 0.0010
0.0000 0.4510 0.0010
0.0000 0.4513 0.0010
0.0000 0.4526 0.0010
0.0000 0.4539 0.0010
0.0000 0.4553 0.0010
0.0000 0.4568 0.0010
0.0000 0.4611 0.0010
0.0000 0.4658 0.0010
0.0000 0.4709 0.0010

10.8482
11.1559
11.4636
11.7713
12.0789
12.2403
12.4017
12.5631
12.7245
12.8859
13.0473
13.2087
13.3701
13.5895
13.8089
14.0283
14.2477
14.4976
14.7476
14.9975
15.2474
15.5887
15.9301
16.2715
16.6128
17.0907
17.5685
18.0463
18.5241
18.8931
19.2621
19.6310
20.0000

0.0000
0.0000
0.0000
0.0000
0.0001
0.0001
0.0001
0.0001
0.0001
0.0001
0.0001
0.0002
0.0002
0.0002
0.0003
0.0003
0.0004
0.0005
0.0005
0.0006

0.4763
0.4823
0.4888
0.4961
0.5041
0.5131
0.5233
0.5350
0.5485
0.5645
0.5837
0.6071
0.6366
0.6741
0.7241
0.7902
0.8735
0.9321
0.9906
1.0437

0.0010
0.0010
0.0010
0.0010
0.0010
0.0010
0.0010
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009

0.0006
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007

1.0870
1.1049
1.1195
1.1313
1.1405
1.1476
1.1530
1.1569
1.1599
1.1626
1.1643
1.1651
1.1654
1.1655
1.1653

0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0009
0.0008

0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007
0.0007

1.1648
1.1642
1.1634
1.1625
1.1614
1.1604
1.1589
1.1574
1.1559
1.1543
1.1532
1.1520
1.1508
1.1496

0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008
0.0008

Laboratory Exercise 10
Dynamics of a Heated Tank with Proportional/Integral (PI) Temperature Control
PROBLEM NO. 10
%filename Prob_10.m

clear all
clc
global qsetpt taud taui Kc Tsetpt onoff
qsetpt=1e4; taud=1; taui=2; Tsetpt=80;
Kc=input('enter the gain ');
onoff=input('enter 0 for no integrator, enter 1 if integrator on ');
% initialization
to=0; tfin=200; %limits of integration
tspan = [to tfin];
To=[80 80 80 0]; % initial condition of system. Tank Temp, Outlet
% Temp Thermocouple Temp and error signal
[t,T] = ode45('tempdyn',tspan,To);
% For version 4 use
% [t,T] = ode45('tempdyn',to,tfin,To);
T;
plot(t,T(:,1),'r',t,T(:,2),'ro',t,T(:,3),'r:')
grid
title('Temperature vs time')
xlabel('time in minutes')
ylabel('Temperature in C')
legend('Tank','Outlet T','Measured T')
%filename tempdyn.m
function Tdot=tempdyn (t,T)
global qsetpt taud taui Kc Tsetpt onoff
% Use logical block to model the step change at 10 min.
if t<10
Tinlet = 60;
else
Tinlet = 40;
end
qin= qsetpt+Kc*(Tsetpt-T(3))+onoff*Kc/taui*T(4);% total heat sent in
% use the following statement for part (e)
%qin=max(0,min(2.6*qsetpt,qin));
row(1)= (500*(Tinlet-T(1))+qin)/(4000); % energy balance
row(2) = (T(1)-T(2)-0.5*taud*row(1))*2/taud;
% Pade approximation for delay
row(3) = (T(2)-T(3))/5; % Thermoouple dynamics
row(4) = Tsetpt - T(3); % the error message
% row(4) not needed for part (e), but is calculated anyway
Tdot = row';

Answer for (a) 0 , 1

Answer for (b) 50 , 1

Answer for (c) 500 , 1

Answer for (d) 500 , 1

Answer for (e) 5000 , 0