pendulum_animation_template.m 508 B

12345678910111213141516171819202122232425262728293031
  1. clear; clc; close all
  2. %-------------------------------------------------
  3. % Pendulum's base position
  4. x0 = 0; y0 = 0;
  5. % Animation loop
  6. figure;
  7. for i = 1:length(t)
  8. % Update pendulum position
  9. % string
  10. hold on
  11. % ball
  12. hold off
  13. axis equal;
  14. xlim([-L, L]); % Set x-axis limits
  15. ylim([-L, 0.5]); % Set y-axis limits
  16. xlabel('x (m)');
  17. ylabel('y (m)');
  18. title(sprintf('Pendulum Animation (Angle = %.0f deg)', rad2deg(theta0)),'FontSize',14);
  19. pause(0.1);
  20. end