Functions > Data Analysis > Curve Fitting > Example: Linear Combination of Functions
  
Example: Linear Combination of Functions
Use the linfit function to model of a data set by a linear sum of terms. Each term consists of a function to fit and a coefficient calculated by linfit.
1. Define the following matrix.
Click to copy this expression
2. Define a vector of functions to fit.
Click to copy this expression
The model function is y(x) = c0 * ln(x) + c1 * sqrt x +c3.
3. Call the linfit function to calculate the coefficient for each function. Record the coefficients in vector c.
Click to copy this expression
Click to copy this expression
Click to copy this expression
4. Define the fitting function f to be the linear combination of the functions in vf multiplied by the coefficients in c.
Click to copy this expression
5. Plot the data points and the fitting function.
Click to copy this expression
The linear combination of functions is a good fit to the data. This is confirmed by the value of the correlation coefficient which is close to 1:
Click to copy this expression