This preview shows page 1. Sign up to view the full content.
Unformatted text preview: Page 1 of 6 CHE 361: Leastsquares Fit of Step Responses: step2g
First copy the Simulink example file "HW5_1sim.mdl" from the class web site into your
directory folder where all your other MATLAB files for this course are stored. Then start
MATLAB and "browse" to your MATLAB folder (which contains the .p files from the
Bioreactor project) and double click on "HW5_1sim.mdl". You should see: The "U_steps_in" block has been set up for a unit step input. (Double click to open).
Under the Simulation pulldown menu select "Start" or click on the > arrow in the tool bar to
run the simulation and create the plot shown: Y', output deviation variable HW5  Problem 1: CHE 361
1
0.8
0.6
0.4
0.2
0 0 1 3 2
Time Double click the button box with a bottom label of "Step_Analysis" and go to the MATLAB
Command Window to see the following output: 4 5 Page 2 of 6 step2g.m Nonlinear curve fit with simplex algorithm.
step2g.p = pcode version for consistency
MATLAB v2011b use  Feb. 7, 2012
G(s) from step response data.
FMINSEARCH uses the NelderMead simplex algorithm
to minimize the norm of the error (datamodel).
Copyright (c) 20012012 Dr.K.L. Levien
Chemical Engineering, Oregon State University
First ... loading the response data file.
This file must have 3 columns containing
ascii data (t,yfull,ydev)
 it MUST be named tYout.dat
First look at the shape of the data response.
Then make your choice of the kind of transfer function.
Step Response DATA: to be fitted using step2g.m MATLAB File
1 Output Deviation Variable, ydev 0.9
0.8
0.7
0.6 GO TO THE
COMMAND WINDOW !! 0.5
0.4 Use the Figure Editor to remove these
four text lines if you PRINT this plot 0.3
0.2
0.1
0 0 1 3 2
Time You may now EXIT (pick 0) in order to
EDIT & PRINT this plot of only the data,
or you can go on to the fitting step .... Specify general type of G(s)

 Enter:




0 to EXIT




1 for 1st order model


2 for 2nd order model


3 for 1st/2nd order model




4 for 1st/2nd with zero at origin 

Enter choice 1,2,3 or 4 : 1 4 5 Page 3 of 6 HOW to treat KM
Enter 0 for computer adjusted
Enter 1 for fixed KM : 1
For standard G(s) form
Fixed KM = 1
HOW to treat time delay
Enter 0 for computer adjusted
Enter 1 for fixed time delay : 1
For standard G(s) form
Fixed time delay = 0
Enter estimate of tau : 2
End
 Final Parameters Final KM
= 1.0000
Final time delay = 0.0000
Final tau
= 1.0000
 Poles and zeros One pole at s = 1
How GOOD was your fit ??
The sum of the squares of
your model errors = 2.0783e008
but the more data points you have, the bigger the
number will be. Thus you need to divide by the
number of points to get the per_data_pt
contribution to the sum of the squared errors.
Your value for this model
and data set was = 3.9213e010
for a total of 53 data points.
 Page 4 of 6 Often you will use the fixed KM = gain*step size and fixed time delay options to reduce the
