How do I keep my array size consistent?

2 次查看(过去 30 天)
I'm working on a school project where I need to calculate the time it takes to fall through the earth, by calculating it through iterations. So the first iteration would using the radius of the earth to find the final velocity at the center of the earth and then from there calculate the time it takes to get there and back. Then the next iteration would split the distance in half and then using half the radius and then half the acceleration for the second part. The problem Im having is that my array that saves the ,information from the calculations, keeps changing in size from the pre-allocation and in doing so prevents me from subtracting the arrays from each other. So if someone could take a look at my code and see what I'm doing wrong it would be greatly appreciated. Also if anyone could give me any tips for MATLAB that'd really help this is my first time using it.
prompt={'Enter the number of N'};
name = 'Number of Runs';
answer = inputdlg(prompt,name);
q = str2num(answer{1});
V_O = 0;
R = 6371000;
figure(1); hold on
valueofVF = zeros(1,q);
valueoft_t = zeros(1,q);
valueoft = zeros(1,q);
valueoft2 = zeros(1,q);
valueoft3 = zeros(1,q);
for n = 1:q
for i = 1:n
if i > 1
V_O = valueofVF(i-1);
end
V_f = sqrt(((9.81*(i/n))* 2 * (R/n)) + (V_O)^2);
valueofVF(i) = V_f;
for m = 1:n
t = V_f/(V_O + (9.81*(m/n)));
valueoft(n) = t;
end
valueoft2 = valueoft(1:2:end,1:2:end);
valueoft3 = valueoft(1:3:end,1:3:end);
valueoft_t(n) = (sum(valueoft) * 4)/60;
end
plot(i,valueoft_t(n),'.k','markersize', 10);
end
hold off
  1 个评论
Walter Roberson
Walter Roberson 2018-2-14
I do not encounter a problem when I paste in your code and integers like 10 or 128 ?

请先登录,再进行评论。

回答(0 个)

类别

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

标签

Community Treasure Hunt

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

Start Hunting!

Translated by