I have a problem creating MeanPredictionBands
for my function which I fitted using NonlinearModelFit
. I have a complex-valued function and I am fitting the real part of the function. Mathematica 8 gives me back a fitted function and with it the BestFitParameters
. But as soon as I try to feed it the "MeanPredictionBands"
command, it gives me back the following line:
Experimental`NumericalFunction::nnum: The function [...] is not a number at {fitparameters}.
I have also tried using the ComplexExpand
function on the real part of my function, which still doesn't help with my situation. Has anybody encountered this particular problem before? All my variables are real, as are the fit parameters.
Thank you all for your help!
From the file linked in comment a reduced code sample that exhibits the same problem:
ClearAll[msymm2fit];
msymm2fit = Re[0.145` mV^6 Log[-(0.5929`/mV^2)] + 12 b0V \[Nu]^2 + 8 bDV \[Nu]^2]
MyData2 = {{0.332, 0.807^2}, {0.386, 0.821^2}, {0.447, 0.855^2}};
MyError2 = {0.027, 0.011, 0.029};
MyFit2 = NonlinearModelFit[MyData2, msymm2fit, {mV, b0V, bDV}, \[Nu],
VarianceEstimatorFunction -> (1 &), Weights -> 1/(MyError2)^2,
Method -> {NMinimize, Method -> "DifferentialEvolution"}]
MyFit2["BestFitParameters"]
MyFit2["MeanPredictionBands"]
The inability to create the Bands apparently comes simply from taking the Real part of the function. I tried this out on another, really easy function. If you take
ComplexExpand[Re[]]
of a real valued function, this problem with creating the error bands goes away.
In my case, taking the Real part analytically (i.e. by hand) is not that easy, since it is created while i am fitting the data.
TL;DR Simply taking the Real part of any function will hinder Mathematica 8 from creating error bands from the fitted function.
ComplexExpand
cast light on your problem. Seems irrelevant to me. $\endgroup$