You are on page 1of 13

2/4/22, 6:46 PM CALCULUS (2).

html

Shri Ramdeobaba College of Engineering and Management, Nagpur

Department of Mathematics

Computational Mathematics Lab

Name: VEDANT ABHAY PULIWAR

Roll Number: 85

Section: M(M3)

Experiment 4: Differantial Calculus and its Applications

Aim: To Learn Calculus with SageMat

1.Limit

To Evaluate limx→a ​ f (x)syntax is:

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).

x
Problem: Find the limit of limx→0 ∣x∣ ​ ​

In [4]: f(x)=x/abs(x)

plot(f(x),(x,-2,2),figsize=3)

Out[4]:

In [5]: limit(f(x),x=0)

Out[5]: und

In [6]: limit(f(x),x=0,dir="+") ## gives right limit

Out[6]: 1

In [7]: limit(f(x),x=0,dir="-") ## gives left limit

Out[7]: -1

Problem:
x2 −4
Evaluate limx→2 x−2
​ ​

In [8]: plot((x^2-4)/(x-2),0,4,figsize=3)

Out[8]:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 1/13


2/4/22, 6:46 PM CALCULUS (2).html

In [9]: limit((x^2-4)/(x-2),x=2)

Out[9]: 4

Problem:
a
Evaluate limx→a x for various values of a.

In [1]: var('a')

Out[1]: a

In [2]: assume(a>0)

In [3]: limit(x^a,x=infinity)

Out[3]: +Infinity

In [4]: forget()

In [5]: assume(a<0)

In [6]: limit(x^a,x=oo)

Out[6]: 0

Exercise 3.1
Find the following limits

1. limx→0 (x2 − 2x

1000 )

2. limx→0.5− ( ∣2x2x−1
3 −x2 ∣ )
​ ​

solution 1

In [11]: f(x)=x^2-(2^x/1000)

limit(f(x),x=0)

Out[11]: -1/1000

solution 2

In [23]: f(x)=(2*x-1)/abs(2*x^3-x^2)

limit(f(x),x=0.5,dir="-")

Out[23]: -4.0

2.Derivatives
The syntax for derivative of f(x) is

diff(f, args)
Repeated differentiation is supported by the syntax given in the examples below.

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 2/13


2/4/22, 6:46 PM CALCULUS (2).html

In [29]: f(x)=x*sin(1/x)

In [32]: f.diff(x) # first order derivative of f(x)

Out[32]: x |--> -cos(1/x)/x + sin(1/x)

In [34]: f.diff() # first order derivative of f(x)

Out[34]: x |--> -cos(1/x)/x + sin(1/x)

In [35]: diff(f(x),x) # first order derivative of f(x)

Out[35]: -cos(1/x)/x + sin(1/x)

In [37]: f.diff(4) # or diff(f(x),x,4) gives fourth order derivative of f(x)

Out[37]: x |--> -12*sin(1/x)/x^5 - 8*cos(1/x)/x^6 + sin(1/x)/x^7

In [38]: f.diff(3) # or diff(f(x),x,4) gives third order derivative of f(x)

Out[38]: x |--> 3*sin(1/x)/x^4 + cos(1/x)/x^5

Problem:
2
Consider a function f (x) = sin(cos(5x)) − e(x−1) . Plot the graph of f (x) along with first two derivative in [0.5, 2].

In [39]: f(x)=sin(cos(5*x))-exp((x-1)^2)

In [42]: f1(x)=f.diff()

In [44]: f2(x)=f.diff(2)

In [46]: p1=plot(f(x),0.5,2,color='green')

p2=plot(f1(x),0.5,2,color='red')

p3=plot(f2(x),0.5,2,color='magenta')

show(p1+p2+p3,figsize=5)

Out[46]:

Exercise 3.2

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

2. Find the first four derivative of f(x) = sin(3x) + e −2x + ln(7x)

In [0]: solution 1:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 3/13


2/4/22, 6:46 PM CALCULUS (2).html

In [46]: var('t')

f= log(1+t^2)

f1=f.diff(1),show(f1)

f2=f.diff(2),show(f2)

f3=f.diff(3),show(f3)

f4=f.diff(4),show(f4)

Out[46]: 2t
t2 +1

4 t2 2
− 2 +
(t2 t2 + 1
​ ​

+ 1)
16 t3 12 t
3 − 2
(t2 (t2
​ ​

+ 1) + 1)
96 t4 96 t2 12
− 4 ​
+ 3 ​
− 2 ​

(t2 + 1) (t2 + 1) (t2 + 1)

In [42]: p1=plot(f1,color='green')

