Numerical integration and KNITRO

108 views
Skip to first unread message

louisperrault

unread,
Jan 24, 2017, 7:42:49 AM1/24/17
to AMPL Modeling Language
Hello,

Is it possible to use some type of canned numerical integration in AMPL? Something along the lines of "integral" in Matlab (https://www.mathworks.com/help/matlab/ref/integral.html). The integral would be part of the objective function in a problem I would like to solve using KNITRO. I have looked online and in the ampl manual and I can't find anything.

Thank you so much.

Louis Perrault

Robert Fourer

unread,
Jan 25, 2017, 11:14:33 AM1/25/17
to am...@googlegroups.com
There is nothing in AMPL like MATLAB's "integral" where you define a function by an algebraic expression and then pass your function to a built-in function that numerically integrates it. If your integral can't be computed from standard integral functions that are already in the AMPL Extended Function Library (http://ampl.com/resources/extended-function-library/) then it will be necessary to create your own user-defined function; there are instructions and examples under "User-defined functions" at http://ampl.com/REFS/hooking2.pdf#page=19.

Bob Fourer
am...@googlegroups.com

=======

louisperrault

unread,
Jun 17, 2017, 11:02:11 AM6/17/17
to AMPL Modeling Language, 4...@ampl.com
Hi Bob,

Thanks for the answer. I found in the library a Numerical Integration function (http://www.gnu.org/software/gsl/manual/html_node/Numerical-Integration.html#Numerical-Integration), although I am unsure on how to use it. Their example isn't very useful. In any case, would that allow me to put a definite integral with a given function to integrate where one of the bound is a choice variable in the optimization process?

Thanks

Louis Perrault

Robert Fourer

unread,
Jun 19, 2017, 10:10:37 AM6/19/17
to am...@googlegroups.com
The GSL numerical integration functions -- gsl_integration_qng, gsl_integration_qag, etc. -- require as their first argument a pointer to another function, written in C, that is to be integrated. Since AMPL does not have function pointers, it is not possible to provide these routines directly as AMPL functions (as is done with the GSL functions that are included in the AMPL Extended Function Library).

However you could write your own AMPL user-defined function that takes a variable as an argument, and then passes that variable to one of the gsl_integration_... functions as either argument a (lower bound) or argument b (upper bound). Your user-defined function would be a C function that includes both a gsl integration function and a C implementation of the function that you want to integrate. For writing user-defined functions, there are general instructions and examples under "User-defined functions" at http://ampl.com/REFS/hooking2.pdf#page=19. The best approach is to start with a simple example and then modify it for your needs.
Reply all
Reply to author
Forward
0 new messages