Calculus I:  Mathematica Practice 6

Syntax Checks

Clear[f,g,h]

The following Mathematica commands have syntax errors. Fix the errors so the commands will work.

Problem 1: Integration

We want to calculate (∫_0^(2π))cos(7x)dx:

integrate[cos(7x),{x,0,2pi}]

Problem 2: Sum

We want to calculate (∑_(i=1)^n)(i^2):

Sum[{i=1,n},i^2]

Problem 3: Sum

We want to calculate (∑_(i=1)^n)(i^4):

Sum[i**4,(i,1,n)]

Example Based on 4.8 Newton's Method

Use Newton's method to find all the roots of the equation (e^(-(x^2)))=(x^2)-x correct to eight decimals. Start by drawing a graph to get an estimate of starting values.

Barry's Solution

First, the equation can be written as f(x)=(e^(-(x^2)))-(x^2)+x=0.

As suggested, let's start with a plot to see what is going on:

f[x_]=Exp[-x^2]-x^2+x
Plot[f[x],{x,-5,5}]

It looks like there are two roots, one near x=-0.5 and another near x=1.0. These are the only two real valued roots. How do we know that? Well, If we didn't have the exponential, f(x) would simply be a quadratic function, opening down--which is basically what we see, since the exponential part is zero except where x is close to zero (this is really just an end behaviour argument). The exponential modifies the function so that we can not simply use the quadratic formulas to get the roots.

Let's try and see if Mathematica can get the roots for us:

Solve[f[x]==0,x]

We really are forced to use Newtons method to answer this question!

Let's set up Newton's method, and use SetPrecision to get the 8 decimals we want. When the result stops changing, we will know we have 8 decimals of accuracy:

xnew[x_]:=SetPrecision[x-f[x]/f'[x],8]

xnew[-0.5]

xnew[%]

xnew[%]

Well, that was quick--one root is x=-0.5103115581441670656`8.. Let's check it:

f[-0.5103115581441670656`8.]

Let's repeat the process for the other root:

xnew[1.0]

xnew[%]

xnew[%]

xnew[%]

The other root is x=1.1984387126285582781`8.. Let's check:

f[1.1984387126285582781`8.]

Example Based on 5.2 The Definite Integral

Express the integral (∫_0^π)sin (5x)dx as a limit of sums. Then evaluate, using Mathematica to find both the sum and the limit.

Barry's Solution

The basic relation we want is the Reimann Sum relation, which is

(∫_a^b)f(x)dx=(lim_(n→∞))(∑_(i=1)^n)f((SuperStar[(Subscript[x, i])]))(((b-a))/n)

In our case, f(x)=sin(5x), a=0, and b=π.

We can choose to work with left hand endpoints, right hand endpoints, or something else! Let's choose left hand endpoints (which means (SuperStar[(Subscript[x, i])])=a+(i-1)*((b-a)/n)) and the Reimann sum becomes

(∫_a^b)f(x)dx=(lim_(n→∞))(∑_(i=1)^n)f(a+(i-1)*((b-a)/n))(((b-a))/n)

First, we want to evaluate the sum, so that means we need to work out

(∑_(i=1)^n)f(a+(i-1)*((b-a)/n))(((b-a))/n)
=(∑_(i=1)^n)sin(5(0+(i-1)*((π-0)/n)))(((π-0))/n)
=(∑_(i=1)^n)sin(5(i-1)*(π/n))(π/n)

Let's input this into Mathematica and see if Mathematica can evaluate this sum. You could either cut/paste from above (that should work--but you will have to change some syntax!) or type the sum in using the alternate sum notation. I will do the latter.

Sum[Sin[5*(i-1)*Pi/n]*Pi/n,{i,1,n}]

Mathematica could evaluate the sum, but it looks like you get a different expression if -(5/(2 n))is an integer (which it is not). Taking the part of the If statement that applies to our case, we see that the sum is

sum[n_]=(1/n)(π (Cos[((5 π)/n)] Cot[((5 π)/(2 n))]+Sin[((5 π)/n)]))

