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
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