How to animate multiple lines at the same time

9 views (last 30 days)
Hey, I have this code and have been using the comet function to animate each line. I want to animate all of the at the same time but have not been able to do so... Anybody have ideas?
clear all
% Initial Values
m = 1.6e-27;%(Kg)
m1 = 1.04e-25;
m2 = 1.04e-26;
d = 0.1; %cm
q = 1.6e-19; %(C)
v = 2e5; %(m/s)
B = 0.01; %Kg/(C)(s)
%Formulas
r= m*v/(B*q);%m
r1= m1*v/(B*q);
r2= m2*v/(B*q);
%Angle
Theta_max = acosd(1-d/(2*r));
Theta_max1 = acosd(1-d/(2*r1));
Theta_max2 = acosd(1-d/(2*r2));
%Point of Impact
x_max= r*sind(Theta_max); %m
x_max1= r1*sind(Theta_max1); %m
x_max2= r2*sind(Theta_max2); %m
%Graph
theta=0:0.1:Theta_max;
theta1=0:0.1:Theta_max1;
theta2=0:0.1:Theta_max2;
x=r*sind(theta);
x1=r1*sind(theta1);
x2=r2*sind(theta2);
y=r-r*cosd(theta);
y1=r1-r1*cosd(theta1);
y2=r2-r2*cosd(theta2);
figure(3)
plot(x,-y)
title('movement of a particle through a magnetic field')
xlabel('x(m)')
ylabel('y(m)')
hold on
plot(x1,-y1)
hold on
plot(x2,-y2)
hold off

Accepted Answer

KSSV
KSSV on 10 Jun 2020
clear all
% Initial Values
m = 1.6e-27;%(Kg)
m1 = 1.04e-25;
m2 = 1.04e-26;
d = 0.1; %cm
q = 1.6e-19; %(C)
v = 2e5; %(m/s)
B = 0.01; %Kg/(C)(s)
%Formulas
r= m*v/(B*q);%m
r1= m1*v/(B*q);
r2= m2*v/(B*q);
%Angle
Theta_max = acosd(1-d/(2*r));
Theta_max1 = acosd(1-d/(2*r1));
Theta_max2 = acosd(1-d/(2*r2));
%Point of Impact
x_max= r*sind(Theta_max); %m
x_max1= r1*sind(Theta_max1); %m
x_max2= r2*sind(Theta_max2); %m
%Graph
M = 500 ;
theta=linspace(0,Theta_max,M);
theta1=linspace(0, Theta_max1,M);
theta2=linspace(0,Theta_max2,M);
x=r*sind(theta);
x1=r1*sind(theta1);
x2=r2*sind(theta2);
y=r-r*cosd(theta);
y1=r1-r1*cosd(theta1);
y2=r2-r2*cosd(theta2);
figure(3)
plot(x,-y)
title('movement of a particle through a magnetic field')
xlabel('x(m)')
ylabel('y(m)')
hold on
plot(x1,-y1)
hold on
plot(x2,-y2)
hold off
X = [x ; x1 ;x2]' ;
Y = [-y ; -y1 ; -y2]' ;
%Animate
for i = 1:M
plot(X(1:i,:),Y(1:i,:),'r')
drawnow
end

More Answers (0)

Categories

Find more on Animation in Help Center and File Exchange

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!