Code
Code
function KineticMotion
clear
clc
syms t;
m = input('Input m = ');
r = sqrt(x^2+y^2);
vx = diff(x,t);
vy = diff(y,t);
v = sqrt(vx^2+vy^2);
vector_r = [x y 0];
disp('r = ');
disp(vector_r);
disp('v = ');
disp(vector_v);
L = m*r*v*sin(acos((x*vx+y*vy)/(r*v)));
vector_L = m*cross(vector_r,vector_v);
disp(vector_L)
disp(L);
while 1
T0 = input('Input T0 ');
if T0 > 0
t = 0:1:T0;
subplot(1,2,1);
plot(subs(x),subs(y));
title('Trajectory');
xlabel('x');
ylabel('y');
subplot(1,2,2);
plot(t,subs(sqrt(vector_L*vector_L')));
title('L(t)');
xlabel('t');
ylabel('L');
Break
else
end
end
Step 1: To begin, create the function and enter expressions for x(t) 𝒙 ( 𝒕 ) , y(t) 𝒚
( 𝒕 ) and the mass.
function KineticMotion
clear
clc
syms t;
m = input('Input m = ');
r = sqrt(x^2+y^2);
m = input('Input m = ');
r = sqrt(x^2+y^2);
vx = diff(x,t);
vy = diff(y,t);
v = sqrt(vx^2+vy^2);
vector_r = [x y 0];
disp('r = ');
disp(vector_r);
disp('v = ');
disp(vector_v);
L = m*r*v*sin(acos((x*vx+y*vy)/(r*v)));
vector_L = m*cross(vector_r,vector_v);
disp(vector_L)
disp(L);
Step 4: Plot the trajectory and the change of angular momentum with time.
while 1
T0 = input('Input T0 ');
if T0 > 0
t = 0:1:T0;
subplot(1,2,1);
plot(subs(x),subs(y));
title('Trajectory');
xlabel('x');
ylabel('y');
subplot(1,2,2);
plot(t,subs(sqrt(vector_L*vector_L')));
title('L(t)');
xlabel('t');
ylabel('L');
break
else
end
end