Challenge

Week 3 - Solving second order ODEs

Aim :- To find second order eqation in simple harmonic motion of simple pendulum

Introduction:-

in second order ode

((d^2theta/dt^2)+(b/m)*(dtheta/dt)+(g/l)*sin_theta)=0

dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2 - (g/l)*sin(theta1);
dtheta_dt = [dtheta1_dt; dtheta2_dt];
b=damping coefficient
g=gravity in m/s2
l= length of pendulum in m
m=mass of the ball in m2
we can use
b=0.05
g=9.81 m/s2
l=1 m2
m=1 kg

code:-

clear all
close all
clc
b = 0.05;
g = 9.81;
l = 1;
m = 1;
% initial condition
theta_0 = [0;3];
% time points
t_span = linspace(0,10,20);
% solve ODE
[t,results] = ode45(@(t,theta) sode(t,theta, b,g,l,m),t_span,theta_0);
plot(t,results(:,1))
hold on
plot(t,results(:,2))
% To defined pivot point of pendulum and plot it.
x0 = 0;
y0 = 0;
plot(x0,y0,'marker','o')
% to extract the first column of result and assigned it to y
y = results(:,1); % Theta/Angular displacement
% to create image for each time value and stored it in array 'M'
ct = 1;
for i=1:length(t_span) % i=1,2,3,,,,,,500
x1 = 1*sin(y(i));
y1 = -1*cos(y(i));
plot([x0,x1],[y0,y1],'linewidth',3,'marker','o')
hold on
plot(x1,y1,'marker','o','color','g','markersize',30,'markerfacecolor','g')
hold off
title({'Simple harmonic motion';'of a pendulum'}, 'color','r')
axis([-1 1 -2 0])
pause(0.03)
M(ct)= getframe(gcf);
ct=ct+1;
end
% To create animation of S.H.M of simple pendulum
movie(M)
videofile = VideoWriter('pendulum.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Outputs:-
Animation of simple pendulum:-
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.