MathGroup Archive 2011

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

Search the Archive

How-to create a mathematica notebook in a Java program ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg122994] How-to create a mathematica notebook in a Java program ?
  • From: Nilo de Roock <ndroock1 at gmail.com>
  • Date: Sun, 20 Nov 2011 05:34:31 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: comp.soft-sys.math.mathematica at googlegroups.com

The Java program below is self-contained and works. It starts a Mathematica kernel, asks the kernel for Sum[k^2,{k,1,11}] and retrieves and prints the answer. I want to do it differently. I want the kernel to create a Notebook, put Sum[k^2,{k,1,11}] in it, evaluate it and show it on screen. - Is that possible from within a Java program? - If yes, then how do I do it??

package graphica;

 import com.wolfram.jlink.*;

 /**
  *
  * @author Nilo
  */
public class MathematicaTester {

public static void main(String[] args) {

    KernelLink ml = null;
    String jLinkDir = "C:\\Program Files\\Wolfram Research\\Mathematica\\8.0\\SystemFiles\\Links\\JLink";
    System.setProperty("com.wolfram.jlink.libdir", jLinkDir);

    try {
        ml = MathLinkFactory.createKernelLink("-linkmode launch -linkname'C:\\Program Files\\Wolfram Research\\Mathematica\\8.0\\MathKernel.exe'");

        ml.discardAnswer();
        String expr = "Sum[k^2,{k,1,11}]";
        ml.evaluate(expr);
        ml.waitForAnswer();
        String x = ml.getString();
        System.out.println("Result = " + x);

    } catch (MathLinkException e) {
        System.out.println("Fatal error opening link: " +
        e.getMessage());
        return;
    }
}
}



  • Prev by Date: Re: Solve equation with summation?
  • Next by Date: Re: EmpiricalDistribution bug
  • Previous by thread: Re: Matrices as operators
  • Next by thread: Re: How-to create a mathematica notebook in a Java program ?