THE AREA OF A TRIANGLE PROBLEM
Given the lengths of three sides of a triangle X, Y, Z. How to calculate the area of this triangle?
Numerically unstable and numerically stable solution
The classical formula due to Heron of Alexandria first calculates a semiperimeter, S, as half the sum of the sides, and then evaluates the area as in the following internal function HERON
IMPLEMENTATION
Unit: internal function
Interface: the functions SQRT Parameters: positive real numbers X, Y, Z - lengths of three sides of a triangle a positive integer P - number of significant digits of result, default is 9 Returns: the area of a triangle
This function is numerically unstable for needle-shape triangle. W. Kahan describes a good, numerically stable, function. It follows:
Example (W. Kahan) The following program
displays on the screen:
Literature
Kahan W., Mathematics Written in Sand Version of 22 Nov. 1983 http://www.cs.berkeley.edu/~wkahan/MathSand.pdf
|
|
|
|
|
|
![]()