'Sympy evaluates integral sign wrong
For an integral calculation, Sympy evaluates the same result as me and wolframalpha with a negative sign.
The integral I am evaluating is strictly positive so it can't have a negative value. My first assumption was that either sympy misunderstood the integral limits or I put them in the wrong order, thus giving me the negative result. So I tried
g=x**2
print((sympy.integrate(g, (x, 1/2**.5, 1))).evalf())
which is evaluated perfectly.
Here is my full code, including my function.
import sympy
import matplotlib.pyplot as plt
import numpy as np
sympy.init_printing(use_unicode=False, wrap_line=False, no_global=True)
x = sympy.symbols('x')
f=(1-x**2)**(.5)/(4*x)
print((sympy.integrate(f, (x, 1/2**.5, 1))).evalf())
x1=np.linspace(1/2**.5,1,10000)
f1=np.asarray(list(map(lambda a: (1-a**2)**(.5)/(4*a),x1)))
print(sum(f1)*(x1[1]-x1[0])) #my evaluation, close to wolframalpha
plt.plot(x1,f1) #f1 is fully positive.
plt.show()
Thanks in advance.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|