1
$\begingroup$

I want to find a function $w=f(x,y,z)$ that fits experimentally determined values of w.

For example, assume

x = {1, 1, 1, 2, 2, 2}

y = {1, 2, 3, 1, 2, 3}

z = {1, 2, 3, 4, 5, 6}

and experiments have given

w = {.531, .341, .163, .641, .713, -0.40e-1}

I want to fit this data according to this relationship:

w = x^a + (b x^2)/y + c y z

How can I find the constants a, b and c and estimate the error the model produces?

$\endgroup$
  • 1
    $\begingroup$ NonlinearModelFit will help you out. You have to take care with your symbol definitions, though, if the data you are passing to NonlinearModelFit is in the symbol x, then the value should not also be called x. $\endgroup$ – bobthechemist Dec 17 '13 at 21:42
8
$\begingroup$

This is certainly answered in another elsewhere on the site, but I can't find a simple example.

1. Ensure proper formatting

If you wish to have your experimental data in the symbols x, y, and z, then these symbols cannot show up in your model. Adjust the model slightly such as this:

x = {1, 1, 1, 2, 2, 2}
y = {1, 2, 3, 1, 2, 3}
z = {1, 2, 3, 4, 5, 6}
w = {.531, .341, .163, .641, .713, -0.040}
model = x1^a + (b x1^2)/y1 + c y1 z1

Also make sure that your numbers are interpreted as numbers by Mathematica. The last term in w needs to be fixed.

2. Follow the documentation

The documentation for NonlinearModelFit is pretty good and provides you with examples as well as the summary statistics that can be easily extracted after the fitting is complete.

NonlinearModelFit wants the data entered in the format {{xi, yi, zi, wi}, {...},...} which can be achieved easily with Transpose

nlm = NonlinearModelFit[Transpose[{x,y,z,w}],model,{a,b,c},{x1,y1,z1}]

3. View Results

By assigning NonlinearModelFit to a symbol, you can easily access summary statistics as well as the information in which you are interested:

nlm["BestFitParameters"]

Mathematica graphics

nlm["ParameterTable"]

Mathematica graphics

$\endgroup$
  • 3
    $\begingroup$ Hey, man! You should teach science! :) $\endgroup$ – Dr. belisarius Dec 17 '13 at 22:57

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.