how to combine two plots in one figure
Mostrar comentarios más antiguos
I have the following code and would like to plot the motion of a particle under the influence of magnetic field with two intensity It should look something like this:
But for some reason my code doesn't show the right sizes:
dt = 1e-2; % time step
mass = 1.0; % mass of particle
charge = 1.0; % charge of particle
n = 500; % number of time steps
%Initial parameters:
v = [0, 1, 0]; % initial velocity
x = [0, 0, 0]; % initial position
B1 = [0, 0, 10];%B = [0, 0, 10]; initial mag. field along z directions
B2 = [0, 0, 2];
E = [0, 0, 0]; % initial E field, for case 1) E = 0 and B =/ 0
X = zeros(n,3); % initialize an array of zeros with size nx3 for positions
V = zeros(n,3);
X1 = zeros(n,3); % initialize an array of zeros with size nx3 for positions
V1 = zeros(n,3);
X2 = zeros(n,3); % initialize an array of zeros with size nx3 for positions
V2 = zeros(n,3);
for time = 1:1:n
[x1,v] = boris_rotation(x,v,charge,mass,dt,B1,E);
[x2,v2] = boris_rotation(x,v,charge,mass,dt,B2,E);
X1(time,:) = x1;
V1(time,:) = v;
X2(time,:) = x2;
V2(time,:) = v2;
end
figure;
plot(X1(:,1),X2(:,2),'k','Linewidth',2);
grid on
hold on
plot(X2(:,1),X1(:,2),'r','Linewidth',2);
I am getting this:

Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Surface and Mesh Plots en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!