CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.

| Download
Project: Calculus
Views: 25
Image: ubuntu2004
Kernel: SageMath 9.2

Shri Ramdeobaba College of Engineering and Management,Nagpur

\hspace{85pt} Department of Mathematics

\hspace{105pt} Computational Mathematics Lab

Name:Sharvari Gohane

Roll Number:67

Section: C

\hspace{50pt}Experiment 3: Differential Calculus and its Applications

Aim: To Learn Calculus with SageMath

1. Limit

To Evaluate limxaf(x)\lim_{x \to a} f(x) syntax is:

\hspace{115 pt} Syntax: limit(f(x),x=a, dir='+'or '-')

"dir" - (default: None); dir may have the value 'plus' (or '+' or 'right' or 'above') for a limit from above, 'minus' (or '-' or'left' or 'below') for a limit from below, or may be omitted (implying a two-sided limit is to be computed).

Problem: Find the limit of limx0xx lim_{x \to 0} \frac{x}{|x|}
f(x)=x/abs(x) plot(f(x),(x,-2,2))
Image in a Jupyter notebook
limit(f(x),x=0)
und
limit(f(x),x=0,dir = "+")
1
limit(f(x),x=0,dir = "-")
-1
Problem:
Evaluate limx2x24x2 lim_{x \to 2} \frac{x^2-4}{x-2}
plot((x^2-4)/(x-2),0,4,figsize=3)
Image in a Jupyter notebook
limit((x^2-4)/(x-2),x=2)
4
Problem:
Evaluate limxaxa lim_{x \to a} x^a for various values of aa.
var('a')
a
assume(a>0)
limit(x^a,x=infinity)
+Infinity
forget()
assume(a<0)
limit(x^a,x=oo)
0

Exercise 3.1

Find the following limits
  1. limx0(x22x1000) lim_{x \to 0} (x^2-\frac{2^x}{1000})

Solution-1
f(x)=(x^2-(2^x)/(1000))
limit(f(x),x=0)
-1/1000
limit(f(x),x=0,dir= "+")
-1/1000
limit(f(x),x=0,dir= "-")
-1/1000
  1. limx0.5(2x12x3x2) lim_{x \to 0.5^-} (\frac{2x-1}{|2x^3-x^2|})

Solution 2

limit((2*x-1)/abs(2*x^3-x^2),x=0.5,dir='-')
-4.0

2.Derivatives

The syntax for derivative of f(x) is

\hspace{80pt} diff(f, args)

Repeated differentiation is supported by the syntax given in the examples below.

f(x)=x*sin(1/x)
f.diff(x) # first order derivative of f(x)
x |--> -cos(1/x)/x + sin(1/x)
f.diff() # first order derivative of f(x)
x |--> -cos(1/x)/x + sin(1/x)
diff(f(x),x ) # first order derivative of f(x)
-cos(1/x)/x + sin(1/x)
f.diff(4) # or diff(f(x),x,4) gives fourth order derivative of f(x)
x |--> -12*sin(1/x)/x^5 - 8*cos(1/x)/x^6 + sin(1/x)/x^7
Problem

Consider a function f(x)=sin(cos(5x))e(xa)2 f(x)=sin(cos(5x))-e^{(x-a)^{2}} . Plot the graph of f(x) f (x) along with first two derivative in [0.5,2][0.5, 2].

f(x) = sin(cos(5*x))-exp((x - 1)^2)
f1(x) = f.diff()
f2(x) = f.diff(2)
p = plot(f(x),0.5,2,color='red') p1 = plot(f1(x),0.5,2,color='green') p2 = plot(f2(x),0.5,2,color='black') show(p+p1+p2, ymax=20,ymin=-30,figsize=5)
Image in a Jupyter notebook

Exercise 3.2

  1. Find the first four derivatives of f(t)=ln(1+t2)f(t)=ln(1+t^2) and plot them along with the graph of f(t)f(t).

