当时做毕设突发奇想顺手写的。
代码如下
function threebody(Mass1x3,Velocity3x3,Position3x3,Frequency)
%%——————————————————————————————————————————————————————————————————————————————
%% 初始状态
if nargin < 3
%速度
v1 = [0,0,0];
v2 = [0,0,0];
v3 = [4000,4000,-4000];
%质量
m1 = 15*10^24; %蓝
m2 = 10*10^24; %红
m3 = 5*10^24; %黄
%初始点
m1_position = [0,10000000,10000000];
m2_position = [10000000,0,0];
m3_position = [-5000000,0,5000000];
tstep = 0.005;
elseif nargin < 4
tstep = 0.01;
v1 = Velocity3x3(1:3,1);
v2 = Velocity3x3(1:3,2);
v3 = Velocity3x3(1:3,3);
m1 = Mass1x3(1);
m2 = Mass1x3(2);
m3 = Mass1x3(3);
m1_position = Position3x3(1:3