getting error Not Enough input arguments
Show older comments
Hi everybody ! I have this code as my main function : function [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,varargin) % goldmin: minimization golden section search % [x,fx,ea,iter]=goldmin(f,xl,xu,es,maxit,p1,p2,...): % uses golden section search to find the minimum of f % input: % f = name of function % xl, xu = lower and upper guesses % es = desired relative error (default = 0.0001%) % maxit = maximum allowable iterations (default = 50) % p1,p2,... = additional parameters used by f % output: % x = location of minimum % fx = minimum function value % ea = approximate relative error (%) % iter = number of iterations if nargin<3,error('at least 3 input arguments required'),end if nargin<4||isempty(es), es=0.0001;end if nargin<5||isempty(maxit), maxit=50;end phi=(1+sqrt(5))/2; iter=0; fprintf('xl f(xl) xu f(xu)\n') fprintf('%.3f %9.3f %9.3f %9.3f\n',xl,f(xl,varargin{:}),xu,f(xu,varargin{:}) ) while(1) d = (phi-1)*(xu - xl); x1 = xl + d; x2 = xu - d; if f(x1,varargin{:}) < f(x2,varargin{:}) xopt = x1; xl = x2; else xopt = x2; xu = x1; end iter=iter+1; fprintf('%.3f %9.3f %9.3f %9.3f\n',xl,f(xl,varargin{:}),xu,f(xu,varargin{:}) ) if xopt~=0, ea = (2 - phi) * abs((xu - xl) / xopt) * 100;end if ea <= es iter >= maxit,break,end end x=xopt;fx=f(xopt,varargin{:}); and this is the function which i want to find the minimum point : function y=p3function(x) y=(1.5.*x.^6-2.*x.^4+12.*x);
each time i call the function i encounter : >> gm(p3function,-3,3) Error using p3function (line 2) Not enough input arguments. what should i do ?
Answers (1)
Massimo Zanetti
on 6 Oct 2016
0 votes
Look into the "gm" function file, and heck how many inputs you have to supply. Most probably it requires more than 3 inputs.
1 Comment
Erfan Hamdi
on 6 Oct 2016
Categories
Find more on Mathematics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!