问题描述
如何计算(0.015 *(0.05 * 0.05))
的立方根?
I尝试了以下解决方案:
I tried the following solutions:
double result = Math.Pow(0.015 * (0.05 * 0.05), 1.0/3.0);
我得到 0.03347
。
来自Volframalpha的相同计算: 0.015 *(0.05 * 0.05)^ 0.33
得到 0.00207
。
我在这里做什么错了?
推荐答案
有三个问题我有。
-
您在表达式的一部分中使用Math.Pow(),但是,您将需要使用
You are utilizing Math.Pow() in one part of your expression, however, you will want to use Math.Sqrt() in the first part of the expression which was later given during the conversation.
第二个是括号内的问题。表达式导致对表达式的无效评估
Secondly, there is an issue with the parenthetical groupings within the expression causing a invalid evaluation of the expression
第三,您需要在没有十进制值的数值后使用'd'字符后缀来评估预期结果。
Thirdly, you will need to use the 'd' character suffix after your numerical values that do not have a decimal value to evaluate the expected result.
等式:
(0.3d *((0.0015d *( 0.793700526d + Math.Sqrt(0.7071068)))+(0.015d * Math.Pow((0.05d * 0.05d),(1d / 3d))))))
The equation:(0.3d * ((0.0015d * (0.793700526d + Math.Sqrt(0.7071068))) + (0.015d * Math.Pow((0.05d * 0.05d), (1d/3d)))))
代码:
using System;
namespace POW
{
class Program
{
static void Main(string[] args)
{
// Corrected calculation derived from comment conversation given by author
double myCalculation1 = (0.3 * ((0.0015 * (0.793700526 + Math.Sqrt(0.7071068))) + (0.015 * Math.Pow((0.05 * 0.05), (1 / 3)))));
// d suffix used to ensure the non decimal value is treated as a decimal
double myCalculation2 = (0.3 * ((0.0015 * (0.793700526 + Math.Sqrt(0.7071068))) + (0.015 * Math.Pow((0.05 * 0.05), (1d/3d)))));
// Output the value of myPow
Console.WriteLine("The value of myCalculation is: {0}", myCalculation1);
Console.WriteLine("The value of myCalculation is: {0}", myCalculation2);
}
}
}
重要的是,按照惯例,想要在每个数字后使用'd'后缀。
Importantly, by convention you will want to use a 'd' suffix after each number.
这篇关于C#math.pow多维数据集根计算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!