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:
- (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?
Chop
? $\endgroup$ – mmeent Jan 22 at 8:2910^-24
. $\endgroup$ – TeM Jan 22 at 8:32