Click here to Skip to main content
15,843,200 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am trying to create a simple windows form application in visual studio 2010 using C#.

I want to feed the program 5 (x,y) coordinates and based on these points have the program fit a line through them.

For example, if my x values are dollars and my y values represent customer satisfaction, then I will feed the program the following 5 points:


(x,y)

($0,0)
($25000, 0.10)
($50000, 0.25)
($75000, 0.60)
($100000, 1.0)

Based on these points given to the program, I would like the program to create a smooth curve through the points and give me y values that fall between the points above.

In other word, I will ask the program based on the 5 points to now tell me what the satisfaction level is for $60000 which falls between 0.25 and 0.60 as per the table above.

I don't really need a graph to be drawn - just need the correct y value for any x value I ask.

Any help would be greatly appreciated. :)

Thanks,

Hunter
Posted
Updated 21-May-10 9:47am
v2

1 solution

First, figure out how to do linear regression with C# C# linear regression[^]

Then, use that calculated regression to determine your next value.
 
Share this answer
 
Comments
Hunter James 21-May-10 14:41pm    
Thanks for the reply.

I am looking to fit a smooth curve rather than a linear line.
khalidSabtan 21-May-10 15:42pm    
you need to study linear interpolation ,breifly find the equation of the line between ur 2 points (.25,50000) (.60,75000) knownig that slope (=m)
m=(y2-y1)/(x2-x1) then your equation -> y=m*x+b to get the 60000
60000=slope*x+b
solve for x
if however u need to fit it in smoothe curve u have to study curve fitting such as tylor Polynomial,Lagrange Polynomial..,Newtons Interpolatory divided diffrence and many more
cheer
Hunter James 21-May-10 17:14pm    
Thanks so much. That really helps guide me in the right direction.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900