Monday, December 1, 2008

One diamensional lagrangian interpolation using fortran

c One diamensional lagrangian interpolation

integer n
real x(50),f(50),a,sm,pro
print *, 'Enter the number of available stations'
read *, n

open(1,file='onedim.dat')
do i=1,n
read(1,*)x(i),f(i)
write(*,*)x(i),f(i)
enddo
close(1)

print*, 'Enter position of unknown data station'
read *, a

sm=0
pro=1

do i=1,n
pro=f(i)
do j=1,n
if(j.ne.i)then
pro=pro*(a-x(j))/(x(i)-x(j))
endif
enddo
sm=sm+pro
enddo
write(*,2)a,sm
2 format('The value at station ',f5.2,'is',f7.2)
stop
end

No comments: