Using Mathematica to Evaluate Areas

Consider the function we looked at in class today f(x)=(x^2), 0≤x≤1. We saw that the area under this curve can be expressed as

Area=(lim_(n->∞))((b-a)/n)(∑_(i=1)^n)f(a+((b-a)/n)i)
=(lim_(n->∞))((1-0)/n)(∑_(i=1)^n)f(0+((1-0)/n)i)
=(lim_(n->∞))(1/n)(∑_(i=1)^n)f((i/n))
=(lim_(n->∞))(1/n)(∑_(i=1)^n)((((i/n)))^2)

Let's see what Mathematica can do with this.

Define the sum:

oursum=(∑_(i=1)^n)(((i/n))^2)

Mathematica is able to assign a sum to this quantity! Awesome. Let's continue (we could do this limit by hand):

Limit[(1/n)*oursum,n->Infinity]

This is the same result the text found on page 372 in Example 2, except we worked it out using Mathematica. Now that we know that Mathematica can do these summations and limits, we could use Mathematica to do this for more complicated problems. Doing these by hand is typically quite difficult, but we will develop techniques to calculate quantities like the area under a curve using more advanced techniques later in this chapter.

Example: Area under y=x cos x for 0≤x≤π/2

Let's get a plot:

Plot[x Cos[x],{x,0,Pi/2}]

Area=(lim_(n->∞))((b-a)/n)(∑_(i=1)^n)f(a+((b-a)/n)i)
=(lim_(n->∞))((π/2-0)/n)(∑_(i=1)^n)f(0+((π/2-0)/n)i)
=(lim_(n->∞))((π/2)/n)(∑_(i=1)^n)f(((π/2)/n)i)
=(lim_(n->∞))(π/(2n))(∑_(i=1)^n)f((π/(2n))i)
=(lim_(n->∞))(π/(2n))(∑_(i=1)^n)((π/(2n))i)cos ((π/(2n))i)

Let's see what Mathematica can do with this.

Define the sum:

oursum=(∑_(i=1)^n)((π/(2n))i)Cos[(π/(2n))i]

It got something--but look how crazy it is! I doubt I could have figured this out by hand. Let's continue, and see if it can perform the limit for us:

Limit[(π/(2n))*oursum,n->Infinity]

Not bad--we've got an answer! Right now, we may not be extirely sure how to check if it is correct.

Note: this problem is one that you would be able to answer by a hand calculation once you learn the concepts of Chapter 5 and the idea of integration by parts in Calculus II!

One way to check our result is to evaluate the area using n large, instead of taking the limit as n->∞.

n=300
SetPrecision[(π/(2n))(∑_(i=1)^n)((π/(2n))i)Cos[(π/(2n))i],12]

n=400
SetPrecision[(π/(2n))(∑_(i=1)^n)((π/(2n))i)Cos[(π/(2n))i],12]

SetPrecision[(1/2) (-2+π),12]

So we have confidence that we (with Mathematica's help!) did the question correctly.