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 allh0 = 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
Best Answer