Mathematica examples relevant to Gamma and Beta...

6
Mathematica examples relevant to Gamma and Beta functions Gamma function: Gamma[x] Check that the defining integral indeed gives Gamma function Integrate[x^ (p 1) Exp[ x], {x, 0, Infinity}, Assumptions Re[p]> 0] Gamma[p] Check recursion relation (following quantity should equal 1) check[p_] = Gamma[p] p Gamma[p + 1]; Plot[check[p], {p, 10, 10}, PlotStyle {Red, Thick}] 10 5 5 10 0.0 0.5 1.5 2.0 Gamma[p] is indeed (p-1)! for integer p: {Gamma[7],6 !} {720, 720} Plot shows the poles in the Gamma function on the real axis. Plot[Gamma[x], {x, 3, 3}, PlotStyle Thick] 3 2 1 1 2 3 10 5 5 10 Heres a 3D plot of the absolute value of the Gamma function in the complex plane. Note that you can rotate the view around.

Transcript of Mathematica examples relevant to Gamma and Beta...

Page 1: Mathematica examples relevant to Gamma and Beta functionscourses.washington.edu/ph227814/228/nb/Gamma.nb.pdfPlot shows the poles in the Gamma function on the real axis. Plot[Gamma[x],

Mathematica examples relevant to Gamma and Beta functions

Gamma function: Gamma[x]Check that the defining integral indeed gives Gamma function

Integrate[x^(p -− 1) Exp[-−x], {x, 0, Infinity}, Assumptions → Re[p] > 0]

Gamma[p]

Check recursion relation (following quantity should equal 1)

check[p_] = Gamma[p] p /∕ Gamma[p + 1];

Plot[check[p], {p, -−10, 10}, PlotStyle → {Red, Thick}]

-−10 -−5 5 10

0.0

0.5

1.5

2.0

Gamma[p] is indeed (p-1)! for integer p:

{Gamma[7], 6!}

{720, 720}

Plot shows the poles in the Gamma function on the real axis.

Plot[Gamma[x], {x, -−3, 3}, PlotStyle → Thick]

-−3 -−2 -−1 1 2 3

-−10

-−5

5

10

Here’s a 3D plot of the absolute value of the Gamma function in the complex plane. Note that you can rotate the view around.Note the poles at x=0, -1, -2, -3,...

Page 2: Mathematica examples relevant to Gamma and Beta functionscourses.washington.edu/ph227814/228/nb/Gamma.nb.pdfPlot shows the poles in the Gamma function on the real axis. Plot[Gamma[x],

Here’s a 3D plot of the absolute value of the Gamma function in the complex plane. Note that you can rotate the view around.Note the poles at x=0, -1, -2, -3,...

Plot3D[Abs[Gamma[x + I y]], {x, -−4, 4}, {y, -−4, 4},PlotRange → {-−1, 10}, AxesLabel → {"Re[z]", "Im[z]", "Abs[Gamma[z]]"}]

This is the argument---a rather complicated plot!

Plot3D[Arg[Gamma[x + I y]], {x, -−5, 5}, {y, -−5, 5},PlotRange → {-−π, π}, AxesLabel → {"Re[z]", "Im[z]", "Arg[Gamma[z]]"}]

Notice that Arg[Gamma[z]]=0 when z is real and positive, as expected.

Keep in mind that Arg is between -π𝜋 and π𝜋. We can see the “sheets” are connected up to factors of 2π𝜋.

Plot3D[{Arg[Gamma[x + I y]], Arg[Gamma[x + I y]] + 2 π, Arg[Gamma[x + I y]] + 4 π},{x, -−5, 5}, {y, -−5, 5}, AxesLabel → {"Re[z]", "Im[z]", "Arg[Gamma[z]]"}]

Here follows the real and imaginary parts---a more complicated structure emerges around the poles.

2 RevisedGamma.nb

Page 3: Mathematica examples relevant to Gamma and Beta functionscourses.washington.edu/ph227814/228/nb/Gamma.nb.pdfPlot shows the poles in the Gamma function on the real axis. Plot[Gamma[x],

Plot3D[Re[Gamma[x + I y]], {x, -−4, 4}, {y, -−4, 4},PlotRange → {-−10, 10}, AxesLabel → {"Re[z]", "Im[z]", "Re[Gamma[z]]"}]

Plot3D[Im[Gamma[x + I y]], {x, -−4, 4}, {y, -−4, 4},PlotRange → {-−10, 10}, AxesLabel → {"Re[z]", "Im[z]", "Im[Gamma[z]]"}]

For comparison a single pole

Plot3D[Abs[1 /∕ (x + I y)], {x, -−3, 3}, {y, -−3, 3},PlotRange → {-−1, 5}, AxesLabel → {"Re[z]", "Im[z]", "Abs[1/∕z]"}]

Here’s the real part , which is x/(x^2+y^2)

RevisedGamma.nb 3

Page 4: Mathematica examples relevant to Gamma and Beta functionscourses.washington.edu/ph227814/228/nb/Gamma.nb.pdfPlot shows the poles in the Gamma function on the real axis. Plot[Gamma[x],

Plot3D[Re[1 /∕ (x + I y)], {x, -−3, 3}, {y, -−3, 3},PlotRange → {-−2, 2}, AxesLabel → {"Re[z]", "Im[z]", "Re[1/∕z]"}]

...and the imaginary part which is -y/(x^2+y^2)

Plot3D[Im[1 /∕ (x + I y)], {x, -−3, 3}, {y, -−3, 3},PlotRange → {-−10, 10}, AxesLabel → {"Re[z]", "Im[z]", "Im[1/∕z]"}]

Qualitatively these should make sense. The real part flips sign as x goes from negative to positive and the imaginary part flips sign as y goes from negative to positive.

Beta function: Beta[x,y]The following integral defines Beta[x,y] for Re[p,q]>0Mathematica jumps directly to the expression for Beta in terms of Gamma functions

Integrate[x^(p -− 1) (1 -− x)^(q -− 1), {x, 0, 1}, Assumptions → p > 0 && q > 0]

Gamma[p] Gamma[q]

Gamma[p + q]

Checking relation between Gamma and Beta functions

{Beta[.5, .6], Gamma[.5] Gamma[.6] /∕ Gamma[.5 + .6]}

{2.7745, 2.7745}

You can get the definition of the Beta function out of Mathematica by using FunctionExpand[ ]

FunctionExpand[Beta[p, q]]

Gamma[p] Gamma[q]

Gamma[p + q]

4 RevisedGamma.nb

Page 5: Mathematica examples relevant to Gamma and Beta functionscourses.washington.edu/ph227814/228/nb/Gamma.nb.pdfPlot shows the poles in the Gamma function on the real axis. Plot[Gamma[x],

Lets try visualizing the Beta function

-−1

5

Lets look at slices, holding one variable fixed.

Manipulate[Plot[Beta[p, q], {q, -−10, 10}], {p, 5, -−5}]

p

-−10 -−5 5 10

-−1.0

-−0.5

0.5

1.0

To look at the contours, varying both p and q

ContourPlot[Re[Beta[p, q]], {p, -−5, 5}, {q, -−5, 5}, Contours → 15]

RevisedGamma.nb 5

Page 6: Mathematica examples relevant to Gamma and Beta functionscourses.washington.edu/ph227814/228/nb/Gamma.nb.pdfPlot shows the poles in the Gamma function on the real axis. Plot[Gamma[x],

The contour plot is a little easier to look at compared to the 3D plot

Plot3D[Re[Beta[p, q]], {p, -−5, 5}, {q, -−5, 5}]

11.7 #2

IntegrateSqrt[Sin[x]^3 Cos[x]], x, 0, Pi 2

π

4 2

Matching this to the trig form of the Beta funciton (Boas equation 7.6.2):

B (p, q) = 2 ∫π𝜋/∕2

0sin(θ𝜃)2 p-−1 cos(θ𝜃)2 p-−1 dθ𝜃

2p-1 = 3/2 , 2q-1 = 1/2

1

2Beta[5 /∕ 4, 3 /∕ 4]

1

2Gamma

3

4 Gamma

5

4

% /∕/∕ FunctionExpand

π

4 2

6 RevisedGamma.nb