Curve Fitting

Curve fitting is finding a line or curve that passes most closely through a given set of points, minimizing the distances between the line and the actual points and providing the function whose curve is the line.

Entering the points

Suppose you have some data involving two variables, in the form of several pairs of values for them. To find about the relationship between the variables, the first step is to plot the pairs of values as points on a graph, using the tool. In case you have only two points you can use the tool to mark them.

I n case you have several different sets of points marked on the image with the tool, open the Measurement window, select the desired set of points in the measurement grid and then click the button on the Measurement window toolbar. Alternatively you can click the same button on the Main toolbar. If you do not select any point, the program will offer you two choices: cancelling or using all points on the image.

If either line or only two points are selected, the program will calculate a lineal function for that line, but if more than two points are used the program will open a the following window to select which best-fit line method you want to use:

In all cases you can set the color used to plot the line. Each time you click Apply, a new function will be calculated and another line will be drawn. Click close when you are done.

Notice that the best-fit line does not necessarily pass through any of the points plotted.

If a segment was used, then the calculation results will be appended a comment to the segment drawn to show the best-fit line.

Options tab

When a set of points is used, a new measurement showing the curve will be added and the function and settings will be appended as a comment.

The image to the left shows the Curve fitting window, it has Apply and Close buttons. Click Apply to draw the curve, if you are satisfied with the curve, then click Close to terminate the measurement.
In case you want to play with different functions and settings, you can modify the settings and the curve color and click Apply again, each time you click Apply a new curve will be drawn. or the previous curve will be replaced if Replace select curve is selected. If a new curve is added, consequently a new measurement will be created.

Export tab

Curves always will be calculated using Cartesian coordinates, no matter if another origin of coordinate system is set in the Preferences window,

Function Type of line Plotting
Tool
Options
Straight line Straight or

None

Constant X or Y Linear Straight  
Polynomial Approximation Curve Precision*
Polynomial Grade****
Polynomial Interpolation Curve Precision*
Exponential 1 Curve (line plotted in the metafile)  

Precision*
Metafile size**

Exponential2

Precision*
Metafile size**

Power Fit

Precision*
Metafile size**
Hyperbolic Precision*
Metafile size**
*

Precision can vary from 53 to 380 bits and is supported for all non lineal functions.
The precision is the number of bits used to represent the mantissa of a floating-point number. With a precision of 53 bits (the default value), calculations should be able to exactly reproduce all computations with double-precision machine floating-point numbers (double type in C), except the default exponent range is much wider and subnormal numbers are not implemented.

** Metafile size: Some equations can generate not only a curve, but also a linear or logarithmic equation, producing so a separate image that is stored as a Windows Enhance Metafile. Width and Height set the metafile dimensions, in pixels. To view, copy, print or save the metafile associated with any curve, click the Best Fit Line > Show Metafile menu, in the Measurements window.
*** A high Polynomial Grade will take a while to be calculated (maximum is 50). Adjust the Polynomial Grade to achieve the best curve fittings for your points.

Note:

Origin of coordinates system: Different from usual standard graphing, computer graphic coordinates start at the top left corner of the image, so the Y axis goes from top to bottom, not otherwise.
Nevertheless, when calculating a Curve fitting measurement, normal Cartesian coordinates are used in all cases, so graphics coordinates are counted from the bottom left corner of the image.
From all other measurements, you can use upper or lower left coordinates, setting them in the Preferences window.
Notice that the set of points used to calculate may or not show its coordinates as Cartesian in the Measurement windows, it depends on Preferences settings, but the coordinates always will be converted to Cartesian before calculating a Curve Fitting measurement.

Example

Two Polynomial Approximation curves and plotted points. Equation and settings as shown in the measurement comments pane, for the magenta curve

Polynomial Approximation
Polynomial Grade: 3
Precision: 83
Conversion factor: 5.40540540540541
Polynomial Approximation:y= -x^3*0.0000019634157449615690609+ x^2*0.003574258163867946972814-x*2.035402615688351599509343+ 204019077686786698928263764322864371992241597868361111724971244331215360/ 296464399273805806941904709964673302334661178973817857498863944515649

Note: depending on the chosen Precision setting, the resulting numbers will be longer or shorter.

 

Two-variable Statistics and Linear Regression

Two  variable statistics make possible the development of a relationship (correlation) between two sets of data. Each pair of data has x and y values. From these sets of data a line of regression can be established. The relationship of the two sets of data by use of the straight line method is called Linear Regression. In Linear Regression there are three important values, r, a, and b.

The equation of the straight line is y  = a + bx, where a is the point at which the line crosses the Y-axis and b is the slope of the line.

The correlation coefficient r shows the relationship between two sets of data. A perfect correlation between two values is an r equal to 1 (-1 is a perfect negative correlation); in other words, by knowing the value of one variable you can predict with 100% accuracy the value of the other variable. The further the value of r is from 1, the less reliable will your predictions be. The following table can be used as a set of definitions of the values of the correlation coefficient:

 

Value of r Call it

Positive
Correlation

+0.80 to +1.00
+0.60 to +0.80
+0.40 to +0.60
+0.20 to +0.40

Extra High
High
Moderate
Low

 

-0.20 to +0.20

Nil

Negative
Correlation

-0.20 to -0.40
-0.40 to -0.60
-0.60 to -0.80
-0.80 to -1.00

Low
Moderate
High
Extra High