Message Boards Message Boards

0
|
6266 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Avoid problem with Minimize of a WSTP function?

Posted 7 years ago

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

3 Replies

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.

POSTED BY: Szabolcs Horvát

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

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[{}]"
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract