I asked a question in a previous post that was closed because "The title of the question is not correct and the issue here is too trivial to help anyone later".
http://mathematica.stackexchange.com/questions/19297/nonlinearmodelfithttps://mathematica.stackexchange.com/questions/19297/nonlinearmodelfit
It's possible because I'm not so smart in Mathematica. But in this period I've tried a lot of alternative solutions.
Recall my problem
data={{220., 542.821}, {225., 531.898}, {230., 521.391}, {235.,
510.596}, {240., 499.603}, {245., 488.585}, {250., 479.002}, {255.,
468.574}}
func= a0*Exp[a1 t + a2 t^2]
nlm = NonlinearModelFit[data, func , {a0, a1, a2}, t]
which gives the result:
FittelModel = 0.
Some answers told me that it is not an exponential, but linear problem. But this problem is a physical problem that comes out from a lot of papers that describes this phenomenum as having exponential behavior. So also if my question was trivial, I've continued to solve it.
I read a lot of posts, and I tried this solution in Mathematica, using NMinimize
and not NonLiNearModelFit
.
f[a0_, a1_, a2_][t_] := a0*Exp[a1*t + a2*t^2 ];
error[a0_, a1_, a2_][x_, y_] := (f[a0, a1, a2]@x - y);
errorSum[a0_, a1_, a2_] = Total[(error[a0, a1, a2] @@@ data)];
bestFitVals =
NMinimize[{errorSum[a0, a1,
a2], {600 < a0 < 1500&& -0.01 < a1 < 0 && -0.0000001 < a2 < 0}}(*,
Thread[0<{a0,a1,a2}]*), {a0, a1, a2}, Method -> "SimulatedAnnealing"]
soln[x_] = f[a0, a1, a2]@x /. bestFitVals[[2]]
limits = Flatten@{x, Through[{Min, Max}@data[[All, 1]]]};
Show@{Plot[soln@x, Evaluate@limits, PlotRange -> All],
ListPlot[data, PlotStyle -> Red]}
I tried all the methods available to NMinimize
, changing starting values or removing them, but no choice works. So finally a collegue suggested that I try another software package: SigmaPlot. I said him that Mathematica is superior, but Sigmaplot gives me an exponential solution, with these coefficients
a0 = 1072.637060511283
a1 = -2.128998307513597e-3
a2 = -4.390602833555603e-6.
and with residuals that are very low.
I tried with another set of data, but the solution is the same: Mathematica is not be able to regress or minimize and Sigmaplot is able to.
I hope my question is not trivial, but I hope more that someone can solve my question: is Sigmaplot superior of Mathematica, or is it the case that I'm not applying Mathematica properly to my problem?