# How do I construct a non-linear model from experimental data?

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?

• 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. – bobthechemist Dec 17 '13 at 21:42

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.

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"] nlm["ParameterTable"] • Hey, man! You should teach science! :) – Dr. belisarius Dec 17 '13 at 22:57