Of course, it is:

double jn(int n,double x);

and

vardef jn(expr n, x) = scantokens(lua("mp.quoted( ffi.C.jn(" & decimal n & "," 
& decimal x & "))")) enddef ;

Alan

(shows that I have yet to use jn ;-)


On Thu, 13 Dec 2018 14:32:39 +0100
Otared Kavian <ota...@gmail.com> wrote:

> Hi Mikael,
> 
> Thank you, as ell as Alan and Henri, for giving us a simple way to use Bessel 
> functions, directly in ConTeXt.
> However I have a question, which may show my total ignorance of the maths 
> libraries ffi and consorts: how do you specify the value of the integr $n$ 
> when you want to use $J_{n}(x)$?
> 
> Best regards: OK
> 
> > On 12 Dec 2018, at 21:13, Mikael P. Sundqvist <mic...@gmail.com> wrote:
> > 
> > On Wed, Dec 12, 2018 at 9:02 PM Henri Menke <henrime...@gmail.com> wrote:  
> >> 
> >> On 13/12/18 8:56 AM, Alan Braslau wrote:  
> >>> On Wed, 12 Dec 2018 20:42:56 +0100
> >>> "Mikael P. Sundqvist" <mic...@gmail.com> wrote:  
> >>>> 
> >>>> Thanks, Alan! That looks very promising. I could not make it work,
> >>>> though, and I guess that is because I use linux and do not know what
> >>>> to change for what. I installed libcerf but I assume something else is
> >>>> missing. In any case, this is one of the things it would be nice to
> >>>> have, at least as a module. I have no idea on how to realize that,
> >>>> though.
> >>>> 
> >>>> /Mikael  
> >>> 
> >>> You likely also need to install libffi - I do not know what package
> >>> this is on your flavor of linux - Luigi is the ffi specialist!  
> >> 
> >> FFI is integrated in LuaTeX >= 1.03
> >> 
> >> In you example you load libcerf but you are not using it.  What you are
> >> actually using are the Bessel function from the C Standard library.  GCC
> >> includes them as a GNU extension.
> >> https://www.gnu.org/software/libc/manual/html_node/Special-Functions.html#index-j0
> >> Your example also works if you remove libcerf (at least for me on Linux).
> >>   
> > 
> > Thanks Henri! Indeed it worked now. The following example (just in
> > case someone else did not get what to change) compiles here, and shows
> > the expected graph. This is very good news!
> > 
> > \startluacode
> > 
> > ffi = require("ffi")
> > ffi.cdef[[
> > double j0(double x);
> > double j1(double x);
> > double jn(double x);
> > ]]
> > 
> > \stopluacode
> > 
> > \startMPdefinitions{doublefun}
> >  vardef jzero primary x = scantokens(lua("mp.quoted( ffi.C.j0(" &
> > decimal x & "))")) enddef ;
> >  vardef jone  primary x = scantokens(lua("mp.quoted( ffi.C.j1(" &
> > decimal x & "))")) enddef ;
> >  vardef jn    primary x = scantokens(lua("mp.quoted( ffi.C.jn(" &
> > decimal x & "))")) enddef ;
> > \stopMPdefinitions
> > 
> > 
> > \starttext
> > \startMPpage[instance=doublefun]
> > draw function(1,"x","jone(x)",epsed(0),epsed(10),1/10) scaled 1cm;
> > \stopMPpage
> > \stoptext
> > 
> > /Mikael
> > ___________________________________________________________________________________
> > If your question is of interest to others as well, please add an entry to 
> > the Wiki!
> > 
> > maillist : ntg-context@ntg.nl / 
> > http://www.ntg.nl/mailman/listinfo/ntg-context
> > webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> > archive  : https://bitbucket.org/phg/context-mirror/commits/
> > wiki     : http://contextgarden.net
> > ___________________________________________________________________________________
> >   
> 
> ___________________________________________________________________________________
> If your question is of interest to others as well, please add an entry to the 
> Wiki!
> 
> maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
> webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
> archive  : https://bitbucket.org/phg/context-mirror/commits/
> wiki     : http://contextgarden.net
> ___________________________________________________________________________________
___________________________________________________________________________________
If your question is of interest to others as well, please add an entry to the 
Wiki!

maillist : ntg-context@ntg.nl / http://www.ntg.nl/mailman/listinfo/ntg-context
webpage  : http://www.pragma-ade.nl / http://context.aanhet.net
archive  : https://bitbucket.org/phg/context-mirror/commits/
wiki     : http://contextgarden.net
___________________________________________________________________________________

Reply via email to