Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*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 1996

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

Search the Archive

Re: C problem with Mathematica

  • To: mathgroup at smc.vnet.net
  • Subject: [mg4115] Re: C problem with Mathematica
  • From: wagner at motel6.cs.colorado.edu (Dave Wagner)
  • Date: Wed, 5 Jun 1996 01:37:49 -0400
  • Organization: University of Colorado, Boulder
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4ojdrs$5i8 at dragonfly.wolfram.com>,
JANAUDY Thierry  <janaudy at eerie.fr> wrote:
>
>  MLPutFunction(lp, "D", 2);         
>  MLPutString(lp, "Sin[x*x]") ;    <-- I tried this ... but no result :-(
>  MLPutSymbol(lp, "x");   
>  MLEndPacket(lp) ;

You are sending the expression D["Sin[x*x]", x].  If you type this in
a Mathematica session, you won't get a result either!

You need to send Sin[x*x] as an expression.  You could do this with a
nested sequence of MLPutFunction and MLPutSymbol calls, but it's far
easier to do this:

	MLPutFunction(lp, "ToExpression", 1);
	MLPutString(lp, "Sin[x*x]");

Now you will be sending D[ToExpression["Sin[x*x]"], x].  As long as you're
doing this, might as well wrap the entire thing in ToExpression:

	MLPutFunction(lp, "ToExpression", 1);
	MLPutString(lp, "D[Sin[x*x], x]");

The only reason to send expressions to the kernel a bit at a time is if
your program is actually calculating those expressions as they are sent.
Even if the expression is very complicated and is constructed from other
pieces, it's still far easier to do something like this:

	char buf[size1], expr[size2], sym[size3];
	/* Calculate expr and sym */
	...
	/* send ToExpression[D[expr, sym]] to the kernel */
	sprintf(buf, "D[%s, %s]", expr, sym);
	MLPutFunction(lp, "ToExpression", 1);
	MLPutString(lp, buf);

In fact, if you want the result to be a string as well, send the expression
this way:

	MLPutFunction(lp, "ToString", 1);
	MLPutFunction(lp, "ToExpression", 1);
	MLPutString(lp, buf);

Now you are sending the expression ToString[ToExpression["D[expr, sym]"]],
so you'll get back a string.

		Dave Wagner
		Principia Consulting
		(303) 786-8371
		dbwagner at princon.com
		http://www.princon.com/princon

==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Modification date message
  • Next by Date: Re: Series problem
  • Previous by thread: Modification date message
  • Next by thread: athenaps PS interpreter for NeXTStep/Intel Mma 2.2