Bouncing ball's height and velocity!
Afficher commentaires plus anciens
I want to make a graph when the ball drop from the height(20m). I insert what I wanted! I want to know what I do wrong.
clear all
h0 = 20;
v = 0;
g = 10;
t=0;
dt = 0.01;
rho = 0.75;
tau = 0.10 ;
hmax = h0 ;
h = h0;
hstop = 0.01;
freefall = 1;
t_last = -sqrt(2*h0/g);
vmax = sqrt(2 * hmax * g);
H = [];
T = [];
while(hmax > hstop)
if(freefall==1)
hnew = h + v*dt - 0.5*g*dt*dt;
if(hnew<0)
t = t_last + 2*vmax;
freefall = 0;
t_last = t + tau;
h = 0;
else
t = t + dt;
v = v - g*dt;
h = hnew;
end
else
t = t + tau;
vmax = vmax * rho;
v = vmax;
freefall = 1;
h = 0;
end
hmax = 0.5*vmax*vmax/g;
H.append(h);
T.append(t);
end
%% Simulation
plot(time, height, 'r.', 'MarkerSize', 50);
axis([-2, 20, 0 25]); grid;
xlabel('ball position X [m]')
ylabel('ball position Y [m]')
title('TaengTaeng Ball')
drawnow

Réponse acceptée
Plus de réponses (1)
Image Analyst
le 27 Juin 2020
You never defined the "time" vector. Also, you can't do this:
H.append(h);
T.append(t);
since H and T are null and don't have an append method.
Also there is a glaring lack of comments.
Did you try to translate this from another language, or did you write this from scratch in MATLAB?
Catégories
En savoir plus sur General Applications dans Centre d'aide et File Exchange
Produits
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


