Graphmatica performs curve-fitting using a very flexible algorithm known as the Levenberg-Marquardt method. For polynomial curve fitting of small data sets, you can choose to use Lagrange interpolation instead. Depending on your data set and expected results, you may need to experiment with the options in the Curve Fit tab of the Settings dialog box to get the best results.

Maximum number of iterations The Levenberg-Marquardt method is an iterative algorithm. Up to a point, the longer you run it, the more accurate the result. Graphmatica monitors the value and difference between the chi2 value on each iteration and automatically stops when the calculation appears to have converged within the limits of precision of this implementation. If your approximation converges, increasing the number of iterations will not make any difference. However, some data sets may not converge within this number of iterations, in which case the program stops the curve-fitting process to prevent it from taking too long. In this case, you may want to increase this option and see if you can achieve any significant reduction in the chi2 value with further iterations.

There are also several different forms of equations you can attempt to fit your data to:


This option fits a curve to the generalized polynomial

    y = A0x^n + A1x^n-1 + … + An-1x + An

You can control the number of coefficients that the program will attempt to fit (i.e. the value of n in the above equation) using the box for Maximum order of polynomial. Note that if the maximum number of iterations is high enough, you will probably get the same result even if this value is set higher than it needs to be (i.e. if you set it to 4 and the curve is best fit by a quadratic equation). However, the algorithm runs to completion much more quickly if you set this number as low as needed because there number of possibilities to consider increases exponentially as you increase this value.

For data sets with a small number of points (<= 10), you can choose to perfom Lagrange interpolation instead of running the Levenberg-Marquardt algorithm by marking the Use Lagrange interpolation checkbox. This method is very fast and guarantees an exact fit for all of the points in the data set. However, it cannot be used with data sets that contain multiple y values for a single x value. Also, the solution will be a polynomial of order n-1 (where n is the number of points in your data set), unless there is a lower-order polynomial that fits all of your data exactly. An error message wil be displayed if you attempt a Lagrange interpolation with the maximum order set to less than n-1 and there is no exact solution.


Use this option to fit the curve to the generic sinusoidal equation

    y = A sin (Bx + C) + D

That is, find the best values for amplitude, period, phase shift, and y offset to fit the data set to a sine curve. Note that due to the periodicity of this curve, the curve-fitting algorithm doesn't work so well if it is not given a relatively close estimate of the parameter B to start out with (it tends to get stuck in the local minimum for an erroneous value of B). To help it out fill in the field marked estimate number of periods with your best guess at the number of peaks or valleys in the data set. The program will automatically calculate a starting value for B based on this and the domain of the data set. Usually if you are off by one in either direction, the curve-fitting algorithm will still work, but if you fail to provide this parameter or are off by more than that, you will get a result that is obviously wrong.


Use this option to fit the data to an exponential growth curve of the form

    y = a b^x

Since the curve fitting in this case is performed by fitting the polynomial y = ax+b to the logarithms of the y values, you may not use this option with points whose y coordinate is less than or equal to zero.


This is an S-shaped curve of the form

    y = k / (1 - ce^bx)

Where the coefficient k is the peak carrying capacity, and b and c determine the rate at which the curve tends from zero to k. (For graphs in the first quadrant, b and c will usually be negative.)

Power function

Use this option to fit the curve to the equation

    y = a x^b

Note that since the curve-fitting is actually performed on the logarithms of both coordinates in each point, all of your data points must be in the first quadrant (i.e. > 0 on both axes).

Logarithmic function

Use this option to fit the curve to the equation

    y = a + b ln x

All of the x coordinates in your data set must be greater than zero to user this option, since ln x is not defined for x ≤ 0

Help contents

Back to kSoft homepage...

kSoft, Inc. Last updated: Sun 11 Jun 2017