In [1]:
import numpy as np
import sympy as sym
import matplotlib.pyplot as plt
from IPython.display import display,Math
In [2]:
print('Part 1: Implement and plot these functions')
display(Math('f(x) = e^{-x}\\sqrt {x+1}'))
display(Math('g(x) = \\cos(x + \\sin(x))'))
Part 1: Implement and plot these functions
$\displaystyle f(x) = e^{-x}\sqrt {x+1}$
$\displaystyle g(x) = \cos(x + \sin(x))$
In [3]:
x = sym.symbols('x')

fx = sym.sqrt(x+1)*sym.exp(-x)
gx = sym.cos(x + sym.sin(x))

fxx = sym.lambdify(x,fx)
gxx = sym.lambdify(x,gx)
print(fxx(1))
print(gxx(1))

xx = np.linspace(0,10,100)

plt.plot(xx,fxx(xx),label='f(x)')
plt.plot(xx,gxx(xx),label='g(x)')
plt.legend()
plt.show()
0.520260095022889
-0.26738159169423864
In [4]:
print('Part 2: Confirm this properlty of limits')
display(Math('\\frac{\\lim_{x\\to 5}f(x)}{\\lim_{x\\to 5}g(x)}=\\lim_{x\\to5}\\frac{f(x)}{g(x)}'))
Part 2: Confirm this properlty of limits
$\displaystyle \frac{\lim_{x\to 5}f(x)}{\lim_{x\to 5}g(x)}=\lim_{x\to5}\frac{f(x)}{g(x)}$
In [5]:
lim_pnt = 5

# compute the limits of f and g separately
lim_fx = sym.limit(fx,x,lim_pnt)
lim_gx = sym.limit(gx,x,lim_pnt)

# compute the limit of f/g
hx = fx/gx
lim_fgx = sym.limit(hx,x,lim_pnt)

print(lim_fx)
print(lim_gx)
display(Math('\\frac{\\lim_{x \\to %g} f(x)}{\\lim_{x \\to %g} g(x)} = \\frac{%g}{%g} = %g' \
             %(lim_pnt, lim_pnt, lim_fx, lim_gx, lim_fx/lim_gx)))
print(lim_fgx)
display(Math('\\lim_{x\\to %g}\\frac{f(x)}{g(x)} = %g' \
             %(lim_pnt, lim_fgx)))
sqrt(6)*exp(-5)
cos(sin(5) + 5)
$\displaystyle \frac{\lim_{x \to 5} f(x)}{\lim_{x \to 5} g(x)} = \frac{0.0165045}{-0.622015} = -0.026534$
sqrt(6)*exp(-5)/cos(sin(5) + 5)
$\displaystyle \lim_{x\to 5}\frac{f(x)}{g(x)} = -0.026534$