Using JLink to get a Complex number out

Using JLink to get a Complex number out

Post by aaronfud » Thu, 16 Dec 2004 19:00:34


Hi,

Why does ml.getComplex() throw an exception in the following code?


ml.evaluate("1+I");
ml.waitForAnswer();
System.out.println(myML.getComplex());


What is a good strategy for getting complex numbers out of Mathematica with JLink?

Many thanks in advance!

Aaron Fude
 
 
 

Using JLink to get a Complex number out

Post by Todd Gayle » Sat, 18 Dec 2004 20:26:24


Aaron,

Because Java does not have a built-in class to represent complex numbers,
you have to tell J/Link what class you want it to use for this purpose. You
do this by calling the setComplexClass() method:

ml.setComplexClass(MyComplexClass.class);

Look at the JavaDocs for this method for information on what features a
class needs to have to be able to be used for this (such as re() and im()
methods or fields--things that any self-respecting complex class is certain
to have already.) You can get a complex number class from
http://www.yqcomputer.com/ 't already have one
and don't want to write one.


Todd Gayley
Wolfram Research