【发布时间】:2015-09-21 21:01:35
【问题描述】:
我正在编写一些代码来计算流体中两个粒子之间的相互作用。获得新职位的主要公式依赖于其他 3 个函数,它们为公式获取必要的组件。
公式基本上是:
new position = old position + Important_matrix * Important_Force + (other force)^2
这是我的代码的基本布局:
initial position of particle 1 = [1,1,1]
initial position of particle 2 = [2,2,2]
def GetImportantMatrix(position of first particle, position of second particle):
'code here'
return the_important_matrix
def GetImportantForce(the_important_matrix):
'code here'
return important_force
def GetOtherForce():
'code here'
return other_force
def getnewposition(initial position of part. 1, initial position of part. 2, the_important_matrix, important_force, other_force, iterations):
???
我的实际问题是:如何将公式实现到函数中,以便它自动调用其他函数来获取所需的变量,同时在每次迭代后更新?例如,如何我开始调用其他函数以确保当前函数获得所需的信息,并且每次都正确更新。
我已经在我见过的其他代码 sn-ps 中看到了一些这样的例子,但是我无法弄清楚如何将它应用到我的代码中,因为位置变量每次都在变化,而且这也是使其他变量每次都发生变化。
我希望这是有道理的?我对 Python 很陌生,还在学习,如果你们能指出任何有助于解决此问题的资源,我将不胜感激。
【问题讨论】:
-
我不太明白你的意思,你能进一步解释一下这行吗
the position variable changes each time, and that also makes the other variables change each time -
调用每个函数,将返回值赋给一个变量,使用最终方程上的变量。
标签: python simulation physics