Rewriting a function

In the following code I would like to replace the definition of the function f

x0=[1 1 1];
lb=[0 0 0];



function [c,ceq] = constr(x)
c = [2*x(1)*x(2)+2*x(1)*x(3)+2*x(2)*x(3)-100 ; 1-x(1)*x(2)];
ceq = [];

I replaced it with

function erg = f(x)
erg = -x(1)*x(2)*x(3);

but unfortunatly it doesn’t work. What am I doing wrong?

The error message is "Not enough input arguments."

>Solution :

In your first code snippet, f is a function handle, while in the second, its a function.

You can easily make it a function handle to be called by fmincon by calling x=fmincon(@f,x0,[],[],[],[],lb,[],nonlincon)

Otherwise matlab is trying to call f and give its output to fmincon, which is not what you want to do.

Leave a Reply