Message Boards Message Boards

0
|
4561 Views
|
1 Reply
|
1 Total Likes
View groups...
Share
Share this post:

[?] Use NMinimize calling an own defined function?

Posted 5 years ago

I want to call an own defined function through NMinimize. For the sake of simplicity, let us define the problem as follow:

radpatt[x1_] := (Print[x1]; x1 )

NMinimize[{radpatt[xx], 0.1 <= xx <= 1.1}, {xx}]

If you run the above-listed instructions, you will notice that x1 is not number as soon as the function radpatt is called by NMinimize, but it is equal to xx. This causes me an issue because in my original problem x1 needs to be a number just at the beginning of my own function. Any ideas?

Many many thanks in advance.

A user-supplied objective function for NMinimize or FindMinimum needs to be "protected" from premature evaluation when given symbolic input. Therefore, use a definition like this

radpatt[x1_?NumberQ] := (Print[x1]; x1 )
POSTED BY: Robert Nachbar
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