这将是:
static double Compute(double x)
{
return -1E-06 * Math.Pow(x, 6)
+ 0.0001 * Math.Pow(x, 5)
- 0.0025 * Math.Pow(x, 4)
+ 0.0179 * Math.Pow(x, 3)
+ 0.0924 * Math.Pow(x, 2)
- 0.6204 * x + 55.07;
}
Run Code Online (Sandbox Code Playgroud)
这是一个完整的测试程序,用于演示:
using System;
class Test
{
static double Compute(double x)
{
return -1E-06 * Math.Pow(x, 6)
+ 0.0001 * Math.Pow(x, 5)
- 0.0025 * Math.Pow(x, 4)
+ 0.0179 * Math.Pow(x, 3)
+ 0.0924 * Math.Pow(x, 2)
- 0.6204 * x + 55.07;
}
static void Main()
{
Console.WriteLine("Value for x {0} == {1}", 5, Compute(5));
Console.ReadKey();
}
}
Run Code Online (Sandbox Code Playgroud)
我认为令人困惑的是你假设需要-1E-06 Math.Exp,但事实并非如此.这只是科学记数法中的一个简单数字.
E是科学记数法,所以基数10. Math.Exp是自然幂数,即e^x.
而不是写-Math.Exp(-06)*Math.Pos(x, 6)你只是写-1E-06*Math.Pow(x, 6).