Re: Using JLink to get a Complex number out
- To: mathgroup at smc.vnet.net
- Subject: [mg52939] Re: [mg52882] Using JLink to get a Complex number out
- From: Todd Gayley <tgayley at wolfram.com>
- Date: Fri, 17 Dec 2004 05:19:13 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
At 03:27 AM 12/15/2004, Aaron Fude wrote:
>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
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.netlib.org/java/JavaComplex.tgz if you don't already have one
and don't want to write one.
Todd Gayley
Wolfram Research