# Fitting problem - comparison between two functions

Writing:

k = 0;
points = Catenate[Table[{i, j, 2 i^2 + 3 j^2 + 4 i + 5 j + 6} +
RandomReal[{-k, k}, 3],
{i, -1, 1, .05}, {j, -1, 1, .05}]];

f1[{x_, y_, z_}] := a x^2 + b y^2 + c x + d y + e - z
g1 = Sum[f1[points[[i]]]^2, {i, 1, Length[points]}];
fit1 = NMinimize[g1, {a, b, c, d, e}][[2]] // Chop;
f1[{x, y, z}] /. fit1 // Factor

f2[{x_, y_, z_}] := a x^2 + b y^2 + c x + d y + e + f z
g2 = Sum[f2[points[[i]]]^2, {i, 1, Length[points]}];
fit2 = NMinimize[g2, {a, b, c, d, e, f}][[2]] // Chop;
f2[{x, y, z}] /. fit2 // Factor


I get:

1. (3. + 2. x + 1. x^2 + 2.5 y + 1.5 y^2 - 0.5 z)

-0.0209977 (3. + 2. x + 1. x^2 + 2.5 y + 1.5 y^2 - 0.5 z)

that is as desired.

Unfortunately, setting k = .01 I get:

1.99709 (3.00463 + 2.0019 x + 1. x^2 + 2.50138 y + 1.50023 y^2 - 0.500729 z)

0

where in the first case I get what is desired, in the second no.

Any ideas on how to repair?

• What happens when you remove the Chop? – mmeent Jan 22 at 8:29
• The coefficients are of the order of 10^-24. – TeM Jan 22 at 8:32
• And why did you expect anything different? We trivially see that f2 = 0 always minimizes g2. – mmeent Jan 22 at 8:39
• In fact I think I have made a lot of confusion, now I understand, thank you! – TeM Jan 22 at 9:57