How can I declare a nonlinear constraint in MATLAB as an anonymous function. I don't have any inequality constrained, only one equality.
Asked
Active
Viewed 543 times
0
-
When you say "nonlinear", do you mean *piecewise*. If so, these other questions should help you: [How can I create a piecewise inline function in MATLAB?](http://stackoverflow.com/questions/796072/how-can-i-create-a-piecewise-inline-function-in-matlab), [How would perform a piecewise equation with multiple variables in matlab?](http://stackoverflow.com/questions/4383078/how-would-perform-a-piecewise-equation-with-multiple-variables-in-matlab) – gnovice Mar 15 '11 at 02:36
-
I guess you want to use that constraint with fmincon but you should edit your question and explictly say so. – jmbr Mar 15 '11 at 05:21
1 Answers
3
What you need to do is to create an anonymous functions that outputs two arguments. You can do that as follows:
@(x) deal(x^2, 0 )
is what you want. The inequality constraint is the first argument. If you want to have both then equality and inequality constraints it is just.
@(x) deal(x^2, x+1)