Drexel dragonThe Math ForumDonate to the Math Forum



Search All of the Math Forum:

Views expressed in these public forums are not endorsed by Drexel University or The Math Forum.


Math Forum » Discussions » sci.math.* » sci.math.symbolic.independent

Topic: Recusively calculating curve length question
Replies: 2   Last Post: Nov 23, 2012 10:23 PM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Rouben Rostamian

Posts: 17
Registered: 12/13/04
Re: Recusively calculating curve length question
Posted: Nov 23, 2012 9:32 PM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

In article <GASrs.1180$1k5.38@viwinnwfe01.internal.bigpond.com>,
Brad Cooper <Brad.Cooper_17@bigpond.com> wrote:
>I have spent quite a few hours trying to write a recursive routine
>to calculate the length of a curve by adding up small secants.
>
>secantLen := proc(a, b, tolerance)
>begin
> L := sqrt( (X(b)-X(a))^2 + (Y(b)-Y(a))^2 ):
> c := (a+b)/2:
>
> if L > tolerance then
> L := secantLen(a, c, tolerance) + secantLen(c, b, tolerance):
> end_if:
>
>return(L):
>end_proc:
>


That termination condition is muddy. Try:

secantLen := proc(a, b, tolerance)
local L, c;
L := evalf(sqrt( (X(b)-X(a))^2 + (Y(b)-Y(a))^2 )):
if L < tolerance then
return L;
else
c := (a+b)/2:
return secantLen(a, c, tolerance) + secantLen(c, b, tolerance):
end_if:
end_proc:

--
Rouben Rostamian



Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© Drexel University 1994-2014. All Rights Reserved.
The Math Forum is a research and educational enterprise of the Drexel University School of Education.