Services & Resources / Wolfram Forums / MathGroup Archive
-----

MathGroup Archive 2009

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

Search the Archive

Re: How to get the output of FindFit from MathLink in

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105196] Re: [mg105169] How to get the output of FindFit from MathLink in
  • From: 董理 <dongli2020 at gmail.com>
  • Date: Tue, 24 Nov 2009 05:47:41 -0500 (EST)
  • References: <200911231151.GAA21851@smc.vnet.net>

¶­Àí дµÀ:
> Hi, all,
>
> I want to write a C program that calls MathLink to use "FindFit" in
> Mathematica. The output of "FindFit" is a list of rules. How can I get
> those packets? Thanks for help!
>
> Best regards,
>
> DONG Li
>
>   
Hi guys,

Finally, I have worked out this problem. Summarized as following, the
procedures are:

1. send FindFit EvaluatePacket

In Mathematica, it reads:
rules = FindFit[<some data>, <some fit model>, <some parameters>, <some
variables>];

In C program, it reads:
MLPutFunction(link, "EvaluatePacket", 1);
MLPutFunction(link, "CompoundExpression", 2);
MLPutFunction(link, "Set", 2);
MLPutSymbol(link, "rules");
MLPutFunction(link, "FindFit", 4);
MLPutRealArray(link, (double *) data, dims, NULL, 2);
MLPutFunction(link, "ToExpression", 1);
MLPutString(link, model);
MLPutFunction(link, "ToExpression", 1);
MLPutString(link, param);
MLPutFunction(link, "ToExpression", 1);
MLPutString(link, var);
MLPutSymbol(link, "Null");
MLEndPacket(link);

2. discard the return packet of FindFit EvaluatePacket

3. send ReplaceAll EvaluatePacket

In Mathematica, it reads:
{<some parameters>}/.rules

In C program, it reads:
MLPutFunction(link, "EvaluatePacket", 1);
MLPutFunction(link, "ToExpression", 1);
MLPutString(link, param_list);
MLEndPacket(link);
here "param_list" is a string of " {<some parameters>}/.rules"

4. receive the final answer

MLGetReal64List(<link>, <parameters pointer>, <number of parameters
pointer>);

Hope this can help others.

Best regards,

DONG Li


  • Prev by Date: Re: Not all points plot on my graph...
  • Next by Date: Re: .NET/LINK USER GUIDE Comment: Calling static generic C# method
  • Previous by thread: Re: How to get the output of FindFit from MathLink in
  • Next by thread: how to read in a number in hex and then get it in binary?