I need help writing this python program n number of rectang
I need help writing this python program.
n = number of rectangles and/or trapezoids a = beginning times value b = ending times value w = width of each rectangle/trapezoid, (b-a)/n f(x) = height of rectangle (f(x1)+f(x2))/2 = height of trapezoid Area = width*height Integration Program Definition: Your program should determine the area under these different functions, f1 (x) = 5x^4 + 3x^3 - 10x + 2 f2(x) = x^2 - 10 f3(x) = 40x + 5 f4(x) = x^3 f5(x) = 20x^2 + 10x - 2 The functions are bounded by any interval on the x-axis, including both positive and negative values!!!. The area calculated will be determined by the user\'s choice of function and method to use to calculate the integral, and it is possible for the user to choose to see the area for one function calculated by both methods. For example: Choose a function (1, 2, 3, 4, 5, other(quit)): 1 Would you like to calculate the area using the rectangle, trapezoid, or both (1, 2, 3): 2 How many trapezoids do you want? 1000 Please select a starting point, a = 1 Please select an ending point, b = 2 The area under 5x^4 + 3x^3 - 10x + 2 between 1 and 2 is 29.25Solution
def f1(x):
return 5*x**4 + 3*x**3 - 10*x + 2
def f2(x):
return x**2 - 10
def f3(x):
return 40*x + 5
def f4(x):
return x**3
def f5(x):
return 20*x**2 + 10*x - 2
function = input(\"Choose a function (1, 2, 3, 4, 5, other(quit)): \")
way = input(\"Would you like to calculate the area using rectangle, trapezoid, or both (1, 2, 3): \")
if way==1:
num = input(\"How many rectangles do you want? \")
elif way==2:
num = input(\"How many trapezoids do you want? \")
start = input(\"Please select a starting point\")
end = input(\"Please select an ending point\")
f = 0
if way==1:
if function == 1:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f1(x)*(end-start)/num)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
elif function == 2:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f2(x)*(end-start)/num)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
elif function == 3:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f4(x)*(end-start)/num)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
elif function == 4:
for i in range(num+1):
x = start+i*(end-start)/num
f+=abs(f4(x)*(end-start)/num)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
elif way ==2:
if function == 1:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs(h*(f1(x1) + f1(x2))/2.0)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
if function == 2:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs(h*(f2(x1) + f2(x2))/2.0)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
if function == 3:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs(h*(f3(x1) + f3(x2))/2.0)
print \"The area under the curve between\", start, \"and\", end, \"is\", f
if function == 4:
for i in range(num+1):
h = end-start
x1 = start + (i-1)*h/num
x2 = start + (i)*h/num
f += abs(h*(f4(x1) + f4(x2))/2.0)
print \"The area under the curve between\", start, \"and\", end, \"is\", f

