JavaScript calculus
Zeno and Archimedes are having a drink when they see an attractive lady across the bar. Archimedes gets up to go talk to her. Zeno says, “Why bother? You will first need to cover half the distance, and then half the remaining distance, and so on, so you will never get there.” Archimedes says, “Maybe not, but I’ll get close enough.”
As a student, it is easy to get the impression that calculus is a magnificent system of integrals and derivatives that someone somewhere has validated with rigorous limit proofs. In the real world, not all datasets are able to be represented by elementary functions, and some seemingly-straightforward problems (such as the circumference of an ellipse !) have no elementary solution. So, mathematical purists notwithstanding, calculus must sometimes be performed with infinitesimals and brute-force numeric methods. (Plus, infinitesimals are a lot easier to understand! Plus, rigorous or not, they work! Must side with Leibniz here.)
To approximate the area under a curve (the integral), partition it into narrow trapezoids and find the sum of the areas (the method of exhaustion).
The area of each trapezoid is the area of the rectangle plus the area of the triangle on top.
It is equivalent to the width × the average of the heights:
The arc length is approximated by the diagonal:
The narrower the trapezoids, the closer the approximation.
To approximate area using polar coordinates, partition the figure into narrow triangles.
If the incremental angle
The area of each right triangle would be approximately
The area of the segment of the figure may be more closely approximated by averaging the areas of the
The arc length is approximated by the
or, in Cartesian form:
The narrower the angle, the closer the approximation.
The above may be applied to three-dimensional figures as well, by summing the areas and volumes of infinitesimal strips and slices.
To test the accuracy of the above, we can apply it to figures whose math is well-known.
Begin with a parabola,
Let
Using an x increment of 0.000001, the slope of the line connecting points on either side is 0.800000000003.
Let
The calculated area by trapezoids is 0.443668.
Now for an ellipse, where
When the origin is at one focus,
Let θ0 = 5°. The slope of the tangent at θ0 is
Using an angle increment of 0.000001 radians, the slope of the line connecting points on either side is -0.5309683217.
The area of an ellipse is
The calculated area by triangles is 251.327413.
The circumference of an ellipse has no elementary solution, but may be calculated to any degree of precision by the following formula:
Taken to greater than 15 significant figures, the circumference of the ellipse is 70.5824241.
The calculated circumference by
Note that infinitesimal methods may be used to find the tangent to any ellipse, such as one rotated at an arbitrary angle; and they may be used to find any segment of area or circumference.
Now for something a lot more practical. What is the area of the shaded slice of pizza?
The pizza radius is 1 and the slice dimensions are 1⁄3 × 1⁄3.
The equation for the top half of the pizza is
Using an x increment of 0.000001, the calculated area by trapezoids is 0.06404, or 58 % of a full slice.
The length of the crust by
Starting the year in which the owner turns 72, retirement accounts must make an annual required minimum distribution based on life expectancy tables published by the Internal Revenue Service. The graph at right shows what happens to a $100,000 account with the specified growth rate as RMD’s are withdrawn in monthly installments.
growth rate: 4.0 %
age: 84 | month: February
The rate of change in February the year the owner turns 84 is $ -1,852 per year.
The area under the curve (total value × time) is $ 2,489,786.
Please visit russellcottrell.com | blog