简体   繁体   English

C#math.pow立方根计算

[英]C# math.pow cube root calculation

How can I calculate a cube root of (0.015*(0.05*0.05)) ? 如何计算(0.015*(0.05*0.05))的立方根?

I tried the following solutions: 我尝试了以下解决方案:

double result = Math.Pow(0.015 * (0.05 * 0.05), 1.0/3.0);

and I am getting 0.03347 . 我得到0.03347 The same calculation from Volframalpha: 0.015*(0.05*0.05)^0.33 gives 0.00207 . 来自Volframalpha的相同计算: 0.015*(0.05*0.05)^0.33得到0.00207

What am I doing wrong here ? 我在这做错了什么?

There are three concerns that I have. 我有三个问题。

  1. 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. 您正在表达式的一部分中使用Math.Pow(),但是,您将希望在表达式的第一部分中使用Math.Sqrt(),该部分稍后在对话期间给出。

  2. Secondly, there is an issue with the parenthetical groupings within the expression causing a invalid evaluation of the expression 其次,表达式中的括号分组存在问题,导致对表达式的无效评估

  3. 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. 第三,您需要在没有小数值的数值后使用'd'字符后缀来评估预期结果。

The equation: (0.3d * ((0.0015d * (0.793700526d + Math.Sqrt(0.7071068))) + (0.015d * Math.Pow((0.05d * 0.05d), (1d/3d))))) 等式:(0.3d *((0.0015d *(0.793700526d + Math.Sqrt(0.7071068)))+(0.015d * Math.Pow((0.05d * 0.05d),(1d / 3d)))))

The code: 编码:

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);
        }
    }
}

Importantly, by convention you will want to use a 'd' suffix after each number. 重要的是,按照惯例,您需要在每个数字后面使用'd'后缀。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM