How would one go about finding the area of functions such as y=x^3?

Hello.
For my computer engineering class, I was asked to write a C++ program to compute the area of y=0, y=x^3, and x=1 and display the results on the screen (And set a domain of x from 0 to 1 and intervals dx=0.001). How would one go about finding the area of the functions stated previously? Thank you.


0|0
1|7

Most Helpful Guy

  • I assume you're talking about the AREA under the function? Functions themselves don't technically have an area.

    The operation that gives you the area under a curve of a function is called integration. You might have heard of it if you've taken any calculus courses.

    There are actually a few ways to compute the definite integral of a function (look up numerical integration if you want to know more). The easiest one to conceptualize, and the one your teacher probably had in mind to use was something called a Riemann Sum:
    https://en.wikipedia.org/wiki/Riemann_sum
    http://mathworld.wolfram.com/RiemannSum.html
    www.khanacademy.org/.../riemann-sums-and-integrals

    Here's how it works:
    We can easily calculate area of a rectangle (A = width * height), yeah? So the idea behind it is this: if we have some arbitrary function f (x), we can split the area under the curve between the points x=a and x=b into rectangles of width dx, and height of f (x). You simply calculate the area of each rectangle and add them all up and this will give you an approximation of the area under the curve. The smaller the value of dx, the more rectangles, and hence, the more accurate the approximation.

    So given a function f (x) and the values a, b and dx we can compute the area under it by looping through the x values starting at a and ending at b, incrementing x by dx every iteration. For every value of x, calculate the area of that rectangle (f (x) * x) and adding it to a sum counter variable.

    Hope that helps.

    By the way: if you have programming questions you might want to try a proper programming forum like stackoverflow. com. GirlsAskGuys isn't the best place for computer questions.

    0|1
    0|0
    • Sorry, the area of the rectangle should read (f (x) * dx) NOT (f (x) * x)

What Guys Said 6

  • In very general terms, as a computer science professor who assigns work like this, you should be able to look up the formula pretty easily. Write out your pseudocode of what you want your program to do first, then translate that to code. You'll need to use the proper using directives to access exponents in C++. Be sure to watch your formatting - showpoint and setprecision will help you get that down. Comments! I can't stress that enough. Put comments in your programs. Always. Forever. Doooo iiiiiit.

    0|1
    0|0
  • I'd love to help, but my math grades were always terrible and I'd probably give you the wrong answer...

    0|1
    0|0
  • I'd love to help you, and although I'm pretty experienced with programming, I don't know much about advanced math and the terms used therein.

    0|0
    0|0
  • Go do your own homework

    0|0
    0|2
  • lol I took an Intro to computer prof class last year and have a C++ book in my house but I don't understand it at all

    0|0
    0|0
  • How old are you really?

    0|1
    0|0

What Girls Said 1

Loading...