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:
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 changechireflect 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); endthe first input
fminsearchrequired function handle if read documentation carefully. therefore, need changefminsearchcall this:a = fminsearch(@chi, var);when did before:
a = fminsearch(chi, var);matlab interprets
chivariable, not function.... why getting error. need pass handle function first input parameterfminsearch. 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
Post a Comment