简体   繁体   English

相同的数学表达式返回不同的结果

[英]Same mathematical expression returns different result

I am baffled by this one.我对这个感到困惑。

So I have a console application doing a lot of calculations (trust me, thousands of them ).所以我有一个控制台应用程序进行大量计算(相信我,有数千个)。 In one method, I have some parameters that need calculating, in different situations.在一种方法中,我有一些需要在不同情况下计算的参数。 For one of them, the mathematical expression is basically the same, only one difference in a term.对于其中之一,数学表达式基本相同,仅在一个术语中有所不同。 Here is the code snippet along with all the lines between the 2 formulas in question, the Nq1 and Nq2 ones ( first formula of the code and last one to be more easy ):这是代码片段以及有问题的 2 个公式之间的所有行,即 Nq1 和 Nq2(代码的第一个公式和最后一个更简单):

//drained conditions
        Nq1 = Math.Round((Math.Pow(Math.E, Math.PI * Math.Tan(studiu.Fi * Constants.ConversionToDeg)) * Math.Pow((Math.Tan(45 + studiu.Fi / 2.00) * Constants.ConversionToDeg), 2)), 2);

        //Combination 2

        studiu.Fi = FiAfectat;


        //drained conditions
        Nq2 = Math.Round((Math.Pow(Math.E, Math.PI * Math.Tan(studiu.Fi * Constants.ConversionToDeg)) * Math.Pow((Math.Tan(45 + studiu.Fi / 2.00) * Constants.ConversionToDeg), 2)), 2);

The first formula returns 18.04 but the second one returns 0.01.第一个公式返回 18.04,但第二个公式返回 0.01。 How is this possible ?这怎么可能 ? Only the studiu.Fi term differs, but not by that much ( 32 in the first case and 27 in the second ).只有 studio.Fi 术语不同,但差别不大(第一种情况为 32,第二种情况为 27)。

How can Nq1 be 18 and Nq2 be 0.01 ? Nq1 怎么可能是 18 而 Nq2 怎么可能是 0.01 ? Am I missing something here ?我在这里错过了什么吗?

Tan(x) is a periodic function that will change drastically for a small change in x. Tan(x) 是一个周期函数,它会随着 x 的微小变化而剧烈变化。 Since the two formulas only differ by a term inside the Tan function, this is likely your problem.由于这两个公式仅在 Tan 函数内有一项不同,因此这可能是您的问题。

Also, it is likely that you should be using radians instead of degrees.此外,您可能应该使用弧度而不是度数。 If this is the case you should use a command that converts real numbers to radians instead of one that converts to degrees.如果是这种情况,您应该使用将实数转换为弧度的命令,而不是将其转换为度数的命令。

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

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