Fortran minimization of a function with additional arguments

后端 未结 2 1369
眼角桃花
眼角桃花 2020-11-27 23:34

In fortran I have an external optimization routine that takes as an input the function f(x) and the starting point and returns the value for local minimum. For

2条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-28 00:11

    You don't need anonymous functions for this. Your Matlab example is also not anonymous in the end, it has a name g.

    Fortran internal functions are of great use here (Fortran 2008 feature, but supported in gfortran and ifort, not supported in Solaris Studio):

    call minimum(g, x0, xopt)
    
    contains
    
      real function g(x)
        real, intent(in) :: x
        g = f(x,data)
      end function
    
    end
    

提交回复
热议问题