Help with using arrays to create variables

1 次查看(过去 30 天)
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 个评论
Scott Hunter
Scott Hunter 2018-10-25
Update;
If I change the test section to
th0 = zeros(1,length(t));
th = zeros(1,length(t));
for i = 1:8
th0(1,i) = deg2rad(45*(i-1));
th(1,i) = th0(1,i) + 2*atan(tan(M1/2));
end
I end up with "Unable to perform assignment because the size of the left side is 1-by-1 and the size of the right side is 148-by-1."
Can't figure out what the 1 by 1 is?

请先登录,再进行评论。

采纳的回答

Stephan
Stephan 2018-10-25
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 个评论
Scott Hunter
Scott Hunter 2018-10-25
编辑:Scott Hunter 2018-10-25
Sorry yes I thought I had to do that to get it to work, here's my most recent attempt;
th0 = zeros(1,32);
th = zeros(1,32);
for i = 1:8
th0(i) = deg2rad(45*(i-1));
end
th = th0 + 2*atan(tan(M1/2));
This gives me a 148x32 which is progress! Not sure where to go next but I'll keep bashing on! Thanks for your help!
Stephan
Stephan 2018-10-25
If my answer was useful for you please accept it. I wish you success.

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Graphics 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by