Você está na página 1de 3

Simulink Exercise Part II:

You are given a set of time-series data: 1.time, 2. F_exp and 3. ys_exp
(download from SAKAI. Folder is named expdata.mat) . exp denotes
experimental data
A unit step change (F_spec) was made in a process at t=20 and the
process was run till t=200. Timestep was 0.1s.
As a process engineer, your job is to recover all the transfer function
parameters and to come up with the optimal transfer functions.
You may assume 1st order form for valve and process and a time delay
for sensor.
Therefore, we need to find 4 variables (tau_v, k, tau_p and theta)
Valve: tau_v = unknown: Therefore, Gv = 1 / (tau_v.s + 1).
Process: K=unknown, Tau_p=unknown: Therefore, Gp = k/
(tau_p.s+1)
Sensor: theta = unknown: Therefore, Gs = exp^(-theta.s).
Steps to follow:
1. Continue from previous class/examples. Open up simulink
process diagram
2. Save as another name now (e.g. process_opt) in the same folder.
3. Go to all the block diagrams. Replace the parameters with the
unknowns defined above. (Note: at this point you will be unable
to run the simulink model since the variables are undefined).
Everything else can remain the same
4. Create a main_opt.m
5. type clc; clear all ; close all.
6. Define global variables : variables that are global should be time,
F_exp, ys_exp (note: exp is added to denote experimental data. )
and any variable that is obtained in the function file but needs to
be used in the main file. see help global.
7. Load the experimental dataset (see help load)
8. Now if you run the main_opt file and type whos you should see
three variables (time, F_exp ys_exp).
9. set initial conditions for the set of variables. Let x0 = [6 8 5 7].
Note: we do not know the optimal values at this point so we need
some set of starting values. x is the vector of [tau_v, k, tau_p and
theta] and 0 indicates initial point.
10.
we are now ready to use the command fminsearch. This is
a gradient-free optimization algorithm (nelder-mead) that takes a
starting point, checks the sum of squared error (sse) and further
advances to a better point and keeps advancing till the sse
cannot be improved any further.
11.
type help fminsearch to key in the syntax

12.
In the syntax, the last argument should be options
13.
in the line above the fminsearch command type the line,
options=optimset(). Type help optimset to learn what the
should be. Once of the things to fill in is the display iteration
option.
14.
you will now also need to create a function file (name it
opt.m)
15.
place the 2 files (main_opt and opt) side by side (split
screen). It is easier this way to code and run the main_opt file.
16.
the function file (opt.m) must start with the function
command. See help function to learn how to write a function file
17.
the function name is opt since you saved the file as opt.m
as well (note: this same name will be called by the fminsearch
command in the main_opt file)
18.
the output of the function file must be sse
19.
the input of the function file must be x (which is the vector
of the 4 variables you want to find)
20.
below the function file define global variables (Exactly
same as no. 6)
21.
remember at this point, your process_2 file contains 4
unknowns (tau_v, k, tau_p and theta). You need to set these
values to the x data. Make tau_v = x(1), k = x(2)..so on so forth
22.
now we need to set some simulink options. Type these
commands:
op=simset(SrcWorkspace,Current)
;
sim(process_opt,[0 200],op)
these 2 lines set the options and runs the simulink process from
0 to 200 seconds in steps of 0.1 which is the same format as the
experimental data.
23.
Now you will need to calculate the sse
24.
type sse=0.d00 (d is for double precision). This is the initial
value
25.
write a for loop that calculates the sse of the difference of
(F_out-F_out_exp)2+(ys-ys_exp)2. Understand why this is the form
of the sse and why you need the square.
26.
Note: you dont have to consider t=0 to 20 since the step
was made at t=21.
27.
type return at the end of the function file
28.
Plot and overlay the variables in the main file. Also plot the
residuals (what are residuals? ) . check how they compare.
29.
Now you should be ready to run the files. Remember to run
the main_opt file and it will automatically call the opt file and the
process_2 files.
30.
You should be able to see the display of iterations in the
command prompt

31.
at the first iteration the sse is ~55330 (quite high) but it
quickly converges to ~1^-9 (extremely small) implying that the
optimization was recovered
32.
type x in command prompt and you should see x = [16.5
15.2 19.75 7.25 ] . (Also try different initial conditions and see
what happens)
33.
this means that the code was successful and the exact
transfer function parameters were recovered!
Final answers:
Tau_v = 16.5
K = 15.2
Tau_p = 19.75
Theta = 7.25

Você também pode gostar