You are on page 1of 1

Shri Ramdeobaba College of Engineering and Management, Nagpur

Department of Mathematics

Computational Mathematics Lab

Name:

Roll Number:

Section:

Experiment 3: Differantial Calculus and its Applications

Aim: To Learn Calculus with SageMath

1. Limit

To Evaluate lim x → af(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 lim x → 0 | x |

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

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

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

In [ ]: limit(f(x),x=0,dir = "+")

In [ ]: limit(f(x),x=0,dir = "-")

Problem:

x2 − 4
Evaluate lim x → 2 x−2

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

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

Problem:

Evaluate lim x → ax a for various values of a.

In [ ]: var('a')

In [ ]: assume(a>0)

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

In [ ]: forget()

In [ ]: assume(a<0)

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

Exercise 3.1

Find the following limits


2x
1. #### lim x → 0(x 2 − )
1000
2x − 1
2. ##### lim x → 0.5 − ( )
| 2x 3 − x 2 |

Solution 1

In [ ]:

Solution 2

In [ ]:

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.

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

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

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

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

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

Problem:

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

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

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

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

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

Exercise 3.2

1. Find the first four derivatives of f(t) = ln(1 + t 2) 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).

Solution 1

In [ ]:

Solution 2

In [ ]:

3. Partial Derivatives

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

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

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 a
lso.

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

Problem:

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

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

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

show(f(x,y))

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

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

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

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

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

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

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

Exercise 3.3

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

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

Solution 1

In [ ]:

Solution 2

In [ ]:

4. Implicit Derivative

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

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

Exercise 3.4

dy
1. Find the dx
for the implicit function 2(x 2 + y 2) 2 = 25(x 2 − y 2).

dy
2. Find the for the implicit function y 2 = x 3(2 − x).
dx

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 [ ]: f(x) = exp(-x/2) + exp(-2*x^2)

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

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

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

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

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

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

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

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

c1

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

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

Problem:

Consider a function f(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.

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

pf = plot(f,0,3)

show(pf,figsize=4)

In [ ]: df = f.diff()

d2f = f.diff(2)

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

cpts

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

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

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

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

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

In [ ]: var('t')

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

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

In [ ]: a = v.diff()

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

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

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

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

Exercise 3.5

1. Find the local maximum and local minimum of f(x) = x 4e − x.

2. The power needed to propel an airplane forward at velocity v is

3
BL 2
P = Av +
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 [ ]:

Solution 2

In [ ]:

Solution 3

In [ ]:

Learning:(Write in details about your Learnings from the activity)

In [ ]:

Loading [MathJax]/jax/output/HTML-CSS/jax.js

You might also like