Documente Academic
Documente Profesional
Documente Cultură
KULLIYYAH OF ENGINEERING
DEPARTMENT OF BIOCHEMICAL-BIOTECHNOLOGY ENGINEERING
BTE 4225
COMPUTER SIMULATION IN BIOLOGICAL SYSTEM
MATLAB REPORT
AND
ASSIGNMENT FIVE
Combination of using MATLAB Function and Function Blocks in SIMULINK
and Data Fitting
Simulink model:
Ramp 1
MATLAB
Function
eqn _mlfcn function
Ramp 2
Scope
EXAMPLE 1 MODEL 2
Simulink model:
Ramp 1
XY Graph
XY Graph
MATLAB
Function
eqn _ mlfcn function
Scope
Ramp 2
Results:
XY Graph 1:
XY Graph 2:
u The input to the block. If u is a vector, u(i) represents the ith element of the vector; u(1) or u
alone represents the first element.
Numeric constants
Arithmetic operators (+ - * /^)
Relational operators (== != > < >= <=) The expression returns 1 if the relation is true;
otherwise, it returns 0.
Logical operators (&& || !) The expression returns 1 if the relation is true; otherwise, it returns
0.
Parentheses
Mathematical functions abs, acos, asin, atan, atan2, ceil, cos, cosh, exp, fabs, floor, hypot, ln,
log, log10, pow, power, rem, sgn, sin, sinh, sqrt, tan, and tanh.
Workspace variables Variable names that are not recognized in the preceding list of items are
passed to MATLAB for evaluation. Matrix or vector elements must be specifically referenced
(e.g., A(1,1) instead of A for the first element in the matrix).
XY Graph
XY Graph 1
Ramp
f(u)
sin(u(1)*exp (2.3*(-u(2))))
Scope
Ramp 1
Results:
XY Graph:
XY Graph 1:
ASSIGNMENT 4:
A mass balance for a chemical in a completely mixed bioreactor can be written as
Vdc/dt = F Qc kVc2
Where V = volume (12 m3), c = concentration (g/m3), F = feed rate (175 g/min), Q =flow rate (1
m3/min), and k = a second order reaction rate (0.15 m#/g/min). If c(0)=0, solve the ODE until the
concentration reaches a stable level.
The model diagram:
175
Constant
Clock
F
c(0)=0
Vc'
c'
1/12
Integrator 1
1/m
Add
1/s
XY Graph
Graph x versus t
Qc
c
1
Q
kVc2
0.15
k
Results:
12
V
c2
Pv = 10
A+
T +C
Command in M-file:
function Antoine
clear, clc, format short g, format compact
% X = Temperature in deg C
% Y = vapour pressure in mm Hg
xyData=[-187.68 1.268E-06; -183.15 7.268E-06;
-173.15 0.0001883; -163.15 0.0025884;
-153.15 0.0221106; -143.15 0.1315085;
-133.15 0.5900482; -123.15 2.117681;
-113.15 6.352669; -103.15 16.50044;
-93.15 37.87601;
-83.15 78.7521;
-73.15 150.754;
-63.15 269.2572;
-53.15 453.7621;
-42.08 757.5202;
-33.15 1110.03;
-23.15 1635.044;
-13.15 2332.562;
-3.15
3225.086;
6.85
4365.116;
16.85
5767.654;
26.85
7485.2;
36.85
9525.254;
46.85
1.2E+04;
56.85
1.485E+04;
66.85
1.823E+04; 76.85
2.213E+04;
86.85
2.663E+04];
% Assign the data properly
X=xyData(:,1);
m=size(X,1); %Determine the number of data points
Y=xyData(:,2);
% set the descriptions
prob_title = ([' Antoine Equation Parameters, Nonlinear Regression']);
dep_var_name=['Vapor Pressure (mmHg) '];
ind_var_name=['Temperature (C)'];
parm=[6 -1000 200];
Result as graph:
%linear
Residual
10
0
-10
-20
-30
-40
-50
x 10
0.5
1
1.5
2
Vapor Pressure (mmHg) (Measured)
2.5
3
4
x 10
2.5
1.5
0.5
0
-200
-150
-100
-50
Temperature (C)
50
100
ASSIGNMENT 5
Fitting data to Eqn & MATLAB Functions in SIMULINK
Apply Fitting data to Eqn & MATLAB Functions in SIMULINK to any data or equation from BTE text
books.
Topic: Environmental Engineering.
Adsorption using activated carbon.
The following is the given data of adsorption of PNP (p-Nitrophenol) from an aqueous solution at 25 oC by
5 g activated carbon
PNP sorbed, q (mg/g)
125.1
152.9
194.6
222.4
264.1
291.9
2. If the initial concentration of PNP is 50 mg/L. Find the q for the sorbed PNP until 100% sorbed by
activated carbon.
ANSWER FOR PART 1
1. Command in M-file:
function adsorption_langmuir
clear, clc, format short g, format compact
% X = Concentration of PNP in solution (mg/L)
% Y = Sorbed of PNP (mg/g)
xyData=[0.834 125.1;
1.529 122.9;
3.197 194.6;
6.255 222.4;
25.02 264.1;
45.87 291.9]
% Assign the data properly
X=xyData(:,1);
m=size(X,1); %Determine the number of data points
Y=xyData(:,2);
% set the descriptions
prob_title = ([' LANGMUIR ISOTHERM FOR ACTIVATED CARBON ADSORPTION OF PNP']);
dep_var_name=['q, Sorbed PNP (mg/g) '];
ind_var_name=['C, Concentration of PNP (mg/L)'];
parm=[6 -1000 200];
npar=size(parm,2); % Determine the number of the parameters
options=optimset('MaxFunEvals',1000); % Change the default value for MaxFunEvals
Beta=fminsearch(@AntFun,parm,options,X,Y); % Find optimal parameters using fminsearch
[f,Ycalc]=AntFun(Beta,X,Y); % Compute Y (calculated) at the optimum
disp(['
Results,' prob_title ]);
Res=[ ];
for i=1:npar
Res=[Res; i Beta(i)];
end
disp('
Parameter No.
Value
');
disp(Res);
s2=sum((Y-Ycalc)'*(Y-Ycalc))/(m-npar); %variance
disp([' Variance ', num2str(s2)]);
ymean=mean(Y);
R2=(Ycalc-ymean)'*(Ycalc-ymean)/((Y-ymean)'*(Y-ymean));
correlation coefficient
disp([' Correlation Coefficient ', num2str(R2)])
plot(Y,Y-Ycalc,'*') % Residual plot
title(['Residual Plot, ' prob_title ])
xlabel([dep_var_name '(Measured)'])
ylabel('Residual')
pause
plot(X,Ycalc,'r-',X,Y,'b+' ) %Plot of experimental and calculated data
title(['Calculated/Experimental Data ' prob_title])
xlabel([ind_var_name])
%linear
ylabel([dep_var_name])
%------------------------------------function [f,Ycalc]=AntFun(parm,X,Y)
a=parm(1);
b=parm(2);
c=parm(3);
for i=1:size(X,1);
Ycalc(i,1)=10^(a+b/(X(i)+c));
end
resid(:,1)=Y-Ycalc;
f=resid'*resid;
2. Results:
In command window:
xyData =
0.834
125.1
1.529
122.9
3.197
194.6
6.255
222.4
25.02
264.1
45.87
291.9
Results, LANGMUIR ISOTHERM FOR ACTIVATED CARBON ADSORPTION OF PNP
Parameter No.
Value
1
2.4773
2
-1.0566
3
1.7194
Variance 243.1844
Correlation Coefficient 0.97148
Residual plot:
10
Residual
-5
-10
-15
-20
120
140
160
180
200
220
240
q, Sorbed PNP (mg/g) (Measured)
260
280
300
280
260
240
220
200
180
160
140
120
10
15
20
25
30
C, Concentration of PNP (mg/L)
35
40
45
2. Simulink model:
XY Graph
MATLAB
Function
Ramp 1
(Value of Cf )
3. Results:
adsorption function
Scope
50
XY Graph:
Scope window: