Help with using arrays to create variables
显示 更早的评论
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 个评论
Stephan
2018-10-25
G is missing
Scott Hunter
2018-10-25
Scott Hunter
2018-10-25
Stephan
2018-10-25
Die you try the code from my answer?
采纳的回答
更多回答(0 个)
类别
在 帮助中心 和 File Exchange 中查找有关 Resizing and Reshaping Matrices 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!