-- We know that there is intelligent life in the universe because they have never attempted to contact us. Lily Tomlin "none (Rouben Rostamian)" <rouben@shady.> wrote in message news:firstname.lastname@example.org... > In article <GASrs.email@example.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
The secret sauce is to declare L and c as local. I haven't programmed for 12 years, am very rusty. Your help has been fantastic!!