number of parameters that must be fitted. For example in the bioreactor project there is NO
time delay and you can preCALCULATE your new output steadystate value from the
steadystate equations.
NOTE  BE CAREFUL: step2g uses KM, not just K. This means that to calculate the
"gain", the final (new steadystate) KM value of the output deviation variable must be divided
by the size of the input step (M).
To try a more complicated transfer function, change G to the 1st/2nd form shown in the
diagram below where K = 2, tau = 0.25, zeta = 1.25 and tauz = 1: Changing the t and y limits of the plot block "PC_graphY", running the simulation and then
using the "button" box results in the following selfscaled plot from step2g. Page 5 of 6 Step Response DATA: to be fitted using step2g.m MATLAB File
3.5 3 Output Deviation Variable, ydev Y', output deviation variable HW5  Problem 1: CHE 361
6
5
4
3
2
1
0 2.5 2 1.5 GO TO THE
COMMAND WINDOW !!
Use the Figure Editor to remove these
four text lines if you PRINT this plot 1 0.5 0 1 2
Time 3 0 0 0.5 1 1.5
Time 2 2.5 3 For this fit, you would select Model #3 to use a 1st over 2ndorder transfer function with
fixed gain of 2 and fixed time delay of 0. Since you know the process dynamics, you can use
the exact value of the 3 other parameters as initial estimates or make small errors to see the
computer start with incorrect estimates and converge to correct results.
In both the previous examples, the "data" was first generated from a known transfer function
and then fitted by using step2g. Obviously the same transfer function is found once the correct
form of model is chosen. In the case of the bioreactor, however, the bioreactor is a nonlinear
process and will only behave like it's local transfer function model when operated near it's
nominal design steady state. Because of the nonlinearity, step response experiments with
different sizes of input steps will in general yield different transfer function models.
The Base Case bio_reac.m file is set up for a step in the input ( flow=F ) from 1 to 1.1
liter/hour. This causes the output ( bugs = B ) to drop from 2 to 1.902415 gm/liter. The new
steadystate bug concentration is found from equations (6a,b) in the handout, where first the
new steadystate N was found to be 11/9 = 1.2222 gm/liter. The "true" gain for this step
experiment can then be calculated from the final and initial steadystate values:
K= new B  old B
1.902415  2
=
=  0.97585
1.1  1
new F  old F However when providing input for step2g, we speify a KM value of only 0.097585, since this
is the final deviation B' value for the step M of +0.1 in F'. In other words, a step of 0.1 was
made, not a unit step, in F'.
Running the Base Case of bio_reac.m and the button boxes for step2g yields the following
plots for B(t) = full variable and B'(t) = deviation variable: Page 6 of 6
Step Response DATA: to be fitted using step2g.m MATLAB File
0 Product Bug Concentration 0.01 Output Deviation Variable, ydev Bout , [ gm / liter] 3
2.5 2 1.5 0.02
0.03
0.04 GO TO THE
COMMAND WINDOW !! 0.05
0.06 Use the Figure Editor to remove these
four text lines if you PRINT this plot 0.07
0.08 1 0.09 0 2
4
Time , [hours] 6 0.1 0 2 1 4 3
Time 5 6 A section of the file tYout.dat showing columns of { t, B and B'} is:
0.0000000e+000
1.4210855e015
1.0000000e001
2.0000000e001 2.0000000e+000 0.0000000e+000
2.0000000e+000 2.2204460e016
1.9820185e+000 1.7981493e002
1.9674573e+000 3.2542663e002 Since you use 0.097585 as the KM value in step2g, you need to calculate the gain for the
transfer function model from the step experiment as KM/(M=0.1) = K = 0.97585.
In this case, the shape is close to being a simple 1storder with a tau of 0.4819, as found using
step2g and plotted on the left below. A careful examination shows, however, that a slightly
better fit may be obtained for a 1st/2nd model with tau = 0.8648, zeta = 1.1177, and tauz =
1.4815, as shown in the plot on the right. In both cases a fixed KM = 0.097585 and a fixed
time delay = 0 were used. The final error per point for the 1storder fit was 9.6 x 105 and only
1.63 x 105 for the more complex 1st/2nd model.
FINAL FIT to Step Response DATA using step2g.m MATLAB File FINAL FIT to Step Response DATA using step2g.m MATLAB File 0.01 0.02 0.02 Output Deviation Variable, ydev 0 0.01 Output Deviation Variable, ydev 0 0.03
0.04
0.05
0.06
0.07 0.03
0.04
0.05
0.06
0.07 0.08 0.08 0.09 0.09 0.1 0 1 2 3
Time 4 5  Final Parameters Final KM
= 0.0976
Final time delay = 0.0000
Final tau
= 0.4819
 Poles and zeros One pole at s = 2.0749
 6 0.1 0 1 2 3
Time 4 5 6  Final Parameters Final KM
= 0.0976
Final time delay
= 0.0000
Final tau
= 0.8648
Final zeta
= 1.1177
Final tauz
= 1.4817
 Poles and zeros One zero at s = 0.6749
Fast pole at s = 1.8697
Slow pole at s = 0.7151
 ...
View
Full
Document
This note was uploaded on 03/01/2012 for the course CHE 361 taught by Professor Staff during the Winter '08 term at Oregon State.
 Winter '08
 Staff

Click to edit the document details