You are on page 1of 3

Applied Calculus for IT Anh H.

Vo

1 Limits and Continuity


1 from sympy import ∗
2
cos(x)
Find lim f (x) = 3 x = symbols (’x’)
x→0 x
4 f = 5∗ x − 3∗ x ∗ ∗ 2
1 from sympy import ∗ 5 df = diff(f,x, 2)
2 6 print (’The second order of
3 x = symbols (’x’) derivative of f(x) = {}’.
4 f = cos(x)/x format (df))
5 lm = limit (f, x, 0)
6 print (’The limit of f(x) at x = Find the first order of derivative of f (x) = 5x − 3x2 at x = 2
0: {} ’. format (lm))
cos(x)
Find lim f (x) = 1 from sympy import ∗
x→0− x
2
3 x = symbols (’x’)
1 from sympy import ∗
4 f = 5∗ x − 3∗ x ∗ ∗ 2
2
5 dfa = diff(f,x, 1).subs(x, 2)
3 x = symbols (’x’)
6 print (’ df (2) : {}’. format (dfa))
4 f = cos(x)/x
5 lml = limit (f, x, 0 ,’− ’)
6 print (’The left limit of f(x) at
x = 0: {}’. format (lml)) 3 Sequences and Series

cos(x)
Find lim f (x) =
x→0+ x Find the Taylor polynomial generated by f (x) = sin(x) at x = 1
and order 3
1 from sympy import ∗
2
1 from sympy import ∗
3 x = symbols (’x’)
2
4 f = cos(x)/x
3 x = symbols (’x’)
5 lmr = limit (f, x, 0 ,’+’)
4 expr = sin(x)
6 print (’The right limit of f(x)
5 taylor_poly = expr. series (x, 1,
at x = 0: {}’. format (lmr))
3)
6 print (’Taylor polynomial {}’.
2 Derivatives format ( taylor_poly ))

Find the first order of derivative of f (x) = 5x − 3x2 Find the Maclaurin polynomial generated by f (x) = sin(x) at
x = 0 and order 3

1 from sympy import ∗


2
1 from sympy import ∗
3 x = symbols (’x’) 2
4 f = 5∗ x − 3∗ x ∗ ∗ 2 3 x = symbols (’x’)
5 df = diff(f,x, 1) 4 expr = cos(x)
6 print (’The first order of 5 maclaurin_poly = expr. series (x,
derivative of f(x) = {}’. 0, 3)
format (df)) 6 print (’Maclaurin polynomial {}’.
Find the second order of derivative of f (x) = 5x − 3x2 format ( maclaurin_poly ))

© October 17, 2021 Anh H. Vo


4 Partial Derivatives
1 from sympy import ∗
2 from sympy import oo
∂f ∂f
f (x, y) = x2 + 3xy + y − 1 find the first-order derivative and 3
∂x ∂y
4 x = symbols (’x’)
5 f = x∗∗2 + x + 1
1 from sympy import ∗
6 fin = integrate (f, x)
2
7 print (’The integrate of f(x) =
3 x, y = symbols (’x, y’)
{}’. format (fin))
4 f = x ∗ ∗ 2 + 3∗ x ∗ y + y − 1
5 dfx = diff(f, x, 1) Z 2
1
Find the integrate of f (x, c) =
6 dfy = diff(f, y, 1) 0 x3 − 2x − c
7 print (’The first order of
partial derivative of f(x, y) 1 from sympy import ∗
w.r.t x = {}’. format (dfx)) 2 from sympy import oo
8 3
9 print (’The first order of 4 x = symbols (’x’)
partial derivative of f(x, y) 5 f = lambda x, c:1/(x ∗ ∗ 3 − 2 ∗ x −
w.r.t y = {}’. format (dfy)) c)
6 fin = integrate (f(x ,5) , (x, 0,
2))
5 Extreme Values and Saddle Points 7 print (’The integrate of f(x) =
{}’. format (fin.evalf ()))
Find the critical value of f (x) = x3 − 2x + 1

1 from sympy import ∗ 7 Graph


2
3 x = symbols (’x’) 1
Draw a graph of f (x) = ln(x) +.
4 f = x ∗ ∗ 3 − 2∗ x + 1 2
There are two ways to show a function of single variable in 2D
5 df = diff(f, x)
space as follows:
6 cvals = solveset (df , x)
7 print (’Critical values :’,[i for 1. using sympy
i in cvals.evalf ()]) 1 from sympy import ∗
2 from sympy import oo
Find the absolute maximum and minimim values of f (x) = x2 on
3
[−2, 1]
4 x = symbols (’x’)
5 f = log(x) + 0.5
1 from sympy import ∗ 6
2 7 f = plot(f, (x, −4, 4),
3 x = symbols (’x’) line_color = ’green ’,
4 f = x∗∗2 title = ’f(x) = log(x)’,
5 x_c = solve (diff(f),x) show=True)
6 candidates = [ − 2, 1] + x_c
7 yvals = [f.subs(x, v).evalf ()
for v in candidates ]
8 print (’The absoluate maximum is
’, max( yvals))
9 print (’The absoluate minimum is
’, min( yvals))

6 Integrals
Z
Find the integrate of f (x) = x2 + x + 1
2. using matplotlib.pyplot

© October 17, 2021 Anh H. Vo


19 plt.title(’$cos(x) ∗ cos(y) ∗ e^{( − \
1 from sympy import ∗ sqrt {(x^2 + y^2) }/4)}$’)
2 import matplotlib . pyplot as 20 plt.show ()
plt
3 import numpy as np
4
5 value = np. arange ( − 5,5,0.1)
6 f1 = lambda x: np.log(x) +
0.5
7 plt.plot(value , f1(value))
8 plt. title (’f(x) = log(x)’)
9 plt. xlabel (’x’)
10 plt. ylabel (’f(x)’)
11 plt.grid ()
12 plt.show ()

A function of multi-variable has been shown in 3D space as follows

1 from sympy import ∗


2 from sympy import oo
3 import numpy as np
4 import math
5 import matplotlib . pyplot as plt
6 from mpl_toolkits . mplot3d import
Axes3D
7
8 x, y = symbols (’x y’)
9
10 f = cos(x) ∗ cos(y) ∗ exp (1) ∗ ∗ ( − sqrt
(x ∗ ∗ 2 + y ∗ ∗ 2 ) /4)
11 fa = lambdify ((x, y), f)
12 xa , ya = np. meshgrid (np. linspace
( − 1,1,10), np. linspace
( − 1,1,10))
13 za = fa(xa , ya)
14 fig = plt. figure ()
15 ax = fig .add _subplot (111 ,
projection = ’3d’)
16 ax. plot_surface (xa , ya , za , cmap
= plt.cm.ocean , alpha = 0.5)
17 plt. xlabel (’x’)
18 plt. ylabel (’y’)

© October 17, 2021 Anh H. Vo

You might also like