恶搞美女过安检被脱:拉格朗日插值算法 源程序代码

来源:百度文库 编辑:查人人中国名人网 时间:2024/05/12 06:35:18
要用c语言的
只要c的或c++的,别的不要,谢谢

ForTran写的,要不?
subroutine LInsertValue(X,Y,n,InsertX,InsertV)
dimension x(n),y(n)
real InsertX,InsertV,temp
temp=1.0
InsertV=0.0
do i=0,n-1,2
temp=1.0
do j=0,n-1,2
if (j.ne.i) then
temp=temp*(InsertX-X(j))/(x(i)-X(j))
end if
end do
InsertV=InsertV+y(i)*temp
end do
end subroutine

program Main
character*32 nodes
real InV
real,allocatable::x(:),y(:)
nodes="NODES.DAT"
open(11,file=nodes,status='old',form='formatted')
n=0
do while(.not.eof(11))
read(11,*,end=102)
n=n+1
102 end do
write(*,*) n
rewind(11)
allocate(x(0:(n-1)),y(0:(n-1)))
do i=0,n-1
read(11,100) x(i),y(i)
end do
100 format(2e16.6)
close(11)
do i=0,n,2
call LInsertValue(x,y,n,x(i+1),InV)
write(*,'(2e16.6)') x(i),y(i)
write(*,'(2e16.6)') x(i+1),InV
end do
end program

把数据放在nodes.dat下

大家谁有C或C++的啊,我也来看看