Skip to content Skip to sidebar Skip to footer

Trapezoid And Simpson Rule In Python?

I have to write the trapezoid and simpson rule in python for the function e^((-x)^2). Here's what I got so far. The answer it gives out is 8218.7167913 but the answer according to

Solution 1:

Look at your function: e^((-x)^2). The negative sign isn't doing anything because you're squaring it away immediately. That seems strange. More likely is that you were supposed to integrate e^(-x^2). Let's test:

>>> trapezoid(lambda x: e**((-x)**2), -3, 3, 1000)
2889.3819494560144
>>> trapezoid(lambda x: e**(-x**2), -3, 3, 1000)
1.7724146920763713

Post a Comment for "Trapezoid And Simpson Rule In Python?"