Using cell array of function handles as nonlinear constraints in fmincon

I have a cell array of function handles called Eqn, the unknown variable is called T. I want to use these function handles as my nonlinear equality constraints using fmincon.
I am calling my nonlinear constraint function like this:
nonlcon = @(T)EnergyBalance(T,Eqn);
The function is defined as:
function [c,ceq] = EnergyBalance(T,Eqn)
c = [];
ceq = Eqn;
end
When running I am getting the error "FMINCON requires all values returned by functions to be of data type double." which makes sense as ceq is a cell array. However I cannot convert ceq into a double as it contains multiple function handles.
So my question is: Is there a way to use a group of function handles stored in a cell array as the nonlinear constraints for fmincon?

11 Comments

Does it suffice to evaluate them at T to get the correct double vector ceq ?
Sorry, I am not sure what you mean by evaluating them at T
One of the function handles could be
Eqn{1}=@(T)T-298
If the equality constraint would be T-298=0, you only had to evaluate Eqn{1} at T to get the correct ceq.
How would you do that?
Defining ceq like
ceq = Eqn(T);
?
I am getting "Not enough input arguments" for that line
Well, T is the unknown vector I am searching for, so it is not sensible to assign a random value to it
T is a numerical value handed to nonlcon, thus known during the evaluation of your function handles.
Ok then T is not handed correctly atm. T is supposed to be the unknown vector I am searching for
T is unknown, but a vector of doubles during the solution process, and your function handles have to be evaluated with this vector of doubles. T is not a vector of symbolic variables. I think you mix up symbolic with numerical computations.

Sign in to comment.

Answers (0)

Categories

Products

Release

R2018a

Tags

Asked:

on 14 Nov 2018

Commented:

on 14 Nov 2018

Community Treasure Hunt

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

Start Hunting!