0% found this document useful (0 votes)
6 views

Code

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Code

Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Full MATLAB code of this project:

function KineticMotion

clear

clc

syms t;

% Input the coordinates equation and the mass

x = input('Input x(t) = ');

y = input('Input y(t) = ');

m = input('Input m = ');

r = sqrt(x^2+y^2);

% Finding the velocity vector and position vector

vx = diff(x,t);

vy = diff(y,t);

v = sqrt(vx^2+vy^2);

vector_r = [x y 0];

vector_v = [vx vy 0];

disp('r = ');

disp(vector_r);

disp('v = ');

disp(vector_v);

% Finding momentum vector and magnitude of angular momentum

L = m*r*v*sin(acos((x*vx+y*vy)/(r*v)));

vector_L = m*cross(vector_r,vector_v);

disp('Momentum vector L is ');

disp(vector_L)

disp('Magnitude of angular momentum: ');

disp(L);

% Sketch the graph

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

disp('T0 must be larger than 0');

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;

% Input the coordinates equation and the mass

x = input('Input x(t) = ');

y = input('Input y(t) = ');

m = input('Input m = ');

r = sqrt(x^2+y^2);

Step 2: Calculate the velocity and position vector.

% Input the coordinates equation and the mass

x = input('Input x(t) = ');


y = input('Input y(t) = ');

m = input('Input m = ');

r = sqrt(x^2+y^2);

% Finding the velocity vector and position vector

vx = diff(x,t);

vy = diff(y,t);

v = sqrt(vx^2+vy^2);

vector_r = [x y 0];

vector_v = [vx vy 0];

disp('r = ');

disp(vector_r);

disp('v = ');

disp(vector_v);

Step 3: Calculate the momentum vector and magnitude of angular momentum.

% Finding momentum vector and magnitude of angular momentum

L = m*r*v*sin(acos((x*vx+y*vy)/(r*v)));

vector_L = m*cross(vector_r,vector_v);

disp('Momentum vector L is ');

disp(vector_L)

disp('Magnitude of angular momentum: ');

disp(L);

Step 4: Plot the trajectory and the change of angular momentum with time.

% Sketch the graph

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

disp('T0 must be larger than 0');

end

end

You might also like