23.10.2014 Views

Numerical Analysis Programs Using Fortran 90 - University of ...

Numerical Analysis Programs Using Fortran 90 - University of ...

Numerical Analysis Programs Using Fortran 90 - University of ...

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Problem: Write a program to find the interpolated value for x = 3, using<br />

Lagrangian Polynomial, from the following data.<br />

X 3.2 2.7 1 4.8<br />

F(x) 22 17.8 14.2 38.3<br />

program Lagrange_Iterpolation<br />

dimension x(20),y(20)<br />

n=4<br />

xx=3<br />

data (x(i), i=1,4)/3.2,2.7,1,4.8/<br />

data (y(i), i=1,4)/22,17.8,14.2,38.3/<br />

s=0<br />

do i=1,n<br />

p=1<br />

do j=1,n<br />

if (i.eq.j) goto 5<br />

p=p*(xx-x(j))/(x(i)-x(j))<br />

5 enddo<br />

s=s+p*y(i)<br />

enddo<br />

print*,'Interpolation <strong>of</strong>(',xx,')=',s<br />

end<br />

^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^<br />

Interpolation <strong>of</strong> (3) = 20.21196<br />

22

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!