资源描述:
《有趣的matlab动画演示程序汇总》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、MATLAB动画演示程序汇总1.弹性蹦球演示程序figure(1);%定义函数axis([-5.1,5,-0.05,1.05]);%绘制二维图形holdon;%保持当前图形及轴系所有的特性axis('off');%覆盖坐标刻度,并填充背景%通过填充绘出台阶及两边的挡板fill([4.12,4.22,4.22,4.12],[-0.05,-0.05,1.05,1.05],'y');fill([-5,-3.2,-3.2,-5],[-0.05,-0.05,0,0],'g');fill([-3.2,-2.8,-2.8,-3.2],[-0.05,-0.05,0.2,
2、0.2],'g');fill([-3.2,-1.4,-1.4,-3.2],[0.2,0.2,0.25,0.25],'g');fill([-1.4,-1,-1,-1.4],[0.2,0.2,0.45,0.45],'g');fill([-1.4,0.4,0.4,-1.4],[0.45,0.45,0.5,0.5],'g');fill([0.4,0.8,0.8,0.4],[0.45,0.45,0.7,0.7],'g');fill([0.4,2.0,2.0,0.4],[0.7,0.7,0.75,0.75],'g');fill([2.0,2.3,2.3,2.0],[
3、-0.05,-0.05,0.75,0.75],'g');fill([2.3,4.12,4.12,2.3],[-0.05,-0.05,0,0],'g');%x2=line([-5,5],[0.25,0.25],'color','g','linestyle','-','markersize',50)%设置台阶边框线,颜色,擦试方式%line([-5,5],[0.5,0.5],'color','b','linestyle','-','markersize',50)%设置球与地面接触面的颜色,擦试方式%line([-5,5],[0.75,0.75],'color
4、','b','linestyle','-','markersize',50)%设置球与地面接触面的颜色,擦试方式head=line(-5,1,'color','r','linestyle','.','erasemode','xor','markersize',60);%设置小球颜色,大小,线条和擦试方式%body=line(-5,1,'color','b','linestyle','-','erasemode','none');%描绘轨迹线%设置初始条件while1t=4;dt=0.001;w=0;dw=0.001;w=0;%设置球弹起的初始位置%设置球
5、弹起的高度whilet<=4.12t=dt+t;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=0;%设置球弹起的初始位置%设置球弹起的高度whilet>=2.11t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xda
6、ta',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=0;%设置球弹起的初始位置%设置球弹起的高度whilet>=1.11t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)/4+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=-0.71;%设置球弹起的初始位置%设置球弹起的高度whilet>=-0.62t=t-dt;ifw<=1w=dw+w;elsew=-1;
7、endy=(-w*w)/2+1;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end%结束程序w=-0.71;%设置球弹起的初始位置%设置球弹起的高度whilet>=-2.31t=t-dt;ifw<=1w=dw+w;elsew=-1;endy=(-w*w)/2+0.75;set(head,'xdata',t,'ydata',y);%设置球的运动%set(body,'xdata',t,'ydata',y);%描绘轨迹线drawnow;end
8、%结束程序w=-0.71;%设置球弹起的初始位置%设置球弹起的高度whilet>