Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8708649
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T04:11:09+00:00 2026-06-13T04:11:09+00:00

I am trying to calculate the area of a graph using integrals. The user

  • 0

I am trying to calculate the area of a graph using integrals.

The user is supposed to give me 3 numbers:

  • x1, x2 – the bounds of the integral
  • N is in how many pieces the program will divide the function

However, I keep getting wrong results.

The first difficulty that I faced is that range accepts only integers.

Also z=(x2-x1)/N if I try and make it a float, I can’t make it a step after, and I don’t make it float it approaches to zero so Python shows me an error that the step is zero.

Also how can I summarize (z*(f(i)+f(i+z)/2)?

Here is my code:

# -*- coding: UTF-8 -*-
import math

def f(x) :
    y = (-1/6.0)*(x-1)*(x-2)*(x+2)*(x-4)
    return y 
x1=int(raw_input ('Δωστε το χ1 οπου αρχιζει η μετρηση του ολοκληρωματος \n ')) #greek letters
x2=int(raw_input ('Δωστε χ2 οπου θελετε να ολοκληρωνεται η μετρηση \n '))
N=int(raw_input('Δωστε τον αριθμο n που θα ειναι το πληθος \n των τραπεζιων που θα χρησιμοπιουνται στη προσσεγγιση  \n '))
z=(x2-x1)/N
for i in range(x1,x2,z):
    z=float(z)
    x1=float(x1)
    x2=float(x2)
    print (z*(f(i)+f(i+z))/2) 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T04:11:10+00:00Added an answer on June 13, 2026 at 4:11 am
    • Let x1, x2 and therefore the step size z be floats.
    • Instead of a for-loop, a while-loop may be easier here.

    x1 = float(raw_input ('Δωστε το χ1 οπου αρχιζει η μετρηση του ολοκληρωματος \n ')) #greek letters
    x2 = float(raw_input ('Δωστε χ2 οπου θελετε να ολοκληρωνεται η μετρηση \n '))
    N = int(raw_input('Δωστε τον αριθμο n που θα ειναι το πληθος \n των τραπεζιων που θα χρησιμοπιουνται στη προσσεγγιση  \n '))
    z = (x2-x1)/N
    x = x1
    while x < x2:
        print (z*(f(x)+f(x+z))/2)
        x += z
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to calculate the area of the circle and the rectangle by using
am trying to calculate mean and variance using 3X3 window over image(hXw) in opencv...here
I am trying to calculate the area of union of n circles in a
I'm trying to calculate triangles base on the Area and the angles. If Angle-B
I'm trying to write a program to calculate triangles. Can anyone give me a
Am trying to calculate the number of rows in a table depending on a
I am trying to calculate number of users, cumulatively for the dellstore2 database. Looking
I'm trying to calculate the time it takes to receive all data from a
I am trying to calculate a ranking of a team in an ordered MySQL
I am trying to calculate a position to place label on the screen. The

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.