matlab多体,请问MATLAB参数问题,多体运动建模。

function SunEarthMoon

load planets;

[sun, earth, moon] = deal(18, 3, 25);%单个赋值,sun=18应该是质量吧,很多数据,18 3 25应该是对应所在位置

list = [sun, earth, moon]; % 12 24 lis成为一个数组

G = 6.67e-11; %gravitational constant引力常量

dt = 24*3600;%一天为一个基本常量

N = length(list);%有3个星球

mass = mass(list);

position = position(list,:);%应该是初始位置

velocity = velocity(list,:);

h = plotplanets(position);

for t = 1:365

plotplanets(position,h);

force = zeros(N,3);

for i = 1 : N

Pi = position(i,:);

Vi = velocity(i,:);

Mi = mass(i);

for j = (i+1):N; %the i+1 is in to create diagonal

Mj = mass(j);

Pj = position(j,:);

dr =  Pj - Pi; %方向的指向应该是从i指向j

forceij = G*Mi*Mj./(norm(dr).^3).*dr;%norm函数是用来求向量的摸

force(i,:) = force(i,:) + forceij;

force(j,:) = force(j,:) - forceij;

end;

end

velocity = velocity + force./repmat(mass,1,3)*dt;%重构函数,将mass变成一行3列

position = position + velocity*dt;

end

% -

function h = plotplanets(pos,h)

scale = 50;

total_planets = size(pos,1);

[sun, earth, moon] = deal(1, 2, 3);

radius = [50, 30, 20];

marker = {'.r', 'b.','m.'};

pos(moon,:) = pos(earth,:) + scale*(pos(moon,:)-pos(earth,:));

if nargin==1

hold on; axis image

axis( [-2 2 -2 2]*1e11 );

for i = 1:total_planets

if any(i == [sun, earth, moon])

h(i) = plot(pos(i,1),pos(i,2),marker{i},'markersize',radius(i));

plot(pos(i,1), pos(i,2), marker{i}, 'markersize',5);

else

h(i) = plot(pos(i,1), pos(i,2), 'k.', 'markersize', 20);

plot(pos(i,1), pos(i,2), 'k.', 'markersize',5);

end

end

else

for i = 1:total_planets

set(h(i), 'Xdata', pos(i,1)  , 'Ydata', pos(i,2)  )

if any(i == [sun, earth, moon])

plot(pos(i,1), pos(i,2), marker{i}, 'markersize',5);

else

plot(pos(i,1), pos(i,2), 'k.', 'markersize',5);

end

end

drawnow

end

在这里面,第二个函数h = plotplanets(pos,h),以形式参数作为返回参数不太懂,还有画图的这个问题,这段函数有谁能来探讨一下吗?

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值