# 'nonlinear regress' function in mathematica & lsqcurvefit in matlab

I was looking for a function for numerical optimization(in nonlinear least square sense) in mathematica and have some simple questions.

Here is the thing: At the beginning, I found the MATLAB function called 'lsqcurvefit' and this seemed to be the one I was looking for. Here is the link: http://www.mathworks.com/help/optim/ug/lsqcurvefit.html

After that, I found the same(?)(Hopefully) function in the Mathematica. This is the example code in the Wolfram (I tried to put the link but I couldn't because I didn't have enough reputation points to put more than 2 links, I'm sorry):

    In:= NonlinearRegress[{{2, -0.99}, {6, -0.7}, {10, 0.58}, {14,
0.41}, {18, -0.66}}, Sin[a + b*x^2], {a, b}, x]
Out= BestFitParameters -> {a -> 0.776944, b -> 1.00375}


But my situation is that, I have more than one variable in the equation. I hope this link might be the one in this case: http://reference.wolfram.com/language/NonlinearRegression/tutorial/NonlinearRegression.html

In:= data = {{1.0, 1.0, .126}, {2.0, 1.0, .219}, {1.0, 2.0, .076}, {2.0,
2.0, .126}, {.1, .0, .186}};
In:= NonlinearRegress[data, (theta1 theta3 x1)/(
1 + theta1 x1 + theta2 x2), {theta1, theta2, theta3}, {x1, x2}]
Out= BestFitParameters -> {theta1 -> 3.13151, theta2 -> 15.1594,
theta3 -> 0.780063}


Now I have two questions.

1.In the last link where the case that has the equation with three parameters to solve and two variables in the equation (when comparing with the first MATLAB link), does the first vector of the input data (1.0,2.0,1.0,2.0,.1) correspond to the x1? and the second (1.0,1.0,2.0,2.0,.0) and the third vector (.126,.219,.076,.126,.186) indicates x2 and ydata, respectively?

2.To make this sure, I tried to run the same thing in the first link using the Mathematica, but kept failing to solve. Here is my code:

    In:= data1 = {{0.9, 455.2}, { 1.5, 428.6}, { 13.8, 124.1}, { 19.8,
67.3}, { 24.1, 43.2}, { 28.2, 28.1}, { 35.2, 13.1}, {
60.3, -0.4}, { 74.6, -1.3}, { 81.3, -1.5}};
In:= NonlinearRegress[data1,
theta1*e^((theta2)*(x1)), {theta1, theta2}, {x1}]

FindFit::nrlnum: The function value {-455.2+1. e^0.9,-428.6+1. e^1.5,-124.1+1. e^13.8,-67.3+1. e^19.8,-43.2+1. e^24.1,-28.1+1. e^28.2,-13.1+1. e^35.2,0.4 +1. e^60.3,1.3 +1. e^74.6,1.5 +1. e^81.3} is not a list of real numbers with dimensions {10} at {theta1,theta2} = {1.,1.}.
NonlinearRegress::fitfail: The fitting algorithm failed.


Can anyone help me out what I did wrong or what I understood completely wrong?

Appreciated.

• What version of Mathematica are you using? From the documentation in version 10.4.1 one finds the following about NonlinearRegress: As of Version 7.0, NonlinearRegress has been superseded by NonlinearModelFit and is part of the built-in Wolfram Language kernel. – JimB Dec 17 '16 at 5:30
• After changing e to E and including Needs["NonlinearRegression"] , your last bit of code runs on MMA 11 without error. To avoid that mistake, I usually use the Exp function instead. – LouisB Dec 17 '16 at 10:55

data = {{1.0, 1.0, .126}, {2.0, 1.0, .219}, {1.0, 2.0, .076}, {2.0, 2.0, .126}, {.1, .0, .186}};
`