本文介绍了C#查找第N个根的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我使用以下方法来计算双精度值的第N个根,但是计算第240个根需要花费大量时间.我发现了有关牛顿方法的信息,但无法将其实现为方法.任何帮助,将不胜感激.
I use below method to calculate Nth Root of double value, but it takes a lot of time for calculating the 240th root. I found out about Newton method, but was not able to implement it into a method. Any help would be appreciated.
static double NthRoot(double A, int N) { double epsilon = 0.00001d;// double n = N; double x = A / n; while (Math.Abs(A-Power(x,N)) > epsilon) { x = (1.0d/n) * ((n-1)*x + (A/(Power(x, N-1)))); } return x; }推荐答案
static double NthRoot(double A, int N) { return Math.Pow(A, 1.0 / N); }
来自维基百科:
在微积分中,根被视为幂的特殊情况,其中幂是分数:
In calculus, roots are treated as special cases of exponentiation, where the exponent is a fraction:
\sqrt[n]{x} \,=\, x^{1/n}更多推荐
C#查找第N个根
发布评论