You can use numerical integration methods such as the Trapezoidal Rule or Simpson's Rule to evaluate the integral. Here's an example using the Trapezoidal Rule in Python:
```python
def trapezoidal_rule(f, a, b, n):
h = (b - a) / n
integral = 0.5 * (f(a) + f(b))
for i in range(1, n):
integral += f(a + i * h)
integral *= h
return integral
# Example usage:
# Define your function f(x)
def f(x):
return x**2 # Example function
# Set the limits of integration and number of intervals
a = 0
b = 1
n = 1000 # More intervals for higher accuracy
result = trapezoidal_rule(f, a, b, n)
print(result)
```
The maximum accuracy of this algorithm depends on the number of intervals `n
import math
# Function to calculate f(x)
def func( x ):
return math.log(x)
# Function for approximate integral
def simpsons_( ll, ul, n ):
# Calculating the value of h
h = ( ul - ll )/n
# List for storing value of x and f(x)
x = list()
fx = list()
# Calculating values of x and f(x)
i = 0
while i<= n:
x.append(ll + i * h)
fx.append(func(x[i]))
i += 1
# Calculating result
res = 0
i = 0
while i<= n:
if i == 0 or i == n:
res+= fx[i]
elif i % 2 != 0:
res+= 4 * fx[i]
else:
res+= 2 * fx[i]
i+= 1
res = res * (h / 3)
return res
# Driver code
lower_limit = 4 # Lower limit
upper_limit = 5.2 # Upper limit
n = 6 # Number of interval
print("%.6f"% simpsons_(lower_limit, upper_limit, n))