首页 > 解决方案 > fortran 坐标函数 f(x)

问题描述

我需要在 FORTRAN 90 中进行一些数学计算。为此,我需要使用其他函数的坐标函数。一个例子如下

program test1
implicit none
    integer :: i, Nend
    double precision :: step, a, b
    double precision, dimension(:), allocatable :: t

    Nfim = 10
    a = 0.d0
    b = 1.d0
    step = (b-a)/Nend

    allocate(t(0:Nfim))
    t(0) = a
    do i=0,Nfim
        t(i+1) = t(i) + step
        write(*,*) i, t(i), f(t(i)),g(t(i))
    end do

contains
    function f(x)
        implicit none
        double precision :: f
        double precision, dimension(2) :: f
            f(1) = x-1.d0
            f(2) = 2.d0*x
        return
        end function

    function g(x)
        implicit none
        double precision :: x, g
            g = f(1)(x)+2.d0*f(2)(x)
        return
        end function
end program

我提示我有回报

34 |     g = f(1)(x)+2.d0*f(2)(x)
   |           1
Error: Invalid character in name at (1)

我确实明白,在 f(...) 中,''...'' = x 而不是 ''...'' = 1。我不喜欢使用 f1,因为在我的程序中,维度函数 f 将是可变的,该程序将适用于其他情况,这将为我节省一些时间。你能帮助我吗?现在谢谢你!

标签: mathfortrancoordinatesfortran90

解决方案


推荐阅读