Created
October 22, 2019 16:25
-
-
Save md-abdul-halim-rafi/62daeac4ec69460f296efdb10b1aa851 to your computer and use it in GitHub Desktop.
Lagrange Interpolation using Fortran
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
1.0 181.0 | |
2.0 155.0 | |
3.0 161.5 | |
4.0 183.0 | |
6.0 214.1 | |
10.0 319.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
program lagrange | |
implicit none | |
integer, parameter :: n = 6 | |
integer :: i, j | |
real :: x(n), y(n), output, xp, p | |
open(unit = 2, file = 'input.txt') | |
do i = 1, n | |
read(2,*)x(i), y(i) | |
end do | |
do i = 1, n | |
write(*,*)x(i), y(i) | |
end do | |
output = 0; xp = 7!Approximation point | |
do i = 1, n | |
p = 1 | |
do j = 1, n | |
if(i == j) then | |
p = p * 1 | |
else | |
p = p * (xp-x(j)) / (x(i)-x(j)) | |
end if | |
end do | |
output = output + p * y(i) | |
end do | |
write(*,'(2/, A24, F10.4, 2/)')"Approximate result : ", output | |
end program |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment