Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News AboutSign UpSign In
| Download

All published worksheets from http://sagenb.org

Views: 168716
Image: ubuntu2004

Curve Properties

This worksheet will provide you with examples of code to:

  • Understand Rolle's and the Mean Value Theorem. In particular, find points on a curve whose instantaneous slope matches the average slope.
  • Find antiderivatives (indefinite integrals)
  • Find and use differentials and linearizations (tangent lines)
  • Use L'Hopitals rule

Using Rolle's Theorem and The Intermediate Value Theorem to show there is only one root.

Type in a function and a range of values (if (,)(-\infty,\infty), then put in two finite values).  The code below will evaluate the function at the endpoints of your interval (hopefully showing one value is positive while the other is negative). Then it will compute the derivative and find where it is zero.  If the derivative is never zero on the interval, then you immediately know that the function cannot have two zeros, otherwise Rolle's theorem would require that f=0f'=0 somewhere on the interval.

f(x)=x^3+3*x+2 xrange=(-10,10) Df=diff(f,x) html.table([ ["f",f(x)], ["f at left endpoint", f(xrange[0])], ["f at right endpoint", f(xrange[1])], ["f'",Df(x)==Df(x).factor()], ["f'=0",solve(Df(x)==0,x)], ["Graph",plot(f,xrange)] ])
f x^{3} + 3 \, x + 2
f at left endpoint -1028
f at right endpoint 1032
f' 3 \, x^{2} + 3 = 3 \, x^{2} + 3
f'=0 \text{[ x == -I, x == I ]}
Graph

The Mean Value Theorem

Recall that the mean value theorem guarantees the existence of a value cc in the interval (a,b)(a,b) such that f(c)=f(b)f(a)ba.f'(c)=\frac{f(b)-f(a)}{b-a}. The code below will help you find that value of cc.

f(x)=x^3-3*x xrange=(-3,3) Df=diff(f,x) a=xrange[0] #grab the left endpoint b=xrange[1] #grab the right endpoint m=(f(b)-f(a))/(b-a) #use m to simplify typing the average slope sol=solve(Df(x)==m,x) #find where f'(c)=m p=plot(f,xrange) #plot f p+=plot(f(a)+m*(x-a),xrange,color='green') #add the line connecting the endpoints sols=[] #Get rid of solutions not in [a,b], and graph them. for cp in sol: c=x.subs_expr(cp) if(c>a): if(c<b): sols.append(x==c) p+=point((c,f(c)),pointsize=20,rgbcolor='black') p+=plot(f(c)+m*(x-c),xrange,color='red') html.table([ #create a pretty table ["f",f(x)], ["f'",Df(x)], ["m=(f(b)-f(a))/(b-a)",m], ["c such that f'(c)=m",sols], ["Graph",p] ])
f x^{3} - 3 \, x
f' 3 \, x^{2} - 3
m=(f(b)-f(a))/(b-a) 6
c such that f'(c)=m \left[x = -\sqrt{3}, x = \sqrt{3}\right]
Graph

The code can be much shorter, but then the output is not as nice.

f(x)=x^3-3*x xrange=(-3,3) Df=diff(f,x) a=xrange[0] b=xrange[1] m=(f(b)-f(a))/(b-a) sol=solve(Df(x)==m,x) sol
[x == -sqrt(3), x == sqrt(3)]

Antiderivatives

To compute antiderivatives (indefinite integrals), use the integrate command. Notice that the computer does not include the +C+C. You have to do that yourself.

integrate(x^2,x)
1/3*x^3
f=x^2-sqrt(x)+sin(4*x)-1/(1+x^2) integrate(f,x).show()
\frac{1}{3} \, x^{3} - \frac{2}{3} \, x^{\left(\frac{3}{2}\right)} - \frac{1}{4} \, \cos\left(4 \, x\right) - \arctan\left(x\right)

Position from Velocity

