I have this function GuessError, here's a plot assuming a single variable x, Plot[GuessError[10^x, etc..], {x, 8, 12}]
, being etc some more variables which are previously defined, machine-type numbers.
It shows that minimum near x=9.
Now if I try NMinimize[{GuessError[10^x, etc..], {8.8 < x < 9.2}}, x]
, I get this error message:
Nearest::neard: "The default distance function does not give a real numeric distance when applied to the point pair Max[0.23359984866812222`,-(3.23*10^15\10^-x)/(1+<<23>>\10^(<<5>><<1>><<1>>]))^0.5+ ..."
It does not have to do with Real
or Complex
values, because my function returns always Abs[...]
. What could be the problem here?
Here is the function, in the minimization, I use ni = 10^x
:
GuessError[IVcurve_,Area_,ni_,mue_,krec_,Jgen_,d_,T_]:=Module[{Vext,q,Vt,Jsim,Vexp,Vsup,Vinf,ninf,nsup,Jexp,Jrange,Vrange,Iexp,Vint,imin,imax,JV},
Vt = 8.61733238 10^-5 (T + 273.15);
q = 1.6 10^-19;
Iexp = Transpose[IVcurve][[2]]/Area;
Vexp = Transpose[IVcurve][[1]];
Jexp = Iexp/Area;
Vint = Vt Log[(Jexp + Jgen)/(q d krec ni^2) + 1];
Vext = Vint + (d Jexp)/(2 q mue ni E^(Vint/(2 Vt)));
Vinf = Max[First[Vext], First[Vexp]];
ninf = Flatten[Position[Vexp, Nearest[Vexp, Vinf][[1]]]][[1]];
Vsup = Min[Last[Vext], Last[Vexp]];
nsup = Flatten[Position[Vexp, Nearest[Vexp, Vsup][[1]]]][[1]];
Vrange = Take[Vext, {ninf, nsup}];
Abs@Total[(Vrange - Take[Vexp, {ninf, nsup}])^2]]
GuessError[ ]
? $\endgroup$_?NumericQ
problem. $\endgroup$Interpolation
of a table of my function as a function of x,NMinimize
works. $\endgroup$GuessError
, rather than its plot. $\endgroup$GuessError[.., .., 10^x, etc.]
does not itself evaluate to a number at all. (TryGuessError[Table[{t, 10^t + RandomReal[]}, {t, 10}], 1, 10^x, 1, 1, 1, 1, 1]
.) $\endgroup$