Anda di halaman 1dari 10

Nonlinear Paramter Estimation via

fmincon in MATLAB

Xueyang Feng
Dept. of Energy, Environmental & Chemical
Engineering
fengx@seas.wustl.edu

Parameter Estimation
References
(e.g. literature)

Mathematic
Model

References
(e.g. literature)

Mathematic
Model

v.s.
Known
Parameters

Unknown
Parameters
Simulated
Results

Parameter
estimation

v.s.
Forward problem

Experimental
Results

Simulated
Results

Inverse problem

Experimental
Results

Nonlinear Parameter Estimation

Parameter estimation for linear systems


y = Ax + b
y, x are the vector of dependent and independent variables,
A, b are parameters to be estimated
For example, y=1+2sin(2t)
regress command in MATLAB

Parameter estimation for nonlinear systems


y = f (parameters, x)
f is the nonlinear function of the estimated paramters
For example, y=1+2sin(3 t)
fmincon , nlinfit, etc. in MATLAB

Case study: parameter estimation in bioengineering

Bioreactor model
dX
X
dt
dP
YP / X X
dt
dS
1

X X
dt
YX / S

max S
KS S

Five parameters to be estimated:


YP/X, YX/S, max, Ks, and S(0)
Initial conditions:
X(0) = 0.05 g/L; P(0) = 0 g/L;

Experimental data
t
0.0
3.0
6.0
9.0
12.0
15.0
18.0
21.0
24.0
27.1

X
0.51
0.15
0.42
0.56
0.33
0.09
1.01
1.60
2.62
3.73

P
0.28
0.47
0.21
0.61
0.12
0.09
0.16
0.34
0.52
1.13

S
14.86
14.93
14.30
14.00
13.80
12.00
11.11
6.00
3.50
0.70

We will use fmincon to


find the parameters

fmincon in MATLAB

ceq, and c describes the nonlinear equalities/inequalities


among parameters
A and b describes the linear inequalities among
parameters
Aeq and beq describes the linear equalities among
parameters

[x fval] = fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

Estimated
parameters

Errors of predicted Function that you Initial guess of


and observed
want to minimize, the parameters
results
i.e. the error

Boundaries of
the parameters

Choose the right


solver

The Error Function


function [error,ypred] = reactor_model(beta)
global yobs
global t

Input the observed data

%reactor model
S0=beta(5);
y0=[0.05 0 S0];
tspan=t; %we want y at every t
[t,y]=ode45(@ff,tspan,y0);

Settings to run ODEs

function dy = ff(t,y) %function that computes


the dydt
umax=beta(1);
Ks=beta(2);
Ypx=beta(3);
Yxs=beta(4);
X=y(1);
P=y(2);
S=y(3);
u=umax.*S./(Ks+S);
dy(1)=u.*X;
dy(2)=Ypx.*u.*X;
dy(3)=-1/Yxs.*u.*X-u.*X;
dy=dy';
end
y1=y(:,1); y2=y(:,2); y3=y(:,3);
ypred=[y1; y2; y3];
error=sum((ypred-yobs).^2);
end

The ODEs that describe


bioreactor behaviors

Calculate the error

The fmincon Function


%Use fmincon to find the parameters in reactor
model
clear
clc
data =xlsread('reactor_model_data.xlsx');
t=data(:,1);
X=data(:,2);
P=data(:,3);
S=data(:,4);

Read data from Excel

x=t;
global yobs
global t
yobs=[X;P;S];
umax=0.1;
Ks=10;
Ypx=0.11;
Yxs=0.45;
S0=14.86;
beta0(1)=umax; %initial guess
beta0(2)=Ks; %initial guess
beta0(3)=Ypx; %initial guess
beta0(4)=Yxs; %initial guess
beta0(5)=S0; %initial guess

Set up the initial guess of


parameters

The fmincon Function (continued)


%fmincon
fun=@reactor_model;
A=[];
b=[];
Aeq=[];
beq=[];
lb=zeros(5,1);
ub=lb+20;
nonlcon=[];
x0=beta0;%lb+rand.*(ub-lb);
options=optimset('Algorithm','interior-point');

Settings to run fmincon

[param, fval] =
fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

Q: How to find the global solution?

%get the predicted resutls


[error,ypred]=reactor_model(param);

Run the
model again to
A: Randomly perturb the initial
guess

n=length(t);
Xpred=ypred(1:n);
Ppred=ypred(n+1:2*n);
Spred=ypred(2*n+1:3*n);

get the predicted results

figure(1)
set(gca, 'fontsize',14,'fontweight','bold');
hold on
plot(x,Xpred,'-r','linewidth',2.5);
plot(x,Ppred,'-g','linewidth',2.5)
plot(x,Spred,'-b','linewidth',2.5)
plot(x,X,'r+','markersize',10);
plot(x,P,'go','markersize',10)
plot(x,S,'bx','markersize',10)
xlabel('time')
ylabel('y')
legend('X g/L','P g/L','S g/L')

Plot the predicted v.s. observed


results

Parameters Estimated via fmincon


param =
0.2248
14.9987

3.8128

fval =
4.3559

max = 0.2248 (1/h)


Ks = 3.8128 (g/L)
Ypx = 0.2606 (g/g)
Yxs = 0.3029 (g/g)
S0 = 14.9987 (g/L)

0.2606

0.3029

Estimating confidence intervals of parameters via fmincon


Which one makes sense? Numbers in the brackets are the 95% confidence interval of
max
max = 0.2248 [0.1700 0.2797] (1/h)
Or
max = 0.2248 [-0.1064 0.2874] (1/h)

Estimation of max is reliable


max cannot be accurately estimated

How to estimate the confidence intervals of parameters?


bootstrap method: randomly resample the experimental observations; and for
each new set of sampled experimental observations, use fmincon to find a new set
of parameters.
Monte Carlo method: randomly perturb the experimental observations within the
measurement errors (i.e. standard derivation); and for each new set of perturbed
experimental observations, use fmincon to find a new set of parameters.

Anda mungkin juga menyukai