4

I need to maximize this function on the positive real line:

$$ \frac{1}{\Gamma(x)^{14}}\cdot\frac{1}{{\frac{323.6}{14x}}^{14x}}\cdot(1.22578*10^{19})^{x-1}e^{-14x} $$ the correct answer should be around $x=514$, but I could not use mathematica to show it. My plot has a peak at $x=680$ instead. I want to ask if anyone has any idea how to get the correct answer.

The code I am using now is:

A = 1/Gamma[x]^{14}*(301.6/(14*x))^{-14 *x}*(1.22578*10^{19})^{x -1} E^{-14 x}

and I plot it by

Plot[A, {x, 513, 700}, PlotPoints -> 1000]

The result is something very strange:

enter image description here

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Bombyx mori
  • 165
  • 6
  • 1
    Could you provide the code you've used? Interestingly, using NMaximize I'm getting results depending on the upper bound of x. However with NMaximize[{f[x], 10^3 > x > 0}, x] I get {1.82059*10^-9, {x -> 514.197}} which seems correct comparing with an appropriate plot. – Artes Feb 21 '14 at 22:33
  • I used:A = 1/Gamma[x]^{14}(301.6/(14x))^{-14 x}(1.22578*10^{19})^{x - 1} E^{-14 x}, Plot[A, {x, 513, 700}, PlotPoints -> 1000] – Bombyx mori Feb 21 '14 at 22:46
  • What do you mean? I have answered your question with my code. – Bombyx mori Feb 21 '14 at 22:57
  • @Szabolcs: Fine. I shall correct it. – Bombyx mori Feb 21 '14 at 23:05
  • @Artes: Updated. Hopefully now it is clearer. – Bombyx mori Feb 21 '14 at 23:09
  • Given the syntax you used in the expression, e.g. E^{-14 x}, are you aware that { brackets are used for lists in Mathematica? You might easily run into problems if you use this notation for something it's not meant for ... – Szabolcs Feb 21 '14 at 23:13
  • @Szabolcs: I see. I double checked, I think it is the $1/(1618/(70 x))^(14 x)$ term that caused the problems. Thanks for his/her's answer. – Bombyx mori Feb 21 '14 at 23:22

2 Answers2

9

I don't like using approximate numbers when we can use exact ones, therefore with Rationalize and RootApproximant I can rewrite the function this way:

f[x_] := 1/Gamma[x]^14 1/(1618/(70 x))^(14 x) 12257800000000000000^(x - 1) Exp[-14 x]

let's plot this function:

Plot[ f[x], {x, 0, 1500}, PlotStyle -> Thick]

enter image description here

We can use:

NMaximize[{ f[x], 10^5 > x > 0}, x]
{1.82059*10^-9, {x -> 514.198}}

which most likely is a good approximation. However when we use e.g.

NMaximize[{ f[x], 10^6 > x > 0}, x]
{3.92756*10^-30, {x -> 0.327666}}

we get an incorret result. It may depend on the computer system one uses.
I guess this issue is explained with anwswers to this post: Numerical underflow for a scaled error function.

Artes
  • 57,212
  • 12
  • 157
  • 245
4

Following Artes' Rationalizeation, why don't you simply find where the first derivative goes to zero?

f[x_] := 1/Gamma[x]^14 1/(1618/(70 x))^(
    14 x) 12257800000000000000^(x - 1) Exp[-14 x]

Plot[f'[x], {x, 100, 1100}]

FindRoot[f'[x] == 0, {x, 500}]

    {x -> 514.198}
Peltio
  • 5,516
  • 3
  • 27
  • 27
  • For the record: A zero derivative is only a necessary condition for a local extremum, not a sufficient condition. And even if have a local extremum there, you still don't know from the first derivative's vanishing whether it's a local minimum or a local maximum. Of course additional information, such as a plot, can suggest (but not prove) you really have a local max and that it's a global max. – murray Feb 22 '14 at 17:58
  • 1
    The OP already knew there was a maximum near 500. By looking at the plot of the derivative you can see what is happening. The black-box NMaximize is no different than looking to a plot (there is no proof, just the hope that it is as the software says). A detailed study of the function can be done by analyzing how first and second derivative behave, but that's math, not Mathematica... – Peltio Feb 23 '14 at 04:50