Help with using arrays to create variables
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Scott Hunter
am 25 Okt. 2018
Kommentiert: Stephan
am 25 Okt. 2018
I'm trying to use arrays to create variables related to 32 different satellites (which I currently have fully written out it's awful making changes) orbiting a planet and am getting stuck quite early on. As a small example I'm trying to get working, I've got two angles for each satellite (being done in blocks of 8), th0(i) and th(i). The angle th0 works fine, however th relies upon th0 and a parameter, also an angle, called M, which relies on time. As I have 148 timesteps, M is a 148x1 array. When I input my code below, I get an error about the element numbers not matching up. I tried using the transverse of th and th0 but no joy. Can anyone suggest my next move?
%%Relevant parameters
timestep = 600;
G = 6.67408*10^-11; %[m^3kg^-1s^-2]
% Mars data
Mars.m = 6.39*10^23; %[kg]
Mars.mu = Mars.m*G; %[m^3s^-2]
Mars.r = 3389.5*10^3; %[m]
Mars.v = 241.17; %[ms^-1]
Mars.T = (2*pi*Mars.r)/Mars.v; %[s]
Mars.o = Mars.v/Mars.r; %[rads^-1]
Mars.th = Mars.o*timestep; %[rad] for every second
t = (0:timestep:Mars.T)'; %Mars.T, Length of martian day in seconds
H1 = 9610.5*10^3; %[m]
a1 = Mars.r + H1; %[m]
T1 = 2*pi*sqrt(a1^3/Mars.mu); %[s]
n1 = (2*pi)/T1; %[kms^-1]
M1 = n1*t; %[rad]
%%Test Section
th0 = zeros(1,length(t));
th = zeros(1,length(t));
for i = 1:8
th0(i) = deg2rad(45*(i-1));
th(i) = th0(i) + 2*atan(tan(M1/2));
end
4 Kommentare
Akzeptierte Antwort
Stephan
am 25 Okt. 2018
Hi,
try:
%%Relevant parameters
timestep = 600;
G = 6.67408*10^-11;
% Mars data
Mars.m = 6.39*10^23; %[kg]
Mars.mu = Mars.m*G; %[m^3s^-2]
Mars.r = 3389.5*10^3; %[m]
Mars.v = 241.17; %[ms^-1]
Mars.T = (2*pi*Mars.r)/Mars.v; %[s]
Mars.o = Mars.v/Mars.r; %[rads^-1]
Mars.th = Mars.o*timestep; %[rad] for every second
t = (0:timestep:Mars.T)'; %Mars.T, Length of martian day in seconds
H1 = 9610.5*10^3; %[m]
a1 = Mars.r + H1; %[m]
T1 = 2*pi*sqrt(a1^3/Mars.mu); %[s]
n1 = (2*pi)/T1; %[kms^-1]
M1 = n1*t; %[rad]
%%Test Section
th0 = zeros(1,length(t));
th = zeros(1,length(t));
for i = 1:148
th0(i) = deg2rad(45*(i-1));
end
th = th0'+ 2*atan(tan(M1/2));
Best regards
Stephan
4 Kommentare
Weitere Antworten (0)
Siehe auch
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!