WeBWorK Main Forum

by Darwyn Cook -
Number of replies: 2
I am writing some questions for our Advanced Engineering Math course that require the use of Bessel functions. I am trying to install the PDL library to support these functions, following the directions here: http://webwork.maa.org/moodle/mod/forum/discuss.php?d=799#p2607.

I have PDL installed, and have checked that it works through the command line interface. I moved two modules, Math.pm and BESSEL.pm, into the pg/lib directory. I added these module names to the PG_module_list.pl file and into global.conf. I then created a macro file PGspecialfunctionsmacros.pl in the pg/macros folder which handles the sub _*_init.

I wrote a simple problem to test the module, using

$x = bessjn(4.1,3). In the PDL shell this returns 0.433314702561693 in the perl shell. In a problem if I use the code$x= bessjn(4.1,3)
BEGIN_TEXT
$$x$$
END_TEXT
I get Error: Operation ".": no method found as an output.

If I use $x = Compute("bessjn(4.1,3)" ); I get Not a HASH reference at [PG]/lib/Value.pm. Any ideas on where I should go next? In reply to Darwyn Cook Re: adding PDL support by Michael Gage - I wouldn't expect a new function to work with MathObjects without a bit more work. For your first example though, try something a little less sophisticated than Maria's example. create something like this in PGspecialfunctionsmacros.pl (and make sure this file is included in the loadMacros segment of the problem) sub bessjn { my ($a, $b) = @_; return MATH::bessjn($a,\$b);
}

Perhaps it should be PDL::MATH::bessjn.  Look at the package declarations in the code to see what the full namespace should be.

Once you get something like this working you can use shortcuts such as Maria's to automatically import a bunch of subroutines without having to write everything out.

I wasn't aware of the CPAN PDL modules.  They look like they might be useful for many things.

Hope this helps.

-- Mike