p2=plot(f2,color='red')

p3=plot(f3,color='magenta')

p4=plot(f4,color='blue')

(p1+p2+p3+p4)

Out[42]:

In [0]: solution 2:

In [48]: var('x')

f= sin(3*x)+exp(-2*x)+log(7*x)

f1=f.diff(1),show(f1)

f2=f.diff(2),show(f2)

f3=f.diff(3),show(f3)

f4=f.diff(4),show(f4)

Out[48]:
1
( ​
+ 3 cos (3 x) − 2 e(−2 x) , None)
x
1
(− + 4 e(−2 x) − 9 sin (3 x) , None)
x2

(
file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html
) 4/13
2/4/22, 6:46 PM CALCULUS (2).html
2
( − 27 cos (3 x) − 8 e(−2 x) , None)
x3

6
(− + 16 e(−2 x) + 81 sin (3 x) , None)
x4

Partial Derivatives

xy ∂f ∂f ∂ 2 f ∂ 2 f ∂ 2 f ∂2 f
For f (x) = x+y find ∂x , ∂y , ∂x2 , ∂y 2 , ∂x∂y , ∂y∂x
​ ​ ​ ​ ​ ​ ​

In [48]: var('x,y')

f(x,y)=x*y/(x+y)

show(f(x,y))

Out[48]: xy
x+y

In [51]: show(f.diff(x))

Out[51]: y xy
(x, y )  ↦  −
x+y (x + y )2
​ ​

In [52]: show(f.diff(x,y))

Out[52]: 1 x y 2 xy
(x, y )  ↦  − 2 − 2 +
x+y (x + y ) (x + y ) (x + y )3
​ ​ ​ ​

In [53]: show(f.diff(y))

Out[53]: x xy
(x, y )  ↦  −
x+y (x + y )2
​ ​

In [54]: show(f.diff(y,x))

Out[54]: 1 x y 2 xy
(x, y )  ↦  − 2 − 2 +
x+y (x + y ) (x + y ) (x + y )3
​ ​ ​ ​

In [56]: f.diff(x)(x=1.0,y=2.0)

Out[56]: 0.444444444444444

In [64]: show(f.diff(2)(x=2.0,y=5.0))

Out[64]:
−0.145772594752187 0.0583090379008746
( )
0.0583090379008746 −0.0233236151603499
​ ​

In [58]: show(f.diff(x,2))

Out[58]: 2y 2 xy
(x, y )  ↦  − 2 ​ + 3 ​

(x + y ) (x + y )

In [60]: show(f.diff(x,3)(x=2.0,y=5.0))

Out[60]:
0.0624739691795085

In [62]: show(f.diff(y,3))

Out[62]:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html


6 6 5/13
2/4/22, 6:46 PM CALCULUS (2).html
6x 6 xy
(x, y )  ↦  3 −
(x + y ) (x + y )4
​ ​

In [65]: f.diff(x,y)(x=2,y=1)

Out[65]: 4/27

In [67]: show(f.diff(x,2,y,3))

Out[67]:
36 72 x 48 y 120 xy
(x, y )  ↦  − 4 + 5 + 5 −
(x + y ) (x + y ) (x + y ) (x + y )6
​ ​ ​ ​

In [69]: show(f.diff(y,2,x,3))

Out[69]: 36 48 x 72 y 120 xy
(x, y )  ↦  − 4 + 5 + 5 −
(x + y ) (x + y ) (x + y ) (x + y )6
​ ​ ​ ​

In [70]: show(f.diff(x,2,y,4))

Out[70]: 192 480 x 240 y 720 xy


(x, y )  ↦  5 − 6 − 6 +
(x + y ) (x + y ) (x + y ) (x + y )7
​ ​ ​ ​

In [71]: var('x,y')

f(x,y)=log(x^2+y^2)

In [73]: show(f.diff(x,2,y,2))

Out[73]:
96 x2 y 2 16 x2 16 y 2 4
(x, y )  ↦  − 4 + 3 + 3 − 2
(x2 y2 ) (x2 y2 ) (x2 y2 ) (x2 + y2 )
​ ​ ​ ​

+ + +

