0
|
4784 Views
|
7 Replies
|
3 Total Likes
View groups...
Share
GROUPS:

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

Posted 10 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?
7 Replies
Sort By:
Posted 10 years ago
 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 10 years ago
 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 10 years ago
 It's c*m.Ok, I'll try, thanks.
Posted 10 years ago
 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 10 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 10 years ago
 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 10 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?