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!(adsbygoogle = window.adsbygoogle || []).push({});

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

**Physics Forums - The Fusion of Science and Community**

The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

# Numerical recipe problem

Can you offer guidance or do you also need help?

Draft saved
Draft deleted

Loading...

Similar Threads - Numerical recipe problem | Date |
---|---|

Python Numerical integration 'quad' error | Jan 29, 2018 |

Numerical Integration with variable limits MATLAB | Jan 15, 2018 |

Python Integrating to Infinity Numerically | Sep 14, 2017 |

C/++/# How to integrate when one of the limits is a variable? | Jun 13, 2017 |

Getting xodeint from numerical recipes to work in dev-c++ | Feb 1, 2015 |

**Physics Forums - The Fusion of Science and Community**