 
6 December 2009 Author: Giorgos Lazaridis The Least Squares FittingWhat is this Least Square Fitting? This method is a mathematical procedure for finding the bestfitting line (for linear systems) or curve (for nonlinear), for a given set of points. Using this method, the sum of squares of the offsets is used, instead of the offset absolute value. This means that to find a point on X axis, the Y axis is vertically increased or decreased. This causes sometimes a disproportionate effect on the fit which is not always desirable, but that depends on the problem itself. To understand this difference look at the following two images. The left one shows the way that the least squares fitting is working. The Y axis is vertically increasing or decreasing until the X value is returned. This is most of the time what the experiments request. The right image shows the perpendicular offsets.
The vertical offsets fitting is more simple and more often used method. Equations To calculate the vertical offsets fitting line, you need to make a series of calculations. Suppose that we have taken n pairs of X and Y values: First you calculate the Sum of X values: Sum_{X} = X_{1} + X_{2} + X_{3} + ...+ X_{n} Then you calculate the Sum of X^{2} values: Sum_{X2} = X_{1}^{2} + X_{2}^{2} + X_{3}^{2} + ...+ X_{n}^{2} Next calculation is the Sum of Y values: Sum_{Y} = Y_{1} + Y_{2} + Y_{3} + ...+ Y_{n} And then, the Sum of X*Y pairs: Sum_{XY} = X_{1} * Y_{1} + X_{2} * Y_{2} + X_{3} * Y_{3} + ...+ X_{n} * Y_{n} Using the calculations above, you can directly find the slope and offset of the best fitting line:
And:
To find two sets of XY points and draw a line, you use the line equation: Y = a * X + b You do this for two Xvalues and you get two Yvalues. Example For this example, i use the Dr. Calculus Least Squares calculator to do the calculations Suppose that after an experiment, we acquired the following XY pairs of values:
Now i will calculate the required sums: Sum_{X} = 224 Sum_{X2} = 8110 Sum_{Y} = 128 Sum_{XY} = 4433 And now, i will use the above numbers to find the slope and offset of the line: a = 0.46b = 3.07 Using the line equation, if will calculate the Y for two values of X. The first value will be zero (0) and the other 60: Y_{0} = a * 0 + b => Y_{0} = 3.07 Y_{60} = a * 60 + b => Y_{0} = 30.67 In the following diagram, the red points indicate the XY pairs taken from the experiment, and the orange points indicate the two XY pairs calculated using the least square method. The line that connects these two points is the bestfitting line: Relative pages Comments


Contact
Forum
Projects
Experiments
Circuits
Theory
BLOG
PIC Tutorials
Time for Science
RSS
Site design: Giorgos Lazaridis © Copyright 2008 Please read the Terms of services and the Privacy policy 