0% found this document useful (0 votes)
5 views2 pages

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

Code

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

% Define symbolic variables for time t, and position functions

x(t) and y(t)


syms t
x = input('Enter the expression for x(t): ', 's'); % x(t)
y = input('Enter the expression for y(t): ', 's'); % y(t)
% Convert input strings to symbolic expressions
x = str2sym(x);
y = str2sym(y);

% Calculate velocity components (derivatives of x and y)


vx = diff(x, t);
vy = diff(y, t);

% Calculate the position vector and velocity vector


r = [x; y]; % Position vector r
v = [vx; vy]; % Velocity vector v
% Calculate the angular momentum (cross product of position and
velocity vectors)
L = cross([r; 0], [v; 0]); % Extend to 3D for cross product
(z=0)

% Simplify angular momentum expression


Lz = simplify(L(3)); % Only z-component is relevant for 2D
motion
% Plot the trajectory (x vs y)

figure; % Open a new figure window for the graph of x vs y

% Define the time range for plotting


t_vals = linspace(0, 10, 100); % 100 points between t=0 and t=10

% Evaluate x(t) and y(t) over the time range


x_vals = subs(x, t, t_vals);
y_vals = subs(y, t, t_vals);

plot(double(x_vals), double(y_vals)); % Convert symbolic results


to numeric for plotting
title('Trajectory of the Object');
xlabel('x(t)');
ylabel('y(t)');
grid on;

% Plot angular momentum as a function of time

figure; % Open a new figure window for angular momentum

fplot(Lz, [0, 10]); % Adjust time limits for the plot


title('Angular Momentum vs Time');
xlabel('Time (t)');
ylabel('Angular Momentum (Lz)');
grid on;
% Display the angular momentum expression
disp('Angular Momentum Lz(t) = ');
disp(Lz);

You might also like