Fortran 90:调用函数时(1)处无法分类的语句

问题描述 投票:0回答:2

我对于fortran来说还比较陌生,我有一项任务是查找正交权重和点,其中这些点是第n个Legendre多项式的零(使用newtons方法找到);我创建了函数来查找Pn(x)和P'n(x)的值以将其子类化为newtons方法。但是,当在正交子例程中实际使用函数时,它会返回:

Coursework2a.f90:44.3:

x = x-P(n,x)/ dP(n,x)1个错误:无法分类的陈述在(1)

有人知道为什么将此陈述归为无法归类吗?

subroutine Quadrature(n)

implicit none
integer, parameter :: dpr = selected_real_kind(15) !Double precision
real(dpr) :: P, dP, x, x_new, error = 1, tolerance = 1.0E-6, Pi = 3.141592 !Define Variables
integer, intent(in) :: n
integer :: i

!Next, find n roots. Start with first guess then iterate until error is greater than some tolerance.

do i = 1,n

    x = -cos(((2.0*real(i)-1.0)/2.0*real(n))*Pi)

    do while (error > tolerance)

        x_new = x

        x = x - P(n,x)/dP(n,x)

        error = abs(x_new-x)


    end do 

    print *, x

end do

end subroutine Quadrature
fortran fortran90
2个回答
3
投票

x = -cos(((2.0*real(i)-1.0)/2.0*real(n))*Pi)

很可能在分母周围缺少括号。照原样,该行将(2.0*real(i)-1.0)除以​​2.0,然后将整个内容乘以real(n)。这可能就是为什么每个循环的根都相同的原因。


0
投票

实函数p(n,x)实数:: n,xp = 2 * x ** 3!或输入给您的函数。结束功能

实函数dp(n,x)实数:: n,xdp = 6 * x ** 2!我想是指多项式p的导数。结束功能

这样在主程序之外单独定义功能。在主程序中,声明如下功能:真实的,外部的:: p,dp

© www.soinside.com 2019 - 2024. All rights reserved.