Temel olarak, gezegenlerin yörüngelerini gösteren bir şekil üreten aşağıdaki betiğe sahibim ve hiçbir fikrim yokken onu bir animasyon haline getirmek için bir sonraki adımların ne olacağını merak ettim ...?MATLAB'de bir animasyonda yörüngeyi gösteren bir komut dosyasını nasıl dönüştürebilirim?
Aşağıdaki senaryoyu yayınladım ve eğer birileri yardım ederse çok minnettar olurdum! Bu canlandırmak için teşekkürler
clear all
% Set time interval of interest
tspan = [0 165]; % Let ode45 figure out the intermediate times
G = 2.959233074*365*365*(10^-4);% AU^3 M^-1 yr-2 Gravitational constant
ds = dataset('XLSFile','Planetdatayears.xlsx');
M = xlsread('Planetdatayears.xlsx','B:B')'; %masses in solar mass units
xp = xlsread('Planetdatayears.xlsx','C:C')';
yp = xlsread('Planetdatayears.xlsx','D:D')';
zp = xlsread('Planetdatayears.xlsx','E:E')';
xv = xlsread('Planetdatayears.xlsx','I:I')';
yv = xlsread('Planetdatayears.xlsx','J:J')';
zv = xlsread('Planetdatayears.xlsx','K:K')';
%Initial positions and velocities
z00=[xp(1) yp(1) zp(1) xp(2) yp(2) zp(2) xp(3) yp(3) zp(3) xp(4) yp(4) zp(4) xp(5) yp(5) zp(5) xp(6) yp(6) zp(6) xp(7) yp(7) zp(7) xp(8) yp(8) zp(8) xp(9) yp(9) zp(9) xv(1) yv(1) zv(1) xv(2) yv(2) zv(2) xv(3) yv(3) zv(3) xv(4) yv(4) zv(4) xv(5) yv(5) zv(5) xv(6) yv(6) zv(6) xv(7) yv(7) zv(7) xv(8) yv(8) zv(8) xv(9) yv(9) zv(9)]'; %Initial z for 3d
options = odeset('RelTol',1e-10,'AbsTol',1e-10);
[t z] = ode45('ninebodyrhs', tspan, z00, options);
%The output is a column vector t, with a bunch of times,
% and a matrix z. Each row of z corresponds to one
% time. z has as many rows as t has elements. Each row gives
% the values of all of the components of z at one time.
%Unpack the z matrix into variables you can understand
x0 = z(:,1); y0 = z(:,2); z0 = z(:,3);
x1 = z(:,4); y1 = z(:,5); z1 = z(:,6);
x2 = z(:,7); y2 = z(:,8); z2 = z(:,9);
x3 = z(:,10); y3 = z(:,11); z3 = z(:,12);
x4 = z(:,13); y4 = z(:,14); z4 = z(:,15);
x5 = z(:,16); y5 = z(:,17); z5 = z(:,18);
x6 = z(:,19); y6 = z(:,20); z6 = z(:,21);
x7 = z(:,22); y7 = z(:,23); z7 = z(:,24);
x8 = z(:,25); y8 = z(:,26); z8 = z(:,27);
%plot the trajectories
plot3(x0, y0, z0, x1, y1, z1, x2, y2, z2, x3, y3, z3, x4, y4, z4, x5, y5, z5, x6, y6, z6, x7, y7, z7, x8, y8, z8)
title('Planets orbiting the sun in the solar system')
xlabel('x positions')
ylabel('y positions')
zlabel('z positions')
function zdot =ninebodyrhs(t,z)
% This example is "The planets orbiting the sun."
%G = 2.959233074*365*365*(10^-4);% AU^3 M^-1 yr-2 Gravitational constant
G = 4.498572832*(10.^-12);% kpc^3 M^-1 milyrs-2 Gravitational constant
%M = [1,1.660506399000000e-07,2.448266325000000e-06,3.003288829000000e-06,3.227728747000000e-07,9.545296823999999e-04,2.857956803000000e-04,4.365507531000000e-05,5.149983655999999e-05]';
M = [850000000000,200000000,4000000000,1000000000,20000000000,2000000000,...
1000000000,300000000,15000000,50000000000,114043100.189036,1500000000000]';
%Unpack the column vector z into things one can understand:
%four 2-element column vectors.
%%Positions
r{1} = z(1:3); %Sun
r{2} = z(4:6); %Mercury
r{3} = z(7:9); %Venus
r{4} = z(10:12); %Earth
r{5} = z(13:15); %Mars
r{6} = z(16:18); %Jupiter
r{7} = z(19:21); %Saturn
r{8} = z(22:24); %Uranus
r{9} = z(25:27); %Neptune
v{1} = z(28:30); % Same as above but for velocities
v{2} = z(31:33);
v{3} = z(34:36);
v{4} = z(37:39);
v{5} = z(40:42);
v{6} = z(43:45);
v{7} = z(46:48);
v{8} = z(49:51);
v{9} = z(52:54);
N=9; %Nine bodies
for i=1:N
vdot{i} = [0;0;0];
for j=1:i-1
vdot{i}=vdot{i}+G*M(j)*(r{j}-r{i})./((r{i}-r{j}).'*(r{i}-r{j})).^1.5;
end
for j=i+1:N
vdot{i}=vdot{i}+G*M(j)*(r{j}-r{i})./((r{i}-r{j}).'*(r{i}-r{j})).^1.5;
end
end
zdot= [ v{1}; v{2}; v{3}; v{4}; v{5}; v{6}; v{7}; v{8}; v{9}; vdot{1}; vdot{2}; vdot{3}; vdot{4}; vdot{5}; vdot{6}; vdot{7}; vdot{8}; vdot{9}];
bakınız: [ 'VideoWriter'] (http://www.mathworks.com/help/matlab/ref/videowriter-object.html) komut ve çalışma halinde aşağıdaki hatayı olsun ekleme – excaza