Saturday, December 22, 2007

Double Integrals (and some probability)

Rather than mentioning what I have not been doing, I will talk about what very little I have accomplished over the past four days! (I will save the "whinging" for another post.)

Double integration was taught in my first year as part of the calculus and vectors module. Initially I had difficulty understanding it but when it came to revising, things made a little more sense. I actually was able to evaluate a double integral last year - whatever the region of integration might be! (I had to know this to use Green's/Stoke's Theorems).

However during the first few stats lectures this semester, when double integrals were evaluated, my mind didn't register what was happening. Somewhere a part of me knew what to do, but I blindly assumed that it will all come back to me in due course. (Note: just because we have to evaluate double integrals in stats doesn't make it any nicer). I stupidly left it at that i.e. assumed that my last years knowledge of how to answer questions with double integrals would return magically. Clutching at straws I suppose.

Evaluating a double integral is "easy" (one could say). Well if the limits have been given and everything is hunky dory, then hopefully I can do the integration. What I can't do though is set the integral up. I had forgotten how to choose the limits of integration, which turns out to be important!

So why not make this a big deal. Over the past four days... yes four days I lie to you, I have been bravely (without a doubt!) struggling with mastering the art of finding limits for double integrals. A mouthful isn't it? Having (I hope) mastered this successfully, I proceed to kick myself with a certain venom! WHY couldn't I have done this before my stats coursework test? WHY?! Had I done so, I wouldn't have done as badly in my coursework! (Bad relative to the other tests and my own marker.) I got one question wrong due to my stupidity* but the rest of the marks were lost on evaluating double integrals. Hence why I will now attempt to solve the question here!

Question
The joint probability density function (pdf) of the random variables X and Y is given by:

f(x,y)=\begin{Bmatrix} 2 & & 0 \le y \le x \le 1; \\0 &  & \text{elsewhere}.
a) Find the marginal pdf of X.

Solution
The marginal pdf of X is found by  f_x(x)= \int^{\infty}_{-\infty} f(x,y) \,dy . (The limits in this case are symbolic and will be determined by the region of integration).

Firstly we will (roughly!) sketch the region in order to deduce the limits:The shaded in part (i.e. the yellow region) is the region of our integration. The integral tells us that we will be integrating with respect to y. So now to determine the limits, we draw a vertical rectangle (or line) through the shaded region on the diagram:

The red spot is where our pen should be. Unfortunately I can't give a concise mathematical explanation as to why we do this, but it is something along the lines that x is fixed and we want to see how y varies within this region. So we move upwards from the red spot until we hit the line y=0. We have to pass this line to enter the region and so it is the lower limit for this integral. Now that we are in the region we continue travelling along this green line until we hit the line y= x. We could carry on moving upwards until we hit the line y=1, but then we will be out of the region (and not answering the question). Hence when we hit the line y=x we stop and choose that to be our upper limit.

This gives us the integral  f_x(x)= \displaystyle \int^{x}_{0} 2 \,dy , which is left as an exercise for the reader! (I love saying that, but hopefully you get that this integrates to 2x!)

The question however asks for the pdf, and simply writing 2x is wrong. The correct answer (by elimination) then is:
f(x,y)=\begin{Bmatrix} 2x & & 0 \le  x \le 1; \\0 &  & \text{elsewhere}.

I didn't choose that option which is why it must be correct, for mine was wrong! I don't understand the reasoning for choosing 0 \le x \le 1, but then again somethings will never be understood. (I had "guessed" the other option with region y \le x \le 1 which was incorrect).

The question doesn't ask for the marginal pdf of Y, but I will mention it here. This time the integral will be f_y(y)= \int^{\infty}_{-\infty} f(x,y) \,dx (with symbolic limits).

The region for the integration is the same, however to find the limits we now draw a horizontal line on the graph through the shaded region:So we start at the big red spot and move towards the right on the green line. To enter the region we have to "hit" the line y=x first, which becomes the lower limit in the integral. Then we merrily continue our journey along the line until wham, we hit the line x=1 -- the upper limit. Thus our integral is f_y(y)= \int^{x=1}_{x=y} 2 \,dx. (Once again left as an exercise!)

