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

2 次查看(过去 30 天)
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?

回答(1 个)

vijaya lakshmi
vijaya lakshmi 2018-3-1
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.

类别

Help CenterFile Exchange 中查找有关 Get Started with Optimization Toolbox 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by