计算 4 次幂差
我正在使用 Modelica 来求解传热问题的方程组,其中之一是辐射,其写为
Ta^4-Tb^4
有人能说用以下方程求解方程组是否计算速度更快:
(Ta-Tb)(Ta+Tb)(Ta^2+Tb^2)
?
I am using Modelica for solving a system of equations for heat transfer problems, and one of them is radiation which is written as
Ta^4-Tb^4
Can someone say if it is computationally faster solving a system with the equation written as:
(Ta-Tb)(Ta+Tb)(Ta^2+Tb^2)
?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这个问题不可能有明确的答案。这是因为 Modelica 规范用于正式定义问题陈述,但它没有说明工具如何求解此类方程。此外,由于大多数 Modelica 工具无论如何都会进行符号操作,因此很难预测它们对这样的方程可能采取什么步骤。例如,一个工具很可能自行将其转换为霍纳多项式(无需您的手动干预)。
如果您要求解非线性系统等方程中的温度,请注意负温度解。当这些温度是非线性问题中的迭代变量时,您应该研究“start”属性来指定初始(正)猜测。
There cannot be a definitive answer to this question. This is because the Modelica specification is used to formally define the problem statement but it says nothing about how tools solve such equations. Furthermore, since most Modelica tools do symbolic manipulation anyway, it is hard to predict what steps they might take with such an equation. For example, a tool may very well transform this into a Horner polynomial on its own (without your manual intervention).
If you are going to solve for the temperatures in such an equation as a non-linear system, be careful about negative temperature solutions. You should investigate the "start" attribute to specify initial (positive) guesses when these temperatures are iteration variables in non-linear problems.
我想说,将其分成 (Ta-Tb)(Ta+Tb)(Ta^2+Tb^2) 速度更慢而不是更快有两个原因。
(Ta^2+Tb^2) 需要 2 次乘法和一次加法,这意味着 (Ta-Tb)(Ta+Tb)(Ta^2+Tb^2) 需要 4 次乘法和 3 次加法。另一方面,我猜 Ta^4-Tb^4 是这样完成的:((Ta^2)^2 - (Tb^2)^2) 这意味着 1 次加法和 4 次乘法。
Mathematica,就像一个更通用的编译器,可能非常清楚如何优化这些非常简单的表达式。这意味着使用简单的模式在计算时间方面通常更安全,这些模式很容易被捕获并转换为超高效的机器代码。
我显然可能是错的,但我看不出任何理由为什么 (Ta-Tb)(Ta+Tb)(Ta^2+Tb^2) 可以更快。希望有帮助。
奥斯卡
I would say that there are two reasons why splitting it into (Ta-Tb)(Ta+Tb)(Ta^2+Tb^2) is SLOWER and NOT FASTER.
(Ta^2+Tb^2) requires 2 multiplications and an addition, which means that (Ta-Tb)(Ta+Tb)(Ta^2+Tb^2) requires 4 multiplications and 3 additions. On the other hand, i guess that Ta^4-Tb^4 is done like this: ((Ta^2)^2 - (Tb^2)^2) which means 1 addition and 4 multiplications.
Mathematica, like a more generic compiler probably knows very well how to optimise these very simple expression. Which means that it is generally safer in terms of computation time to use simple patterns which will be easily caugth and translated into super efficient machine code.
I might obviously be wrong, but I cannot see any reason why (Ta-Tb)(Ta+Tb)(Ta^2+Tb^2) could be FASTER. Hope it helps.
Oscar