Problem:
2 −y 2 )
For f (x) = f (x, y) = 4xye(−x , find all first order and second order derivatives at point (1,2).

In [2]: var('x,y')

f(x,y)=4*x*y*exp(-x^2-y^2)

show(f(x,y))

Out[2]:
4 xye(−x −y )
2 2

In [53]: show(f.diff(x)) # Gives Derviative of f with respect to x

Out[53]:
(x, y )  ↦  − 8 x2 ye(−x −y ) + 4 ye(−x −y )
2 2 2 2

In [54]: show(f.diff(x)(x,y)) # Gives Derviative of f with respect to x

Out[54]:
−8 x2 ye(−x −y ) + 4 ye(−x −y )
2 2 2 2

In [55]: show(f.diff(x)(x,y)) # Gives Derviative of f with respect to x

Out[55]:
−8 x2 ye(−x −y ) + 4 ye(−x −y )
2 2 2 2

In [3]: f.diff(x)(x=1.0,y=2.0) # Gives Derviative of f with respect to x at (1,2)

Out[3]: -0.0539035759926837

In [4]: f.diff(y)(x=1,y=2) # Gives Derviative of f with respect to y at (1,2)

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 6/13


2/4/22, 6:46 PM CALCULUS (2).html

Out[4]: -28*e^(-5)

In [5]: f.diff(x,2)(x=1,y=2) # Gives double Derviative of f with respect to x at (1,2).

Out[5]: -16*e^(-5)

In [6]: 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).

Out[6]: 28*e^(-5)

In [7]: 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).

Out[7]: 28*e^(-5)

EXERCISE 3.3
∂2 f ∂2 f
1. Let f (x, y) = ln(x2 + y 2 ). Show that ∂x2

+ ∂y 2

= 0.
2. Find all the first order partial derivatives of w = x2 y − 10y 2 z 3 + 43x − 7tan(4y)

Solution 1:

In [4]: var('x,y')

f(x,y)=log(x^2+y^2)

f1=f.diff(x,2)

f2=f.diff(y,2)

show(f1+f2)

Out[4]:
4 x2 4 y2 4
(x, y )  ↦  − − +
(x2 + y 2 )2 (x2 + y 2 )2 x2 + y2
​ ​ ​

4(x2 +y 2 ) 4
− (x2 +y2 )2 + ​

(x2 +y 2 ) ​ =0

Solution 2:

In [32]: var('x,y,z')

w(x,y,z)=(x^2)*y-10*(y^2)*(z^3)+43*x-7*tan(4*y)

show(w.diff(1))

show(w.diff(x,1))

show(w.diff(y,1))

show(w.diff(z,1))

Out[32]:
(x, y, z )  ↦  (2 xy + 43, −20 yz 3 + x2 − 28 tan (4 y )2 − 28, −30 y 2 z 2 )

(x, y, z )  ↦ 2 xy + 43

(x, y, z )  ↦  − 20 yz 3 + x2 − 28 tan (4 y )2 − 28

(x, y, z )  ↦  − 30 y 2 z 2

4. Implicit Derivative

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

In [79]: x=var('x')

y=var('y')

f(x,y)=x^3+y^3-6*x*y

y=function('y')(x)

a=diff(f(x,y))

show(solve(a,diff(y)))

[ ]
file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 7/13
2/4/22, 6:46 PM CALCULUS (2).html

[ ]
Out[79]: ∂ x2 − 2 y (x)
y (x) = −
∂x y (x)2 − 2 x
​ ​

EXERCISE 3.4
dy
1. Find the dx for the implicit function 2(x2
​ + y 2 )2 = 25(x2 − y 2 ).
2. Find the dx for the implicit function y 2 = x3 (2 − x).
dy

Solution 1:

In [33]: x=var('x')

y=var('y')

f(x,y)=(2*(x^2+y^2)^2)-25*(x^2-y^2)

y=function('y')(x)

a=diff(f(x,y))

show(solve(a,diff(y)))

Out[33]:
4 x3 + 4 xy (x)2 − 25 x
[ ]

y (x) = − 3
∂x 4 y (x) + (4 x2 + 25)y (x)
​ ​

Solution 2:

In [34]: x=var('x')

y=var('y')

f(x,y)=y^2-x^3*(2-x)

y=function('y')(x)

a=diff(f(x,y))

show(solve(a,diff(y)))

Out[34]:
∂ 2 x3 − 3 x2
[ y (x) = − ]
∂x y (x)
​ ​

5. Local Maximum and Minimum

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

