Processing math: 100%
In [1]:
from sympy import *
# create symbol X
x = symbols('x')
# define f(x)
f = x**2 + 2*x + 1
f
Out[1]:
x2+2x+1
In [2]:
plot(f)
Out[2]:
<sympy.plotting.plot.Plot at 0x7f92485f2080>
In [3]:
# Differentiate f(x)
f_diff = diff(f)
f_diff 
Out[3]:
2x+2
In [4]:
# Plot both
p1 = plot(f_diff,show=False,line_color="red")
p2 = plot(f,show=False)
p1.append(p2[0])
p1.show()