Source code:
c Lagrange's interpolation
dimension x(1000), f(1000)
write(*,*)'x,n'
read(*,*)a,n
write(*,*)'xi, fi'
read(*,*)(x(i),i=1,n)
write(*,*)'f'
read(*,*)(f(i),i=1,n)
c prod=(a-x(j))/(x(i)-x(j))
sum=0
prod=1
do i=1, n
do j=1, n
c prod=(a-x(j))/(x(i)-x(j))
if(j.NE.i) then
prod=(a-x(j))/(x(i)-x(j))
sum=sum+f(i)*prod
endif
enddo
enddo
write(*,*)'ans',sum
stop
end
No comments:
Post a Comment