在Matlab中比较双打 [英] Comparing doubles in Matlab
问题描述
我正在编写一个程序,让我可以对Matlab中行星的轨道进行动画处理.这是可行的,但是我想显示它们在一定时间间隔内完全绕着太阳转过的时间.我一直在通过将它们开始的位置与当前位置进行比较来进行此操作: abs(current_position-begin_position< precision
.但是,这是我的问题:每个行星及其数据的精度差异很大.像木星一样,我必须将精度设置为0.2,而海王星必须将精度设置为0.001,所以我不能只说 precision = 0.2
,因为如果我这样做的话,它会与我的其他行星产生故障所以.有没有其他方法可以比较这些数字或实现此目的的另一种方法?我也一直在尝试使用角度,但是效果不是很好.
I'm writing a program that lets me animate the orbits of the planets in Matlab. This is working, but I would like to display the amount of times they fully went around the sun in a certain time lapse. I've been doing this by comparing the position they begin with with their current position: abs(current_position - begin_position < precision
.
But here's my problem: this precision is very different for each planet and their data. Like for Jupiter I have to set this precision to 0.2, while for Neptune it has to be 0.001, so I can't just say precision = 0.2
, because it generates faults with my other planets if I do so. Is there another way to compare these numbers or another way to achieve this? I've been trying to use angles also, but that didn't worked out quite well.
谢谢.
推荐答案
我将使用向量存储每个行星的精度.但是,您将必须在每次迭代中检查位置是否匹配,然后增加一个轨道数计数器.
I would use a vector to store the precision of each planet. However you will have to check in each iteration if the position match and then increase a counter for the number of orbits.
为什么角度会给您带来麻烦?您可以累加该角度,减去初始角度,然后计算模数360(或2 * pi)以了解轨道数.
Why angles give you problems? You can accumulate the angle, subtract the initial angle and then calculate a modulus 360 (or 2*pi) to know the number of orbits.
这篇关于在Matlab中比较双打的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!