- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试通过速度 verlet 模拟地球-太阳系统,但不知何故,太阳不会围绕原点(质量减少的位置)运行,而是漂移。我花了很多时间查看我的算法,但找不到缺陷。
有人知道这里出了什么问题吗?
这是模拟图:http://i.imgur.com/5l8GzZS.png
#include <stdio.h>
#include <math.h>
double xearth,yearth,vxearth,vyearth;
double xsun,ysun,vxsun,vysun;
double dt=0.5;
double fxearth,fyearth;
double fxsun,fysun;
double r;
double G;
double ms, ma;
double rx,ry;
double t;
main(){
FILE * pFile;
int n;
xearth= -2.569651552438753*pow(10,-2); /* in AU */
yearth= -1.008909556982513;
xsun= 2.563054664344734*pow(10,-4);
ysun= 6.897319465467234*pow(10,-3);
vxearth= 1.690809814669721*pow(10,-2); /* in AU per day */
vyearth= -4.950293720310762*pow(10,-4);
vxsun= -5.788119594348977*pow(10,-6);
vysun= 3.335986886320253*pow(10,-6);
G=1.488*pow(10,-34); /* G in AU, t in day */
ms=1.9884*pow(10,30); /* kg */
ma=5.9722*pow(10,24); /* kg */
t=0;
pFile = fopen ("/file.txt", "w");
rx=xearth-xsun;
ry=yearth-ysun;
r=sqrt((rx*rx+ry*ry));
fxearth= -G*ms*ma*(rx)/pow(r,3);
fyearth= -G*ms*ma*(ry)/pow(r,3);
fxsun= -G*ms*ma*(-rx)/pow(r,3);
fysun= -G*ms*ma*(-ry)/pow(r,3);
vxearth=vxearth+.5*dt/ma*fxearth;
vyearth=vyearth+.5*dt/ma*fyearth;
vxsun=vxsun+.5*dt/ms*fxsun;
vysun=vysun+.5*dt/ms*fysun;
for(n=1; n<60000; n++){
xearth=xearth+dt*vxearth;
yearth=yearth+dt*vyearth;
xsun=xsun+dt*vxsun;
ysun=ysun+dt*vysun;
rx=xearth-xsun;
ry=yearth-ysun;
r=sqrt((rx*rx+ry*ry));
fxearth= -G*ms*ma*(rx)/pow(r,3);
fyearth= -G*ms*ma*(ry)/pow(r,3);
fxsun= -G*ms*ma*(-rx)/pow(r,3);
fysun= -G*ms*ma*(-ry)/pow(r,3);
vxearth=vxearth+dt/ma*fxearth;
vyearth=vyearth+dt/ma*fyearth;
vxsun=vxsun+dt/ms*fxsun;
vysun=vysun+dt/ms*fysun;
t=t+dt;
fprintf(pFile,"%f\t %f\t %f\t %f\t %f\n",xearth,yearth,xsun,ysun,t);
}
fclose (pFile);
return 0;
}
最佳答案
发生这种情况是因为您的初始条件为系统提供了非零净动量。您可以通过计算系统的初始平均速度并从所有物体速度中减去它来解决这个问题:
double vxavg = (vxsun*ms + vxearth*ma) / (ms + ma);
double vyavg = (vysun*ms + vyearth*ma) / (ms + ma);
vxsun -= vxavg;
vysun -= vyavg;
vxearth -= vxavg;
vyearth -= vyavg;
关于c - C 中的 Velocity Verlet 实现困难(太阳漂移),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24124111/
我希望创建能够快速重复的功能 - 大约 50 毫秒。然而,我需要在调用中尽可能保持一致性,并且我发现 NSTimer 有点不稳定。看来我可能会从 mach_absolute_time 找到一些保持时间
根据 API 文档以及之前的 SO threads , SystemClock.elapsedRealtime() 应该即使在设备处于 sleep 状态时也能保持准确的时间。这不是我观察到的。 我编写
我想开发在谷歌地图上绘制当前位置的应用程序。在这里,我通过 LocationManager(GPS 提供商和网络提供商)的 onLocationChanged 获取位置详细信息。我能够获取位置详细信息
我有一个使用 MKMapView 的简单 iPhone 应用程序。它有一个分段控件,可以调整要缩放的区域(街道、社区、城市、州、世界)。它工作正常,但如果我缩小到州级别并回到街道,我注意到中心点已经移
我正在尝试在连接到本地 NTP 服务器的 Mac 上获取实际的 NTP 漂移。 读取/var/db/ntp.drift 文件时,根据PPM to milliseconds conversion 得到-
我有一个 AWS Cloud Formation 堆栈。我启动并停止了该堆栈中的 EC2 实例。现在堆栈已漂移,下面是漂移结果。我该如何解决这个问题,因为预期和实际都是相同的。 最佳答案 我不相信这与
我是一名优秀的程序员,十分优秀!