Error associated with parameters in Minimize (or NMinimize) in discrete fitting - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-17T05:18:04Z https://mathematica.stackexchange.com/feeds/question/64969 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/64969 1 Error associated with parameters in Minimize (or NMinimize) in discrete fitting LeFerret https://mathematica.stackexchange.com/users/21930 2014-11-05T20:03:28Z 2014-11-05T20:03:28Z <p>my problem goes as follows:</p> <p>I need to a discrete fit of a discrete function. Say I have the following made up data points, which are generated by the parabola <code>f[x_]:=x^2</code> with some "experimental error" added:</p> <pre><code>data := {{-3, 8.9}, {-2, 4.1}, {-1, 1}, {0, 0}, {1, 1.2}, {2, 3.9}, {3,9.2}}; valuex := {-3, -2, -1, 0, 1, 2, 3} valuey := {8.9, 4.1, 1, 0, 1.2, 3.9, 9.2} </code></pre> <p>These points should be fitted by a curve of the general formula <code>f[x_]:= a*x² + b*x + c</code>, and I built a <code>NMinimize</code> algorithm as:</p> <pre><code>Minimize[Sqrt[Plus @@ ((a*valuex^2 + b*valuex + c - valuey )^2)], {a, b, c}] </code></pre> <p>This gives off a pretty accurate value for a, b and c</p> <pre><code>{0.282, {a -&gt; 0.99881, b -&gt; 0.025, c -&gt; 0.0476191}} </code></pre> <p>these are basically the same values I got when using <code>NonlinearModelFit</code></p> <pre><code>nmf = NonlinearModelFit[data, a x^2 + b x + c, {a, b, c}, x] FittedModel[0.047619+0.025x+0.99881x^2 </code></pre> <p>Now what <code>nmf</code> gives me, that I need to calculate in the <code>NMinimize</code> case is the <code>nmf["ParameterErrors"]</code>, <code>{0.0153843, 0.0266465, 0.0814063}</code>.</p> <p>How can I do that manually? I tried looking it up how <code>NonlinearModelFit</code> does it, but my lack of mathematical knowledge is making things pretty hard.</p> <p>Any help regarding that matter is welcomed!</p> <p>Thanks in advance.</p> <p>p.s.: I don't know if I made it clear enough, but that is just an example function. The one I need to fit is much more complicated and cannot be analytically evaluated, making <code>NMinimize</code> essential.</p>