I am using quad method of Scipy library and I want to evaluate numerical integration of a function that entered by a user. The function is stored as a string. However, quad method does not except string input. So, how can I convert this string expression into a numerical value?
Assume that, the string expression is:
s1 = "5*x**2 - 4*x + 2" and lower_bound = 0 , upper_bound = 5
quad(s1, lower_bound, upper_bound)
I've tried splitting this string into tokens with respect to arithmetic symbols then invoke the quad method but the independent variable(x in this case) still remains as string.
How can I solve this problem?