资源描述
电路中电流流向例如图
首先创立坐标系,再关闭坐标抽显示,用plot函数搭建好电路图及相关元 件,并绘制箭头表示电流的流向。运行程序时,在开关闭合之后,灯泡发出黄色 光,箭头开始沿导线移动一圈后停止,开关也相应断开,灯泡黄色光逐渐熄灭。 figureCname1」基本电路的模拟。;axis([-3」2Q」0]);%建立坐标系
hold on %保持当前图形的所有特性axis('off'); %关闭所有轴标注和控制
%下面是画电池的过程fill([-l.5,-15151.5UL551]「y,);%确定坐标轴范围并填充 fill([-0.5,-0.5/0.5,0.5],[5,5.5,5.5,5];k,); %确定坐标轴范围并填充 text(-0.5,l.5/负极,);%在坐标上标注说明文字
text(-0.5,3/电池');%在坐标上标注说明文字text(-0.5,45'正极,);%在坐标上标注说明文字
%下面是画导电线路的过程plot([0;0U5.5;6.7],Eolor1,匕,1访651丫心,-1,linewidth1,4);% 绘制二维图形线竖实心红 色
plot([0;4]46.7;6,刀「colo'E'linestyle'JTIinewidth'M); %绘制二维图形线实心红 色为导线_a=line([4;5]/[6.7;7.7],,color,,,b,,,linestyle,,,-7linewidth,,4,,erasemode,7,xor,);% 画开关 蓝色
plot([5.2;9.2U6・7;6.刀,,color,,匕,linestyle,「-,,Ilinewidth,,4);%绘制图导线为红色 plot([9.2;9.2],[67;3.7];color7r7linestyle7-7linewidth\4);% 绘制图导线竖线为红 线plot([9.2;9.7U3.7;3.7]「color'「rVlinestylHE'linewidth',4); % 绘制图导线横线为红 色
plot([0;0]/l;0]「color,匕'linestyle'「-'「linewidth',4);% 如上画红色竖线 plot([0;10],[0;0],,color,7,r,,llinestyle,,,-,,,linewidth,/4);%$nJLiii11t^ plot([10;10U0;3]「color,,,r,「linestyle,u「linewidth,,4);% 画竖线%下面是画灯泡的过程
fill([9.7,10310L[33333L,k,);% 确定填充范围,color,,,b:,linestyle,「-'「linewidth,,0.5);% 绘制灯 泡外形线为蓝 色
plot([103403],[33A45],,color,,,b',,linestyle,,,J,,linewidth,,0.5); %绘制灯泡外形线 为蓝色%以下为绘圆
乂二9・7个"50:10.3;%绘圆plot(x,4.3+0.l*sin(40*pi*(x-9.7)),'color','b',linestyle',^'/linewidth^O.5); %绘圆
t=0:pi/60:2*pi; %绘圆plot(10+0.7*cos(t),4.3+0.6*sin(t),'color1,'b'); %绘圆
%下面是箭头及注释的显示text(4510「电流运动方向,);%在坐标上标注说明文字
line([4.5;6.6]/[9.4;9,4],,color,,lr,,llinestyle,,,-,,,linewidth,/47,erasemodel,,xor,);%^^lJ W 头横线line(6.7,9.4,'color','b','linestyle','erasemode','xor'/markersize',10);% %绘制箭头三 角形
pause(l);%下面是开关闭合的过程
t=0;y=7.7;
while y>6.7 %电路总循环控制开关动作条件
x=4+sqrt(2)*cos(pi/4*(l-t));
y=6.7+sqrt(2)*sin(pi/4*(l-t));
set(a「xdata'J4;x]「ydata'46.7;y]);
drawnow;
t=t+0.1;end
%下面是开关闭合后模拟大致电流流向的过程pause(l);
light=line(10,4.3,^olor'/y','marker1,\Vmarkersize'^O/erasemode'/xor');% 画灯丝发 出的光:黄色%画电流的各局部
h=line([l;l],[5.2;5.6],,color'/,r,,,linestyle7-,,,linewidth,,4,,erasemode,,,xor,);g=line(l,5.7,,color,,,b,,,linestyle,,,A,,,erasemode','xor,,,markersize,,10);
%给循环初值t=0;
m2=5.7;n=5.7;
while n<6.3;%确定电流竖向循环范围
m=l;
n=0.05*t+5.7;
set(h,,xdata,,[m;m],,ydata,,[n-0.5;n-0.1]);
setfg/xdata\m/ydata^n);
t=t+0.01;drawnow;
endt=0;
while t<2;%在转角处的停顿时间
m=1.2-0.2*cos((pi/4)*t);
n=6.3+0.2*sin((pi/4)*t);
set(h「xdata'/m-0.5;m-0.l]「ydata'/n;n]);
set(g,,xdata,,m,,ydata,,n);
t=t+0.05;drawnow;
endt=0;
while t<0.5 %在转角后的停顿时间
t=t+0.5;
g=line(1.2,6.5,,color,,,b,,,linestyle,,'A,,'markersize,,10,,erasemode,,,xor,);%^$iJM 二个箭头
g=line(1.2,6.5,,color,,,b,,,linestyle,,'>,,,markersize,,10,,erasemode,,,xor,); % 绘制 第二个箭头
set(g「xdata',1.2「ydata',6.5);drawnow;
endpause(0.5);
t=0;while m<8%确定第二个箭头的循环范围
m=l.l+0.05*t;
n=6.5;
set(g「xdata',m+0.l「ydata',6.5);
set(h「xdata'/m-0.4;m]「ydata'16.5;6.5]);
t=t+0.05;drawnow;
endt=0;
while t<2 %%在转角后的停顿时间
m=8.1+0.2*cos(pi/2-pi/4*t);
n=6.3+0.2*sin(pi/2-pi/4*t);
set(g/xdata,/m/ydata',n);
set(h「xdata'Jm;m]「ydata'Jn+O.l;n+O,5]);
t=t+0.05;drawnow;
endt=0;
while t<0.5 %在转角后的停顿时间
t=t+0.5;%绘制第三个箭头
g=line(8.3,6.3,,color,,,b,,,linestyle7>',,markersize,,10,,erasemode,,,xor,);
g=line(8.3,6.3,'color','b'/linestyle'/v'/markersize',10,'erasemode','xor');
set(g/xdata,/8.3/ydata',6.3);drawnow;
endpause(0.5);
t=0;while n>l %确定箭头的运动范
m=8.3;
n=6.3-0.05*t;
setfg/xdata\m/ydata^n);
set(h,,xdata,,[m;m],'ydata,/[n+0.1;n+0.5]);
t=t+0.04;drawnow;
endt=0;
while t<2 %箭头的起始时间
m=8.1+0.2*cos(pi/4*t);
n=l-0.2*sin(pi/4*t);
setfg/xdata\m/ydata^n);
set(h「xdata'Jm+0.l;m+0.5]「ydata'」n;n]);
t=t+0.05;drawnow;
endt=0;
while t<0.5
t=t+0.5;%绘制第四个箭头
g=line(8.1,0.8,,color,7,b,,,linestyle,,,v,,,markersize,,10,,erasemode,,,xor,); g=line(8.1,0.8,,color,,,b,,,linestyle,/<,,,markersize,,10/erasemode,,,xor,); setfg/xdata^S.l/ydata^O.S);drawnow;
endpause(0.5);
t=0;while m>1.2 %箭头的运动范围
m=8.1-0.05*t;
n=0.8;
setfg/xdata\m/ydata^n);
set(h/xdata',[m+0.1;m+0.5]/ydata',[n;n]);
t=t+0.04;drawnow;
endt=0;
while t<2 %停顿时间
m=1.2-0.2*sin(pi/4*t);
n=l+0.2*cos(pi/4*t);
set(g,,xdata'/m,,ydata,,n);
set(h「xdata'Im;m+0.5]「ydata'」n-0.l;n-0.5]);
t=t+0.05;drawnow;
endt=0;
while t<0.5 %画第五个箭头
t=t+0.5;
g=line(l,l,'color','b','linestyle^^'/markersize',10,'erasemode'/xor');
g=line(l,1,,color,,,b,,,linestyle,/A,,'markersize',10,'erasemodeVxor');
setfg/xdata\l/ydata',!);drawnow;
endt=0;
while n<6.3 %循环范围
m=l;
n=l+0.05*t;
setfg/xdata\m/ydata^n);
set(h「xdata'Jm;m]「ydata'1n-0.5;n-0.l]);
t=t+0.04;drawnow;
end%下面是开关断开后的情况
t=0;y=6.7;
while y<7.7 %开关的断开
x=4+sqrt(2)*cos(pi/4*t);
y=6.7+sqrt(2)*sin(pi/4*t);
set(a「xdata',[4;x]/ydata'46.7;y]);
drawnow;
t=t+0.1;end
pause(0.5);%开关延时作用nolight=line(10,4.3/color',,y,,'marker'/.'/markersize'^O/erasemode'/xor'); end
展开阅读全文