Message Boards Message Boards

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

Why does FindMinimum return 'The function value Null is not a real number'?

Posted 9 years ago

I am working with the following function

Catch[Do[a = 2^(m(1 - c)) - 2.718/((m^.5)23.14c^(cm + .5) (1 - c)^((1 - c)*m + .5)); If[a <= 0, Throw[m/(m (1 - c) + 1)]], {c, 0.006, 1, 0.001}]], {m, 4, 2500}]

and would like to find its minimum between m=4 and m=2,500.

However, if I try writing

FindMinimum[ Catch[Do[a = 2^(m(1 - c)) - 2.718/((m^.5)23.14c^(cm + .5) (1 - c)^((1 - c)*m + .5)); If[a <= 0, Throw[m/(m (1 - c) + 1)]], {c, 0.006, 1, 0.001}]], {m, 4, 2500}]

it returns "FindMinimum::nrnum: The function value Null is not a real number at \ {m} = {4.}. >>".

I'm not sure why this is, as the function is equal to 1.11235 at m=4, with no imaginary part.

How can I get the 'FindMinimum' function to work?

POSTED BY: Marco Gorelli
7 Replies

For optimizing a numerical function, the best approach for FindMinimum is to define a function and specify that the argument or arguments are numeric using _?NumberQ

POSTED BY: Frank Kampas
Posted 9 years ago

I've tried

m = 4; NumberQ[ Catch[Do[a = 2^(m(1 - c)) - 2.718/((m^.5)23.14c^(cm + .5) (1 - c)^((1 - c)m + .5)); If[a <= 0, Throw[m/(m(1 - c) + 1)]], {c, 0.006, 1, 0.001}]]]

but it just returns 'true.' How should I use the function?

POSTED BY: Marco Gorelli

NumberQ returns True means the argument is a number. I suspect NumberQ is not the function you wanted to use. It might also be simpler to use the While function rather than Throw and Catch. Also note that cm is a new variable. If you want c*m you need to put a space between them or a multiplication symbol.

POSTED BY: Frank Kampas
Posted 9 years ago

I've now tried this f[m_?NumberQ] := Catch[Do[a = 2^(m(1 - c)) - 2.718/((m^.5)23.14c^(cm + .5) (1 - c)^((1 - c)*m + .5)); If[a <= 0, Throw[m/(m (1 - c) + 1)]], {c, 0.006, 1, 0.001}]]

however, FindMinimum still doesn't work and tells me I'm making invalid comparisons.

POSTED BY: Marco Gorelli

It would be better if you put your code into a Code Sample block. I can't tell if the cm in your code is actually c m or not.

POSTED BY: Frank Kampas
Posted 9 years ago

It's c*m.

Ok, I'll try, thanks.

POSTED BY: Marco Gorelli

If I plot your function, it appears to have a lot of discontinuous steps in it with a general trend of decreasing for m greater than about 5.5.

POSTED BY: Frank Kampas
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