f.find_local_maximum(a,b

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

f.find_local_minimum(a,b).

Problem:
2
Find the local maximum and local minimum of the function f (x) = e−x/2 + e−2x .

In [6]: f(x) = exp(-x/2) + exp(-2*x^2)

f.plot(-2,2,figsize =4)

Out[6]:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 8/13


2/4/22, 6:46 PM CALCULUS (2).html

In [7]: f.find_local_maximum(-1,1)

Out[7]: (2.0340673102820146, -0.13932332835389183)

In [8]: f.find_local_minimum(-1.5,-0.5)

Out[8]: (1.7650250464715878, -0.8669457216285031)

In [9]: f.find_local_minimum(1,2)

Out[9]: (0.3682149119773104, 1.999999956179319)

In [10]: f.find_local_minimum(-1.5,-0.5)

Out[10]: (1.7650250464715878, -0.8669457216285031)

In [11]: f.find_local_maximum(1,2)

Out[11]: (0.7418659187092465, 1.0000000286997572)

In [12]: plot(f.diff(),-2,2,figsize=4)

Out[12]:

In [13]: c1 = f.diff().find_root(-2,-0.5)

c1

Out[13]: -0.8669457228341761

In [14]: c2 = f.diff().find_root(-0.5,0);c2

Out[14]: -0.13932333585693482

In [15]: f.diff(2)(x=c1), f.diff(2)(x=c2)

Out[15]: (2.17068359111117, -3.280901640208612)

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 9/13


2/4/22, 6:46 PM CALCULUS (2).html

Problem:

Consider a function f (x) = 2x3 − 9x2 + 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.

In [41]: f(x) = 2*x^3 - 9*x^2 + 12*x - 3

pf = plot(f,0,3)

show(pf,figsize=4)

Out[41]:

In [17]: df = f.diff()

d2f = f.diff(2)

In [18]: cpts = solve(df==0,x,solution_dict=True)

cpts

Out[18]: [{x: 1}, {x: 2}]

In [19]: a,b = cpts[0][x],cpts[1][x]

In [20]: infl = solve(d2f==0,x,solution_dict=True);infl

Out[20]: [{x: 3/2}]

In [22]: c = infl[0][x]

In [23]: 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)

Out[23]:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 10/13


2/4/22, 6:46 PM CALCULUS (2).html

In [45]: cpts = solve(df==0,x,solution_dict=True)

cpts

Out[45]: (0.9999999999999964, 2.000000004311239)

In [46]: f.find_local_maximum(0,3)

Out[46]: (1.9999999999999991, 0.9999999956620956)

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=0$ until the solid rocket boosters were jettisoned at $t=126$ seconds, is given by

v(t) = 0.001302t3 − 20.09029t2 + 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.

In [3]: var('t')

v(t) =0.001302*t^3-0.09029*t^2+23.61*t-3.083

In [26]: plot(v,0,126,figsize=4)

Out[26]:

In [4]: a = v.diff()

a.plot(0,126,figsize=4)

Out[4]:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 11/13


2/4/22, 6:46 PM CALCULUS (2).html

In [28]: a.find_local_minimum(0,126)

Out[28]: (21.52288169482847, 23.115720101631652)

In [5]: a.find_local_maximum(0,126)

Out[5]: (62.868574472665756, 125.9999980996971)

In [30]: a(0),a(23.115720101631652), a(126)

Out[30]: (23.6100000000000, 21.5228816948285, 62.8685760000000)

Exercise 3.5
1. Find the local maximum and local minimum of f (x) = x4 e−x .
2. The power needed to propel an airplane forward at velocity v is

BL2
P = Av 3 + ​

v
where A and B 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 1:

In [3]: f(x)=(x^4)*exp(-x)

plot(f,-1,6,figsize=4)

Out[3]:

In [4]: df = f.diff()

d2f = f.diff(2)

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 12/13


2/4/22, 6:46 PM CALCULUS (2).html

In [5]: cpts = solve(df==0,x,solution_dict=True)

cpts

Out[5]: [{x: 0}, {x: 4}]

In [6]: a,b = cpts[0][x],cpts[1][x]

In [14]: pf = plot(f,-1,6,thickness=0.5)

pt1 = point((a,f(a)),color='red',size=30) # Gives point where function has maximum value

pt2 = point((b,f(b)),color='green',size=30)# Gives point where function have minimum


value

pd2f = plot(d2f,0,6,thickness=0.5,color='green')

pdf = plot(df,0,6,thickness=0.5,color='violet')
show(pf+pt1+pt2+pd2f+pdf,figsize=4)

Out[14]:

In [76]: f.find_local_maximum(-1,6)

Out[76]: (4.688803555515951, 3.999999996078297)

In [12]: f.find_local_minimum(0,0)

Out[12]: (0.0, 0.0)

Solution 2:

In [7]: var('v')

f(v)=(a*(v^3))+(b*(l^2)/v)

df= f.diff()

show(df)

Out[7]:
bl2
v ↦  (3 av 2 − )
v2

bl2
v= 4
3a ​ ​

In [0]:

file:///C:/Users/VEDANT PULLIWAR/Downloads/CALCULUS (2).html 13/13

You might also like