I encountered a problem calling the function defined in the code below.. According to Matlab I do not have enough input arguments in the nested function Chi, when I use the function by typing in "Awesomefit(V,I,Ierr)". However I cannot really explain why, since all the input the function needs should be provided.. V, I and Ierr are matrices of 148x1 double and get initialized before calling up the function.
Does anyone have an idea what could be missing?
Matlab also shows an error message in the line with fminsearch. I do not know if this is related to the other error message or to wrongly using the "fminsearch" command. Right now I would think it is the latter possibility. But this is definitely not my main issue. I hope I can cope with that once i got the other problem solved.
Please excuse my unorthodox programming style, but I'm a physicist trying to program :/ I'm still giving my best though..
%% do stuff
function a = Awesomefit(V,I,Ierr)
% initialize starting values
A = 1;
Vbd = 25;
n = 1.2;
b = -0.01;
Var = [Vbd n b];
%do stuff
a = fminsearch(Chi,Var);
function Ifit = InotNorm(V,Vbd,n,b)
Ifit = zeros(size(V));
for i = 1:length(V)
if V(i) < Vbd,
Ifit(i) = 2*10^-12;
else
Ifit(i) = A * 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