mgorelli49
(Marco Gorelli)
February 24, 2015, 11:51am
1
I am working with the following function
Catch[Do[a = 2^(m*(1 - c)) - 2.718/((m^.5)2 3.14c^(c m + .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)2 3.14c^(c m + .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?
fkampas
(Frank Kampas)
February 24, 2015, 1:31pm
2
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
mgorelli49
(Marco Gorelli)
February 26, 2015, 4:48pm
3
I’ve tried
m = 4; NumberQ[
Catch[Do[a =
2^(m*(1 - c)) -
2.718/((m^.5)2 3.14c^(c m + .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?
fkampas
(Frank Kampas)
February 26, 2015, 5:01pm
4
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.
mgorelli49
(Marco Gorelli)
February 26, 2015, 5:08pm
5
I’ve now tried this
f[m_?NumberQ] :=
Catch[Do[a =
2^(m*(1 - c)) -
2.718/((m^.5)2 3.14c^(c m + .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.
fkampas
(Frank Kampas)
February 26, 2015, 5:43pm
6
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.
fkampas
(Frank Kampas)
February 26, 2015, 6:35pm
8
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.