- Practice
- Functional Programming
- Introduction
- Area Under Curves and Volume of Revolving a Curve
- Discussions

# Area Under Curves and Volume of Revolving a Curve

# Area Under Curves and Volume of Revolving a Curve

mattklein999 + 2 comments I'm pretty sure the sample data is wrong.

For the first given sample, the only way to get the "correct" value of

`2435300.3`

is if you sum up all of the slices between 1.0 and 4.0, inclusive.However, that would be incorrect. It should be all of the slices between 1.0 and 3.999, inclusive, which sums to

`2428775.4`

. By including the last slice**STARTING**at 4.0, you're actually including the slice representing 4.0 to 4.001, which is clearly outside the target bounds.I'm somewhat disappointed with this "Introduction" to "Functional Programming" example, since its mostly just an exercise in calculus (but there is already a Mathematics domain here for that). This should have given us the motivation

*and*the formulas, and then we pratice implementing them in our given language.naderghanbari + 0 comments I think this is not true.

If you sum slices between

`1.0`

and`4.0`

excluding the`first`

slice you get`2435300.3`

.The problem I have with this exercise is that it doesn't precisely specify which numerical method and which convention to use but the given article (link) uses a summation from

`1`

to`n`

which means we have to exclude the first slice and include the last slice.M_F_H + 0 comments Yes I agree.

FlavioFernandes4 + 0 comments Scala:

def f(coefficients:List[Int],powers:List[Int], x:Double):Double = coefficients.zip(powers) .foldLeft(0.0){case (acc,(c,p))=> acc + c * math.pow(x,p)} def area(coefficients:List[Int],powers:List[Int],x:Double):Double = math.Pi * math.pow(f(coefficients,powers,x),2) def summation(func:(List[Int],List[Int],Double)=>Double, upperLimit:Int, lowerLimit:Int, coefficients:List[Int], powers:List[Int]):Double = { val step = 0.001 val subIntervals= lowerLimit.toDouble to upperLimit by step subIntervals .foldLeft(0.0){case (acc,x)=> acc + func(coefficients,powers,x)*step} }

anandrajj + 2 comments This link has simple tutorial. This could help you to understand the problem well. http://www.intmath.com/applications-integration/4-volume-solid-revolution.php

giaym + 0 comments wouldnt have bothered otherwise, thanks!

naderghanbari + 0 comments Multiplying the

`π`

at the end makes perfect sense but for languages with a predefined template we can't do that here as the predefined function has to return the area of each slice (disk).Multiplying all terms (slices) or mutlplying at the end affects the double precision so probably better not to bother with that here, i.e. just multiply all slices by

`π`

if you are solving this with a language which doesn't come with a template (Erlang for instance).

hungryfrog + 1 comment There is something wrong with the sample output , it is not 2435300.3 but 2432036.5

naderghanbari + 0 comments Wolfram Alpha probably calcuates the exact value because this is a polynomial. It might use analytical methods or even numerical methods which are exact for polynomials (up to a certain degree). What we're asked to do here is specifically using the limit definition of integral.

The precision also matters, here we have to sum slices between 1.0 and 4.0 excluding the first slice (as in the link, i.e. summation from

`1`

to`n`

), then we get`2435300.3`

.By the way there seems to be a problem with the relative error. My Scala code passed all the tests but I couldn't make my Erlang code work after spending 1h, the results are definitely within the

`0.01`

relative margin but tests are failing.

oscar_garcia3 + 0 comments This is more a calculus problem than a functional programming problem. The problem requires calculus knowledge to understand the requirement and implement the solution.

We are testing functional programming skills not calculus, there is a maths folder in the website for this type of challenges.

Sort 80 Discussions, By:

Please Login in order to post a comment