[Haskell-cafe] Geometry
Arie Groeneveld
bradypus at xs4all.nl
Mon Aug 27 13:05:06 EDT 2007
Steve Schafer wrote:
>
> x = a - sqrt(a^2 - b^2)
>
> I don't know offhand if there's a straightforward way to arrive at this
> result without using trigonometry.
Here you go, though with a slightly different result
(same as Joel Koerwer):
a^2=(b^2)/4+(a-x)^2 (Pythagoras)
solving x: -->
x(1,2) = a +/- sqrt (a^2 - b^2/4) (I)
Did anyone compare the answers?
(I)
aai a b = (x1,x2)
where x1 = a + sqrt disc
x2 = a - sqrt disc
disc = a^2-b^2/4
Others:
schafer a b = a - sqrt(a^2 - b^2)
jedaï a b = a * (1 - cos (b/(2*a)))
stefan a b = a - a * sqrt (1 - b*b / a*a)
joel a b = a - sqrt (a*a - b*b/4)
Assume a and b are given: a=10; b=8
Results:
*Main> aai 10 8
(19.165151389911678,0.8348486100883203)
the answer is the smaller value
the other value =
the diameter of the circumference minus x
(0.00 secs, 523308 bytes)
*Main> schafer 10 8
4.0
(0.01 secs, 524924 bytes)
*Main> jedaï 10 8
0.789390059971149
(0.01 secs, 524896 bytes)
*Main> stefan 10 8
NaN
(0.00 secs, 524896 bytes)
*Main> stefan 10 8
4.0
(0.01 secs, 524896 bytes)
*Main> joel 10 8
0.8348486100883203
(0.01 secs, 524896 bytes)
Where do I go wrong (I)?
Thanks
@@i
More information about the Haskell-Cafe
mailing list