Fortran:错误:函数的返回类型不匹配

时间:2019-03-19 13:59:49

标签: fortran

我正在尝试使用Fortran实现Newton–Raphson方法,但是会出现错误:

      enNew=en-(cumulativa(z,A,M,T,en)-random)/sigma(z,A,M,T,en)
                                                   1 Error: Return type mismatch of function ‘sigma’ at (1) (UNKNOWN/REAL(4)) prova_estrazione.f90:83:47:

      enNew=en-(cumulativa(z,A,M,T,en)-random)/sigma(z,A,M,T,en)
                                                   1 Error: Function ‘sigma’ at 

(1) has no IMPLICIT type

这是我的代码:

FUNCTION cumulativa(z,A,M,T,en)
    INTEGER::z
    INTEGER::A
    REAL::M
    REAL::T
    REAL::en
    REAL::cumulativa

    cumulativa=6.8951*(en*beta(A,M,T)*((0.14503*sqrt(we(A,M,T))+1.4503/sqrt(we(A,M,T))-0.458627*sqrt(en/we(A,M,T)))*Zs(z,A,M,T)**2-&
10.*log(en/10.)*beta(A,M,T))+we(A,M,T)*(-10+en-0.458627*sqrt(en/we(A,M,T))*Zs(z,A,M,T)**2*beta(A,M,T)))/en/&
(-68.951+6.8951*we(A,M,T)+(-6.32456+sqrt(we(A,M,T))+10./sqrt(we(A,M,T))*Zs(z,A,M,T)**2*beta(A,M,T))-&
log(we(A,M,T)/10.)*beta(A,M,T))
    RETURN
END FUNCTION cumulativa


FUNCTION sigma(z,A,M,T,en)
    INTEGER::A
    REAL::M
    REAL::T
    INTEGER::z
    REAL::en
    REAL::sigma

    sigma=68.951*we(A,M,T)*(1.+3.14/137.*(1.-en/we(A,M,T)*sqrt(en/we(A,M,T))*Zs(z,A,M,T)**2*beta(A,M,T)-en*beta(A,M,T)**2/we(A,M,T)))/&
en**2/(-68.951+6.8951*we(A,M,T)+(-6.32456+sqrt(we(A,M,T))+10./sqrt(we(A,M,T))*Zs(z,A,M,T)**2*beta(A,M,T))-&
log(we(A,M,T)/10.)*beta(A,M,T))
    RETURN
END FUNCTION sigma

SUBROUTINE Newton(z,A,M,T,en,random,enNew)
    IMPLICIT NONE
    REAL, INTENT(in)::M, T, en, random
    INTEGER, INTENT(in)::z, A
    REAL, INTENT(out)::enNew

    enNew=en-(cumulativa(z,A,M,T,en)-random)/sigma(z,A,M,T,en)
END SUBROUTINE Newton



PROGRAM estrazione
    IMPLICIT NONE
    REAL T, sigma, en, enNEW, M, cumulativa
    INTEGER z, A
    REAL dx, random, tols
    INTEGER n, maxiterator,i

    tols=0.001
    n=1
    dx=1000.
    maxiterator=100

    T=1.*10**9
    z=1
    A=1
    M=938000000.
    en=rand()*10**9

    DO i=1,10
        random=rand()
        DO WHILE((dx>tols) .and. (n<maxiterator) )
            enNEw=en-(cumulativa(z,A,M,T,en)-random)/sigma(z,A,M,T,en)
            dx=abs(enNew-en)
            en=enNew
            n=n+1

        END DO
        WRITE(*,*) enNew
        WRITE(*,*) en
    END DO
END PROGRAM estrazione

betawe是复杂的函数。错误在哪里?我以相同的方式使用cumulativasigma,为什么我只对sigma遇到错误?

0 个答案:

没有答案