This code will demonstrate from equations of motion of simple harmonic motion that SHM is a type of circular motion.



clear all       % Clears the workspace
close all       % Close all previous plots and figures
clc             % Clears the command window


N = 1080;       % Declare total phase of oscillation
A0 = 10;        % Declare amplitude
theta(1) = 0;   % Initial value of theta


for i=1:N;      % For loop to find phase angle
    theta(i+1) = theta(i) + 1;



    alpha(i) = (pi/180) * theta(i+1);


end



for i=1:N;      
    x(i) = A0 * cos(alpha(i));     % Position equation of first SHO
    y(i) = A0 * sin(alpha(i));     % Position equation of second SHO
end

for i=1:N;      
    vx(i) = - A0 * sin(alpha(i));  % Velocity equation of first SHO
    vy(i) = A0 * cos(alpha(i));    % Velocity equation of second SHO
end

for i=1:N  
    ax(i) = - A0 * cos(alpha(i));  % Acceleration equation of first SHO
    ay(i) = - A0 * sin(alpha(i));  % Acceleration equation of second SHO
end

figure(1);
hold on     

    plot(alpha,x,'linewidth',1.5)   % LineWidth sets the width of line.
    plot(alpha,y,'linewidth',1.5)
    xlabel('Phase Angle')   % xlabel('text') adds text beside the X-axis.
    ylabel('Amplitude')     % ylabel('text') adds text beside the Y-axis.
    ylim([-12 12])          % ylim([YMIN YMAX] sets the y limits.
    legend('x(i)','y(i)')
    title('Phase Angle vs. Position (in SHM)')
    grid on                 % grid ON adds major grid lines.
hold off    


figure(2);
hold on
    plot(alpha,vx,'linewidth',1.5)
    plot(alpha,vy,'linewidth',1.5)
    xlabel('Phase Angle')
    ylabel('Velocity')
    ylim([-12 12])
    legend('v_{x}(i)','v_{y}(i)')
    title('Phase Angle vs. Velocity (in SHM)')
    grid on
hold off

figure(3);
hold on
    plot(alpha,ax,'linewidth',1.5)
    plot(alpha,ay,'linewidth',1.5)
    xlabel('Phase Angle')
    ylabel('Acceleration')
    ylim([-12 12])
    legend('a_{x}(i)','a_{y}(i)')
    title('Phase Angle vs. Acceleration (in SHM)')
    grid on
hold off

figure(4);
    plot(x,y,'linewidth',1.5)
    xlabel('x(t)')
    ylabel('y(t)')
    xlim([-12 12])
    ylim([-12 12])
    title('Simple Harmonic Motion as Circular Motion')
    grid on

figure;

subplot(3,1,1)          
title('Phase Angle vs. Position, Velocity and Acceleration (in SHM)');
hold on
    plot(alpha,x,'linewidth',1.5)
    plot(alpha,y,'linewidth',1.5)
    ylabel('Amplitude')
    ylim([-12 12])
    legend('x(i)','y(i)')
    grid on
hold off


subplot(3,1,2)
hold on
    plot(alpha,vx,'linewidth',1.5)
    plot(alpha,vy,'linewidth',1.5)
    ylabel('Velocity')
    ylim([-12 12])
    legend('v_{x}(i)','v_{y}(i)')
    grid on
hold off


subplot(3,1,3)
hold on
    plot(alpha,ax,'linewidth',1.5)
    plot(alpha,ay,'linewidth',1.5)
    xlabel('Phase Angle')
    ylabel('Acceleration')
    ylim([-12 12])
    legend('a_{x}(i)','a_{y}(i)')
    grid on
hold off

Generated plots will be like these.

Phase Angle vs. Position, Velocity and Acceleration

Simple Harmonic Motion as Circular Motion

Share: