C#查找第N个根

编程入门 行业动态 更新时间:2024-10-19 00:22:58
本文介绍了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个根

本文发布于:2023-11-30 04:30:55,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1648733.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!