Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168717
Image: ubuntu2004

Limits and Continuity

This worksheet will help you use Sage to understand the contents of the Limits and Continuity unit.  In particular, you can use this sheet to help you understand

  • The squeeze (sandwich) theorem
  • Definitions of limits
  • Continuity
  • The derivative at a point.

As you read each section, find problems in the book which you can try the code on.  I will point you to some of these problems by writing Try:

%auto var('x,y') #This line just tells Sage that x and y are variables.
(x, y)

Squeeze Theorem (Sandwich Theorem)

You can use the following code to help you visualize the squeeze theorem. Just change the bottom, middle, and top functions, and then a graph of all three functions will be created.

Try: 2.2:49-52

bottom=abs(x) middle=x*cos(1/x) top=-abs(x) plot((bottom,middle,top),(x,-.5,.5))

Definitions of Limits

A Finite Limit at x = c: limxcf(x)=L\displaystyle \lim_{x\to c}f(x)=L

If you would like to find a delta given an epsilon, the code below will help. In the example below, we are trying to show the limit as x approaches c of f(x) is L, or limxcf(x)=L\displaystyle \lim_{x\to c}f(x)=L.

Try: 2.3: 7-26, 31-36

f(x)=x^2 c=2 L=limit(f(x),x=c) epsilon=1/2 print[f(x),x==c,L,epsilon] #this will just show you what you have typed
#find the x values for which f(x) = L+epsilon abovex=solve(L+epsilon==f(x),x,solution_dict=True) #then display them. abovex
#find the distance from each x value to c #delta is the smallest of these distances delta1=min([abs(s[x]-c) for s in abovex]) print delta1 #let's get a numerical value to make it easy to compare. print delta1.n()
belowx=solve(L-epsilon==f(x),x,solution_dict=True) #find the x values for which f(x) = L-epsilon belowx #then display them.
#find the distance from each x value to c delta2=min([abs(c-s[x]) for s in belowx]) #delta is the smallest of these distances print delta2 #let's get a numerical value to make it easy to compare. print delta2.n()
#Now pick the smaller of delta1 and delta2. delta=min(delta1,delta2) #I'm going to keep track of the larger to use for graphing purposes. bigdelta=max(delta1,delta2) print delta print delta.n()
#Plot the function. p=plot(f(x),(x,c-2*bigdelta,c+2*bigdelta)) #Add horizontal lines for L+epsilon and L-epsilon p+=plot((L+epsilon,L-epsilon),(x,c-2*bigdelta,c+2*bigdelta),color='green') #Add vertical lines for x==c+delta, x==c-delta p+=implicit_plot(x==c+delta,(c-2*bigdelta,c+2*bigdelta),(L-2*epsilon,L+2*epsilon)) p+=implicit_plot(x==c-delta,(c-2*bigdelta,c+2*bigdelta),(L-2*epsilon,L+2*epsilon)) #Add a point at (c,L) p+=point((c,L),pointsize=30) #Show the graph p.show()

An Infinite limit as you approach c from one side: limxc±f(x)=±\displaystyle \lim_{x\to c^\pm}f(x)=\pm \infty

Now let's explore an infinite limit. First, let's look at one sided infinite limits. In the code below, you can select the value where you want to find the infinite limit, the direction (from above or below the value) and the value of M (a large positive number if you want to show the limit is infinity, or a large negative number if you want to show the limit is negative infinity). The code will then help you find delta by finding where the graph intersects the line y=M, and then computing delta.

Try: In trying to show limx>3x5x3=\displaystyle \lim_{x->3^-}\dfrac{x-5}{x-3}=\infty, if M=200M=-200, find the a corresponding δ\delta.

f(x)=-x/(x-3) c=3 #use direction=1 if computing a limit from the right, # direction=-1 if computing a limit from the left. direction=-1 #use positive numbers for M if limit is infinity, # negative numbers for M if limit is -infinity M=1000 print[f(x),c,direction,M]
#Find the x values for which f(x)=M xvalue=solve(f(x)==M,x,solution_dict=True) #Print them print xvalue
#Find the distance from the xvalues above to c. #Delta is the smallest x value from above. delta= min([abs(s[x]-c) for s in xvalue]) #Show the results. print delta print delta.n()
#Plot the function p=plot(f(x),(x,c-2*delta,c+2*delta)) #Add a horizontal line at M p+=plot(M,(x,c-2*delta,c+2*delta),color='green') #Add a vertical line p+=implicit_plot(x==c+direction*delta,(c-2*delta,c+2*delta),(min(0,4*M),max(0,4*M))) p.show(ymin=min(0,4*M), ymax=max(0,4*M))

A Finite limit as you approach plus or minus infinity: limx±f(x)=L\displaystyle \lim_{x\to \pm \infty}f(x)=L

Now let's look at a limit as xx approaches infinity or negative infinity.  Here you must give the limit LL and an epsilon, and then find a value of B (large positive if you want to approach ++\infty, or negative if you want to approach -\infty.

Try: In trying to show limx>5x63x+2=53\displaystyle \lim_{x->-\infty}\dfrac{5x-6}{3x+2}=\frac{5}{3}, if ϵ=1/100\epsilon=1/100, find the a corresponding δ\delta.

