Rocking Pendulum

แชร์
ฝัง
  • เผยแพร่เมื่อ 12 ก.ย. 2024
  • Based on realistic calculations

ความคิดเห็น • 5

  • @AvezSharIQ
    @AvezSharIQ  2 ปีที่แล้ว

    clear all
    clc
    function [thetadot] = pend(t,theta)
    % Constants
    m = 1;
    b = 0.05;
    L = 1;
    g = 9.81;
    thetadot = zeros(2,1);
    thetadot(1) = theta(2);
    thetadot(2) = -(b/m)*theta(2) - (g/L)*sin(theta(1));
    end
    % Initial Conditions
    init = [0, 3];
    % Interval
    interval = linspace(0, 20, 20*24); % 20 seconds x 24 frames per second
    % Solve
    [t, theta] = ode45('pend', interval, init);
    for i=1:length(theta)
    % Vertical Reference Line
    x = [0; 0];
    y = [0; -1];
    % Pendulum Position
    x_p = [0; sin(theta(i,1))];
    y_p = [0; - cos(theta(i,1))];
    plot(x,y,x_p, y_p,'LineWidth', 2, x_p(2), y_p(2), 'o', 'MarkerSize', 20, x_p(2), y_p(2), '*', 'MarkerSize', 20)
    time = round(t(i));
    text(-1.2, 1.2, ['Time = ', num2str(time) ])
    xlim([-1.5 1.5])
    ylim([-1.5 1.5])
    legend('Vertical Line', 'Pendulum Position')
    title('Position of Pendulum')
    % For Saving File
    % saveas(gcf,[ num2str(i) '.jpg']);
    end

  • @Ebrahim4Education
    @Ebrahim4Education 2 ปีที่แล้ว

    very nice ❤
    which program used for doing this animation ?

    • @AvezSharIQ
      @AvezSharIQ  2 ปีที่แล้ว +1

      Matlab / Octave

  • @AvezSharIQ
    @AvezSharIQ  2 ปีที่แล้ว

    Run this code in Matlab / Octave to get these results