在C#中计算多维数据集根的另一种方法 [英] Another way to calculate cube root in C#

查看:64
本文介绍了在C#中计算多维数据集根的另一种方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的计算器中,我正在使用这些语句来计算平方根和立方根.

In my calculator I am using these statements to calculate square root and cube root.

case "sqrt root":
        result = Math.Sqrt(number1);
break;
case "root":
     result = Math.Pow(number1, (1 / number2));
     //"for cubic root" - Math.pow(number, (1/ 3))
break;

我对Math.Pow不太熟悉.还有另一种计算立方根的方法吗?使用Math.Sqrt吗?

I am not very familiar with Math.Pow. Is there another way to calculate cube root? With Math.Sqrt?

推荐答案

我在某处看到了如何使用math.sqrt进行立方根运算,所以我认为也许有人会在这里知道或向我展示另一种方法,如何进行立方根运算. – user3841611

在数学上,您可以使用Sqrt获取多维数据集根:

Mathematically, you can use Sqrt to get the cube root:

x 1/3 = x 1/4 * x 1/16 * x 1/64 * x 1/256 * x 1/1024 * x 1/4096 * x 1/16384 *. ..

x1/3 = x1/4 * x1/16 * x1/64 * x1/256 * x1/1024 * x1/4096 * x1/16384 *...

这来自二进制表示形式的1/3和以下事实:

This comes from the binary representation of 1/3 and the fact that:

  • Sqrt(x)是x 1/2
  • Sqrt(Sqrt(x))是x 1/4
  • Sqrt(Sqrt(Sqrt(x)))是x 1/8 等.
  • Sqrt(Sqrt(Sqrt(Sqrt(x))))是x 1/16 等.
  • Sqrt(x) is x1/2,
  • Sqrt(Sqrt(x)) is x1/4,
  • Sqrt(Sqrt(Sqrt(x))) is x1/8 etc..
  • Sqrt(Sqrt(Sqrt(Sqrt(x)))) is x1/16 etc..

换句话说,您将保持取数字的平方根,然后将其他值相乘得到x 1/3 .一旦值停止变化(浮点精度受到限制,最终产品就不会变化),您将得到非常接近的 x 1/3

In other words, you'd keep taking the square root of your number and multiply every other value to get x1/3. Once the value stops changing (there are limits to floating point precision, so eventually the product won't change), you'll have something very close to x1/3.

如果您愿意,我会发布一些伪代码.

I'll post some pseudo code if you wish.

这篇关于在C#中计算多维数据集根的另一种方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