Challenge

Week 3 - Solving second order ODEs

OBJECTIVE : To write a program that solves the following ODE

`(d^2 theta)/dt^2 +b/m(d theta)/dt+g/lsintheta =0`

This ODE represents the equation of motion of a simple pendulum with damping.

THEORY :

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.

In the above equation,

g = gravity in m/s^2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient.

GIVEN DATA

L=1 metre,

m=1 kg,

b=0.05.

g=9.81 m/s^2.

CONDITION GIVEN

Simulate the motion between 0-20 sec, for angular displacement=0,angular velocity=3 rad/sec at time t=0.

SOLUTION PROCEDURE:

First all to solve any given order of ODE we first need to break that given ODE into no. of first ODE.

The above given ODE can be broken to down to first order ODE as follows

let

`theta = theta_1`

`(d theta )/dt = ( d theta_1)/dt = theta_2`

`(d^2 theta)/dt^2 = ( d theta_2)/dt`

then

`(d theta)/dt = -b/m theta_2 -g/l sintheta_1`

CODE :

Comments are added in between for the complete understanding of code.

About the ode45 solver : The ode45 is a MATLAB function which is used for the solving of the ordinary differential equation of any given order. This function implements a Runge-Kutta method with a variable time step for. efficient computation.

PLOTS

ANIMATION OF PENDULUM .

https://youtu.be/_zaDhm8ggao

ERRORS MADE :

The above error occured because of not using hold off at the end before ending the for loop.

Second error encountered is due to that using the figure command inside the for loop before plot command which leds to pop of 501 plots which really hanged my laptop.

These errors are corrected by reading the code again again and finding out where I m wrong.

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.