Hi,
I have created a WSTP function ReturnEvalErrorP that takes a list of doubles as input and returns a double. I can call this function succesfully:
ReturnEvalErrorP[{0.1}]
and it returns a double. I want to minimize this function, so I defined a function:
Clear[f]; f[p1_] := ReturnEvalErrorP[{p1}]
and f[0.1] returns a double. Calling Minimize with this function however always fails with {$Failed, {p1 → 0}}
Minimize[f[p1], {p1}, Reals]
Any ideas?
Gijsbert
The tm definition of the function is as follows:
double return_eval_error_p P((double *p, long dp));
:Begin:
:Function: return_eval_error_p
:Pattern: ReturnEvalErrorP[p_List]
:Arguments: {p}
:ArgumentTypes: {RealList}
:ReturnType: Real
:End:
:Evaluate: ReturnEvalErrorP::usage = "ReturnEvalErrorP[{}]"
FYI, You have to specify that the argument to f is a real number:
Clear[f]; f[p1_Real] := ReturnEvalErrorP[{p1}]
ReturnEvalErrorP runs parallel using OpenMPI. Feel free to contact me if you want to know how to launch and use OpenMPI from your WSTP function.
Regards,
Gijsbert
szhorvat
(Szabolcs Horvát)
4
Minimize is meant for symbolic computation. Use FindMinimum or NMinimize for numerical calculations.
You will also need to ensure that your function only evaluates with numerical arguments:
You can do this either with a wrapper function (as in the linked article) or by modifying the :Pattern: in the MathLink template.