Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

The thing is that spltest is not a symbolic function and cannot be called on symbolic arguments such as r. That is, spltest(r) you are trying to substitute is undefined.

To overcome this issue, one can define a symbolic function that will call spltest for numerical evaluation, but until then remains "unevaluated". Here is an example:

def spltest_evalf(self, x, parent=None, algorithm=None): return spltest(x)
spltest_func = function("spltest_func", nargs=1, evalf_func=spltest_evalf)
new_eq = eq.subs({nu(r): spltest_func(r)})
print( new_eq) 
print( new_eq(1) )
print( new_eq(1).n() )

which prints:

r |--> 2*spltest_func(r)
2*spltest_func(1)
2.00000000000000

The thing is that spltest is not a symbolic function and cannot be called on symbolic arguments such as r. That is, spltest(r) you are trying to substitute is undefined.

To overcome this issue, one can define a symbolic function that will call spltest for numerical evaluation, but until then remains "unevaluated". Here is an example:

def spltest_evalf(self, x, parent=None, algorithm=None): return spltest(x)
spltest_func = function("spltest_func", nargs=1, evalf_func=spltest_evalf)
new_eq = eq.subs({nu(r): spltest_func(r)})
print( new_eq) new_eq ) 
print( new_eq(1) )
print( new_eq(1).n() )

which prints:

r |--> 2*spltest_func(r)
2*spltest_func(1)
2.00000000000000

For details on the functions machinery, see https://doc.sagemath.org/html/en/reference/calculus/sage/symbolic/function_factory.html