Yes, with this I should be able overcome the restriction on return value of a 
callback, I'll just have to pass an extra pointer. Thank you !

The problem is numerical integration. For example, if there is a surface in 3D 
given in Cartesian coordinates: x, y, z by the equation z=f(x,y) the volume 
under (supposing f>0 for simplicity) this surface above a certain rectangle 
(x0<x<x1, y0<y<y1, z=0) can be expressed as a double integral of f dx dy. 
There many sophisticated Fortran routines to compute this integral very 
efficiently, all of them work by evaluating the function f repeatedly for 
different values of x and y (distributed inside the region in quite a 
complicated way, sometimes randomly). What I want, actually, is to use one of 
these routines (specifically, the Cuba library by Thomas Hahn: 
http://www.feynarts.de/cuba/), calling it from J, but, at the same time, 
being able to define the function f in J too, simply as a verb.

That is, I want to make an adverb "quad", which, after it is applied to a 
verb "f", would produce a dyadic verb, evaluating the quadrature of "f" over 
a given hyper-rectangular region using Cuba. The left argument of this 
resulting verb would be an integer scalar, specifying the integration method 
(or, possibly, a boxed array with the parameters, such as relative precision 
and others, more specific to the integration method). The right argument will 
be a two-dimensional array n x 2, where n is the dimension of the integration 
region and the pair of numbers in each row are the limits of integration 
along the corresponding dimension. The verb "f" will then repeatedly receive 
(from Cuba) a vector of numbers of length n (coordinates of the point) to 
produce a vector of length m. The number m would be determined from the 
initial evaluation of "f" at the midpoint of the integration region before 
calling Cuba. The verb "f quad" would then proceed to simultaneously (that 
is, with the same subdivision of integration region) evaluate m integrals 
(corresponding to each element of the result of "f") and return their values 
and the corresponding error estimates as an array of dimension m x 2.

I don't know if I'll be able to finish this (it seems to require hacking of 
the sort I did not do for a long time)... But, at least, the interface seems 
clear and it is already a step forward.

With the best regards,
                            Konstantin.
----------------------------------------------------------------------
For information about J forums see http://www.jsoftware.com/forums.htm

Reply via email to