Answer to Question #120868 in Python for Manuel

Question #120868
i am making the riemann sum with x**3 but it needs to bo done with dx**3 , for example b - a / n

(5/8)**3 + 10/8**3 + 15/8**3 and this 5 times more because n is 8.

i have made this program so far , it is working with the calculation right now , but it needs to be changed to the example above. With a loop for n.


#formula to calculate dx
dx = float ((b-a)/n)

xi=a
Sum = dx
#loop
for i in range(0,n,n):
xi = a + dx
sum = Sum + f(xi)
print("the surface under the line is ", (sum*dx))
1
Expert's answer
2020-06-09T14:20:53-0400
# this code is for x^3 only with any integer limit and any positive value of n.
# a is lower limit
# b is upper limit
# n is number of rectangles
a = int(input("a = "))
b = int(input("b = "))
n = int(input("n = "))

# dx is denoted as x 
x = (b-a)/n
#s is sum
s = 0
for i in range(0,n+1):
  s = s + (((a + i*x)**3)*(x))
print(s)

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS