0% found this document useful (0 votes)
8 views2 pages

P3

The document contains a Fortran program that reads input values for x and f, computes divided differences, and outputs a formatted table of these values. It also includes a function to evaluate the polynomial at a given point using the divided differences. The program concludes by calculating and displaying the value of f(0.8).

Uploaded by

ZeReF Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views2 pages

P3

The document contains a Fortran program that reads input values for x and f, computes divided differences, and outputs a formatted table of these values. It also includes a function to evaluate the polynomial at a given point using the divided differences. The program concludes by calculating and displaying the value of f(0.8).

Uploaded by

ZeReF Gamer
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

program name

implicit none
integer :: i, j, row
real :: p, x(1:5), f(1:5), d(1:4, 1:5)
real :: fun

read(*,*) (x(i), i=1, 5)


read(*,*) (f(i), i=1, 5)

do i=1, 4
d(1, i) = (f(i+1) - f(i)) / (x(i+1) - x(i))
end do

do i = 2, 4
do j = 1, 4-i+1
d(i, j) = ( d(i-1, j+1) - d(i-1, j) ) / (x(i+j) - x(j))
end do
end do

12 format(6x, "x", 20x, "f(x)", 26x, "D1", 30x, "D2", 28x, "D3", 30x, "D4")
13 format(160('_'))
write(*, 12)
write(*, 13)

do i = 1, 2*5 - 1
row = i;
if(i > 5) then
row = 2*5-i;
end if
do j = 1, row
if(mod(row, 2) .ne. 0) then
if(j == 1) then
write(*, '( 2(f10.5, a12) )', advance="no") x( (i+1) / 2 ), "
", f( (i+1) / 2 )
else if(mod(j, 2) == 0) then
write(*, '(a31)', advance="no") " "
else
write(*, '(f31.5)', advance="no") d(j-1, (i-j+2)/2)
end if
else if(mod(row, 2) == 0) then
if(mod(j, 2) .ne. 0) then
write(*, '(a31)', advance="no") " "
else
write(*, '(f31.5)', advance="no") d(j-1, (i-j+2)/2)
end if
end if
end do
write(*,*)
end do

write(*,'(/)')
write(*, *) "The value of f(0.8) is ", fun(0.8, x, f, d)
end program

function fun(v, x, f, d)
implicit none
integer :: i
real :: x(1:5), f(1:5), d(1:4, 1:5)
real :: v, res, fun

res = 1
fun = f(1)
do i=2, 5
res = res * (v - x(i-1))
fun = fun + res*d(i-1, 1)
end do

end function

You might also like