So I have this for while loop that I am calculating, and what I think is the problem is that it's trying to stuff 121 values into one definition. However when I do things by hand it should equal to 0 whilst n is 1 at the moment. So my ax where the line errors shoiuld become 0. As tn = (n-1)*T with T being .005. If N is 1, then 1-1) * .005 should still be 0, so the Dn line will be 0 whilst N is 1, the next line V will be 50 as square root of 2500 is 50. So my ax(n) is equal to -0 * vx (which has v0 defined as 50) * v(defined as 50 in the previous line). Ax(1) = -0*50*50, which should become 0 whilst N is one. So I'm half puzzled as to why it's giving me the error (stated in title), Im guessing it's trying to put one of these 1x121 doubles into it, but im not sure why...
As always I really appreciate the help I get. It is late when posting this, so my apologies if I do not accept your answer straight away. Thank you to the Matlab forums for the continued help in my coding, learning lots with your support which is greatly appreciated!
clc
clear
p = 1.2;
g = 9.81;
m = 77;
c = 1;
a1 = .7;
a2 = 50;
t1 = 50;
t2 = 70;
h0 = 50;
T = .005;
v0 = 50;
tmid = (t1+t2)/2;
tA = 0:120;
if tA<=tmid
Area = a1;
else Area = a2;
Area = 1/2*(a2-a1)*tanh(10.*((tA-tmid)/((t2-t1))))+(1/2*(a2+a1));
end
D = p*c.*Area /2*m;
plot(tA, Area, 'b-', 50, .7, 'ro', 70, 50, 'ro')
axis([0 120, .6 70]);
xlabel('Time')
ylabel('Area')
title('Area over Time')
x(1) = 0;, vx(1) = v0;, y(1) = 0;, vy(1) = 0;
for n=1
while 1
if y(n) > h0, break; end
tn = (n-1)*T;
tA(n) = tn;
Dn = D.*(tn);
v = sqrt(vx(n)^2+vy(n)^2);
ax(n) = -Dn * vx(n) *v;
ay(n)= -D*vy*v(n)+g;
x(n+1) = x(n)+T*vx(n);
vx(n+1)= vx(n)+T*ax(n);
y(n+1)=y(n)+T*vy(n);
vy(n+1)= vy(n)+T*ay(n);
n = n+1;
end
end
Vc = sqrt(g/D)
plot(tA,ay(tA), 'b-', tA, ax(tA), 'r-');
0 Comments
Sign in to comment.