global q m B E
[t,y]=ode23(@ddlzfun,[0:0.1:20],...
[0,0.01,0,6,0,0.01],[ ],q,m,B,E)
%用 ode23解微分方程组,时间设为20s
%指定初始条件,传递相关参数
plot3(y(:,1),y(:,3),y(:,5),'linewidth',2)
%绘出三维空间内粒子运动的轨迹,线宽2磅
grid on %开启坐标网格线
xlabel('x')ylabel('y')zlabel('z')
function ydot=ddlzfun(t,y,q,m,B,E) %q,m,B,E为参量
global q m B E
q=1.6e-2m=0.02%为粒子的带电量和质量赋值
B=2E=1%为电磁场的磁感强度和电场强度赋值
ydot=[ y(2)
q*B*y(4)/m
y(4)
q*E/m-q*B*y(2)/m
y(6)
0]
画出一个螺旋线啊!
你看这个有没用t=0:0.01:6*pi
v0x=1
v0y=1
a1=1
y1=v0y*t+0.5*a1*t.*t
x1= v0x*t
a2=cos(t)
y2=v0y*t+0.5*a2.*t.*t
x2= v0x*t
subplot(2,2,3)
plot(x1,y1,'g',x2,y2,'r')
grid on
title('叠加')
legend('匀强电场','周期变化电场',3)
x3=t
y3=cos(t)
z3=sin(t)
for i=1:length(t)
subplot(2,2,1)
plot(x1(1:i),y1(1:i))
axis([0,8,0,30])
grid on
hold on
subplot(2,2,1)
plot(x1(i),y1(i),'r.','markersize',20)
title('匀强电场')
grid on
hold off
subplot(2,2,2)
plot(x2(1:i),y2(1:i))
axis([0,8,-30,30])
title('周期变化电场')
grid on
hold on
subplot(2,2,2)
plot(x2(i),y2(i),'r.','markersize',20)
grid on
hold off
subplot(2,2,4)
plot3(x3(1:i),y3(1:i),z3(1:i))
hold on
grid on
axis([0,10,-1,1,-1,1])
title('匀强电场和磁场')
subplot(2,2,4)
plot3(x3(i),y3(i),z3(i),'r.','markersize',20)
view(-100,500)
hold off
M(i)=getframe
end
movie(M,1)
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)