Peque Peque - 7 months ago 99
Python Question

Plotting with SymPy

With SymPy, I can plot a function with:

f, a = symbols('f a')
f = a + 10
plot(f)


However, if I define the function as:

f, a, b = symbols('f a b')
f = a + b
b = 10
plot(f)


Then I get an error stating:

ValueError: The same variable should be used in all univariate
expressions being plotted.


How can I plot
f
if I define
f = a + b
, considering that
b
is assigned a constant value before plotting the function?

Answer

You must substitute b into f:

plot(f.subs('b', b))
Comments