Axel Vogt

5936 Reputation

20 Badges

20 years, 258 days
Munich, Bavaria, Germany

MaplePrimes Activity


These are replies submitted by Axel Vogt

Digging in old stuff where I was going to learn that I came up with
the following wrapper between Maple and GSL (certainly trivial for
those used to such):

__declspec(dllexport)
    long __stdcall GSL_sf_bessel_jl_steed_array(
        long lmax, double x, double * jl_x_array)
{
    char * theLIB;
    long dummy;
    typedef int (*gslfct)(int, double, double *);
    gslfct theFct;

    theLIB = "gsl.dll";

    HINSTANCE hLib=LoadLibrary(theLIB);

    if(hLib==NULL) {
        return(-2);
    }

    theFct = (gslfct)GetProcAddress((HMODULE)hLib, 
        "gsl_sf_bessel_jl_steed_array");

    if((theFct==NULL)) {
        FreeLibrary((HMODULE)hLib);
        return(-1);
    }

    dummy = theFct(lmax, x, jl_x_array);

    FreeLibrary((HMODULE)hLib);

    return(dummy);
}

A sketch to remind myself: one defines a prototype for the function.

Then one tries to load the library and to find (the address) of the
the GSL function (else return error codes -2 and -1).

In case of success tell C to excecute it (using the prototype to tell
it, how it should be used).

That would fill the array (provided from Maple, see below) and then
return the result (where 0 indicates success).

Compiling in MSVC6 with cdecl & multithread (and a *.def file) works,
one produce a DLL and can call the GSL function from Maple on Windows.


Usage in Maple would be (for example, the DLL should be in the path
where the sheet is executed and I use the true & classical interface):

  arrB_GSL_wrapped := define_external(
    'GSL_sf_bessel_jl_steed_array',
    'C', 
    'lmax'::(integer[4]), 
    'x'::(float[8]), 
    'jl_x_array'::(ARRAY(datatype = float[8])), 
    'RETURN'::(integer[4]), 
    LIB = "wrapGSL.dll");

  nTst := 5;
  xTst := 1.0;

  steedArr := Array([0, 1, 2, 3, 4, 5], datatype = float[8], order = C_order):
  arrB_GSL_wrapped(nTst+1, xTst, steedArr);
  steedArr;

    [0.841470984807896505, 0.301168678939756795, 0.0620350520113738604,
     0.00900658111711251722, 0.00101101580841375270, 0.0000925611586112581712]

which gives the expected results.


I also tried to produce the DLL using the Watcom Compiler, which comes
with Maple - Alec once showed how to use it from Maple. However now my
system stumbles into problems with pathes (after several updates) and I
do not feel the terrific need to clear that.
Nice example ... and one step more
  x*sin(Pi*x)*sin(3.141592653*x); 
  convert(%, rational);
  int(%,x=0..1): 
  evalf(%);


                           Float(-infinity)

Thanks for the replies. 

Yes, memory allocation: that is what I meant by "I have tried
with length", sorry for being to vague, but it does not help. 

