I want to define a symbolised function expFun to use it later for an integration. I am referring to this link.
My current code looks like
import numpy as np
import sympy as sym
a1= sym.Symbol('a1')
a2= sym.Symbol('a2')
X1= sym.Symbol('X1')
X2= sym.Symbol('X2')
T= sym.Symbol('T')
u= sym.Symbol('u')
def expFun(a1,a2,X1,X2,T,u):
return X1*sym.exp(-a1*(T-u))+X2*sym.exp(-a2*(T-u))
expFun(sym.Symbol('a1 a2 X1 X2 T u'))
The last line gives an error, saying
TypeError: expFun() missing 5 required positional arguments: 'a2', 'X1', 'X2', 'T', and 'u'
I have also tried this that is not working neither:
expFun(sym.Symbol('a1','a2', 'X1','X2','T','u'))
Putting those arguments into a list or set didn't hep too.
Would anyone please tell me how I can fix this?
#Updates#
Following hpaulj's comments below, I updated my code as follows. But I still get errors :(
from __future__ import division
import sympy as sym
X1, X2, a1, a2, T, u = sym.symbols('a1 a2 X1 X2 T u')
def expFun1(a1,a2,X1,X2,T,u):
return X1*np.exp(-a1*(T-u))+X2*np.exp(-a2*(T-u))
expFun1(*sym.symbols('a1 a2 X1 X2 T u'))
Then the error message
TypeError: loop of ufunc does not support argument 0 of type Mul which has no callable exp method
Then I tried this
def expFun2(a1,a2,X1,X2,T,u):
return X1*sym.exp(-a1*(T-u))+X2*sym.exp(-a2*(T-u))
expFun2(*sym.symbols('a1 a2 X1 X2 T u'))
and getting funny output on the Skpyder 4 console window.
I am using Python 3.7.6 with Spyder version 4.2.1