Grokking Calculus--Integral Calculus

©Fernando Caracena 17 September 2012

The integral of a single valued function, f(x), is the area between the curve generated in x-y coordinates by the assignment y=f(x) and the x-axis, as shown in GC part I as the green area in Fig. 2. This area can be estimated very well numerically, as is illustrated by the python-based calculation in listing 1.

Intergal approximated as 10 rectangular areas

Fig. 1 Integral approximated as the sum of 10 rectangular areas of width dx=0.1

The process of approaching the limit dx-->0 is here demonstrated by using successive values of dx that become smaller by powers of 10. The smaller the value of dx, the greater the number of rectangular area elements. Fig. 1 is an example of one approximation of the area under the curve y=sin(x*pi) over the range 0 to 1(red curve) as the sum of 10 rectangular area elements. The height of each rectangle is approximated as 0.5*(yi+yi+1), and the corresponding area element is 0.5*(yi+yi+1)*dx. Note that the sum runs over i=0, 9.

Integral as a sum of 100 rectangular area elements

Fig. 2 The integral approximated as the sum of 100 rectangular area elements, each having a width of dx=0.01.

Fig. 2 shows the approximation corresponding the that shown in Fig. 1 but with a hundred, rectangular area elements instead of ten. Note that in this case, the areas appear to the eye to be a closer approximation to that under the curve.

 

 

Limit of sum Of rectangular area elements

Fig. 3 The approach to dx=0 by reducing each sum over rectangular areas by an order of magnitude, successively to dx=1.0 x 10-7.

The integral evaluated by conventional methods of calculus yields the value of 2./pi or 0.63661977236758138.

The value of the integral estimated using dx= 10-7, is 0.636619772368 which compares favorably with the above computed value rounded off at the appropriate decimal place(red and following decimal places).

 

A left brained approach

The integral  of f(x) between x values of 0 and 1 is estimated here as the sum of a series of rectangular areas each having a width of Δx, beginning with the value, Δx=0.1, for which there are ten, rectangular area elements. The range of x-values is a discrete series: xi=i*Δx, where i=0,1,2,....10 (11 points). The values of y=f(x) at each of these points are given the symbol yi, where yi=f(xi). The integral is approximated as the sum of rectangular area elements: 0.5*(yi+yi+1)*Δx , where i=0,2,3,...,9. Note what happens when we add two adjacent area elements:

0.5*(y0+y1)*Δx+0.5*(y1+y2)*Δx=0.5*(y0+2*y1+y2)*Δx

[0.5*(y0+y1)*dx+0.5*(y1+y2)]*Δx=(0.5*y0 + y1  +0.5*y2)*Δx.

Following this logic we can write out the sum over all elements as,

 

 

Σi=010 0.5*(yi+yi+1)*Δx = (0.5*y0+y2+y3+y4+... 0.5*y10)*Δx  .

 

When we use Δx=0.01, we have 100 area elements to sum over, and the expression becomes,

Σi=0100  0.5*(yi+yi+1)*Δx = (0.5*y0+y2+y3+y4+... 0.5*y100)*dx . Note that the number of discrete elements increases as 1/Δx, and that the approximation gets better as Δx gets closer to zero.

Closing the loop on integration

Computationally, we can do very well estimating an integral by numerical methods on a computer. Analytically, we can do better by noting what happens in the limit as Δx approaches zero to the area element (Δ_area)

Δ_area = 0.5*(yi+yi+1)*Δx     (1)

Δ_area =y(x) Δx                     (2)

or

lim Δx->0 Δ_area/Δx = y(x).     (3a)

The limiting process on the left hand side (LHS) of (3a) is usually abbreviated in calculus by the symbol d_area/dx, so that the equation is shown as follows:

d_area/dx =               y(x).     (3b)

Note that the function to be integrated, f(x), is the derivative of the integral of the function. It becomes possible for someone experienced in calculus to guess the form of the integral function from the form of y(x). For example, the integral of f(x)=xn is just xn+1/(n+1), the derivative of which is xn. This form of an integral is called the indefinite integral because the addition of any arbitrary constant added to it does not change its derivatives. Notationally, the function corresponding to the indefinite integral and its relation to the integrand are given by the following formulas, respectively:

I(x)=∫ f(x) dx  + constant,          (4a)

f(x)= dI(x)/dx.                            (4b)

Definite integrals

Often we are interested in the value of an integral over a restricted range of x. In that case, we write the integral as follows:

I = ∫12 f(x) dx,                             (5)

where 1 and 2 in the integral stand for the starting valurediculouse of x and its final value, respectively, over which the integration is performed. The definite integral is evaluated from the inverse derivative function, I(x) evaluated at the end points, the first subtracted from the second,

I12 = I (x2) -I(x1).                                 (6)

Where I(x) is the function that is determined from the indefinite integral, which is of the form (4a).

It is not difficult to show that the integral function I(x) is the inverse-derivative of f(x), or that alternatively, f(x) is the derivative of i(x). First, consider the definite integral performed over a small range,x to x+ Δx,

