Asked by Deepa Maheshvare
on 23 Apr 2019

Hi All,

I am solving an optimization problem.There are no equality constraints in my model. I want to pass ODEs as constraint to fmincon using,non-linear constraint, nlcon argument .

The function model contains odes

function dz = model(t, z, c)

dz(1) = ..

dz(2) = ..

I'd like to ask how the ode intergrator has to be called in the place of nlcon in fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon).

%p0 = Initial Value of Parameters

A = [];

b = [];

Aeq = [];

beq = [];

nlcon = ode45(@(t,z)model(t,z,x), tSpan, z0); % Is this correct?

p = fmincon(@objective,p0,A,b,Aeq,beq,lb,ub,nlcon);

Since the ode function is already called in nlcon , is it required to call the function model again inside the objective function?

function cost = objective(c,time_exp,expZ,tSpan,z0)

sol = ode45(@(t,z)model(t,z,c), tSpan, z0); % Is this step required?

ModelZ = deval(sol, time_exp);

cost = ModelZ-expZ;

Any help would be highly appreciated.

Answer by Alan Weiss
on 23 Apr 2019

I am not sure that I understand what you mean by "I want to pass ODEs as a constraint to fmincon." What about the ODE solution is a constraint? Do you want the minimum value of the solution to be above zero? Do you want the ODE solution to lie in a certain box? Once you explicitly define what you mean by the ODE solution is a "constraint," then I think that the answer to your question will be obvious. You will solve the ODE, get sol, and then write the constraint in terms of sol, maybe fun(deval(sol,tspan)) for some appropriate function fun and set of times tspan.

Alan Weiss

MATLAB mathematical toolbox documentation

Alan Weiss
on 23 Apr 2019

I still do not understand precisely what you are trying to do, so cannot give you a very detailed answer.

If you want your steady-state values to be in a certain range, then you probably want to restrict deval(sol,lasttime), where lasttime is the final time. But if you just want to restrict the steady-state, then probably you shouldn't solve an ODE anyway, just the steady-state equations, which would be an fsolve call, finding the location where dz = zeros(size(z0)).

Maybe you want to restrict the values of the solution at all times to be in a certain range, not just the final values. In that case, you would set constraints on deval(sol,tspan), where tspan is the set of times that you want to restrict.

Maybe you are trying to fit your ODE solution to some observed (measured) values as a function of time. In that case, follow the procedures in this example.

Good luck,

Alan Weiss

MATLAB mathematical toolbox documentation

Deepa Maheshvare
on 23 Apr 2019

Hi,

I'm sorry , I haven't explained it clearly.

"Maybe you are trying to fit your ODE solution to some observed (measured) values as a function of time."

No, the experimental measurements are all steady state values. For example , for the variable z1, there are 5 experimental studies that report the steady state value from experiment(z1_exp1,z1_exp2,z1_exp3,z1_exp4,z1_exp5). This gives me a range i.e. bound

z1_max and z1_min.

With z1_max and z1_min as the constraint , I wish to do the following

" restrict the values of the solution at all times to be in a certain range, not just the final values".Therefore, I am not sure whether it is appropriate to use lsqcurvefit ,used in the suggestions provided,for my problem.

Alan Weiss
on 23 Apr 2019

Sorry, I am unable to understand what you are trying to do, so this will be my last reply. I suggest that you write out equations or inequalities describing your constraint. Seriously, write them down. Then, given those equations or inequalities, you can write a corresponding nonlinear constraint function in fmincon syntax, restricting the result by using deval on the solution at relevant times. If you don't understand what I am suggesting, sorry, maybe someone else can help.

Alan Weiss

MATLAB mathematical toolbox documentation

Sign in to comment.

Opportunities for recent engineering grads.

Apply Today
## 14 Comments

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697189

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697201

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697210

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697215

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697527

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697565

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697635

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697654

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697710

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697714

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_697962

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_698021

## Deepa Maheshvare (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_698462

## Torsten (view profile)

## Direct link to this comment

https://www.mathworks.com/matlabcentral/answers/457960-question-regarding-passing-input-arguments-in-fmincon#comment_698466

Sign in to comment.