I have made a calculator that approximates any given function as an input. They later I want it to calculate an integral, but after writing:
function = str(input("The function that must be expanded and integrated: "))
It doesn't print a number but instead a value. This is my code:
from sympy.functions import sin,cos,tan
from sympy.abc import x
from sympy import *
from sympy import series
from math import *
function = str(input("The function that must be expanded and integrated: "))
x0 = int(input("Point of development: "))
n = int(input("Amount of expressions: "))
print(series(function, x, x0, n))
N = int(input("Amount of summs (Bigger number is more accurate but takes longer time): "))
a = int(input("Integrate from: "))
b = int(input("Integrate to: "))
# We will use the midpoint method to integrate the function
def integrate(N, a, b):
def f(x):
return series(function, x, x0, n)
value=0
value=2
for n in range(1, N+1):
value += f(a+((n-(1/2))*((b-a)/N)))
value2 = ((b-a)/N)*value
return value2
print("...................")
print("Here is your answer: ")
print(integrate(N, a, b))
I think, it's because my input is a string. However I can't choose my input to be an integer, because exp(-x**2)
isn't an integer. If that's the case, how can I input any function in my calculater and still get a value?