# Compose-4000: Compose Math Functions for Fitting Curves

Compose OML language provides functions for fitting equations to data. This tutorial demonstrates how to use the lsqcurvefit and polyfit commands.

## Create Test Data for Fitting with lsqcurvefit

## Define the Fitting Function

The parameters for the fitted curve are the amplitude, the exponential damping
coefficient, and the oscillation frequency. The parameters are designated
`A`, `b` and `f`, and they
are passed to the fitting function in a vector as the first
argument. The second argument is the vector of times at which the function is to be
evaluated.

## Perform the Curve Fit with lsqcurvefit

From the data plot and some calculations, we can estimate the fitting parameters.
These initial estimates are required inputs for lsqcurvefit. The
other inputs are the `t` and `x` raw data
values.

The output is shown below:

The first output, p, contains the fitted parameters. The second output, resnorm, contains the norm of the residual differences between the raw data and the fitted curve.

## Plot the Fitted Curve with the Raw Data

## Create Test Data for Fitting with polyfit

## Perform the Curve Fit with polyfit

From the data plot and some calculations, we can estimate the fitting parameters.
These initial estimates are required inputs for polyfit. The
other inputs are the `t` and `x` raw data
values.

The output is shown below. The first output, p, contains the
fitted polynomial coefficients. The second output, `s`, contains
statistical data. Only the norm of the residuals vector is shown here.

## Plot the Fitted Curve with the Raw Data

Using polyval with the coefficients `(p)`
determined above, the fitted curve can be plotted together with the raw data.