Week 3 - Solving second order ODEs
Second Order ODEs :- In Engineering, ODE is used to describe the transient behavior of a system. A simple example is a pendulum
The way the pendulum moves depends on the Newtons second law. When this law is written down, we get a Second order Ordinary Differential Equation that describes the position of the "ball" w.r.t time.
Similarly, there are hundreds of ODEs that describe key phenomena and if you have the ability to solve these equations then you will be able to simulate any of theses systems.
Your objective is to write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping.

Values To Slove The Second Order Differential Equation Of A Simple Pendulum :-
L=1 metre,
m=1 kg,
b=0.05.
g=9.81 m/s2.
Step (1) :- Creating ODE Function
d^2 theta/(dt)^2 + b/m d theta/dt +g/l sin theta =0
b = damping
g = gravity
m= mass
l = length
theta 1 = theta 2
d theta/dt = d theta1/dt = theta2 --------(1)
d^2 theta /dt^2 = d^2 theta1/dt^2 =d/dt (d theta1/dt) = d/dt(theta2)---------(2)
d^2 theta/dt^2+b/m d theta/dt +g/l sin theta =0
d^2theta1/dt^2 + b/m d theta 1/dt +g/l sin theta 1 =0
d theta 2/dt + b/m (theta2) + g/l sin theta1 = 0
d theta 1/dt = theta 2
d theta 2/dt = -b/m theta1 - g/l sin theta1
Step (2) - Program in Matlab that will simulate the pendulum motion, just like the one shown in the start of this challenge.
L=1 metre,
m=1 kg,
b=0.05.
g=9.81 m/s2.
Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.
When you do this you will get the position of the pendulum as a function of time. Use this information to animate the motion of the pendulum, as shown in the below figure.
The Program is As Follows
close all
clear all
clc
%inputs
b = 0.05;
g = 9.81;
m = 1;
i =1;
%intial conditions
theta_0 = [0;3]; %[angular displacemet =0;angular velocity=3]
%time points
t_span = linspace(0,20,500); %pendulum osicallations between 0-20 seconds
% slove ODE
[t,result]= ode45(@(t,theta)ode_func(t,theta,b,g,l,m),t_span,theta_0);
%plotting the graph
figure(1)
subplot(2,1,1)
p1 = plot(t,result(:,1),'LineWidth',2,'Color','r');
xlabel('time')
ylable('theta')
title('Angular Displacement(theta) v/s Time')
hold on
subplot(2,1,2)
p2 = plot(t,result(:,2),'LineWidth',2,'Color','b')
xlabel('Time')
ylabel('velocity')
title('Angular velocity v/s Time')
legend([p1(1),p2(1)]),'angular displacement' ,'angular velocity')
%pendulum simulation using ode
theta = result(:,1)
ct=1;
%%creating a for loop for osicallating the pendulum
fori=1:length(result)
THETA=result(i,1);
%intial boundary condition
x0 = 0;
y0 = 0;
%defining x and y coordinates
x1= l*sin(THETA);
y1=-1*cos(THETA);
figure(2)
hold on
plot([x0 x1],[y0 ,y1],'LineWidth',4);
plot(x1,y1,'-o','markersize',30,'MarkerEdgeColor','g','MarkerFaceColor',[0.6 0.6 0.6]);
plot(x0 ,y0,'-*','markersize',3,'MarkerEdgeColor','g','MarkerFacecolor'[0.6 0.6 ;.6]);
axis([-2 2 -2 0]);
pause(0.005);
M(ct)=getframe(gcf)
ct=ct+1
clf
end
movie(M)
videofile = videowriter('second_ode_pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
Result :-
A MINOR MISTAKE OCCURED BUT I CANT IDENTIFY IT I TRIED MY LEVEL BEST.
AFTER THIS CHALLENGE I WANT TO GO WITH ONE ON ONE SECTION.
AND PLSE GIVE FEEDBACK WHAT MISTAKES I HAVE DONE AND EXPLAIN IT ALSO IN THIS CHALLENGE.