Talk:Nth root: Difference between revisions

no edit summary
No edit summary
No edit summary
Line 28:
 
example:
<lang cclisp>int_type powInt(int_typedefun x,powint int_type(a nb)
(if (n>= b 0)
{
{1
int_type ret=x,i;
(* a (powint a (- b 1)))))</lang>
if(n>0)
{
for(i=1;i<n;i++)
{
ret*=x;
}
} else return 1;
return ret;
}</lang>
 
 
Line 47 ⟶ 39:
 
the Nth root using only integers.
 
Maybe not the best solution but it could be something like this
<lang clisp>(defun factorial (n)
(if (= n 0)
}1
(* n (factorial (- n 1)))))
 
(defun powint (a b)
(if (= b 0)
{ 1
(* a (powint a (- b 1)))))
 
(defun logS(x n) (if (= n 0) (* 2 x) (+ (* 2 (/ (powint x (+ (* 2 n) 1)) (+ (* 2 n) 1))) (logS x (- n 1)) ) ))
 
(defun loge(x n) (logS (/ (- x 1) (+ 1 x)) n))
 
(defun expon(x n) (if (= n 0) 1 (+ (/ (powint x n) (factorial n)) (expon x (- n 1)))))
 
(defun pown(x a n) (expon (* a (loge x n)) n))</lang>
 
 
example output:
[9]> (* (pown 2 1/3 20) 1.0)
1.2599211
 
--[[User:Spekkio|Spekkio]] 12:05, 29 November 2011 (UTC)
Anonymous user