# Thread: MATLAB - Need Help

1. ## MATLAB - Need Help

Hi guys! I have to write a program to simulate a jump with a parachute, actually i have written a part without opening the parachute. But if I try running it I keep getting this error:

??? Error using ==> plus
Matrix dimensions must agree.

Error in ==> parachute at 24
s=[s,s+ds];
My source code:

Code:
clear all
m=90;               % mass of jumper
cm=0.43;            % cw-Value (value of the air-resistance)
Am=1;               % "surface area" of jumper
g=9.81;
roh=1.2929;         % density air
dt=1;               % at which interval values will be calculated

h=2000;             % total height

k=(cm*Am*roh)/2;    % constant part of the formula for acceleration with air-resistance
a=g;                % a at beginning
v=0;                % v at beginning
t=0;                % t at beginning
s=0;                % s(height jumper already passed) at beginning

% jump's duration
ti=h/(sqrt(2*m*g/(cm*Am*roh)));
ti=floor(ti);

for t=1:dt:ti
ds=v*dt;
s=[s,s+ds];
a=[a,g-(k/m)*v^2];
dv=a*dt;
v=[v,v+dv];
t=[1:0.1:ti];
end

plot(t,v,'b')
grid on
hold on
plot(t,a,'r')
grid on
hold on
I'd be very happy if someone could help me.

Sorry if my English isn't really good at some points, even so I hope you can understand it

Best regards,
unique

2. Code:
% jump's duration
ti=h/(sqrt(2*m*g/(cm*Am*roh)));
ti=floor(ti);

for t=1:dt:ti
ds=v*dt;
s=[s,s+ds];
a=[a,g-(k/m)*v^2];
dv=a*dt;
v=[v,v+dv];
t=[1:0.1:ti];
end
you are effectivly redefiining the loop control variable inside the loop, and I don't care if it is allowed you should never do it. The other thing is what do you think this actualy does?

Second by the look of it you are continualy appending new elements on the end of your vectors, this is very wastefull of processing time and power, you know how big the arrays are going be so create them that size.

RonL

3. Thanks a lot for your help!
Now I first create all the vectors with the right length and after I fill in the values.

Works fast and good now
Later I'll (try to) add the part while opening the parachute.