Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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?

share|improve this question
    
Fit[RotateRight[#, 1] & /@ points, {1, x, z, x x , z z, x z}, {x, z}] –  belisarius Jun 2 at 3:36
    
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! –  Matthew Lee Jun 2 at 4:43

1 Answer 1

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} *)
share|improve this answer
    
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! –  Matthew Lee Jun 2 at 5:02

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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