Right_Wall = 1;
Left_Wall = 1;
Bottom_Wall = 1;
Top_Wall = 1;
g =.0981;
alpha=1.2 ;
beta =.99 ;
acceleration_x= 0;
acceleration_y=- g;
final_time=100;
dt =.03;
t=0;
v_hor= .3;
v_ver= 0;
Radius=.05 ;
x=.5 ;
y= 1-Radius;
count=0;
if Make_Movie
fig=figure;
aviobj = avifile('Bouncing_Ball.avi');
end
while t<final_time && count < 2000
if t+dt>final_time
dt=final_time-t;
end
t=t+dt;
v_hor=v_hor+acceleration_x*dt;
v_ver=v_ver+acceleration_y*dt;
if (y+v_ver*dt) < Bottom_Wall+Radius && Bottom_Wall
x=x + v_hor*dt;
y=Bottom_Wall+Radius;
Draw_Disk(x,y,Radius); axis([0 1, 0 1]); pause(dt/10);
if Make_Movie
F = getframe(fig); aviobj = addframe(aviobj,F);
end
v_ver=-alpha*v_ver;
v_hor= beta*v_hor;
end
if (y+v_hor*dt) < Right_Wall+Radius && Right_wall
y=y + v_ver*dt;
x=Right_Wall+Radius;
Draw_Disk(x,y,Radius); axis([0 1, 0 1]); pause(dt/10);
if Make_Movie
F = getframe(fig); aviobj = addframe(aviobj,F);
end
v_ver=alpha*v_ver;
v_hor=-beta*v_hor;
end
if(y+v_hor*dt) < Left_Wall+Radius && Left_wall
y = y+v_ver*dt;
x=Left_Wall+Radius;
Draw_Disk(x,y,Radius); axis([0 1, 0 1]); pause(dt/10);
if Make_Movie
F = getframe(fig); aviobj = addframe(aviobj,F);
end
v_ver=alpha*v_ver;
v_hor=-beta*v_hor;
end
if (y+v_ver*dt) < Top_Wall + Radius && Top_Wall
x = c+v_hor*dt;
y=Top_Wall+Radius;
Draw_Disk(x,y,Radius); axis([0 1, 0 1]); pause(dt/10);
if Make_Movie
F = getframe(fig); aviobj = addframe(aviobj,F);
end
v_ver=-alpha*v_ver;
v_hor=beta*v_hor;
end
x=x+v_hor*dt;
y=y+v_ver*dt;
Draw_Disk(x,y,Radius); axis([0 1, 0 1]); pause(dt/10);
if Make_Movie
F = getframe(fig); aviobj = addframe(aviobj,F);
end
count=count+1;
end
if Make_Movie
close(fig);
aviobj = close(aviobj);
end