You are on page 1of 1

program langrange

implicit none
real::xf,f=0.0
real,dimension(:),allocatable::x,fx,l_x
integer::i,n=5,j,l,m
print*," enter the point at which value is to be calculated: "
read*,xf
allocate(x(n));allocate(fx(n));allocate(l_x(n))
open(1,file='l1.dat',status='old')
do i=1,n
read(1,*)x(i),fx(i)
end do
close(1)

do j=1,n
l_x(j)=1
do l=1,n
if(j==l) then
continue
else
l_x(j)=((xf-x(l))/(x(j)-x(l)))*l_x(j)
end if
end do
end do
do m=1,n
f=f+fx(m)*l_x(m)
end do
print 5,xf,f
5 format("the value of f(x) at : ",f3.1," is ",f7.4)
end program

OUTPUT

flame@LAPTOP-CKHI1B1D:~/prateek/sem2$ vi lang.f95
flame@LAPTOP-CKHI1B1D:~/prateek/sem2$ gfortran lang.f95
flame@LAPTOP-CKHI1B1D:~/prateek/sem2$ ./a.out
enter the point at which value is to be calculated:
2.0
the value of f(x) at : 2.0 is 1.4141

You might also like