MaplePortal/CurveFitting - Maple Help
For the best experience, we recommend viewing online help using Google Chrome or Microsoft Edge.

Online Help

All Products    Maple    MapleSim

Home : Support : Online Help : MaplePortal/CurveFitting

Curve Fitting in Maple

Go to Maple Portal     



Using the Curve Fitting Assistant

Curve Fitting Task Templates

Overview of Packages Related to CurveFitting.

See Also


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 B-spline, least squares approximation, polynomial or rational interpolation, spline, or Thiele's continued fraction interpolation methods. Two interactive task templates let you draw points, 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 first need to provide data. The data can be specified as a collection of points, or as separate collections of x-values and y-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 2-column Array or Matrix containing the data.


list of data points


two lists, for x-values and y-values


Figure 1 - Two ways to provide data


After you have provided the data, select the data and choose Curve Fitting>Interactive Curve Fitting from the Context Panel.



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>Tutors>Statistics 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 after 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:


1, 2, 3, 4, 5, 6, 7, 8, 4, 10, 22, 44, 102, 190, 300, 436



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 x.  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 least-squares approximation.

1, 2, 3, 4, 5, 6, 7, 8, 4, 10, 22, 44, 102, 190, 300, 436curve fitting assistant3467101821x+25321x2


For more information on the least-squares 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 B-spline, least squares approximation, polynomial or rational interpolation, spline, or Thiele's continued fraction interpolation methods. Two interactive task templates let you draw points, 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, B-spline, 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 (x) 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.





Specify the independent variable, and then calculate the interpolated polynomial.




For example, the data gets replaced with 5 new data points and called the variable t.


The returned curve is a polynomial of degree 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 ax2+bx+c.  Other examples include ax+b and  a3 x+b x.

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:




Fitting Curve:

a x2+b x+c



Independent Variable:




Least Squares Curve:






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 n, 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 n+1 control points Pk,k=0,,n. 


Drag control points to modify the Bézier curve.


Find the Bézier curve

R=k=0nnk1unkuk Pk 


Create an Interpolation with Equispaced Points


The Interpolation with Equispaced Points Task Template is also interactive:


Interpolation with Equispaced Points: Enter f and the interval a,b


a =                b =



Interpolation Type



Number of Points in Addition to a and b


N=  =


Overview of Packages Related to CurveFitting.


This page provided an introduction to the CurveFitting package, which 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.  After 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 Interpolation package provides more interpolation functionality, including a easy-to-use model for inputting the data once and then using it like a normal mathematical function, for example, plotting, integration, or just to evaluate at a given point.  It includes the ability to interpolate over irregularly spaced data in 2 (or more) dimensions, and includes some additional methods of integration, such as Kriging.


In addition, the Statistics package also offers more advanced regression commands.  See Statistics/Regression for more information.

See Also

CurveFitting, Statistics/Regression, Tutorial on Data Manipulation, Using Tasks


Go to Maple Portal