Services & Resources / Wolfram Forums
MathGroup Archive
*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
  • Subject: [mg67063] Re: calling mathematica from an external program
  • From: "ragfield" <ragfield at>
  • Date: Thu, 8 Jun 2006 04:53:57 -0400 (EDT)
  • References: <e66640$n70$>
  • Sender: owner-wri-mathgroup at

peregrine_falcon12 at 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:

FullForm[Hold[FindRoot[3x == 12, {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}]");


  • 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