Talk:Nth root: Difference between revisions

no edit summary
No edit summary
Line 8:
==C edit==
I see the recent edits on C example as having multiple problems: 1) math function pow() was specifically avoided because it makes no sense to do nth root if we could just pow() it; 2) prec parameter is of wrong type; 3) when comparing for convergence, at least take the absolute value; and the comparison should be made against a relative value; 4) requiring 4 parameters is counterintuive. I'll let it stand for now in case the new editor will come and fix it, or it will be reverted. --[[User:Ledrug|Ledrug]] 22:40, 4 September 2011 (UTC)
 
==Maclaurin Series==
Nth root can be calculated using the maclaurin series of exp and ln like this
 
 
<math>x^{\frac{1}{n}} = e^{\frac{1}{n} \log{(x)}}</math>
 
 
<math>\ln{(\frac{1+x}{1-x})} = \sum^{\infty}_{n=0}2 \frac{x^{2 n+1}}{2 n+1}</math>
 
 
<math>\log{x} = \ln{\frac{x-1}{1+x}}</math>
 
 
<math>e^x = \sum^{\infty}_{n=0}\frac{x^n}{n!}</math>
 
 
since n is always an integer >= 0, a simple pow function can be used for the calculations.
 
example:
<lang c>int_type powInt(int_type x, int_type n)
{
int_type ret=x,i;
if(n>0)
{
for(i=1;i<n;i++)
{
ret*=x;
}
} else return 1;
return ret;
}</lang>
 
 
Ofcourse it's not possible to calculate up to an infinity, but the value can be calculated til it is good enough.
 
Using a library that implements a type that includes nominator and a denominator (like GMP's mpt_q), it is possible to calculate
 
the Nth root using only integers.
 
--[[User:Spekkio|Spekkio]] 12:05, 29 November 2011 (UTC)
Anonymous user