[?] Find symbolic values in coefficients from FindFit function?

Hi All,

With the enclosed details & notebook.
I am trying to find the symbolic components of the coefficients of the FindFit function at the end.
Below are the details of my workings.
Here below are the basic components for symbolic representation of the coefficients of the final FindFit function.

{Sq5 = 5^2, Sq3 = 3^2};

then we take the following sequence :-

Table[ 4*i^2 - 9*i + 6, {i, 1, 10}]

= {1, 4, 15, 34, 61, 96, 139, 190, 249, 316};
then I multiply the above sequence by Sq5

Table[ (4*i^2 - 9*i + 6)*Sq5, {i, 1, 10}]

= {25, 100, 375, 850, 1525, 2400, 3475, 4750, 6225, 7900};

then I apply the following NSolve & get the desired results..below

Table[deg /. First@NSolve[Sq3 (-9 + 8 deg) == n && deg > 0, deg], {n, 
  Table[ (4*i^2 - 9*i + 6)*Sq5, {i, 1, 10}]}]

= {1.47222, 2.51389, 6.33333, 12.9306, 22.3056, 34.4583, 49.3889,
67.0972, 87.5833, 110.847}

then if I apply the FindFit function & we get the desired numerical result - which is great!

newTfKnown4 = 
 a x^2 + b x + c /. 
  FindFit[Table[
    deg /. First@NSolve[Sq3 (-9 + 8 deg) == n && deg > 0, deg], {n, 
     Table[ (4*i^2 - 9*i + 6)*Sq5, {i, 1, 10}]}], 
   a x^2 + b x + c, {a, b, c}, x]

= 3.20833 - 3.125 x + 1.38889 x^2

Now - back to my original question :-
From the output given above here - 3.20833 -3.125 x+1.38889 x^2
I am trying to find the symbolic representation of these 3 coefficients based off the above formulas in the NSolve above AND using the symbolic placeholders Sq3 & Sq5.

Can you recommend any approach on how to find each of the 3 coefficients so they can be represented using Sq3 & Sq5?

Many thanks for your help & attention.
Best regards,
Lea…

Have you tried using Minimize on the sum of the squares of the error terms? Note that Minimize switches to NMinimize if its arguments are not infinite precision.

Hi Frank,
I am not sure what you mean.
Would that help me find the symbolic form for the coefficients.
Please could you show. Many thanks Lea…

Here’s an example of what I meant

In[1]:= data = {{1, 2}, {2, 4}, {3, 7}};

In[2]:= Fit[data, {1, x}, x]

Out[2]= -0.666667 + 2.5 x

In[3]:= diffsq[a_, b_][{x_, y_}] = (y - a*x - b)^2;

In[4]:= Minimize[Total[diffsq[a, b] /@ data], {a, b}]

Out[4]= {1/6, {a -> 5/2, b -> -(2/3)}}

Hi Frank,

Many thanks for your example. I could not get any meaningful result from my data - which is strange as it does have mathematical integrity between data & formulas.
Below is my setup. But it does not work like your example.
Please could you take a look & advise how the symbolic values of Sq3 & Sq5 would be represented in the coefficients of the output formula.
3.20833 - 3.125 x + 1.38889 x^2

Many thanks for your help. Lea…

In[29]:= dataMydata = {1.4722222222222223`, 2.513888888888889`, 
   6.333333333333334`, 12.930555555555555`, 22.305555555555557`, 
   34.458333333333336`, 49.388888888888886`, 67.09722222222223`, 
   87.58333333333334`, 110.84722222222223`};

Fit[dataMydata, {1, x, x^2}, x]

diffsq[a_, b_][{x_, y_}] = (y - a*x - b)^2;

Minimize[Total[diffsq[a, b] /@ dataMydata], {a, b}]

Out[30]= 3.20833 - 3.125 x + 1.38889 x^2

In[1]:= dataMydata =
Thread[{Range[10],
Rationalize[{1.4722222222222223, 2.513888888888889,
6.333333333333334, 12.930555555555555, 22.305555555555557, 34.458333333333336, 49.388888888888886, 67.09722222222223,
87.58333333333334, 110.84722222222223}]}]

Out[1]= {{1, 53/36}, {2, 181/72}, {3, 19/3}, {4, 931/72}, {5, 803/
  36}, {6, 827/24}, {7, 889/18}, {8, 4831/72}, {9, 1051/12}, {10, 
  7981/72}}

In[2]:= Fit[dataMydata, {1, x, x^2}, x]

Out[2]= 3.20833 - 3.125 x + 1.38889 x^2

In[3]:= diffsq[a_, b_, c_][{x_, y_}] = (y - a*x - b x^2 - c)^2;

In[4]:= Minimize[Total[diffsq[a, b, c] /@ dataMydata], {a, b, c}]


Out[4]= {0, {a -> -(25/8), b -> 25/18, c -> 77/24}}

In[5]:= N[%]

Out[5]= {0., {a -> -3.125, b -> 1.38889, c -> 3.20833}}

As there is no added error there is a “perfect” solution so I don’t know why NSolve and FindFit are used. Also, if Sq3 > 0 and Sq5 > 0, then adding the condition deg > 0 is not needed.

Will the following do what you want?

Expand[deg /. Solve[Sq3 (-9 + 8 deg) == n, deg] /. n -> (4*i^2 - 9*i + 6)*Sq5][[1]]
(* 9/8 + (3 Sq5)/(4 Sq3) - (9 i Sq5)/(8 Sq3) + (i^2 Sq5)/(2 Sq3) *)

So the coefficients for i^0, i^1, and i^2 are, respectively, 9/8 + (3 Sq5)/(4 Sq3), - 9 Sq5/(8 Sq3), and Sq5/(2 Sq3).

Thanks Frank,
That’s very helpful. I really appreciate your help.

Hi Jim,
PERFECT !!! This is exactly what I was looking for.
Thank you so much. Really appreciate your help.
Best regards,
Lea…