Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

IMSL

Status
Not open for further replies.

ignacio82

Technical User
Joined
Feb 15, 2012
Messages
9
Location
US
Hi everyone,

I'm trying to learn how to use IMSL. I have a very simple program that finds a minimum and I would like to make a modification to it.
Right now the function I'm minimizing is
F = 1.0E2*(X(2)-X(1)*X(1))**2 + (1.0E0-X(1))**2

I'm trying to figure out whether is possible to write my own subroutine (minimize1) that uses IMSL and takes a and b as arguments instead of having 1.0E2 and 1.0E0 as numbers in F.
Is this posible?
Thanks!!

Code:
USE BCONF_INT
USE UMACH_INT
 
      IMPLICIT   NONE
      INTEGER    N
      PARAMETER  (N=2)
!
      INTEGER    IPARAM(7), ITP, L, NOUT
      REAL       F, FSCALE, RPARAM(7), X(N), XGUESS(N), &
                XLB(N), XSCALE(N), XUB(N)
      EXTERNAL   ROSBRK
!
      DATA XGUESS/-1.2E0, 1.0E0/
      DATA XLB/-2.0E0, -1.0E0/, XUB/0.5E0, 2.0E0/
!                                 All the bounds are provided
      ITP = 0
!                                 Default parameters are used
      IPARAM(1) = 0
!                                 Minimize Rosenbrock function using
!                                 initial guesses of -1.2 and 1.0
      CALL BCONF (ROSBRK, ITP, XLB, XUB, X, XGUESS=XGUESS,  &
                 iparam=iparam, FVALUE=F)
!                                 Print results
      CALL UMACH (2, NOUT)
      WRITE (NOUT,99999) X, F, (IPARAM(L),L=3,5)
!
99999 FORMAT ('  The solution is ', 6X, 2F8.3, //, '  The function ', &
            'value is ', F8.3, //, '  The number of iterations is ', &
            10X, I3, /, '  The number of function evaluations is ', &
            I3, /, '  The number of gradient evaluations is ', I3)
!
      END
!
      SUBROUTINE ROSBRK (N, X, F)
      INTEGER    N
      REAL       X(N), F
!
      F = 1.0E2*(X(2)-X(1)*X(1))**2 + (1.0E0-X(1))**2
!
      RETURN
      END
 
You could be sneaky and set them up using ENTRY but I don't know if that works for your version of Fortran.
Code:
      SUBROUTINE ROSBRK (N, X, F)
      INTEGER    N
      REAL       X(N), F
      REAL       A,B
      SAVE       A,B
!
      F = A*(X(2)-X(1)*X(1))**2 + (B-X(1))**2
!
      RETURN
      ENTRY ROSBRKINIT (AVAL, BVAL)
      A = AVAL
      B = BVAL
      RETURN
      END
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top