f(x)=(2*x-3)/(3*x+7) #Use direction=+1 if x approaches infinity. #Use direction=-1 if x approaches -infinity. direction=1 #This will compute the limit. L=limit(f(x),x=direction*infinity) #Choose your epsilon. epsilon=1/10 #This just shows you the things you typed in. print [f(x),direction*Infinity,L,epsilon]
#find the x values for which f(x) = L+epsilon and L-epsilon abovex=solve(L+epsilon==f(x),x,solution_dict=True) belowx=solve(L-epsilon==f(x),x,solution_dict=True) #then display them. print abovex print belowx
#The x value furthest from the origin in the right direction is a good choice for B. B=direction*(max([[direction*s[x] for s in abovex],[direction*s[x] for s in belowx]])[0]) print B print B.n()
#Plot the function. p=plot(f(x),(x,0,5*B),ymin=L-2*epsilon,ymax=L+2*epsilon) #Add horizontal lines for L+epsilon and L-epsilon p+=plot((L+epsilon,L-epsilon),(x,0,5*B),color='green') #Add a vertical lines for x==B p+=implicit_plot(x==B,(B-1,B+1),(L-2*epsilon,L+2*epsilon)) #Show the graph p.show()

Continuity

Remember that we say a function is continuous at an interior point c if the limit as x approaches c exists and equals the function's value at c.  In other words, functions are continuous at a point when you can evaluate the limit by plugging in a point. Most of the functions you are familiar with are continuous.

If the function is continuous at a point then the following code should show that it is.  If it is discontinuous, then you will likely encouter errors. I provide a graph of the function at x = c at the end of the code so you can see what is happening.

Try: 2.6: 13-38

f(x)=(x^2-2*x)/(x-2) c=1
limit(f(x),x=c)
f(c)
bool(limit(f(x),x=c)==f(c))
plot(f(x),(x,c-1,c+1))

If you want to study continuity at an endpoint of a function, then you have to look at one sided limits instead. The function f=xf=\sqrt{x} has no limit at x=0x=0, but it does have a limit from the right at x=0x=0.  We say x\sqrt{x} is continuous at 0 because 0 is the left enpoint of the domain and its limit from the right matches the value of the function at 0.

f(x)=sqrt(x) c=0 direction='above'
limit(f(x),x=c,dir=direction)
f(c)
bool(limit(f(x),x=c,dir=direction)==f(c))
f(x).plot(c-1,c+1)

Here are some examples of functions which are not continuous at a point.

This function has an infinite discontinuity at 0.

f=1/x f.plot(-1,1,ymin=-10,ymax=10)

This function has an jump discontinuity at 0.

f=abs(x)/x f.plot(-1,1)

This function has an oscillating discontinuity at 0.

f=sin(1/x) f.plot(-1,1)

This function has an removable discontinuity at 0. You can redefine the function to be its limit at 0, and then the function would be continuous. When a discontinuity is removable, the graph on a computer may appear to be continuous.

f=(x^2 + 3*x)/x c=0 f.plot(c-1,c+1).show() f.limit(x=c)

The Derivative at a Point

Recall that the derivative at a point is the slope of a tangent line at that point.  The slope of the tangent line is found by considering the slope of secant lines which pass through the point of interest, and another point close by.  If we want to find the derivative at the point c, then we want to find the slope of the line that passes through (c, f(c)) and (c+h, f(c+h)).  The code below illustrates this step by step. This code is very similar to the average velocity section from the previous unit (because it is the same idea). Try changing the values of h so that they get closer to zero, and then you can watch how the secant line becomes the tangent line.

Try: 2.7: 5-22, 27-30, 31-32, 45-48

f(x)=sqrt(x) c=1 h=2
slope_of_secant_line=(f(c+h)-f(c))/h secant_line_equation = y-f(c)==slope_of_secant_line*(x-c) slope_of_secant_line.show() secant_line_equation.show()
var('H') slope_of_tangent_line=limit((f(c+H)-f(c))/H,H=0) tangent_line_equation = y-f(c)==slope_of_tangent_line*(x-c) slope_of_tangent_line.show() tangent_line_equation.show()
xrange=(0,4) p=plot(f(x),xrange) p+=plot(f(c)+slope_of_secant_line*(x-c),xrange,color='red') p+=plot(f(c)+slope_of_tangent_line*(x-c),xrange,color='green') p+=point((c,f(c)),pointsize=30) p+=point((c+h,f(c+h)),pointsize=30) p.show()

The code below graphs many secant lines simultaneously, together with the tangent line.

f(x)=sqrt(x) c=1 xrange=(0,4) hrange=[3,2,1,.5,.25] p=f.plot(xrange) for h in hrange: p+=plot(f(c)+(f(c+h)-f(c))/h*(x-c),xrange,color='red') p+=point((c+h,f(c+h)),pointsize=20) var('h') p+=plot(f(c)+limit((f(c+h)-f(c))/h,h=0)*(x-c),xrange,color='green') p+=point((c,f(c)),pointsize=40) p+=f.plot(xrange) p.show()