|
-
Apr 8th, 2002, 09:48 PM
#1
Thread Starter
Hyperactive Member
A nice easy linear expression question for you (or is it?)
Hiya, i have a database full of records and each has 4 points. i want to take these four points, and plot a line of best fit for them without having to draw the graph for them (cause i want to make my program do it you see). So.. how can you, given four not exactly straight line points, obtain an approxiamte linear equation for them?
Thanks for you time 
Ang
-
Apr 9th, 2002, 04:15 AM
#2
I think...
Not exactly sure, but it has something to do with the sum of the squares of the differences between the points and the line.
Kinda like Chi-squared
-
Apr 9th, 2002, 03:15 PM
#3
Hyperactive Member
Psycho_NZ
What you want to do is called regression. You're trying to choose a slope and intercept that give you the smallest differences between the fitted line and your data points (least-squares).
Anyway, here are the formulas:
The slope of the best-fit line, m, is given by
m = [nSum(xy) - Sum(x)Sum(y)]/[nSum(x^2) - (Sum(x))^2]
where
n is the number of data points
and
Sum(x) is the sum of all your x values
Sum(xy) is the sum of the product of each x and y pair
and so on...
The intercept, b, is given by
b = Yavg - mXavg
where
Yavg = the average of all Y values
Xavg = the average of all X values
That will give you the best fit line.
-
Apr 9th, 2002, 05:15 PM
#4
Thread Starter
Hyperactive Member
Hey your notation is way easier to understand than the websites i found on it.
Thanks 
Ang
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|