This sum approximates the integral, and the approximation gets better for larger values of n.Let's examine this by creating a table.

TableForm[Table[{n,N[sum[n]]},{n,100,1000,100}]]

Looks like our sum might be approaching the limit of 0.4 as n approaches infinity! Let's check it out using Mathematica's Limit command:

Limit[sum[n],n->Infinity]

Let's now use Mathematica's Integrate command to do the integral, and as a final check of our work.

Integrate[Sin[5x],{x,0,Pi}]

Good work--all our calculations make sense together.

Example Based on 5.3 The Fundamental Theorem of Calculus

The sine integral function

Si(x)=(∫_0^x)((sin t)/t)dt

is important in electrical engineering.

(a) Draw the graph of Si(x) for x≥0.

(b) At what values of x does the function have local maximum values?

(c) Find the coordinates of the first inflection point to the right of the origin.

(d) Does this function have horizontal asymptotes?

(e) Solve the following equation correct to one decimal place Si(x)=1.

Barry's Solution

Let's define the function:

Si[x_]=Integrate[Sin[t]/t,{t,0,x}]

Part a

Plot[Si[x],{x,0,20},PlotRange->All]

Part b

This function has lots of local maximums. They will occur where the derivative is equal to zero.

D[Si[x],x]

Notice how Mathematica is giving different results if x is a complex number. Since we know x is real, and with the knowledge of the Fundamental Theorem of Calculus, we know the derivative must be (sin x)/x. The maximum therefore occur where

Solve[Sin[x]/x==0,x]

Solve didn't work, so let's try Reduce (like Mathematica suggests)

Reduce[Sin[x]/x==0,x]

Reading this, it looks like maximums will occur at x=2π n, where n is an integer greater than zero. Let's add one gridline to our plot above and see if that is correct (we have to be careful to get the maximums, and not the minimums):

Plot[Si[x],{x,0,20},PlotRange->All,GridLines->{{2Pi},None}]

Whoops--that's a minimum! The maximums must occur at x=x==π+2 π n, where n is an integer. I can see now that I misread the earlier output, and said n must be greater than zero--that is not what the condition actually says. Let's check again:

Plot[Si[x],{x,0,20},PlotRange->All,GridLines->{{Pi,Pi+2Pi},None}]

Part c

The first inflection point will be where the second derivative is zero.

Reduce[D[Sin[x]/x,x]==0,x]

Oh well, looks like we need to use Newton's method again.

g[x_]=D[Sin[x]/x,x]

From the above graph, the first inflection point looks like it might be around x=4, so we will use that as our starting point.

xnew[x_]:=SetPrecision[x-g[x]/g'[x],8]

xnew[4.0]

xnew[%]

xnew[%]

xnew[%]

Ok, so it looks like our inflection point is at x=4.4934094543568789959`8.000000000000002. Let's plot the second derivative and check, since the first zero of the second derivative should occur at x=4.4934095

Plot[g[x],{x,0,6},PlotRange->All,GridLines->{{4.4934095},None}]

We found it!The first inflection point of the sine integral function is at x=4.4934095.

Part d

It looks like the sine integral function has horizontal asymptotes. Let's check:

Limit[Si[x],x->Infinity]

Aghain, let's plot to check this solution:

Plot[Si[x],{x,0,100},PlotRange->All,GridLines->{None,{Pi/2}}]

Yep, we got the horizontal asymptote correct.

Part e

Solving this equation means we should break out Newton's method again.The equation can be written as g(x)=Si(x)-1=0.

g[x_]=Si[x]-1

Let's try to solve the equation using Mathematica:

Solve[g[x]==0,x]

Oh well, looks like we need to use Newton's method again.

From the sketch, the sine integral function is  close to 1 when x~2.0, so we will use this as our starting value.

xnew[x_]:=SetPrecision[x-g[x]/g'[x],8]

xnew[2.0]

xnew[%]

xnew[%]

xnew[%]

xnew[%]

So the solution to the equation in part (e) is x=1.0648397239856421947`8.. Let's check our answer:

g[1.0648397239856421947`8.]