# How is it possible to define a equation, differentiate and plot it, using Sympy in Jupyter Nootebook?

In Jupyter Notebook i would like to define a equation, differentiate and plot the equation.

```import sympy as sp
from IPython.display import display
sp.init_printing()
import matplotlib.pyplot as plt
import numpy as np

x = sp.symbols('x')

def func(x):
a= sp.sympify("4/5")
return (x**3+a*x**2)
display(func(x))

def dfunc(x):
a = sp.diff(func(x),x)
return a
display(dfunc(x))

x = np.linspace(-10,10,20)

plt.plot(x,func(x))
plt.plot(x,dfunc(x))      # doesn't work
```

`display(dfunc(x))` shows the wanted function but `plt.plot(x,dfunc(x))` returns the error message `ValueError: cannot derive by this array`

Does anyone know how to get the plot?

(It also doesn’t work with `sp.integrate(func(x),x)` instead of `sp.diff(func(x),x)`. Just another error message is returned `ValueError: Invalid limits given: ...`)

Matthias

You can use the SymPy `plot` function rather than the `matplotlib` one. The matplotlib plot function expects arrays as inputs whereas the sympy one accepts sympy expressions (and then calculates values to make the arrays for matplotlib):

```In : import sympy as sym

In : a = sym.Rational(4, 5)

In : x = sym.Symbol('x')

In : f = x**3 + a*x**2

In : f
Out:
2
3   4⋅x
x  + ────
5

In : f.diff(x)
Out:
2   8⋅x
3⋅x  + ───
5

In : sym.plot(f.diff(x))
```