以下为代码,捣鼓一下午了
[Fortran] 纯文本查看 复制代码 Program lagrange
Implicit none
integer::t,n,i,j,k
real::tmp
real,dimension(1)::x,y
real,dimension(2)::p(17,2)
print*,"请输入气压值"
read*,t
open(10,file='d:\my fortran\air_tmp.txt')
read(10,*)((p(k,j),j=1,2),k=1,17)!17行2列
close(10)
do i=1,17
x(i)=p(i,1)
y(i)=p(i,2)
enddo
print*,x,y
tmp=fun(t)
print*,tmp
contains
function fun(t) result(tmp)
implicit none
integer::t,n,i,j
real::tmp
real,dimension(1)::x,y,l
do i=1,n
do j=1,n
if(i/=j) then
l(i)=l(i)*(t-x(j))/(x(i)-x(j))
else
return
endif
enddo
tmp=l(i)*y(i)+tmp
enddo
endfunction fun
end program |