Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Numerical recipe problem

  1. Dec 1, 2009 #1
    The following code is just an example. I try to apply mnbrak.f90 to my function f=(x-i)^2. I want to make i globle variable. If I use internal procedure, I can not use mnbrak.f90, since it can not accept the internal procedure. How do I deal with it? Thanks!

    PROGRAM xbrent
    USE nr
    USE nrtype
    IMPLICIT NONE

    INTEGER(i4b) :: i
    REAL(sp) :: ax, bx, cx, fa, fb, fc
    !real, external:: f
    ! common i

    DO i=1,10
    ax=i-0.5_sp
    bx=i+0.5_sp
    CALL mnbrak(ax, bx, cx, fa, fb, fc, f)
    !!$ WRITE(*,'(1x,t13,a,t25,a,t37,a)') 'A','B','C'
    !!$ WRITE(*,'(1x,a3,t5,3f12.6)') 'X',ax,bx,cx
    !!$ WRITE(*,'(1x,a3,t5,3f12.6)') 'F',fa,fb,fc
    write(*,*) f(ax),f(bx)
    END DO

    contains

    FUNCTION f(x)
    USE nr
    USE nrtype
    IMPLICIT NONE
    REAL(sp) ::f,x
    !common i
    f=(x-i)**2.0_sp
    END FUNCTION f

    END PROGRAM xbrent
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?
Draft saved Draft deleted