1
$\begingroup$

data was given in columns in the order {y, x, z}, with y dependent on x, z

points = {{144, 18, 52}, {142, 24, 40}, {124, 12, 40}, {64, 30, 
    48}, {96, 30, 32}, {74, 26, 56}, {136, 26, 24}, {54, 22, 
    64}, {92, 22, 16}, {96, 14, 64}, {92, 10, 56}, {82, 10, 24}, {76, 
    6, 48}, {68, 6, 32}};

equation2 = A + Bx + Cz + D*x^2 + Ez^2 + Fx*z;
nlm = NonlinearModelFit[points, equation2, {A, B, C, D, E, F}, {x, z}, Method -> NMinimize]

I get errors, and nothing that gives the values of the coefficients A,B,C,D,E,F...

What am I doing wrong?

$\endgroup$
  • $\begingroup$ Fit[RotateRight[#, 1] & /@ points, {1, x, z, x x , z z, x z}, {x, z}] $\endgroup$ – Dr. belisarius Jun 2 '14 at 3:36
  • $\begingroup$ Belisarius: thank you very much, I cut and pasted what you wrote and shift+entered and got a result that seems to work. I'm still trying to figure out how all of your syntax works...but I'll take it for now! You're a boss! $\endgroup$ – Matthew Lee Jun 2 '14 at 4:43
2
$\begingroup$
points = {{144, 18, 52}, {142, 24, 40}, {124, 12, 40}, {64, 30, 48}, {96, 30, 
32}, {74, 26, 56}, {136, 26, 24}, {54, 22, 64}, {92, 22, 16}, {96, 14, 
64}, {92, 10, 56}, {82, 10, 24}, {76, 6, 48}, {68, 6, 32}};

Previous answer from belisarius:

fit = Fit[RotateRight /@ points, {1, x, z, x x, z z, x z}, {x, z}]

(* -9.44205 + 0.824875*x + 0.000781796*x^2 + 0.175003*z - 0.0102413*x*z + 0.00150438*z^2 *)

Alternate

fit == ((lmf = 
 LinearModelFit[RotateRight /@ points, {x, z, x^2, z^2, x*z}, {x, z}]) // Normal)

(* True *)

Note that built-in symbols (e.g., E) cannot be used as user-defined symbols. As a general rule, all user-defined symbols should start with a lower case letter to avoid naming conflicts with built-in symbols.

equation2 = a + b*x + c*z + d*x^2 + e*z^2 + f*x*z;

(nlm = NonlinearModelFit[RotateRight /@ points, 
 equation2, {a, b, c, d, e, f}, {x, z}, Method -> NMinimize]) // Normal // Quiet

(* -9.49492 + 0.825614*x + 0.000777544*x^2 + 0.175796*z - 0.0102451*x*z + 0.00150132*z^2 *)

nlm["BestFitParameters"]

(* {a -> -9.49492, b -> 0.825614, c -> 0.175796, d -> 0.000777544, e -> 0.00150132, f -> -0.0102451} *)

However, since you said that y is the dependent variable, RotateLeft should be used above rather than RotateRight

RotateRight[{y, z, x}]

(* {x,y,z} *)

 RotateLeft[{y, z, x}]

 (* {z,x,y} *)
$\endgroup$
  • $\begingroup$ Thank you for your input. This method also works, I shouldn't have used A,B,C,D,E,F in the example, my code had greek letters, but when I copy and pasted the syntax was very busy, so I substituted capital letters to make it look cleaner in the forum. Your method looks great and I can see how it works. Thank you again for your time, good sir! $\endgroup$ – Matthew Lee Jun 2 '14 at 5:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.