rediculousΔI(x)=∫xx+Δx f(x') dx' .                                (7)

If the range, Δx , the integral is approximated by a small rectangular area of height f(x) and width Δx:

ΔI(x)≈f(x)Δx .                                             (8)

The limiting value of the ratio of the integral over this range, as Δx approaches zero, is just the derivative of I(x),

Lim Δx-> 0 ΔI(x)/Δx =dI(x)/dx ,                    (9)

which in conventional notation appears as

dI(x)/dx=f(x).                                            (10)

Derivative and integral of some trigonometric functions

The sine and cosine functions are of particular interest here. We use the following identities in what follows:

sin(A)2+cos(A)2=1                                             (11)

sin(A+B)=sin(A)*cos(B)+cos(A)*sin(B)            (12)

cos(A+B)=cos(A)*cos(B)-sin(A)*sin(B)              (13)

lim A -> 0 sin(A)/A =1.                                          (14)

In addition, we need the following approximation of the square root:

√(1+ ε)≈ 1+0.5*ε,                                           (15)

when ε << 1.

Using the above properties, we can construct derivatives and integrals of the sine and cosine functions. Note that he angle measure used in these expressions is in radians (not degrees), which are defined as the arc length subtended by a given angle, having its vertex at the center of a circle, divided by the radial distance to that arc. There are 2*π radians in a circle, so that one radian is 180./π degrees, or  57.29577951308232 degrees as computed using python.

Evaluating the derivatives of sine and cosine functions

The derivative of the sine function is derived in sufficient detail below that the reader should be able to follow it without much trouble. First of all, consider what this derivative is by definition:

d sin(x)/dx=Lim Δx-> 0  Δsin(x)/Δx .                                               (16a)

The term to be evaluated on the right hand side of (15) is written out as,

[sin(x+Δx)-sin(x)]/Δx=sin(x)(cos(Δx)-1)/Δx+cos(x)sin(Δx)/Δx . (16b)

Using the trigonometric relation (12) we can evaluate the LHS of (16b)

[sin(x+Δx)-sin(x)]/Δx={sin(x)[cos(Δx)-1]+cos(x)sin(Δx)}/ Δx.     (16c)

Using the trigonometric identity (11) we can solve for the first term on the RHS of (16c) to evaluate the limit of this term,

cos(Δx)=√[1-sin(Δx)2],                                                                     (16d)

which using (15) for small values of Δx, approximates to

cos(Δx)≈1-(1/2)*sin(Δx)2 .                                                                 (16e)

Subtracting 1 from both sides of the equation, we get the following:

cos(Δx)-1≈ -(1/2)*sin(Δx)2 .                                                               (16f)

Note that Lim Δx-> 0  sin(Δx)2 /Δx = (1)*sin(Δx)

or

Lim Δx-> 0  sin(Δx)2 /Δx =0.

Therefore,

Lim Δx-> 0  [sin(x+Δx)-sin(x)]/Δx=cos(x),

where we have inserted the limiting value

Lim Δx-> 0  sin(Δx)/Δx =1

in the RHS second term of (16b). Using conventional notation, we express the derivative of the sine function as follows:

d sin(x)/dx= cos(x).                                                         (17a)

Problem 1. Show that d sin(a*x)/dx= a*cos(a*x).            (17b)

Problem 2. Show that d cos(a*x)/dx= -a*sin(a*x).           (18)

Closure

The function displayed in Fig. 1 was computed using the function,

f(x) = sin(π*x). We look for a function, the derivative of which is this function. We find it in (18), where a=π evaluates it to

d cos(π*x)/dx= -π*sin(π*x). Now the limits of the integral are x=0 and x=1. The indefinite integral of sin(π*x) is there fore given by the following:

I(x)=∫sin(π*x) dx                                                           (19a)

I(x)=-cos(π*x)/π .                                                            (19b)

Now we have sufficient information to evaluate the integral of the function used in generating Figs. 1 and 2:

I12={-cos(π)-[-cos(0)]}/π  ,                                                (2a)

which evaluates to,

I12=2/π .                                                                                (2b)

In python (2b) results in the number, 0.63661977236758138.

End note

Python has great precision in evaluating expressions such as sine and cosine functions. Most fellow physicists looking over my shoulder would criticize me for using ridiculously the extreme of precision afforded by Python. This I did to show how well we can estimated the value of an integral numerically on the computer. Measurements in physics actually have a limit of validity that is imposed by the limit of precision of measurements.

In the early days of atomic physics when various necessary data were not known very precisely, say to only three digits, physicists could easily estimate reaction rates and other features of a reactor using the back of an envelope calculation. Enrico Fermi, whose group achieved the first sustained chain reaction on an atomic reactor that they built, kept notebooks that contained numerous estimates of integrals evaluated numerically by hand. Today, the computer may provide much more precision in our calculations than is justified by the precision of measured values. In that, the results should be rounded off to the number of significant figures supported by the quantities that entered into the calculation.

If you want to hone your skills in calculus, you can go here.

 

 

 

 

 

 

 

 

 

 

 

 

 

Listing 1.

#----------------------------------------------------------------------------------------------------

# Generating Fig. 1

ipython --pylab
from pylab import *

a=1.0
x=arange(0,1.1, 0.1)
y=a*sin(math.pi*x)
sy=shape(y)
sy=sy[0]
figure()
line=plot(x,y, color='r')
plot([0,1.0],[1.2,1.2], color='w')
yold=0
for i in range(0,sy):
yav=0.5*(y[i]+y[i+1])
plot([x[i],x[i]],[0,yav])
plot( [x[i],x[i+1]],  [yav,yav]  )
plot([x[i+1],x[i+1]],[yav,0])
yold=yavxlabel('x', color='k')
ylabel('y', color='k')
title("Integral as sum or rectangular areas", color='k')

#--------------------------------------------------------------------------------------------------

#Generating Fig. 2

a=1.0
x=arange(0,1.01, 0.01)
y=a*sin(math.pi*x)
sy=shape(y)
sy=sy[0]
figure()
line=plot(x,y, color='r')
plot([0,1.0],[1.2,1.2], color='w')
yold=0
for i in range(0,sy):
yav=0.5*(y[i]+y[i+1])
plot([x[i],x[i]],[0,yav])
plot( [x[i],x[i+1]],  [yav,yav]  )
plot([x[i+1],x[i+1]],[yav,0])
yold=yav

#-----------------------------------------------------------------------------------------------------

#Progressive estimates of integral by assigning progressively smaller increments in x (dx) to give and approach of dx to zero.

a=1
dx=1.0
for i in range(0, 7):
dx=0.1*dx
x=arange(0,1.+dx, dx)
y=a*sin(math.pi*x)
area=dx*sum(y)
print dx, area
# At this point, I manually inserted the output into respective arrays.
Area=[0.631375151468,0.636567411629,0.636619248769,0.63661976713,0.63661977231,0.636619772367,0.636619772368]

dx=[0.1, 0.01, 0.001, 0.0001, 1e-05, 1e-06, 1e-07]

plim=plot(dx, Area, color='k')
lim=str(double(2./math.pi))
lines=plot(dx, Area, color='k')
xlabel('dx', color='k')
ylabel('Area', color='k')
title("Area as sum of retangles", color='k')
text(0.02,0.6365,r'limit='+lim)

 

 

 

 

Listing 1.

#----------------------------------------------------------------------------------------------------

# Generating Fig. 1

ipython --pylab
from pylab import *

a=1.0
x=arange(0,1.1, 0.1)
y=a*sin(math.pi*x)
sy=shape(y)
sy=sy[0]
figure()
line=plot(x,y, color='r')
plot([0,1.0],[1.2,1.2], color='w')
yold=0
for i in range(0,sy):
yav=0.5*(y[i]+y[i+1])
plot([x[i],x[i]],[0,yav])
plot( [x[i],x[i+1]],  [yav,yav]  )
plot([x[i+1],x[i+1]],[yav,0])
yold=yavxlabel('x', color='k')
ylabel('y', color='k')
title("Integral as sum or rectangular areas", color='k')

#--------------------------------------------------------------------------------------------------

#Generating Fig. 2

a=1.0
x=arange(0,1.01, 0.01)
y=a*sin(math.pi*x)
sy=shape(y)
sy=sy[0]
figure()
line=plot(x,y, color='r')
plot([0,1.0],[1.2,1.2], color='w')
yold=0
for i in range(0,sy):
yav=0.5*(y[i]+y[i+1])
plot([x[i],x[i]],[0,yav])
plot( [x[i],x[i+1]],  [yav,yav]  )
plot([x[i+1],x[i+1]],[yav,0])
yold=yav

#-----------------------------------------------------------------------------------------------------

#Progressive estimates of integral by assigning progressively smaller increments in x (dx) to give and approach of dx to zero.

a=1
dx=1.0
for i in range(0, 7):
dx=0.1*dx
x=arange(0,1.+dx, dx)
y=a*sin(math.pi*x)
area=dx*sum(y)
print dx, area
# At this point, I manually inserted the output into respective arrays.
Area=[0.631375151468,0.636567411629,0.636619248769,0.63661976713,0.63661977231,0.636619772367,0.636619772368]

dx=[0.1, 0.01, 0.001, 0.0001, 1e-05, 1e-06, 1e-07]

plim=plot(dx, Area, color='k')
lim=str(double(2./math.pi))
lines=plot(dx, Area, color='k')
xlabel('dx', color='k')
ylabel('Area', color='k')
title("Area as sum of retangles", color='k')
text(0.02,0.6365,r'limit='+lim)

 

 

0.63661977236758138

This entry was posted in calculus, derivatives, mathematics and tagged , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *