Program Interpolation; { лллллллллллллллллллллллллллллллллллллллллллллллллл лллнммммммммммммммммммммммммммммммммммммммммммолллББ лллнлл ллолллББ лллнлл Least squares method interpolation ллолллББ лллнлл ллолллББ лллнлл Aleksandar Dlabac ллолллББ лллнлл (C) 1995. Dlabac Bros. Company ллолллББ лллнлл ------------------------------ ллолллББ лллнлл adlabac@urcpg.urc.cg.ac.yu ллолллББ лллнлл adlabac@urcpg.pmf.cg.ac.yu ллолллББ лллнлл ллолллББ лллнпппппппппппппппппппппппппппппппппппппппппполллББ ллллллллллллллллллллллллллллллллллллллллллллллллллББ ББББББББББББББББББББББББББББББББББББББББББББББББББ } { Interpolation is a technique used to calculate estimated function of which we have some experimental points. Firstly, we have to choose order of interpolation. Order of interpolation represents the order of estimated function. For example, if order is 5 function will be in form of: F(x) = a5*x^5 + a4*x^4 + a3*x^3 + a2*x^2 + a1*x + a0 This program (procedure Interpolate) returns coefficients a0..an, where n is order. We have to determine the order considering positions of points. } Uses Crt, Graph; Type Row = array [0..10] of real; { Maximal order } Matrix = array [0..10] of Row; { is 10. } Data = array [1..200] of integer; { Data for interpolation } Coeff = array [0..10] of real; { Coefficients (also max. 10) } Const Order = 5; { Order of interpolated curve. Should be smaller than } { number of points. For orders greater than 6-7 system } { (of equations) becomes unstable, so curve could be } { wrong. Also, for higher orders real type should be } { changed to extended, and $N switch should be on. } Var Gd, Gm, I, J : integer; R : real; InversionOK : Boolean; Mat : Matrix; X, Y : Data; C, YM : Coeff; Function Power (Base,Pow:integer) : real; Var Temp : real; Begin If (Base<0) and (Pow mod 2=1) then Temp:=-Exp (Pow*Ln (-Base)) else Temp:=Exp (Pow*Ln (Abs (Base))); Power:=Temp End; Procedure MatrixInversion (Var A:Matrix; N:integer); Var I, J, K : integer; Factor : real; Temp : Row; B : Matrix; Begin InversionOK:=False; For I:=0 to N do For J:=0 to N do If I=J then B [I,J]:=1 else B [I,J]:=0; For I:=0 to N do Begin For J:=I+1 to N do If Abs (A [I,I])#0; CloseGraph End.