import numpy as np
import sympy as sym
import matplotlib.pyplot as plt
from IPython.display import display,Math
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))'))
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()
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)}'))
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)))