Week 3 - Solving second order ODEs
In this program a Second Order ordinary differential equation is solved using Matlab software to obtain the solutions.
The ODE used in this program is an equation defining the motion of a simple pendulum when the initial conditions are provided.
The ODE is as follows
The terms in the ODE are
g = gravity in m/s2,
L = length of the pendulum in m,
m = mass of the ball in kg,
b=damping coefficient.
and theta which the pendulum makes to origin.
As we know in Matlab we can solve only first order ODEs, So using a function we are transforming second order ODE into first order.The function is as follows
L=1 metre,
m=1 kg,
b=0.05.
g=9.81 m/s2.
intial boundary conditions such as time=0 & velocity=3 rad/s
A time span of 20 second is also given
Command Usage
Linspace command is used to divide time between 0 to 20 sec into 500 equal steps.
Built-in ODE solver 'ode45' is used to solve the ODE & given the inputs as per the specified order.
Hold on & off command are used to incorporate two plots in one figure window.
xlabel and ylabel is used to given x&y axis names.
Using forloop the different positions of pendulum at different time steps are captured as image.
Using ct for each iteration using VideoWriter & writeVideo commands the animation is generated.
The MarkerSize,MarkerFaceColor,MarkerEdgeColor are used to define the size & color of bob at the end of pendulum
Errors Occured
After using hold on inside the for loop,not using hold off at the end resulted in n number of pendulum images in figure(2)
Adding ct=ct+1 before M(ct)=getframe(gcf); resulted in error.

Fixing pendulum on origin(0,0) and using positive values for x1 & y1 resulted in an inverted pendulum plot.

Results obtained after rectifying the errors are


The link for the youtube video is https://youtu.be/7X_0wbALue4
Thank you