SI
SI
discoversearch

We've detected that you're using an ad content blocking browser plug-in or feature. Ads provide a critical source of revenue to the continued operation of Silicon Investor.  We ask that you disable ad blocking while on Silicon Investor in the best interests of our community.  If you are not using an ad blocker but are still receiving this message, make sure your browser's tracking protection is set to the 'standard' level.
Strategies & Market Trends : TA-Quotes Plus

 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext  
To: TechTrader42 who wrote (9083)3/23/1999 9:59:00 AM
From: unixgeek  Read Replies (1) of 11149
 
Re: square roots. I didn't see this actual algorithm in your post,
so I thought I'd forward it to the group in case anyone else wanted
to play around with square roots. I can generalize this into any
arbitrary root (cube, 4'th, whatever) if anyone really wants it, but
I've never seen anyone need anything like that for TA use.

I'm typing this in from memory, so excuse the inevitable syntax
errors, but I did try this and it works fine. This should spit out
today's close and its square root. Season to taste...

output = "root.lst";

float ans, guess, num, eps;

eps := 0.0001; // reduce this to get "closer" to the actual root.

float num; // the number you need the root of.

num := close(0);
guess := num / 2.0; // first guess.
ans := num / guess;

integer i;
for i = 1 to 100 do // most will only take 5 to 12 iteratons.
if (abs(guess - ans) >= eps) then // are we too far away?
guess := (guess + ans) / 2; // average to refine guess...
ans := num / guess; // ...for a more refined answer
else
i := 100; // we're done. Get out of loop
endif;
next i;

println symbol, " ", num, " ", ans;
Report TOU ViolationShare This Post
 Public ReplyPrvt ReplyMark as Last ReadFilePrevious 10Next 10PreviousNext