Week 3 - Solving second order ODEs
Aim: To write a programme to solve ODE which describe simple pendulum motion.
To generate animation for simple pendulum.
Ordinary differential equation
Ordinary differential equation also called as ODE contains only one indipendent variable and one or more derivatives of variable.
There are different types of ODE such as anotomus ODE,Linear ODE,Non linear ODE,Homogeneous and non homogeneous ODE.
According to order of derivative it can be first order ODE,Second order ODE or Nth order differential equation.
Simple pendulum
Simple pendulum is mechanical arrangement that describes periodic motion.
It consist of bob mass m and attached to thi string of length l.String is attached to rigid support.
When we give little push to bob of pendulum it starts oscillating back and forth till it get to rest.
Governing equation
In above equation
g=gravity m/s^2
l=length of string m
m= mass of ball kg
b=damping coefficient
theta=angular displacement
This is 2nd order differential equation.
equation simplification

Programme
Code for function
- Code starts with command clear all close all clc.
- Inputs defines as b=0.05,l=1m,g=9.81m/s^2,m=0.1kg
- Intial condition defines as angular velocity 3rad/sec,angular displacement 0 at time 0 sec.
- time span of 0-20 sec defined.linspace ommand is used to generate linear vector.
- Ode45 function- ode45 is inbuilt matlab function which is use to solve differential equation.Results are stored in an array of row matrix of two column for values ofdisplacement and velocity of different time period
- t and theta are required output.
- @- it is assosciated variable which accepts multiple inputs and return one output.
- odefun is generated to simplify second order derivative and it is called in main ode.
- plot is generated for angular displacement and velocity vs.time
- To animate the motion of simple pendulum for loop is used to create set of points.
- x0 and y0 are the fix end of bob and x1,y1are different position.
- ct command is used to store data of displacement and time
- viscircle command is use to create circle by giving centre and radius as input.
- movie m is usedto create animation file to store data.
- videowriter specifies name and type of data.
- writevideo command is use to creat video.
Results
- Plot of angular displacement and velocity vs time

Animation-
Error occured-
Invalid expression- closing bracket missing in ode45 command

Solution-Issue resolve by adding closing bracket.