Excel趋势行到C#代码错误?

我已经转换下面的expression式

在这里输入图像说明

到这个function

private double getRisingTemp(double x/*time*/) { double y; y = Math.Pow(3 * 10, -12) * Math.Pow(x, 5) - Math.Pow(4 * 10, -9) * Math.Pow(x, 4) + Math.Pow(10, -6) * Math.Pow(x, 3) + 0.0005 * Math.Pow(x, 2) - 0.0302 * x + 23.826; return y; } 

但是C#的graphics与我在Excel中看到的graphics有点不同。 只是想确保我的C#函数100%对应于方程。

在这里输入图像说明

在这里输入图像说明

如果function正常,可能是错误的?

您的x ^ 4和x ^ 5系数expression式不正确。 只需使用内置的double科学记数法:

 y = 3e-12 * Math.Pow(x, 5) - 4e-9 * Math.Pow(x, 4) + 1e-6 * Math.Pow(x, 3) + 0.0005 * Math.Pow(x, 2) - 0.0302 * x + 23.826; 

您需要查看Math.Pow()的文档,可以在这里find它。 例如,你的第一次转换是错误的: Math.Pow(3 * 10, -12) ,并不符合你的:3E-12。 3E-12意思是10到12的3倍。 你可以在这里阅读更多。

希望这可以帮助你!