And since both of you work on Unix and it works while I am on
Win XP the actual reason may be calling conventions as guessed
by Alec. How sad :-(

Strange enough: using a simple function works for me (this is
to call for single results instead of the array):

  B_GSL := define_external(
   'gsl_sf_bessel_jl',
    'C',
    'l'::integer[4],
    'x'::float[8],
    'RETURN'::float[8],
    LIB="gsl.DLL");

  nTst:=20; nTst:=round(nTst):
  xTst:=100.0; xTst:=evalhf(xTst):
  B_GSL(nTst, xTst);

                        0.0101076712838730556

which coincides with Maple's result.

Seems I should relearn some coding and produce the GSL DLLs in
the Windows calling convention ...

Or better look for concurrent stuff and write in Maple and use
'Compile'.

PS: the same with the 'latest' version for Windows, to be found
at http://gnuwin32.sourceforge.net/packages/gsl.htm. The others
I have found do not provide DLL binaries, only LIBs.

restart; interface(version);
 one := 1/((x*Dd-x^2*Dcj)*sqrt(x^2-1)):
 two := int(one,x) assuming (x>1, Dd>0, Dcj>0, Dcj>Dd):
 three := simplify(%):
 four := subs({x = sqrt(1+z^2)}, three):
 five := simplify(four) assuming z>=0;

  Classic Worksheet Interface, Maple 11.02, Windows, Nov 10 2007 Build ID 330022


            /                        2 1/2
            |           -Dcj + (1 + z )    Dd
  five := - |Dcj arctan(---------------------)
            |                2      2 1/2
            \            (-Dd  + Dcj )    z

                                       \
                           2      2 1/2|   /      2      2 1/2
         + arctan(1/z) (-Dd  + Dcj )   |  /  ((-Dd  + Dcj )    Dd)
                                       | /
                                       /

restart; interface(version);
 one := 1/((x*Dd-x^2*Dcj)*sqrt(x^2-1)):
 two := int(one,x) assuming (x>1, Dd>0, Dcj>0, Dcj>Dd):
 three := simplify(%):
 four := subs({x = sqrt(1+z^2)}, three):
 five := simplify(four) assuming z>=0;

  Classic Worksheet Interface, Maple 11.02, Windows, Nov 10 2007 Build ID 330022


            /                        2 1/2
            |           -Dcj + (1 + z )    Dd
  five := - |Dcj arctan(---------------------)
            |                2      2 1/2
            \            (-Dd  + Dcj )    z

                                       \
                           2      2 1/2|   /      2      2 1/2
         + arctan(1/z) (-Dd  + Dcj )   |  /  ((-Dd  + Dcj )    Dd)
                                       | /
                                       /

Int( sin(x), x = 0..Pi); evalf(%); 

  2.000000000 

book? forget a specific version ... http://remote.science.uva.nl/~heck/Maplebook/ 
or of course the guides coming with maple or ...
Int( sin(x), x = 0..Pi); evalf(%); 

  2.000000000 

book? forget a specific version ... http://remote.science.uva.nl/~heck/Maplebook/ 
or of course the guides coming with maple or ...
sin(Pi/3)!; convert(%, GAMMA); evalf(%);
                             0.9505776694

sin(Pi/3)!; convert(%, GAMMA); evalf(%);
                             0.9505776694

Robert and Alec,

Thank you both - it is a nice way to deform the problem for analyzing as well as recognizing it as a problem with residues.

Thx, hope your cold passes away soon!

Ok. BTW I always 'thought' that passing an expression triggers Maple to construct a procedure before it starts to work and may be that fits into what you say .

Thx, hope your cold passes away soon!

Ok. BTW I always 'thought' that passing an expression triggers Maple to construct a procedure before it starts to work and may be that fits into what you say .

acer,

what is the reason for choosing the notation  t->eval(func,:-t=t) in your integrand?

acer,

what is the reason for choosing the notation  t->eval(func,:-t=t) in your integrand?

Alec, I admire your patients and how you still keep good manners in that case or however one should express that in English :-)

@hafizudin: so I understand it is convenient to fire questions and get replies you are going beyond some limit (for my taste). At least you may want to do some searching on your own and struggle through the given hints. You may also try Google, especially google.scholar as well as you may not hesitate to visite the library at the university.

Or in short: try to do some work on your own.

It is a long time ago that I read (parts of) Bloch who called your attitude "bürgerliche Jugendfreude" (w.r.t. 'the best' and the rest), but in short: it is very unkind, at least for me. Neither the world nor the www is going to answer questions in that style and a programmer would get the answer 'RTFM', while students would hear 'try to find out more using the library'. Just try that.

Sorry for that somewhat personal statement, but think it is in place (@admin: delete if you dislike ... no problem for me)

Cheers

First 160 161 162 163 164 165 166 Last Page 162 of 209