Curve Fitting in Maple
Go to Maple Portal Maple Portal for Math Educators

Introduction


Maple includes a number of assistants that allows a user to experiment and easily perform key tasks. The Curve Fitting Assistant provides a quick and easy method to fit a curve to a set of data points and to experiment to find the best curve for your data set. The assistant provides a graph showing both the points in your data as well as the curve returned by the chosen curve fitting algorithm.
Maple also has a number of Task Templates that help with curve fitting. Use these task templates to find a function that fits your data points using Bspline, least squares approximation, polynomial or rational interpolation, spline, or Thiele's continued fraction interpolation methods. Two interactive task templates let you draw points and view the Bézier curve and create an interpolation with equispaced points.


Using the Curve Fitting Assistant



Providing Data


To begin a curve fitting problem, you will need to first provide data. The data can be specified as a collection of points, or as separate collections of values and values.
You may want to import data from a file using Tools>Assistants>Import Data.... For more information on importing data, see the Importing Data section of the Tutorial on Data Manipulation.
If you want to define the data in Maple, you can list the pairs of data or define a 2column Array or Matrix containing the data.
list of data points


two lists, for values and values


Figure 1  Two ways to provide data



After you have provided the data, rightclick on the data and choose Curve Fitting>Interactive Curve Fitting from the context menu.

Figure 2  Access the Curve Fitting Assistant in the context menu



You will be asked to provide a name for the independent variable. Then the assistant opens with the data loaded.
Alternatively, you can use the CurveFitting[Interactive] command to call the Curve Fitting Assistant.
Note: It is possible to launch the Curve Fitting Assistant directly from the Tools>Assistants menu. You will then have an opportunity to import the data. In the Curve Fitting Assistant's first window, click the Import button to use Maple's Import Assistant:
However, this method is less practical because once you close the Curve Fitting Assistant, you cannot review the data or access it for further analysis.


Fitting the Curve


After the data is imported into the Curve Fitting Assistant you can explore different curve fitting methods. The following data is used in this section:

Figure 3  Curve Fitting Assistant



This window displays a plot of the points, an indication of the vertical range of the plot, and a selection of relevant curve fitting commands to the right. At the bottom of the window there is a box that displays the interpolant found with the selected curve fitting algorithm.
Note: Rational interpolation is only available if the data contains no decimal values. Thiele interpolation is available if the dependent variable values in the data are unique.
For the rational interpolation and splines options, sliders allow you to control the maximum degree of the numerator and denominator used in the rational interpolant or the degree of the spline being used during the curve fitting procedure.
The least squares section provides an input box where you can specify an expression in terms of . The parameters will be fit by the Least Squares command with values according to this procedure. Only expressions that are linear in terms of the parameters are allowed.
In this example, enter the expression a*x^2+b*x+c. Then click the Plot button for the least squares method to see the result.

Figure 4  Fitting a curve to the data points



Click Done to return the interpolant for the leastsquares approximation.
For more information on the leastsquares fitting command, see CurveFitting[LeastSquares].
The Curve Fitting Assistant allows you to explore different curve fitting algorithms and easily see the plot of the resulting curve. This interface also allows for experimenting with setting different settings for the curve fitting procedure. When you find the curve that you are looking for, you can choose to return the interpolant (equation) or the plot when you finish using the assistant.



Curve Fitting Task Templates


From the Tools menu, choose Tasks>Browse and then Curve Fitting.
Use these task templates to find a function that fits your data points using Bspline, least squares approximation, polynomial or rational interpolation, spline, or Thiele's continued fraction interpolation methods. Two interactive task templates let you draw points and view the Bézier curve and create an interpolation with equispaced points.

Fit a Function to your Data


The Task Templates show you how to perform this task in Maple using polynomial, rational, spline, Bspline, least squares approximation, or Thiele's continued fraction interpolation methods.
Insert a Task into a worksheet and replace the placeholders with your information. (See Using Tasks for details.)
Example: Polynomial Interpolation
Here, the task was inserted with the Insert Default Content button. This inserts the title and description as well as the example.
To replace the placeholders, place your cursor at the beginning of the first execution group and press tab. Replace the highlighted data with your data. Press tab to move to the next placeholder () and replace with a variable name of your choice.


Polynomial Interpolation


Calculate the interpolated polynomial of specified data points. This produces a polynomial of degree n, where n is one less than the number of data points.
Enter a list of data points.
>


 (1) 
Specify the independent variable, and then calculate the interpolated polynomial.
>


 (2) 
>




For example, we replaced the data with 5 new data points and called the variable .
The returned curve is a polynomial of degree 4.

>


 (3) 
>


 (4) 
>



Example: Least Squares Approximation
Here, in addition to specifying the data points and the variable name, you can also specify the format of the function to be returned.
The Task shows . Other examples include and .


Least Squares Approximation


Calculate a least squares approximation using specified data points.
Least Squares Fit of Data by a Specified Curve

List of Data Points:

>


 (5) 

Fitting Curve:

>


 (6) 

Independent Variable:

>


 (7) 

Least Squares Curve:

>


 (8) 









Generate Bézier Curves Interactively


The Bézier Curves Task Template is an interactive template. As you draw points, the curve fitting is calculated and shown.
Bézier Curves

•

Use the slider to select , the degree of the Bézier curve.

n =
•

Press
to initialize/clear the plot window.

•

Click on the plot area and select the Click and Drag Manipulator (
) from the Plot menu or plotting toolbar.

•

Click to insert control points

•

Drag control points to modify the Bézier curve.

•

Below, find the Bézier curve








Create an Interpolation with Equispaced Points


The Interpolation with Equispaced Points Task Template is also interactive:



Package Overview


Within Maple, the CurveFitting package that contains the following command to fit a curve to your input data:
The commands within this package are the same commands that are called by the Curve Fitting Assistant. Once you have determined the command that best suites your data set, you can call the command directly without needing the Curve Fitting Assistant. More information on each of the commands, including options available with each command, can be found in the help pages.
The Statistics package also offers more advanced regression commands. See Statistics/Regression for more information.

Go to Maple Portal Maple Portal for Math Educators
