Problem in inputting constrains for fmincon with ODE45

I have the following problem:
I am trying to regress a set of parameters of a set of reactions. My reaction rate expressions are formulated as shown below:
R1 = beta(1)*k1*y(1);
R2 = beta(2)*k2*y(2);
R3 = beta(3)*k3*k4*y(1)*y(2);
k1, k2, k3, k4 are all constants fed to the code.
The rate of change of specie y(1) and y(2) are formulated using ode functions
dydz(1) = -R1+R2;
dydz(2) = R3;
these ODEs are implemented in matlab's ode45 solver.
in order to regress the fitting parameters (beta), I am using fmincon to determine the values of these fitting parameters.
Now, my question is:
I have some linear and non-linear constraints on the values of y(1), y(2) that I want to put in the optimisation. but I don't know how to do that. This is because matlab deals with the constraints as function of the optimisation variables (beta(1), beta(2), beta(3)).
Do you have any idea on how to solve this problem??
Thanks

2 Comments

Since y(1), y(2) are functions of z, you will have to tell us the z-value(s) at which you want to constrain y(1) and y(2).
Best wishes
Torsten.
I am solving the problem in the range of zspan = [0:0.01:1]; and I want to constrain y(1) and y(2) at z = 1;

Sign in to comment.

Answers (1)

If you want to set the constraint y1(z=1) <= 3, e.g, you can just set
c(1)=y(end,1)-3.0
in fmincon's "nonlcon" function.
Best wishes
Torsten.

2 Comments

I did the following:
function [c,ceq] = nonlcon(y)
ceq = y(end,1)-0.158;
c = [];
end
and in the solve statement i did
@nonlcon
however, I am getting the following error
''index y out of bounds''
any suggestion?
You get the actual parameters "params" to be fitted handed to nonlcon:
function [c,ceq] = nonlcon(params)
Now with these parameters, solve your differential equations
[T,Y]=ode45(...)
and return
ceq(1) = Y(end,1)-0.158;
c=[];
Best wishes
Torsten.

Sign in to comment.

Asked:

on 1 Aug 2016

Commented:

on 1 Aug 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!