function - Unable to find why error "Not enough input arguments", Matlab -


i encountered problem calling function defined in code below.. according matlab not have enough input arguments in nested function chi, when use function typing in "awesomefit(v,i,ierr)". cannot explain why, since input function needs should provided.. v, , ierr matrices of 148x1 double , initialized before calling function.

does have idea missing?

matlab shows error message in line fminsearch. not know if related other error message or wrongly using "fminsearch" command. right think latter possibility. not main issue. hope can cope once got other problem solved.

please excuse unorthodox programming style, i'm physicist trying program :/ i'm still giving best though..

%% stuff  function = awesomefit(v,i,ierr)  % initialize starting values = 1; vbd = 25; n = 1.2; b = -0.01; var = [vbd n b];  %do stuff = fminsearch(chi,var);   function ifit = inotnorm(v,vbd,n,b)     ifit = zeros(size(v));     = 1:length(v)         if v(i) < vbd,             ifit(i) = 2*10^-12;         else             ifit(i) = * abs( (v(i)-vbd) / (v(i)-vbd+1/(n*b)) )^n;         end     end end   function nm = normmod(vbd,n,b)     nm = sum(inotnorm(v,vbd,n,b) ./ ierr); end   function nd = normdat(i,ierr)     nd = sum(i ./ ierr); end   function c = chi(vbd,n,b)     c = sum(( (inotnorm(v,vbd,n,b) .* normdat(i,ierr) ./ normmod(vbd,n,b) - i) ./ ierr ).^2); end   end 

two problems:

  1. the function trying minimize chi - input of function required single variable. documentation this: http://www.mathworks.com/help/matlab/ref/fminsearch.html.

    as such, if have 3 variables trying minimize, must put them single vector... did var. such, need change chi reflect this:

    function c = chi(in) %// change     vbd = in(1); %// change     n = in(2); %// change     b = in(3); %// change     c = sum(( (inotnorm(v,vbd,n,b) .* normdat(i,ierr) ./ normmod(vbd,n,b) - i) ./ ierr ).^2); end 
  2. the first input fminsearch required function handle if read documentation carefully. therefore, need change fminsearch call this:

    a = fminsearch(@chi, var); 

    when did before:

    a = fminsearch(chi, var); 

    matlab interprets chi variable, not function.... why getting error. need pass handle function first input parameter fminsearch. can think of handle "pointer" function trying minimize. read more function handles here: http://www.mathworks.com/help/matlab/matlab_prog/creating-a-function-handle.html

doing , setting v = = ierr = 1, this:

>> awesomefit(1,1,1)  ans =     25.0000    1.2000   -0.0100 

Comments

Popular posts from this blog

1111. appearing after print sequence - php -

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

Ruby on Rails, ActiveRecord, Postgres, UTF-8 and ASCII-8BIT encodings -