Clear Filters
Clear Filters

how can I use for loop to change non linear constraints?

2 views (last 30 days)
I need to optimize the same function but with different element of the same non linear constraits function(NONLINCON). can I use a for loop to fill the nonlincon and then optimize the objective function? For example:
e=@(x)....
[c,ceq]=nlcon(x,t,p) % function.m
for i=1:p
t=tmax(i,1); %vector
p=pxy(i,2); %vector
constx=nlcon(x,t,p);
[x,fval]=fmincon(e,x0,A,b,Aeq,beq,lb,ub,constx)
end
Can it works?

Answers (1)

vijaya lakshmi
vijaya lakshmi on 1 Mar 2018
Hi Francesco,
I understand that you have a non linear contraint function to be optimized multiple times in for loop which depends on additional parameters .
You can use 'evalin' to access the variable in the base workspace in your nonlinear constraint function.
Here is the documentation for evalin
Hope this helps you.

Categories

Find more on Get Started with Optimization Toolbox in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!