In [1]:
import sympy as sym
from IPython.display import display,Math
In [2]:
print('Partial derivatives')
display(Math('f(x,y) = 2xy^2'))
display(Math('\\frac{\\partial f}{\\partial x} = f_x = 2y^2'))
display(Math('\\frac{\\partial f}{\\partial y} = f_y = 4xy'))
Partial derivatives
$\displaystyle f(x,y) = 2xy^2$
$\displaystyle \frac{\partial f}{\partial x} = f_x = 2y^2$
$\displaystyle \frac{\partial f}{\partial y} = f_y = 4xy$
In [3]:
from sympy.abc import x,y

f = x**2 + x*y**2

display(Math('\\frac{\\partial f}{\\partial x} = %s' %sym.latex(sym.diff(f,x))))
display(Math('\\frac{\\partial f}{\\partial y} = %s' %sym.latex(sym.diff(f,y))))
$\displaystyle \frac{\partial f}{\partial x} = 2 x + y^{2}$
$\displaystyle \frac{\partial f}{\partial y} = 2 x y$

Exercise

In [4]:
display(Math('f(x,y) = x^2 + xy^2'))
display(Math('f_x = 2x + y^2'))
display(Math('f_y = 2xy'))
$\displaystyle f(x,y) = x^2 + xy^2$
$\displaystyle f_x = 2x + y^2$
$\displaystyle f_y = 2xy$
In [6]:
p = sym.plotting.plot3d(f,(x,-3,3),(y,-3,3),title='$f(x,y)=%s$' %sym.latex(f))
p = sym.plotting.plot3d(sym.diff(f,x),(x,-3,3),(y,-3,3),title='$f(x,y)=%s$' %sym.latex(sym.diff(f,x)))
p = sym.plotting.plot3d(sym.diff(f,y),(x,-3,3),(y,-3,3),title='$f(x,y)=%s$' %sym.latex(sym.diff(f,y)))