Documentation |
On this page… |
---|
The toolbox provides a one-term and a two-term exponential model as given by
$$\begin{array}{l}y=a{e}^{bx}\\ y=a{e}^{bx}+c{e}^{dx}\end{array}$$
Exponentials are often used when the rate of change of a quantity is proportional to the initial amount of the quantity. If the coefficient associated with b and/or d is negative, y represents exponential decay. If the coefficient is positive, y represents exponential growth.
For example, a single radioactive decay mode of a nuclide is described by a one-term exponential. a is interpreted as the initial number of nuclei, b is the decay constant, x is time, and y is the number of remaining nuclei after a specific amount of time passes. If two decay modes exist, then you must use the two-term exponential model. For the second decay mode, you add another exponential term to the model.
Examples of exponential growth include contagious diseases for which a cure is unavailable, and biological populations whose growth is uninhibited by predation, environmental factors, and so on.
Open the Curve Fitting app by entering cftool. Alternatively, click Curve Fitting on the Apps tab.
In the Curve Fitting app, select curve data (X data and Y data, or just Y data against index).
Curve Fitting app creates the default curve fit, Polynomial.
Change the model type from Polynomial to Exponential.
You can specify the following options:
Choose one or two terms to fit exp1 or exp2.
Look in the Results pane to see the model terms, the values of the coefficients, and the goodness-of-fit statistics.
(Optional) Click Fit Options to specify coefficient starting values and constraint bounds appropriate for your data, or change algorithm settings.
The toolbox calculates optimized start points for exponential fits, based on the current data set. You can override the start points and specify your own values in the Fit Options dialog box.
The fit options for the single-term exponential are shown next. The coefficient starting values and constraints are for the census data.
For an example specifying starting values appropriate to the data, see Gaussian Fitting with an Exponential Background.
For more information on the settings, see Specifying Fit Options and Optimized Starting Points.
This example shows how to fit an exponential model to data using the fit function.
The exponential library model is an input argument to the fit and fittype functions. Specify the model type 'exp1' or 'exp2' .
Fit a Single-Term Exponential Model
Generate data with an exponential trend and then fit the data using a single-term exponential. Plot the fit and data.
x = (0:0.2:5)';
y = 2*exp(-0.2*x) + 0.1*randn(size(x));
f = fit(x,y,'exp1')
plot(f,x,y)
f = General model Exp1: f(x) = a*exp(b*x) Coefficients (with 95% confidence bounds): a = 2.021 (1.89, 2.151) b = -0.1812 (-0.2104, -0.152)
Fit a Two-Term Exponential Model
f2 = fit(x,y,'exp2')
plot(f2,x,y)
f2 = General model Exp2: f2(x) = a*exp(b*x) + c*exp(d*x) Coefficients (with 95% confidence bounds): a = 3552 (-3.769e+12, 3.769e+12) b = -0.2574 (-2.715e+04, 2.715e+04) c = -3550 (-3.769e+12, 3.769e+12) d = -0.2575 (-2.716e+04, 2.716e+04)
The toolbox calculates optimized start points for exponential fits based on the current data set. You can override the start points and specify your own values.
Find the order of the entries for coefficients in the first model ( f ) by using the coeffnames function.
coeffnames(f)
ans = 'a' 'b'
If you specify start points, choose values appropriate to your data. Set arbitrary start points for coefficients a and b for example purposes.
f = fit(x,y,'exp1','StartPoint',[1,2]) plot(f,x,y)
f = General model Exp1: f(x) = a*exp(b*x) Coefficients (with 95% confidence bounds): a = 2.021 (1.89, 2.151) b = -0.1812 (-0.2104, -0.152)
Examine Exponential Fit Options
Examine the fit options if you want to modify fit options such as coefficient starting values and constraint bounds appropriate for your data, or change algorithm settings. For details on these options, see the table of properties for NonlinearLeastSquares on the fitoptions reference page.
fitoptions('exp1')
ans = Normalize: 'off' Exclude: [] Weights: [] Method: 'NonlinearLeastSquares' Robust: 'Off' StartPoint: [1x0 double] Lower: [1x0 double] Upper: [1x0 double] Algorithm: 'Trust-Region' DiffMinChange: 1.0000e-08 DiffMaxChange: 0.1000 Display: 'Notify' MaxFunEvals: 600 MaxIter: 400 TolFun: 1.0000e-06 TolX: 1.0000e-06
fit | fitoptions | fittype