Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

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 


  • Prev by Date: Re: plotting two functions on the one graph
  • Next by Date: Re: plotting two functions on the one graph
  • Previous by thread: Using JLink to get a Complex number out
  • Next by thread: SymbolShape