Bouncing ball's height and velocity!
이전 댓글 표시
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

채택된 답변
추가 답변 (1개)
Image Analyst
2020년 6월 27일
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?
카테고리
도움말 센터 및 File Exchange에서 MATLAB에 대해 자세히 알아보기
제품
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


