Plotting Orbitals error help
Afficher commentaires plus anciens
I keep getting error message
Index in position 1 exceeds array bounds (must not exceed 1).
Error in Stricklin_Assignment5pt3 (line 43) (surronded by % %)
ccd =((X(i,n) - X(i,m))^2 + (Y(i,n) - Y(i,m))^2);
and I can't seem to fix it. Any help is appreciated.
%This program is intended to simulate planets orbiting the same star
%and how their masses interact with each other.
clc
clear all
close all
G = 6.67e-11;
%gravitational constant of our sun
m = [1.99e30 3.3e23 4.87e24 5.97e24 6.42e23 1.89e27 5.68e26 8.68e25 1.02e26 1.46e22];
%masses of our planets in kg, including the sun
r = [5.79e7 1.08e8 1.49e8 2.27e8 7.79e8 1.43e9 2.87e9 4.50e9 5.91e9];
%radii of planets from the sun in km
phi = [0 35 60 80 120 197 207 296 300 325];
%initial angle, chose arbitrary values in degrees
vinit = sqrt(G*m(1)./r);
%initial velocity
vvinit = [0 vinit];
%sun's initial velocity
rr = [0 r];
%puts sun radius at 0
X(1,:) = rr.*cosd(phi);
Y(1,:) = rr.*sind(phi);
%initial positions for the 9 planets
vx(1,:) = -vvinit.*sind(phi);
vy(1,:) = vvinit.*cosd(phi);
%initial velocities
dT = 86000;
%time step
for i = 1:730;
for n = 1:10;
ccx = 0;
ccy = 0;
for m = 1:10;
if n == m;
continue
end
%
ccd =((X(i,n) - X(i,m))^2 + (Y(i,n) - Y(i,m))^2);
%
ccx = (-G*(X(i,n) - X(i,m))) / (ccd^(3/2)) + ccx;
ccy = (-G*(Y(i,n) - Y(i,m))) / (ccd^(3/2)) + ccy;
end
vx(i+1, n) = vx(i,n) +ccx(i)*dT;
vy(i+1, n) = vy(i,n) +ccy(i)*dT;
end
end
plot(X,Y)
2 commentaires
KSSV
le 13 Mar 2019
YOu need to rethink on your code....
i = 1:730;
not correct..there is no arrray with such rows/ columns.
Hayden Stricklin
le 13 Mar 2019
Réponses (0)
Catégories
En savoir plus sur Earth and Planetary Science dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!