! From: "COMPUTATIONAL PHYSICS, 2nd Ed" ! by RH Landau, MJ Paez, and CC Bordeianu ! Copyright Wiley - VCH, 2007. ! Electronic Materials copyright: R Landau, Oregon State Univ, 2007; ! MJ Paez, Univ Antioquia, 2007; and CC Bordeianu, Univ Bucharest, 2007 ! Supported by the US National Science Foundation ! ! lagrange.f: Langrange interpolation of cross table Program lagrange Implicit none Real*8 :: inter, x, xin(9), yin(9) Integer :: i, e e = 9 open(6, File = 'lagrange.dat', Status = 'Unknown') ! Input data data xin /0, 85, 580, 758, 800, 1285, 850, 795, 82/ data yin /18.6, 16, 85, 83.5, 58.8, 19.9, 10.8, 88.25, 4.7 / ! Calculate f(x) Do i = 0, 1000 x = i*0.2 write (6, *) x, inter(xin, yin, e, x) End Do Close(6) Stop 'data saved in lagrange.dat' End Program lagrange ! Evaluate interpolation function(x) Function inter(xin, yin, e, x) Implicit none Integer :: i, j, e Real*8 :: inter, lambda(9), xin(9), yin(9), x inter = 0 Do i = 1, e lambda(i) = 1 Do j = 1, e If (i.neqv.j) then lambda(i) = lambda(i) * ((x - xin(j))/(xin(i) - xin(j))) Endif End Do inter = inter + (yin(i) * lambda(i)) End Do Return End