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

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

Search the Archive

Re: calling mathematica from an external program

  • To: mathgroup at smc.vnet.net
  • Subject: [mg67063] Re: calling mathematica from an external program
  • From: "ragfield" <ragfield at gmail.com>
  • Date: Thu, 8 Jun 2006 04:53:57 -0400 (EDT)
  • References: <e66640$n70$1@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

peregrine_falcon12 at hotmail.com wrote:
> What I'd like to do now is call the FindRoot function, but this takes a
> list of arguments as its second argument (i'm not sure if that's proper
> terminology or makes sense at all...), so that the mathematica input
> will look like so:
>
> FindRoot[3x == 12, {x, 0}]
>
> I'm not sure how to deal with this. How can I call this function from
> my external program, using the MLPut... functions?


First, find the FullForm of the expression you're trying to send across
the link:

In[5]:=
FullForm[Hold[FindRoot[3x == 12, {x, 0}] ]]

Out[5]//FullForm=
Hold[FindRoot[Equal[Times[3,x],12],List[x,0]]]


So the corresponding MathLink call sequence would be:

MLPutFunction(theLink, "FindRoot", 2);
	MLPutFunction(theLink, "Equal", 2);
		MLPutFunction(theLink, "Times", 2);
			MLPutInteger(theLink, 3);
			MLPutSymbol(theLink, "x");
		MLPutInteger(theLink, 12);
	MLPutFunction(theLink, "List", 2);
		MLPutSymbol(theLink, "x");
		MLPutInteger(theLink, 0);


However, the more complicated your expressions get, the more
complicated your code will be.  The easiest thing to do in this case
would be to enter the expression as InputForm text and have Mathematica
parse it:

MLPutFunction(theLink, "ToExpression", 1);
	MLPutString(theLink, "FindRoot[3 x == 12, {x,0}]");

-Rob


  • Prev by Date: Using a list as a variable
  • Next by Date: RE: RE: Animate
  • Previous by thread: Re: calling mathematica from an external program
  • Next by thread: Re: calling mathematica from an external program