MATLAB Answers

How do I feed data from a non linear constraint function to the objective function when using fmincon?

3 views (last 30 days)
Abhishek Balakrishna Bhat
Abhishek Balakrishna Bhat on 12 Mar 2020
Edited: Matt J on 12 Mar 2020
Hello I am using fmincon for my problem optimization.
I have defined a non linear constraint function,
function [c,ceq,Ae,delta,be] = nonlincon(x), which computes the values of Ae, be. I want to use these values in my objective function.
So I have defined my objective function as follows:
function f = myObjective(Ae,be)
delta = Ae\be;
f = (delta(1)^2+delta(2)^2+delta(3)^2+delta(4)^2+delta(5)^2+delta(6)^2+delta(7)^2+delta(8)^2+delta(9)^2+...
delta(10)^2+delta(11)^2+delta(12)^2+delta(13)^2+delta(14)^2+delta(15)^2+delta(16)^2+delta(17)^2+delta(18)^2);
end
but when I define,
problem.objective = @myObjective;
I get an error saying Ae,be are undefined. This is because I havent linked the output from non linear constraint function to objective function.
So is there a way to fix this?

  0 Comments

Sign in to comment.

Answers (1)

Matt J
Matt J on 12 Mar 2020
Edited: Matt J on 12 Mar 2020
Since your unknown vector is x, your objective and constraints must be functions of x and nothing else (except known constants which can be passed in using techniques described here).
To let the objective and constraints share common quantities that would be burdensome to recompute in each one, follow these guidelines,

  0 Comments

Sign in to comment.

Sign in to answer this question.


Translated by