12 lines
215 B
Text
12 lines
215 B
Text
function r = m_nthroot(n, A)
|
|
x0 = A / n;
|
|
m = n - 1;
|
|
while(1)
|
|
x1 = (m*x0 + A./ x0 .^ m) / n;
|
|
if ( abs(x1-x0) < abs(x0 * 1e-9) )
|
|
r = x1;
|
|
return
|
|
endif
|
|
x0 = x1;
|
|
endwhile
|
|
endfunction
|