Solution-1
f(t)=ln(1+t^2)
f1=f.diff(t) show(f1(t))
2tt2+1\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{2 \, t}{t^{2} + 1}
f2=f.diff(2) show(f2(t))
4t2(t2+1)2+2t2+1\renewcommand{\Bold}[1]{\mathbf{#1}}-\frac{4 \, t^{2}}{{\left(t^{2} + 1\right)}^{2}} + \frac{2}{t^{2} + 1}
f3=f.diff(3) show(f3(t))
16t3(t2+1)312t(t2+1)2\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{16 \, t^{3}}{{\left(t^{2} + 1\right)}^{3}} - \frac{12 \, t}{{\left(t^{2} + 1\right)}^{2}}
f4=f.diff(4) show(f4(t))
96t4(t2+1)4+96t2(t2+1)312(t2+1)2\renewcommand{\Bold}[1]{\mathbf{#1}}-\frac{96 \, t^{4}}{{\left(t^{2} + 1\right)}^{4}} + \frac{96 \, t^{2}}{{\left(t^{2} + 1\right)}^{3}} - \frac{12}{{\left(t^{2} + 1\right)}^{2}}
p1=plot(f(t),-2,2,color='red') p2=plot(f1(t),-2,2,color='blue') p3=plot(f2(t),-2,2,color='green') p4=plot(f3(t),-2,2,color='black') p5=plot(f4(t),-2,2,color='orange') show(p1+p2+p3+p4+p5,ymin=-25,ymax=25,figsize=5)
Image in a Jupyter notebook
  1. Find the first four derivative of f(x)=sin(3x)+e2x+ln(7x)f(x)=sin(3x)+e^{-2x}+ln(7x).

Solution-2
f(x)=sin(3*x)+e^(-2*x)+ln(7*x)
f.diff()
x |--> 1/x + 3*cos(3*x) - 2*e^(-2*x)
f.diff(2)
x |--> -1/x^2 + 4*e^(-2*x) - 9*sin(3*x)
f.diff(3)
x |--> 2/x^3 - 27*cos(3*x) - 8*e^(-2*x)
f.diff(4)
x |--> -6/x^4 + 16*e^(-2*x) + 81*sin(3*x)

3. Partial Derivatives

For f(x)=xyx+yf(x)= \frac{xy}{x+y} find fx,fy,2fx2,2fy2,2fxy,2fyx\frac{\partial f}{\partial x},\frac{\partial f}{\partial y},\frac{\partial^2 f}{\partial x^2},\frac{\partial^2 f}{\partial y^2},\frac{\partial^2 f} {\partial x \partial y},\frac{\partial^2 f}{\partial y \partial x}

var('x,y') f(x,y) = (x*y)/(x+y) fx = f.diff(x) # Gives first order derivative of f with respect to x show(fx(x,y)) fy = f.diff(y) # Gives first order derivative of f with respect to y show(fy(x,y)) fxx=f.diff(x,2) # Gives Second order derivative of f with respect to x . Instead of fxx we can give any other name also. show(fxx(x,y)) fyy=f.diff(y,2) # Gives Second order derivative of f with respect to y . Instead of fyy we can give any other name also. fxy=f.diff(x,y) # Here we are differentiating function first with respect to x and then we differentiate the result with respect to y. show(fxy(x,y)) fyx=f.diff(y,x) # Here we are differentiating function first with respect to y and then we differentiate the result with respect to x. show(fxy(x,y))
yx+yxy(x+y)2\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{y}{x + y} - \frac{x y}{{\left(x + y\right)}^{2}}
xx+yxy(x+y)2\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{x}{x + y} - \frac{x y}{{\left(x + y\right)}^{2}}
2y(x+y)2+2xy(x+y)3\renewcommand{\Bold}[1]{\mathbf{#1}}-\frac{2 \, y}{{\left(x + y\right)}^{2}} + \frac{2 \, x y}{{\left(x + y\right)}^{3}}
1x+yx(x+y)2y(x+y)2+2xy(x+y)3\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{x + y} - \frac{x}{{\left(x + y\right)}^{2}} - \frac{y}{{\left(x + y\right)}^{2}} + \frac{2 \, x y}{{\left(x + y\right)}^{3}}
1x+yx(x+y)2y(x+y)2+2xy(x+y)3\renewcommand{\Bold}[1]{\mathbf{#1}}\frac{1}{x + y} - \frac{x}{{\left(x + y\right)}^{2}} - \frac{y}{{\left(x + y\right)}^{2}} + \frac{2 \, x y}{{\left(x + y\right)}^{3}}
Problem

For f(x)=f(x,y)=4xye(x2y2)f(x)=f(x,y)=4xye^{(-x^2-y^2)}, find all first order and second order derivatives at point (1,2).

var('x,y') f(x,y)=4*x*y*exp(-x^2-y^2) show(f(x,y))
4xye(x2y2)\renewcommand{\Bold}[1]{\mathbf{#1}}4 \, x y e^{\left(-x^{2} - y^{2}\right)}
show(f.diff(x)) # Gives Derviative of f with respect to x
(x,y)  8x2ye(x2y2)+4ye(x2y2)\renewcommand{\Bold}[1]{\mathbf{#1}}\left( x, y \right) \ {\mapsto} \ -8 \, x^{2} y e^{\left(-x^{2} - y^{2}\right)} + 4 \, y e^{\left(-x^{2} - y^{2}\right)}
show(f.diff(x)(x,y)) # Gives Derviative of f with respect to x
8x2ye(x2y2)+4ye(x2y2)\renewcommand{\Bold}[1]{\mathbf{#1}}-8 \, x^{2} y e^{\left(-x^{2} - y^{2}\right)} + 4 \, y e^{\left(-x^{2} - y^{2}\right)}
f.diff(x)(x=1.0,y=2.0) # Gives Derviative of f with respect to x at (1,2)
-0.0539035759926837
f.diff(y)(x=1,y=2) # Gives Derviative of f with respect to y at (1,2)
-28*e^(-5)
f.diff(x,2)(x=1,y=2) # Gives double Derviative of f with respect to x at (1,2).
-16*e^(-5)
f.diff(x,y)(x=1,y=2) # Gives Derviative of f first with respect to x and then with respect to y at (1,2).
28*e^(-5)
f.diff(y,x)(x=1,y=2) # Gives Derviative of f first with respect to y and then with respect to x at (1,2).
28*e^(-5)

Exercise 3.3

  1. Let f(x,y)=ln(x2+y2)f(x,y)=ln(x^2+y^2). Show that 2fx2+2fy2=0\frac{\partial^2 f}{\partial x^2 }+\frac{\partial^2 f}{\partial y^2 }=0.

Solution-1
var('x,y') f(x,y)=ln(x^2+y^2) show(f(x,y))
log(x2+y2)\renewcommand{\Bold}[1]{\mathbf{#1}}\log\left(x^{2} + y^{2}\right)
fxx = f.diff(x,2) show(fxx(x,y))
4x2(x2+y2)2+2x2+y2\renewcommand{\Bold}[1]{\mathbf{#1}}-\frac{4 \, x^{2}}{{\left(x^{2} + y^{2}\right)}^{2}} + \frac{2}{x^{2} + y^{2}}
fyy = f.diff(y,2) show(fyy(x,y))
4y2(x2+y2)2+2x2+y2\renewcommand{\Bold}[1]{\mathbf{#1}}-\frac{4 \, y^{2}}{{\left(x^{2} + y^{2}\right)}^{2}} + \frac{2}{x^{2} + y^{2}}
show(fxx+fyy)
(x,y)  4x2(x2+y2)24y2(x2+y2)2+4x2+y2\renewcommand{\Bold}[1]{\mathbf{#1}}\left( x, y \right) \ {\mapsto} \ -\frac{4 \, x^{2}}{{\left(x^{2} + y^{2}\right)}^{2}} - \frac{4 \, y^{2}}{{\left(x^{2} + y^{2}\right)}^{2}} + \frac{4}{x^{2} + y^{2}}
  1. Find all the first order partial derivatives of w=x2y10y2z3+43x7tan(4y)w=x^2y-10y^2z^3+43x-7tan(4y)

Solution-2
var('x,y,z') w=x^2*y-10*y^2*z^3+43*x-7*tan(4*y) show(w)
10y2z3+x2y+43x7tan(4y)\renewcommand{\Bold}[1]{\mathbf{#1}}-10 \, y^{2} z^{3} + x^{2} y + 43 \, x - 7 \, \tan\left(4 \, y\right)
var('x,y,z') f(x,y) = x^2*y-10*y^2*z^3+43*x-7*tan(4*y) fx = f.diff(x) # Gives first order derivative of f with respect to x show(fx(x,y,z)) fy = f.diff(y) # Gives first order derivative of f with respect to y show(fy(x,y,z)) fz = f.diff(z) # Gives first order derivative of f with respect to z show(fz(x,y,z)) fxx=f.diff(x,2) # Gives Second order derivative of f with respect to x . Instead of fxx we can give any other name also. show(fxx(x,y,z)) fyy=f.diff(y,2) # Gives Second order derivative of f with respect to y . Instead of fyy we can give any other name also. show(fyy(x,y,z)) fzz=f.diff(z,2) # Gives Second order derivative of f with respect to z . Instead of fzz we can give any other name also. show(fzz(x,y,z)) fxy=f.diff(x,y) # Here we are differentiating function first with respect to x and then we differentiate the result with respect to y. show(fxy(x,y,z)) fyz=f.diff(y,x) # Here we are differentiating function first with respect to y and then we differentiate the result with respect to x. show(fxy(x,y,z)) fzx=f.diff(z,x) # Here we are differentiating function first with respect to z and then we differentiate the result with respect to x. show(fzx(x,y,z))
2xy+43\renewcommand{\Bold}[1]{\mathbf{#1}}2 \, x y + 43
20yz3+x228tan(4y)228\renewcommand{\Bold}[1]{\mathbf{#1}}-20 \, y z^{3} + x^{2} - 28 \, \tan\left(4 \, y\right)^{2} - 28
30y2z2\renewcommand{\Bold}[1]{\mathbf{#1}}-30 \, y^{2} z^{2}
2y\renewcommand{\Bold}[1]{\mathbf{#1}}2 \, y
20z3224(tan(4y)2+1)tan(4y)\renewcommand{\Bold}[1]{\mathbf{#1}}-20 \, z^{3} - 224 \, {\left(\tan\left(4 \, y\right)^{2} + 1\right)} \tan\left(4 \, y\right)
60y2z\renewcommand{\Bold}[1]{\mathbf{#1}}-60 \, y^{2} z
2x\renewcommand{\Bold}[1]{\mathbf{#1}}2 \, x
2x\renewcommand{\Bold}[1]{\mathbf{#1}}2 \, x
0\renewcommand{\Bold}[1]{\mathbf{#1}}0

4. Implicit Derivative

Find the slope formula for the Folium of Descartes implicitly defined by x^3 + y^3 = 6xy.( Find dydx\frac{dy}{dx})

x = var('x') y = var('y') f(x,y) = x^3 + y^3 - 6*x*y y=function('y')(x) temp=diff(f(x,y)) solve(temp,diff(y))
[diff(y(x), x) == -(x^2 - 2*y(x))/(y(x)^2 - 2*x)]

Exercise 3.4

  1. Find the dydx\frac {dy}{dx} for the implicit function 2(x2+y2)2=25(x2y2)2(x^2+y^2)^2=25(x^2-y^2).

Solution-1
x = var('x') y = var('y') f(x,y) = (2*(x^2+y^2)^2) - 25*(x^2-y^2) y=function('y')(x) temp=diff(f(x,y)) show(solve(temp,diff(y)))
[xy(x)=4x3+4xy(x)225x4y(x)3+(4x2+25)y(x)]\renewcommand{\Bold}[1]{\mathbf{#1}}\left[\frac{\partial}{\partial x}y\left(x\right) = -\frac{4 \, x^{3} + 4 \, x y\left(x\right)^{2} - 25 \, x}{4 \, y\left(x\right)^{3} + {\left(4 \, x^{2} + 25\right)} y\left(x\right)}\right]
  1. Find the dydx\frac {dy}{dx} for the implicit function y2=x3(2x)y^2=x^3(2-x).

Solution-2
x = var('x') y = var('y') f(x,y) = x^3*(2-x)-y^2 y=function('y')(x) temp=diff(f(x,y)) show(solve(temp,diff(y)))
[xy(x)=2x33x2y(x)]\renewcommand{\Bold}[1]{\mathbf{#1}}\left[\frac{\partial}{\partial x}y\left(x\right) = -\frac{2 \, x^{3} - 3 \, x^{2}}{y\left(x\right)}\right]

5. Local Maximum and Minimum

Syntax for finding local maximum value of function f(x)f(x) in interval (a,b)(a,b) is

\hspace{105 pt} f.find_local_maximum(a,b).

Syntax for finding local minimum value of function f(x)f(x) in interval (a,b)(a,b) is

\hspace{105 pt} f.find_local_minimum(a,b).

Problem:

Find the local maximum and local minimum of the function f(x)=ex/2+e2x2f(x)=e^{-x/2}+e^{-2x^2}.

f(x) = exp(-x/2) + exp(-2*x^2) f.plot(-2,2,figsize =4)
Image in a Jupyter notebook
f.find_local_maximum(-1,1)
(2.0340673102820146, -0.13932332835389183)
f.find_local_minimum(-1.5,-0.5)
(1.7650250464715878, -0.8669457216285031)
f.find_local_minimum(1,2)
(0.3682149119773104, 1.999999956179319)
f.find_local_maximum(1,2)
(0.7418659187092465, 1.0000000286997572)
plot(f.diff(),-2,2,figsize=4)
Image in a Jupyter notebook
c1 = f.diff().find_root(-2,-0.5);c1
-0.8669457228341761
c2 = f.diff().find_root(-0.5,0);c2
-0.13932333585693482
f.diff(2)(x=c1), f.diff(2)(x=c2)
(2.17068359111117, -3.280901640208612)

Problem:

Consider a function f(x)=2x39x2+12x3f(x)=2x^3-9x^2+12x-3

(a) Find the intervals on which f is increasing or decreasing.

(b) Find the local maximum and minimum values of f.

(c) Find the intervals of concavity and the inflection points.

f(x) = 2*x^3 - 9*x^2 + 12*x - 3 pf = plot(f,0,3) show(pf,figsize=4)
Image in a Jupyter notebook
df = f.diff() d2f = f.diff(2)
cpts = solve(df==0,x,solution_dict=True)
a,b = cpts[0][x],cpts[1][x]
infl = solve(d2f==0,x,solution_dict=True);infl
[{x: 3/2}]
c = infl[0][x]
pf = plot(f,0,3,thickness=0.5) pt1 = point((a,f(a)),color='red',size=20) # Gives point where function has maximum value pt2 = point((b,f(b)),color='green',size=30)# Gives point where function have minimum value pt3 = point((c,f(c)),color='black',size=20) # gives point of inflection pdf = plot(df,0,3,thickness=0.5,color='red') pd2f = plot(d2f,0,3,thickness=0.5,color='black') show(pf+pt1+pt2+pt3+pdf+pd2f,ymin=-5,ymax=8,figsize=4)
Image in a Jupyter notebook

Problem:

The Hubble Space Telescope was deployed on April 24, 1990, by the space shuttle Discovery. Amodel for the velocity of the shuttle during this mission, from liftoff at t=0t=0 until the solid rocket boosters were jettisoned at t=126t=126 seconds, is given by

v(t)=0.001302t320.09029t2+23.61t3.083v(t)=0.001302t^3-20.09029t^2+23.61t-3.083

(in feet per second). Using this model, estimate the absolute maximum and minimum values of the acceleration of the shuttle between liftoff and the jettisoning of the booster.

var('t') v(t) =0.001302*t^3-0.09029*t^2+23.61*t-3.083
plot(v,0,126,figsize=4)
Image in a Jupyter notebook
a = v.diff() a.plot(0,126,figsize=4)
Image in a Jupyter notebook
a.find_local_minimum(0,126)
(21.52288169482847, 23.115720101631652)
a(0),a(23.115720101631652), a(126)
(23.6100000000000, 21.5228816948285, 62.8685760000000)

Exercise 3.5

  1. Find the local maximum and local minimum of f(x)=x4exf(x)=x^4e^{-x}.

Solution-1
f(x)=x^4*exp(-x) show(f(x)) f.plot((-2,2),figsize=4)
x4e(x)\renewcommand{\Bold}[1]{\mathbf{#1}}x^{4} e^{\left(-x\right)}
Image in a Jupyter notebook
f.find_local_maximum(-2,2)
(118.22488359077923, -1.9999999605494494)
f.find_local_minimum(-2,2)
(2.8279164949881223e-43, 2.3060389863085893e-11)
  1. The power needed to propel an airplane forward at velocity vv is

P=Av3+BL2vP=Av^3+\frac{BL^2}{v}

where AA and BB are positive constants specific to the particular aircraft and L is the lift, the upward force supporting the weight of the plane. Find the speed that minimizes the required power.

Solution-2
var('p,v') A=3 B=4 L=5
p(v) = A*v^3 + (B*L^2)/v show(p(v))
3v3+100v\renewcommand{\Bold}[1]{\mathbf{#1}}3 \, v^{3} + \frac{100}{v}
p.plot(0,100,figsize=5)
Image in a Jupyter notebook
p.find_local_minimum(0,100)
(73.02967433402215, 1.8257418601157738)

Learning:

In this experiment we learnt to find out the limits,derivatives of a given function,also their partial and implicit derivatives. We also learned to find out the local maximum and local minimum of the functions using sagemath and also plot their graphs.