Now something is telling me that I might have written something horribly wrong! Call it a gut feeling, but have I got this all wrong? Do I need to call it a day, and find myself a nice farm? If I knew what the actual answer was then I would probably be more confident. Hence why I think you should take this post lightly! (I cant believe I am blogging about probability -- maybe that's why I am feeling slightly queasy and unsure about what has been typed? By the way, I realise that I mostly complain about stats but that includes probability. My module is called probability and statistics but it is easier to write just "stats". Maybe I should write "stats inc." to mean probability is included! I dislike both for the record.)

This post hasn't really been about double integrals, but nevertheless the method of finding the limits is similar. If the region we are integrating over is rectangular (i.e a\le x \le b, \quad c \le  y \le d ) then the integral is much nicer. It is only when the region is non-rectangular that things get messy. I think to validate my post title I will now do a proper double integral over a non-rectangular region! (And in future I will try to write the posts first and then choose the title).

Example
Evaluate the volume under the surface given by f(x, y) = x^2+ 0.5y, over the region bounded by the curves y = 2x and y = x^2.

Solution
Before we proceed a (dodgy) diagram is needed (with the region of integration shaded). Always sketch the region first.
At this stage of the game we are faced with a choice -- do we want to integrate with respect to x first or with respect to y? I will choose to integrate with respect to (w.r.t) y first, but if you choose to do otherwise, the answer should still be the same.

Since we have chosen to integrate w.r.t y first, we will be drawing a vertical line through the yellow region as in the example above. (I remember the direction of the line because the y-axis is vertical so the line should be vertical. If you choose to integrate w.r.t x first then draw a horizontal line.) Having drawn the line (on your paper!) we see that to enter the region we have to hit the curve y=x^2 first -- the lower limit; and to exit the region we have to hit the line y=2x -- the upper limit. So we now have our limits for the inner integral w.r.t. y.

For the outer integral (with respect to x), we need the points of intersection of the two curves i.e. the solutions to the equation 2x = x^2. Solving this gives us the limits x=0 and x=2 (I think we are meant to aim to make the outer limits as constants.) Thus our integral becomes:
\int^{x=2}_{x=0} \int^{2x}_{x^2} \left( x^2 +\frac{y}{2} \right) \:dy dx.

Since I am faffing about as it is, here is the solution to the above double integral:

\begin{align*} \int^{x=2}_{x=0} \int^{2x}_{x^2} \left( x^2 +\frac{y}{2} \right) \:dy dx & = \int^{x=2}_{x=0} \left[ x^2y +\frac{y^2}{4} \right]^{2x}_{x^2}\, dx \\*[2.ex] & =  \int^{x=2}_{x=0} \left( x^2 + 2x^3 - \frac{5x^4}{4} \right)\, dx\\ & =\left[ \frac{x^3}{3} + \frac{x^4}{2} - \frac{x^5}{4}\right]^{2}_{0}\\ &= \frac{8}{3} \end{align*}

As you can see, once set up the integration isn't too bad. It is easy to make a mistake, but last year when integrating w.r.t y, I sometimes wrote c instead of x as to avoid confusion. And then when I integrated w.r.t x, I wrote x again. (But with practice this stopped happening). The main thing I feel, is to have the correct limits. Actually I didn't get the stats (inc.) question above wrong because of my inability to integrate, but because I didn't understand the stats behind the pdf! (Although that can't be said for the other questions...)

I have been wanting to post a somewhat mathematical post for sometime; but boy does it take a while to dig them out. (This was meant to be my 30minutes break from marginal distributions, but has become a 2 hour break!) As you might have gathered, I am trying to revise stats even though my first exam is PDEs and vector calculus. I am thinking that I will try not to blog for a week and see how it goes. If I do blog then it means I have been revising which is a good thing! (You might need to read that sentence again). Many thanks to Steve for the cool looking LaTeX images in this blog, and thanks to paint for the horrible graphs!

Now to some nightmares about stats and probability.

EDIT: I think the title "limits of integrals" would be more suited to this post...

PS: This is a reminder to post about my dream. It was really weird and had the formula for the sum of numbers from 1 to n in it and my old school. Not really that weird maybe, because I have been thinking about that formula recently... Oh and if I do post this week the posts most likely will be short!

6 comments:

Anonymous said...

You have saved my life!
Greatest help I've ever seen regarding double integrals.

Beans said...

Thanks, I'm glad I could be of some help.

(I feel better knowing that at least one post from my many millions was useful!)

Isay said...

Very helpful! I have an exam on double integrals and parametric equations on monday and stumbled upon your blog while googling 'cool calculus double integral applications.' :)

Beans said...

Once again thanks, and I am glad if was of some use. :)

As I said above, it makes me feel better that at least two people have now benefited from this blog! Good luck in your exam.

Nobdy said...

I am studying for the first actuarial exam and came across your blog while researching the proper way to set up a double integral.
Thanks for the explanation of drawing a line to see your limits (duh! I should've known that!) As far as why the limit should be 0<=x<=1 and not y<=x<=1, I believe the reason would be simply that you have removed the y by partially integrating by y. Anyway, I think that the inner integral always has the other variable in one or both of the limits and the outer has constants. Perhaps I err in this too...
Continuing the search for knowledge and understanding
//Nobdy

Beans said...

Hi Nobdy,

Good luck with your exam and I'm glad I could be of help. (It's quite easy to forget the lines thing and I had to read the post again to remind myself!)

Somewhere (in my head I hope!) what you are saying about partially integrating to y, is being understood but not processed. (That's what tomorrow is for!)