Week 3 - Solving second order ODEs
clc
clear all
close all
% To simulate simple pendulum ,springs ,dampers .
%Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.
%formula
%Rate of change=change in y/change in x;
%Angular velocity= AngularDisplacement of Theta along y/Time along x
%dv/dt=dtheta/dt
%Angular velocity is directly proportional to angular displacement
% inputs
%Damping_coefficient
b=0.05
%gravity m/s^2
g=9.81
%Length_pendulum
l=1;
%mass_pendulum
m=1;
%initial condition
theta_initial=[0;3]%initial condition of displacement & velocity.
%time points
time_span=linspace(0,20,250)
%solve ODE b/w time & theta
[t,results]=ode45(@(t,theta)ode_function(t,theta,b,g,l,m),time_span,theta_initial);
figure(1)
plot(t,results(:,1),'linewidth',3,'Color','r')%plotting angular displacement vs time
hold on
plot(t,results(:,2),'linewidth',3,'Color','b')%plotting angular velocity vs time
ct=1;
for i=1:length(results(:,1))
x=0;
y=0;
x1= l*sin(results(i,1));
y1=-l*cos(results(i,1));
figure(2)
plot([x,x1],[y,y1],'linewidth',2)
hold on
plot(x1,y1,'o','MarkerSize',10)
hold off
axis([-2 2 -2 2])
M(ct)=getframe(gcf);%Getting all figures & stored in M_file
ct=ct+1;
end
movie(M)%creates movie with all those fig's
videofile=VideoWriter('ODE_function.avi')%dumping all those figures into avi file
videofile.FrameRate=10
open(videofile)
writeVideo(videofile,M)
close(videofile)

https://1drv.ms/u/s!AmEnrD3WneZ6gR3szRT3VTvMyJED?e=BdToDA
Second-order differential equations play a central role in the physicalsciences. They are found, for example, in laws describing mechanicalsystems, wave motion, electric currents and quantum phenomena.
To take a simple case, consider a particle of mass m that moves in onedimension along the x-axis. At any given time t, the particle’s position isx(t), and its velocity and acceleration are given by the derivatives dx/dtand d2x/dt2There are no general laws for the position or velocity of theparticle, but there is a very important law for its acceleration: Newton’s second law tells us that
mass × acceleration = force
which implies that
m*d^2x/dt^2= F,
x=acceleration
where F is the force acting on the particle. The force need not beconstant, and may vary with the position x or the velocity dx/dt of theparticle. So, depending on the precise details, we get a second-orderdifferential equation for x as a function of t, and the solution of this equation tells us how the particle can move..