I have this code in SymPy:
from sympy import *
par_amplitude, par_const_force = symbols('Delta_U f')
equation = par_amplitude * par_const_force
print(equation.evalf(subs={'f':3, 'Delta_U':2}))
The output is obviously 6
.
My problem occurs when I have access to only one parameter, like so:
print(equation.evalf(subs={'Delta_U':2}))
Instead of expected 2 * f
I get Delta_U * f
.
What am I doing wrong? Is there a way to evaluate an expression, where not all parameters are available?
EDIT:
Yes, I am after a mixed numerical/symbolic output. Imagine a situation where there is a lot of parameters (generated automatically, so you're not even sure how many), and there is a function supplying all the subs
values. If you were to miss just one substitution value, you get basically nothing out of evalf
.