If you know the velocity of an object, then all you have to do is integrate to find the position. If the initial position is s0s_0 at time t0t_0, then you can replace each ss with s0s_0 and tt with t0t_0 to find the constant CC from integration.

var('t,s,v,C') v=t^2+exp(t) t0=0 s0=2 s=integrate(v,t)+C sol=solve(s(t=t0)==s0,C) html.table([ ["a",a], ["v",v], ["s = integral of v",s], ["[t0,s0]",[t0,s0]], ["Equation to find C",s0==s(t=t0)], ["s",s.subs_expr(sol[0])] ])
a -3
v t^{2} + e^{t}
s = integral of v \frac{1}{3} \, t^{3} + C + e^{t}
[t0,s0] \left[0, 2\right]
Equation to find C 2 = C + 1
s \frac{1}{3} \, t^{3} + e^{t} + 1

Position from Acceleration

If you know the acceleration at any time tt, as well as the velocity and position at a single time tt, then you can use the following code to find equations for the velocity and position.  The table output at the end shows all the work involved.

var('t,s,v,a,C,D') #we have to start by defining our variables a=t^2+exp(t) t0=0 s0=2 v0=3 #Find v first. v=integrate(a,t)+C solC=solve(v(t=t0)==v0,C) vn=v.subs_expr(solC[0]) #Now find s. s=integrate(vn,t)+D solD=solve(s0==s(t=t0),D) sn=s.subs_expr(solD[0]) #Now format the output to look really nice. html.table([ ["a",a], ["v = integral of a",v], ["[t0,v0]",[t0,v0]], ["Equation to find C",v0==v(t=t0)], ["v",vn], ["s = integral of v",s], ["[t0,s0]",[t0,s0]], ["Equations to find D",s0==s(t=t0)], ["s",sn] ])
a t^{2} + e^{t}
v = integral of a \frac{1}{3} \, t^{3} + C + e^{t}
[t0,v0] \left[0, 3\right]
Equation to find C 3 = C + 1
v \frac{1}{3} \, t^{3} + e^{t} + 2
s = integral of v \frac{1}{12} \, t^{4} + D + 2 \, t + e^{t}
[t0,s0] \left[0, 2\right]
Equations to find D 2 = D + 1
s \frac{1}{12} \, t^{4} + 2 \, t + e^{t} + 1

Differentials

The derivative gives us the slope of a tangent line.  If you increase the xx value of a function from xx to x+dxx+dx, then how much does the yy value increase?  The notation dydx=f(x)\dfrac{dy}{dx}=f'(x) suggests that we can find a small change in yy by multiplying both sides by dxdx to obtain the differential dy=f(x)dx.dy = f'(x)dx. Think of dydy as a small change in yy.  Think of dxdx as a small change in dxdx.  The quantities dydy and dxdx are called differentials. You can use differentials to estimate how much yy will change if xx changes by dxdx. The example below illustates how to do this.  In high dimensional calculus, the differentials become vectors and the derivative becomes a matrix. This differential equation is the key equation needed to extend calculus to higher dimensions.

var('x,dx') f=x^2 dy=diff(f)*dx dy
2*dx*x
xvalue=2 dx=1/2 dy(x=xvalue,dx=dx)
2

The picture below illustrates graphically how the differential comes from using the tangent line to approximate a function.

xrange=(x,xvalue-2*dx,xvalue+2*dx) p=plot(f,xrange) p+=point((xvalue,f(x=xvalue)),pointsize=30) p+=plot(f(x=xvalue)+diff(f)(x=xvalue)*(x-xvalue),xrange,color='red') p+=line([(xvalue,f(x=xvalue)),(xvalue+dx,f(x=xvalue))],rgbcolor='purple') p+=line([(xvalue+dx,f(x=xvalue)),(xvalue+dx,f(x=xvalue)+dy(x=xvalue,dx=dx))],rgbcolor='purple') p+=line([(xvalue,f(x=xvalue)),(xvalue,f(x=xvalue+dx))],rgbcolor='green') p+=line([(xvalue,f(x=xvalue+dx)),(xvalue+dx,f(x=xvalue+dx))],rgbcolor='green') p+=point((xvalue+dx,f(x=xvalue)+dy(x=xvalue,dx=dx)),rgbcolor='purple',pointsize=20) p+=point((xvalue+dx,f(x=xvalue+dx)),rgbcolor='green',pointsize=20) p.show()

