《MATLAB结课作品设计报告.docx》由会员分享,可在线阅读,更多相关《MATLAB结课作品设计报告.docx(5页珍藏版)》请在第一文库网上搜索。
1、电路中电流流向示例图首先创建坐标系,再关闭坐标抽显示,用p1ot函数搭建好电路图及相关元件,并绘制箭头表示电流的流向。运行程序时,在开关闭合之后,灯泡发出黄色光,箭头开始沿导线移动一圈后停止,开关也相应断开,灯泡黄色光逐渐熄灭。figure(,namH,基本电路的模拟,);axis%3,12,0,10);%建立坐标系ho1don%保持当前图形的所有特性axis(off,);%关闭所有轴标注和控制%下面是画电池的过程行1(卜1515151.5,口,5,5,1,?);%确定坐标轴空围并填充fi11(H)50.5,050.5U5,55555,k);%确定坐标轴范围并填充text(-0.5,1.5/负
2、极);在坐标上标注说明文字texg.53,电池在坐标上标注说明文字texU-0.5,45正极);在坐标上标注说明文字%下面是画导电线路的过程P1ot(0R1556.711oTJinesty1e,),1inewidth/);%绘制二维图形线竖实心红色Pot(0z6.7j6.7co1or7r7inesty1e,-7inewidth4);%绘制二维图形线实心红色为导线a=1ine(4j5z6.7j7.7Jco1or,zb7inesty1eJ,z1inewidthz4erasemodeJxor%画开关蓝色PIOt(5.2;9.2,6.7;6.7810叫匕中优5河司巾出匕4);%绘制图导线为红色p1ot
3、(9.2j9.246.73.7z,1or7r7inesty1e7-,z,1inewidth,z4)绘制图导线竖线为红线p1ot(9.2.7z3.73.71co1or7r7inesty1e7-7inewidthz4);%绘制图导线横线为红色PIot(0;OU1;0810上匕防械51丫,简出匕4);%如上画红色竖线PIot(0;IO10;0COIorIineSty1e,j,IineWidth,4);%如上画横线PIot(10;Io10;3co1or,匕1inesty1e,-Jinewidth,4);%画竖线%下面是画灯泡的过程fi11(9.7,10310,33333,k)%确定填充范围PIOt(9
4、.7,9.713.3,4.3co1orj*Jinesty同JineWidt匕0.5);%绘制灯泡外形线为蓝色p1ot(10.3z10.343.3z4.45co1or7b7inesty1e,7inewidth,z0.5);%绘制灯泡外形线为蓝色%以下为绘圆x=9.7:pi/50:10.3;%绘圆p1ot(x,4.3+0.1*sin(40*pi*(x-9.7),co1or,b,1inesty1ez,-7inewidthz0.5);%绘圆t=0:pi/60:2*pi;%绘圆p1ot(10+0.7*cos(t),43+0.6*sin(t)co1orb);%绘圆%下面是箭头及注释的显示text(4.5,
5、10电流运动方向在坐标上标注说明文字Iine(4.5;6.6,9.4;9.4/Cc)Ior,TJinestyIew1ineWidth,4,erasemode,XOr);%绘制箭头横线1ine(6.7,9.4,co1orb,1inesty1ez,erasemodexormarkersizez10)%绘制箭头三角形pause(1);%下面是开关闭合的过程t=0;y=7.7;whi1ey6.7%电路总循环控制开关动作条件x=4+sqrt(2)*cos(pi4*(1-t);y=6.7sqrt(2)*sin(pi4*(1-t);set(az,dataz4jxydata,z6.7jy);drawnow;t
6、=t+0.1;end%下面是开关闭合后模拟大致电流流向的过程pause(1);Iight=Iinef1O,4.3,co1or,ymarker,z.7markersize,40,erasemode,xor,)j%画灯丝发出的光:黄色%画电流的各部分h=1ine(1j1,5.2j5.6co1or,r7inesty1e-1inewidth,4,erasemodexor,);g=1ine(1,5.7/co1or,/b,/1inesty1e,/A7erasemode,/xor7markersize,z10);%给循环初值t=0;m2=5.7;n=5.7;whi1en6.3;%确定电流竖向循环范围m=1;
7、n=0.05*t+5.7;set(hxdata,zmydata,n-0.5jn-0.1);set(gdatazm,ydata,n);t=t+0.01;drawnow;endt=0;whi1et2;%在转角处的停顿时间m=1.2-0.2*cos(pi4)*t);n=6.3+0.2*sin(pi4)*t);set(hxdata,m-0.5jm-0.1,ydataznjn);set(gz,data,m,ydata,n);t=t+0.05;drawnow;endt=0;whi1et7markersize,10,erasemode,z,xor,);%绘制第二个箭头set(gz,data,1.2ydata
8、,6.5);drawnow;endpause(0.5);t=0;whi1em8%确定第二个箭头的循环范围m=1.1+0.05*t;n=6.5;set(gz,data,m+0.1ydata,z6.5);set(hdata,m-0.4jmzydata46.5j6.5);t=t+0.05;drawnow;endt=0;whi1et2%在转角后的停顿时间m=8.1+0.2*cos(pi2-pi4*t);n=6.3+0.2*sin(pi2-pi4*t);set(gxdata,mz,ydata,zn);set(hxdata,mjmydata,zn+0.1jn+0.5);t=t+0.05;drawnow;e
9、ndt=0;whi1et7markersize,10,erasemode,z,xor,);g=1ine(8.3,6.3co1orb,1inesty1e7v,zmarkersize,z10erasemode,xor);set(gzxdata,8.3ydata,6.3);drawnow;endpause(0.5);t=0;whi1en1%确定箭头的运动范围m=8.3;n=6.3-0.05*t;set(gz,data,m,ydatan);set(hzdata,mimydata,n+0.1+0.5);t=t+0.04;drawnow;endt=0;whi1et2%箭头的起始时间m=8.1+0.2*co
10、s(pi4*t);n=1-0.2*sin(pi4*t);set(gz,data,mz,ydatan);set(hxdata,m+0.m+0.5zydatan);t=t+0.05;drawnow;endt=0;whi1et0.5t=t+O.5;%绘制第四个箭头g=1ine(8.1z0.8,co1orb1inesty1e,z,v7markersize,10erasemode7xor,);g=1ine(8.1,0.8,co1orb,1inesty1e,z,1.2%箭头的运动范围m=8.1-0.05*t;n=0.8;set(gz,data,m,ydatan);set(hz,xdata,zm+0.m+0
11、.5Jydata,n;n);t=t+0.04;drawnow;endt=0;whi1et2%停顿时间m=1.2-0.2*sin(pi4*t);n=1+0.2*cos(pi4*t);set(g,xdata,mz,ydata,zn);set(h,xdata,mjm+0.5ydata4-0.1jn-0.5);t=t+0.05;drawnow;endt=0;whi1et0.5%画第五个箭头t=t+O.5;g=1ine(1,1or,b,1inesty1e,markersize10,erasemode,or,);g=1ine(1/1/,co1or,/b,/1inesty1e,/A,/markersize,
12、z10/erasemode,/,xor,);set(gdata,1ydata,1);drawnow;endt=0;whi1en6.3%循环范围m=1;n=1+0.05*t;set(gzdata,zm,ydatan);set(hz,xdata,rimydata,n-0.5jn-0.1);t=t+0.04;drawnow;end%下面是开关断开后的情况t=0;y=6.7;whi1ey7.7%开关的断开=4+sqrt(2)*cos(pi4*t);y=6.7+sqrt(2)*sin(pi4*t);set(azxdata,z4jxydata,z6.7jy);drawnow;t=t+O.1;endPaUSe(0.5);%开关延时作用no1ight=1ine(10,43,co1or,ymarker,z.,markersize,z40erasemode,xor,);end