algorithm for best fit function

  • Hi...

    I need an algorithm which will give the best fit function from given data.

    as in I have 10 values of x and y...

    from this i hv to get a curve of best fit and an equation..

    which will give us the corresponding value of x if v enter a value of y...

    with minimum error..

    the curve should pass thru all the points..

    how to go bout it??

    pleeeeeeease help me..

  • Hi

    I could not really see how does this relate to SQL Server or TSQL, but let's give it a try...

    Please, note that this is not the complete solution but the idea where to look into.

    First, find the values Ki and Ni.

    The algorithm would be:

    K1=( Y2- Y1)/( X2- X1)

    K2=( Y3- Y2)/( X3- X2)

    K3=( Y4- Y3)/( X4- X3)

    K4=( Y5- Y4)/( X5- X4)

    N1= Y1- K1* X1

    N2= Y2- K2* X2

    N3= Y3- K3* X3

    N4= Y4- K4* X4

    for all the values you have.

    Then, draw straight lines through two points:

    (0,N1) and (X1,Y1) - line L1

    (0,N2) and (X2,Y2) - line L2

    etc.

    Intersections of these lines (L1 and L2, L2 and L3, L3 and L4 ...) will give you new points that describe closer the "curviness" of you curve.

    So, drawing the curve through the points you are having + additional points (found in the way described above) will get you closer to your curve.

    Of course, how precise you will get depends on how "close" starting points (values) are.

    There are ways to find in-between values (interpolation) but it's complex to describe here and I would suggest you to look into

    Newton's Interpolation Method, or some other numerical method for finding interpolation points.

    You would probably want to look into Mathematica or some other software that has embedded algorithms for resolving this and similar tasks.

    This might not be the answer you were looking for, but I hope this will at least give you the idea of the direction for finding your solution.

    The problem itself is more for mathematicas forums rather then SQL or programming, in my opinion.

    Also, my idea is based on the assumption that you are not resolving some serious real-world problem but that this is just a programming/algorithm writing excercise. If this is not the case, you will have to do more investigation on the theory of numerical mathematics.

    Good luck!

  • thannk you all.....

    by mistake i posted this on sql forum..

    its not related to sql..

    thnks a lot for the efforts..

Viewing 3 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic. Login to reply