The code below illustrates numerically how dydy is approximately the same as Δy=f(x+dx)f(x)\Delta y = f(x+dx)-f(x).

var('x,dx') f(x)=x^2 xValue=1 dxValue=.01 Df=diff(f,x) dy=Df(x)*dx html.table([ ["f",f(x)], ["f'",Df(x)], ["dy",dy], ["dy evaluated at x and dx",dy(x=xValue,dx=dxValue).n()], ["f at the x value",f(xValue)], ["f at x+dx",f(xValue+dxValue)], ["The actual change in y",f(xValue+dxValue)-f(xValue)], ["The approximate change in y = dy",dy(x=xValue,dx=dxValue).n()], ])
f x^{2}
f' 2 \, x
dy 2 \, \mbox{dx} x
dy evaluated at x and dx 0.0200000000000000
f at the x value 1
f at x+dx 1.02010000000000
The actual change in y 0.0201000000000000
The approximate change in y = dy 0.0200000000000000

The linearization of f(x)f(x) is just another name for the tangent line.  The code below compute the linearization of (1+x)k(1+x)^k for any real number kk.

var('k') f(x)=(1+x)^k c=0 Df=diff(f,x) L(x)=f(c)+Df(c)*(x-c) L(x)
k*x + 1

L'Hopital's Rule

If you cannot find a limit because it is of the form 00\dfrac{0}{0} or \dfrac{\infty}{\infty}, then L'Hopital's rule can often help.  The idea is to take the derivative of the top and bottom separately, and then find the limit.  If is exists, then the original limit equals the limit you found.  You can repeat this as many times as needed, provide at each stage the limit is still of the form 00\dfrac{0}{0} or \dfrac{\infty}{\infty}. The example below illustrates this process for 1cos(x)x2\dfrac{1-\cos(x)}{x^2}. Notice that after putting in zero in the top and bottom in both the original and after taking derivatives, you get 0/0 in both cases. Only after 2 derivatives do you get 1/2.

f(x) = (1-cos(x))/x^2 c=0 num=numerator(f(x)) den=denominator(f(x)) html.table([ ["top",num,limit(num,x=c),"bottom",den,limit(den,x=c)], ["top",diff(num),limit(diff(num),x=c),"bottom",diff(den),limit(diff(den),x=c)], ["top",diff(num,2),limit(diff(num,2),x=c),"bottom",diff(den,2),limit(diff(den,2),x=c)], ]) limit(f(x),x=c)
top -\cos\left(x\right) + 1 0 bottom x^{2} 0
top \sin\left(x\right) 0 bottom 2 \, x 0
top \cos\left(x\right) 1 bottom 2 2
1/2

You can also use this rule when c=c=\infty. In the example below, the second line gives 01=0\dfrac{0}{1}=0, so you not take 2 derivatives.

f(x) = log(x)/x c=infinity num=numerator(f(x)) den=denominator(f(x)) html.table([ ["top",num,limit(num,x=c),"bottom",den,limit(den,x=c)], ["top",diff(num),limit(diff(num),x=c),"bottom",diff(den),limit(diff(den),x=c)], ["top",diff(num,2),limit(diff(num,2),x=c),"bottom",diff(den,2),limit(diff(den,2),x=c)], ]) limit(f(x),x=c)
top \ln\left(x\right) +\infty bottom x +\infty
top \frac{1}{x} 0 bottom 1 1
top -\frac{1}{x^{2}} 0 bottom 0 0
0