MathGroup Archive 2006

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

Search the Archive

Re: Programming with .NET / hand over of variables

At 05:06 AM 8/3/2006, Andreas Baumbach wrote:
>Dear Sir or Madam,
>i don't know how simple or difficult this question is, but i do not know
>how to work this problem out.
>i have an problem with the implementation of Mathematica in my
>Here is the code:
>mathKernel.Compute("puffer1 =
>ReadList[\"v3504b.txt\",{Number,Number}]");  //Read an array of numbers
>from a file
>mathErgebnis = new
>Wolfram.NETLink.Expr(mathKernel.Result);                       //The
>Result, which is send back by mathKernel is saved as an Expression
>double[][] ar = ?
>                                           //Transform the Result in an
>array which i can handle with C#
>I want to have the 2*N array, which is saved in puffer1, transformed in
>an C# equivalent.
>What have i to do, so that it works?
>Thanks for your advice.


Since you want the result as an Expr, set the ResultFormat property to 
ensure that:

     mathKernel.ResultFormat = MathKernel.ResultFormatType.Expr;

     mathKernel.Compute("puffer1 = ReadList[\"v3504b.txt\",{Number,Number}]");

     mathErgebnis = (Expr) mathKernel.Result;

To get the Expr's value as a native C# array, use the AsArray() method:

     double[,] ar = mathErgebnis.AsArray(ExpressionType.Real, 2);

You say you want a double[][] instead of a double[,]. If you really want 
the "array of arrays" format you will have to manually allocate a 
double[][] of the correct size and fill it from the elements in ar. It is 
generally more convenient to work with multidimensional arrays (double[,]) 
than arrays-of-arrays (double[][]) in C#.

Todd Gayley
Wolfram Research

  • Prev by Date: Re: Re: Re: Finding the Number of Pythagorean Triples below a bound
  • Next by Date: Re: Precision of arguments to FunctionInterpolation
  • Previous by thread: Programming with .NET / hand over of variables
  • Next by thread: Pattern match question