Info
This question is closed. Reopen it to edit or answer.
i want to know what is meant by double here pl answer
1 view (last 30 days)
Show older comments
Error using ga (line 342)
Undefined function 'constraints' for input arguments of type 'double'.
Error in main1 (line 11)
[x, fbest, exitflag] = ga(ObjectiveFunction, nvars, [], [], [], [],LB, UB,
ConstraintFunction,1:168, opts);
Caused by:
Failure in initial user-supplied nonlinear constraint function evaluation.
while my constraints function is
function [c, ceq]=constraints(x)
0 Comments
Answers (2)
Walter Roberson
on 15 Nov 2015
In your code calling ga, you show ConstraintFunction . Did you code that as
ConstraintFunction = 'constraints';
and is your code
function [c, ceq]=constraints(x)
in the same file as your main1 ?
In that combination of circumstances, MATLAB would not be able to find the constraints function. When you specify a function name by a string, then MATLAB evaluates the string in the context of the base workspace, and the base workspace can only find named functions which have their own .m file, not functions that are in the same file as the calling code.
The way to fix this would be to change to
ConstraintFunction = @constraints;
2 Comments
Walter Roberson
on 16 Nov 2015
Is your constraints function in the same file as main1.m or is it in a separate file constraints.m ? Please show your code.
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!