Not enough input arguments error/making a function using @ error.

4 vues (au cours des 30 derniers jours)
K_Kharis
K_Kharis le 31 Mar 2016
Commenté : Star Strider le 13 Avr 2016
Hi, I'm trying to do an optimization in matlab for the first time. However, I still don't get how to declare the function using @. I'm trying to do a barrier function method. I've made a function files ObjFun.m and Constr.m and now I'm declaring the barrier function as:
X = [6 6];
penalty_r = 0.5;
f = @ (x) ObjFun - penalty_r .* log(Constr);
and trying to solve:
sol = fminunc(f,X)
and after that proceeds with the rest of the algorithm.
My question is, I always have problems with the declaring function f that consists of other functions like ObjFun and Constr. Such as: not enough input arguments.
How should I declare this?
Please help.
I'm using Matlab R2015b

Réponse acceptée

Star Strider
Star Strider le 31 Mar 2016
You didn’t post ‘ObjFun’, but assuming it is also a function of ‘x’, you need to call it as a function in your anonymous function:
f = @ (x) ObjFun(x) - penalty_r .* log(Constr);
I assume ‘Constr’ is a constant scalar that you’ve already defined in your workspace.
  2 commentaires
K_Kharis
K_Kharis le 13 Avr 2016
Yup, it works! Thanks! :)
Star Strider
Star Strider le 13 Avr 2016
My pleasure!

Connectez-vous pour commenter.

Plus de réponses (0)

Community Treasure Hunt

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

Start Hunting!

Translated by