%% The movement of charged particles in an electromagnetic field (full image) global q m B E q=1.6e-2; % Charge of particle m=0.02; % Mass of particle B=[2;2;0]; % Magnetic flux density in orthogonal electromagnetic field, single magnetic field, single electric field E=[2;0;2]; % Electric field strength under orthogonal electromagnetic field, single magnetic field, single electric field fig{1}='$E\not= 0,B\not= 0$'; fig{2}='$E=0,B\not= 0$'; fig{3}='$E\not= 0, B=0$'; fori=1:3% Choose a different i, switch between "orthogonal electromagnetic field", "single magnetic field", "single electric field" [t,w]=ode23(@(t,w) odefun1(t,w,q,B(i),m,E(i)),[0:0.01:20],[0,0.01,0,6,0,0.01]); subplot(1,3,i),plot3(w(:,1),w(:,3),w(:,5)); grid on title(fig{i},'fontsize',12,'Interpreter','latex'); xlabel('x'); ylabel('y'); zlabel('z'); end
%% Simulate magnetic focusing t=0:0.01:2*pi; for theta=[-10:2:10]*pi/180; grid on; hold on; % comet3(cos(theta).*t,sin(theta).*(cos(t-pi)+1),sin(theta).*sin(t-pi)); plot3(cos(theta).*t,sin(theta).*(cos(t-pi)+1),sin(theta).*sin(t-pi)); end xlabel('x'); ylabel('y'); zlabel('z'); title('Simulate magnetic focusing')
%% Perpendicular incidence to an ideal conductor clear ,clc E0=1; % The amplitude of the incident wave at z = 0 k1=pi/2; % phase
% Draw the interface between lossless medium and conductor forj=1:180 display(j); z = linspace(-3,3,100); y = linspace(-3,3,100); x = 0.*repmat(z,100,1) + 10000.*repmat(y,100,1); surf(z,y,x); alpha(.3); shading interp hold on plot3 ([-155],[00],[00],'k','LineWidth' ,1); hold on plot3 ([00],[-33],[00],'k','LineWidth' ,1); hold on plot3 ([00],[00],[-33],'k','LineWidth' ,1); hold on xlabel('$z$','FontSize',14,'Interpreter','latex');ylabel('$y$','FontSize',14,'Interpreter','latex');zlabel('$x$','FontSize',14,'Interpreter','latex'); grid on set(gca ,'XLim' ,[-155]); set(gca ,'YLim',[-33]); set(gca ,'ZLim',[-33]); ifj==1 annotation('textbox',... [0.4332142857142860.2785238128843770.179790661449210.0733333299727666],... 'String',{'$\varepsilon_1,\mu_1,\sigma_1=0$'},... 'Interpreter','latex',... 'FontSize',13,... 'EdgeColor','none'); annotation('textbox',... [0.6510714285714280.3937619081224760.1952668559274260.0733333299727666],... 'String',{'$\varepsilon_2,\mu_2,\sigma_2=\infty$'},... 'Interpreter','latex',... 'FontSize',13,... 'EdgeColor','none'); annotation('textbox',[0.630.560.070.09],... 'Color',[0.00,0.45,0.74],... 'String',{'${\vec E_i}$'},... 'Interpreter','latex',... 'FontSize',15,... 'FitBoxToText','off',... 'EdgeColor','none'); annotation('textbox',[0.500.650.070.09],... 'Color',[0.47,0.67,0.19],... 'String','${\vec E}$',... 'Interpreter','latex',... 'FontSize',15,... 'FitBoxToText','off',... 'EdgeColor','none'); annotation('textbox',[0.230.430.070.09],... 'Color',[0.85,0.33,0.10],... 'String','${\vec E_r}$',... 'Interpreter','latex',... 'FontSize',15,... 'FitBoxToText','off',... 'EdgeColor','none'); % Preperation of gif % ax = gca; % ax.Units = 'pixels'; % pos = ax.Position; % ti = ax.TightInset; % rect = [-ti(1), -ti(2), pos(3)+ti(1)+ti(3), pos(4)+ti(2)+ti(4)]; % frame = getframe(ax,rect); % im=frame2im(frame); % k = 1; % [I{k},map{k}]=rgb2ind(im,256); % imwrite(I{k},map{k,1},'lab031.gif','gif','Loopcount',Inf,'DelayTime',0.1); % k = k + 1; end % Preperation of drawing z=linspace ( -15 ,0 ,1000); y=zeros (1 ,1000); % Electric field of incident wave Ei=E0.*cos(-k1.*z+(j./90).*pi); plot3(z,y,Ei ,'Color' ,[0.00,0.45,0.74],'LineWidth' ,1.5); grid on % Electric field of reflected wave Er=-E0.*cos(k1.*z+(j./90).*pi); plot3(z,y,Er ,'Color' ,[0.85,0.33,0.10],'LineWidth' ,1); % Electric field of synthetic wave E=E0.*cos(-k1.*z+(j./90).*pi)+E0.*cos(k1.*z+(j./180).*pi); plot3(z,y,E,'Color' ,[0.47,0.67,0.19],'LineWidth' ,1); M(j) = getframe; hold off % Get GIF % ax = gca; % ax.Units = 'pixels'; % pos = ax.Position; % ti = ax.TightInset; % rect = [-ti(1), -ti(2), pos(3)+ti(1)+ti(3), pos(4)+ti(2)+ti(4)]; % frame = getframe(ax,rect); % im=frame2im(frame); % [I{k},map{k}]=rgb2ind(im,256); % imwrite(I{k},map{k},'lab031.gif','gif','WriteMode','append','DelayTime',0.1); % k = k + 1; end
%% Write the image to the GIF in reverse order % for i = (k-1):-1:1 % imwrite(I{i},map{i},'lab031.gif','gif','WriteMode','append','DelayTime',0.1); % end
%% Function to play animation fori=1:2 movie(M,1,30); end
% --- Executes on button press in stimulate. functionstimulate_Callback(hObject, eventdata, handles) % hObject handle to stimulate (see GCBO) % eventdata reserved - to be defined in a future version of MATLAB % handles structure with handles and user data (see GUIDATA) clc; % frequency and Time omega=10; T=2*pi/omega; % wave speed k k=pi/4; % E_m: maximum of E N=str2double(get(handles.N,'String')); E_m=5+0.1*N; angle=str2double(get(handles.angle,'String')); angle_rad=angle./180.*pi; Em_x=E_m.*cos(angle_rad); Em_y=E_m.*sin(angle_rad); set(handles.Em_x,'String',num2str(Em_x)); set(handles.Em_y,'String',num2str(Em_y)); E_x=[ ];E_y=[ ]; E_max=max(Em_x,Em_y); % phi: phase phi_x=str2double(get(handles.phi_x,'String'))*pi/180; phi_y=str2double(get(handles.phi_y,'String'))*pi/180; delta_phi=phi_y-phi_x; if (mod(delta_phi,pi)==0) set(handles.yanshi,'string','线极化'); elseif (mod(delta_phi,2*pi)==3*pi/2) set(handles.yanshi,'string','右旋圆极化'); elseif (mod(delta_phi,2*pi)==pi/2) set(handles.yanshi,'string','左旋圆极化'); elseif(delta_phi<0) set(handles.yanshi,'string','右旋椭圆极化'); else set(handles.yanshi,'string','左旋椭圆极化'); end % other intinal settings zmin=0; zmax=10.*pi; % Range of z coordinate z=zmin:pi/9:zmax; n=length(z);
% Calculation of drawing the outline of z = 0 plane for t1=0:0.01*T:1*T Ex=Em_x*cos(omega*t1-k.*z+phi_x); Ey=Em_y*cos(omega*t1-k.*z+phi_y); E_x=[E_x Ex(1)];E_y=[E_y Ey(1)]; end z1=zeros(length(E_x));
% Calculation of drawing dynamic simulation diagram for t=0:0.01*T:1*T % Calculate the magnitude of the x and y components of the electric field strength at each point Ex=Em_x*cos(omega*t-k.*z+phi_x); Ey=Em_y*cos(omega*t-k.*z+phi_y); %Plot the contour of the z = 0 plane and the electric field vector at time t axes(handles.axes1);cla(handles.axes1); plot(E_x,E_y,'k-','LineWidth',2); plot(Ex(1),Ey(1),'ro','LineWidth',2); plot ([-Em_x Em_x],[00],'k','LineWidth' ,1); plot (Em_x,0,'k>','LineWidth' ,1,'MarkerFaceColor','k'); plot ([00],[-Em_y Em_y],'k','LineWidth' ,1); plot (0,Em_y,'k^','LineWidth' ,1,'MarkerFaceColor','k'); line([0 Ex(1)],[0 Ey(1)],'Color','r','LineWidth',2); xlabel('$x$','FontSize',14,'Interpreter','latex'); ylabel('$y$','FontSize',14,'Interpreter','latex'); grid on; axis equal; axis([-Em_x,Em_x,-Em_y,Em_y]); hold on % Plot the outline of the z = 0 plane and the three-dimensional map of the electric field vector at time t and the dynamic map of the electric field propagation axes(handles.axes2);cla(handles.axes2); plot3(z1,E_x,E_y,'k-','LineWidth',2); plot3(z,Ex,Ey,'b.-','LineWidth',2); line([00],[0 Ex(1)],[0 Ey(1)],'Color','r','LineWidth',2); plot3(z(1),Ex(1),Ey(1),'ro','LineWidth',2); plot3 ([zmin zmax],[00],[00],'k','LineWidth' ,1); plot3 (zmax,0,0,'k>','LineWidth' ,1,'MarkerFaceColor','k'); plot3 ([00],[-E_max E_max],[00],'k','LineWidth' ,1); plot3 (0,E_max,0,'k<','LineWidth' ,1,'MarkerFaceColor','k'); plot3 ([00],[00],[-E_max E_max],'k','LineWidth' ,1); plot3 (0,0,E_max,'k^','LineWidth' ,1,'MarkerFaceColor','k'); for m=1:1:n line([z(m) z(m)],[0 Ex(m)],[0 Ey(m)],'Color','r','LineWidth',0.5); end grid on; box on; axis([zmin,zmax,-E_max,E_max,-E_max,E_max]); axis equal; xlabel('$z$','FontSize',14,'Interpreter','latex'); ylabel('$x$','FontSize',14,'Interpreter','latex'); zlabel('$y$','FontSize',14,'Interpreter','latex'); view(-30,5); hold on end