Nonlinear Regression
Nonlinear regression refers to a regression wherein the dependent (response) variable depends in a nonlinear way on the regression coefficients. The dependence on the independent (predictor) variable is irrelevant when you're trying to decide whether or not a linear or nonlinear fit is required. A fit of the form
is nonlinear because b appears in the exponent but the form
is linear even though sin(x) and cos(x) are nonlinear functions because y varies only linearly with the coefficients a and b.
If for some reason we suspected the pump calibration curve varied in an exponential form like the one above then we can pass such a form to the FIT function along with a starting guess for the coefficients. Before you check out the code, keep in mind two very important features of nonlinear fits:
They almost always require a starting guess for the coefficients (in the example below I chose 1 for each of the coefficients). The quality of the fit and value of the coefficients can vary depending on your initial guess! There's no way to determine which set of variables is the "right" one; you'll just have to use your engineering judgment.
Generally you should try to keep your functional forms as simple as possible, unless you have reason to suspect they are more complex. For example, calibration curves are almost always linear but fits to forms predicted by theory can often be nonlinear.
Here's a simple example using the exponential form given above:
fobj = fit(k', Y', 'a*exp(b*x)', 'Start', [1 1])
fobj =
General model:
fobj(x) = a*exp(b*x)
Coefficients (with 95% confidence bounds):
a = 1.813 (0.4084, 3.217)
b = 0.3831 (0.2045, 0.5616)
errorbar(k, Y, eY, eY, ek, ek, 'ko')
hold on
plot(fobj, 'r')
hold off
axis square
xlabel('Knob Setting')
ylabel('Discharge Rate (mL/s)')
legend('data', 'fit', 'Location', 'Northwest')