> From: Harold Hallikainen[SMTP:harold@HALLIKAINEN.COM] > Sent: Friday, May 14, 2004 6:52 PM > To: PICLIST@MITVMA.MIT.EDU > Subject: [PIC:] Parabolic Interpolation > Anyone have a favorite routine for parabolic interpolation of integer > values in Microchip C? I have an array of x values and an array of y > values. I'd like to pass in an arbitrary x and get a y. > THANKS! > Harold Three points are enough to define a parabola. Choose three of your defined X values such that X' (the arbitrary X) lies between two of them. Usually three consecutive values are used, but this is not necessary. Form the following three terms using the three chosen values of X: L(1) = (X ' - X2) * (X ' - X3) / ( (X1 - X2) * (X1 - X3) ) L(2) = (X ' - X1) * (X ' - X3) / ( (X2 - X1) * (X2 - X3) ) L(3) = (X ' - X1) * (X ' - X2) / ( (X3 - X1) * (X3 - X2) ) Now find Y(X ' ) using Y(X ' ) = sum( Y(k) * L(k) ) k = 1, 2, 3 where Y(k) is the given Y corresponding to the given X(k). This method fits a parabola to the three given (X, Y) pairs and evaluates that parabola for the value X = X '. Only the three points chosen are used in the fit. If you want to use all of the given Y values for the interpolation, you will need a more complicated formula. Basically you fit all of the Y's to a quadratic form, evaluating the a, b, c's in Y = a * X ^ 2 + b * X + c (this is done only once for your data, resulting in a least squares fit to all of the data), and then evaluating Y for X'. You then would not have to choose values of X bracketing your X', but you have to do more work at the beginning. John Power -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads