Project

Solving Second Order ODE - Pendulum_Dampless

Pendulum_No_Damping Main Code

clear all;
close all;
clc;

%input variabes
g = 9.81; % m/s^2
l = 1; %m
m = 0.5; %kg
w = g/(m*l);

%initial conditions
theta_initial = [0; 10];

%time condition
time1 = linspace(0,0.5,500);

[t, results] = ode45(@(t, theta) ode_func(t, theta, w), time1, theta_initial);

figure(1)
plot(t, results(:, 1));
hold on;
plot(t, results(:, 2));
xlabel("Time");
ylabel("Velocity and Displacement"); 

figure(2);
O = [0 0];
axis(gca, 'equal');
axis([-1 1 -2 2]);
grid on;

for i=1:length(t)
    %mass point
    P = l*[sin(results(i,1)) -cos(results(i,1))];
    %draw circle
    %O_circ = viscircles(O, 0.1);
    
    %pendulum rope line
    pend = line([O(1) P(1)], [O(2) P(2)]);
    %ball
    ball = viscircles(P, 0.1);
    
    %time interval
    pause(0.001);
    
    if i<length(t)
        delete(pend);
        delete(ball);
        %delete(O_circ);
    end
   
end    

ODE Solver Code- File Name: ode_func

function [dtheta_dt] = ode_func(t, theta, w)
  theta1 = theta(1);
  theta2 = theta(2);
  dtheta1_dt = theta2;
  dtheta2_dt = -(w^2)*sin(theta1);
  dtheta_dt = [dtheta1_dt; dtheta2_dt];
end

The given dampling less equation of the pendulum is solved and simuated. The youtube video link for the simulaiton is:

https://youtu.be/hXYRFv41uKw

Images of Program Run:

1. Image depicting the velocity(Red curve) and displacement(Blue curve)of the pendulum motion.

2. Image during simulation of pendulum motion.

Your portfolio, next

Ship work like this
in your own course.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.

Talk to a career counsellor

Free 20-minute call. We'll map the right course to where you want to work.

By submitting you agree to our Terms and Privacy Policy.