I wrote a code to use Riemann to calculate the area under certain function. It works well but when I set the boundaries to decimal number I get an error. I think I should tell the function I want to be able to enter floats but I don't see how. I think it is an easy fix, hope someone can help me:
import numpy as np
import math
def func(x):
return x ** 2
def func1(x):
return x ** (x +0.5)
def func2(x):
return np.sin(x)
def func3(x):
return np.sin(x ** 2)
def riemann(f,a,b,N):
dx = (b-a)/N
x_midpoint = np.linspace(dx/2,b - dx/2,N)
riemann_sum = np.sum(f(x_midpoint) * dx)
return riemann_sum
res = riemann(func,0,1,10000)
res1 = riemann(func1,0,1,10000)
res2 = riemann(func2,0,1,10000)
res3 = riemann(func3,0,1,10000)
print("Midpoint Riemann Sum:",res)
print("Midpoint Riemann Sum:",res1)
print("Midpoint Riemann Sum:",res2)
print("Midpoint Riemann Sum:",res3)