how to run the function "fminunc" correctly
8 views (last 30 days)
Show older comments
I got a error message when I try to use the function "fminunc" to optimize the weights of a neural network. At the beginning, I thought it was caused by some tricks of the back-propagation algorithm, So I changed a simple case as follows:
A simple .m file:
function [f,g] = myfun(x)
f = 3*x(1)^2 + 2*x(1)*x(2) + x(2)^2; % Cost function
if nargout > 1
g(1) = 6*x(1)+2*x(2);
g(2) = 2*x(1)+2*x(2);
end
and run the following commands:
options = optimoptions('fminunc','GradObj','on','Algorithm','trust-region');
x0 = [1,1];
[x,fval] = fminunc(@myfun,x0,options);
it causes error like follows:
Error using color
Too many input arguments.
Error in sfminbx (line 150)
group = color(Hstr,p);
Error in fminunc (line 450)
[x,FVAL,~,EXITFLAG,OUTPUT,GRAD,HESSIAN] = sfminbx(funfcn,x,l,u, ...|
I tried the same code in Matlab 2014b and Matlab 2013 and got the same error. I also tried to replace the function "optimoptions" with "optimset" but it didn't work. I noticed that the the function "color" that provided by MATLAB only allows one input argument. However, the default function "color" is used to change the color of a plot handler and it apparently has nothing to do with the function "color" in the function "sfminbx". However I didn't find any other .m files named by "color" in the root directory and its subfolders.
So I am totally confused about this error. Any one can help me? Thank you very much!
0 Comments
Answers (1)
Walter Roberson
on 8 Aug 2015
which -all color
which -all sfminbx
If one of the two comes up first with a routine that is not supplied by Mathworks then remove that routine (or take its directory out of your MATLAB path).
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!