Prev: Mathematica 7.0 - Wrong Documentation on StudentTCI
Next: Solving systems of differential equations
From: 董理 on 24 Nov 2009 05:47 ���� д��: > 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
From: 董理 on 24 Nov 2009 06:04 ���� д��: > 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 > > Dear all, Can I put another EvaluatePacket "{c1,...}/.%" to convert the list of rules to list of real numbers? If so, how to arrange the working flow? Best regards, DONG Li
|
Pages: 1 Prev: Mathematica 7.0 - Wrong Documentation on StudentTCI Next: Solving systems of differential equations |