Week 4.1 - Solving second order ODEs
Objective - Writing a program in MATLAB that will simulate the pendulum motion for given span of time and given angular acceleration and velocity, with these results of angular velocity of pendulum over the time, we need to animate the pendulum motion.
Simple Pendulum -
Equation of motion is:

In the above
equation,
- b = damping coefficient.
- g = gravity in m/s^2.
- L = length of the pendulum in the meter.
- m = mass of the ball in kg.
ODE Function -

Input -
- b = 0.05; %% Damping Coefficient
- g = 9.81; %% Gravitational Force in m/s^2
- l = 1; %% Length of pendulum in m
- m = 0.1; %% Mass in Kg
- Start angular displacement in rad.
- Start angular velocity in rad/sec^2
- Time of oscillation - 0 to 20 secs
MATLAB Code -
%% Solving a Second Order Differential Equation For Simple Pendulum
clear all
close all
clc


- Initialization of start condition of a simple pendulum and pendulum input parameters(b,g,l,m,Time)
- To solve the ODE in which MATLAB inbuilt function (ode45) is used with theta, t, and ode_func - another function is created as a separate own function.
- Results are plotted w.r.t time using plot command with proper legends, label, Plot Titles
- By using the results of angular position (100 position of pendulum in a time span of 3 secs), for loop used to access each value of pendulum position plotted
- Using ‘Line’ command string position plotted and Bob plotted with plot command
- Position of pendulum (theta1 and theta2) for each angular position is created with for loop and increasing the ‘ct’ one by one for 100 times in a span of 3 sec
- Then move command is used to create an animated video of the oscillating pendulum.
Error Faced in this Program -
#1 Pendulum oscillates without fixed position and oscillates in horizontal direction as shown below -
Direction of sin theta and cos theta (x1=1*sin(theta2);y1=-1*cos(theta2)) changed as per pendulum concept and window size 'axis([-1 1 -1.5 0.5])' added in a command to visualize the complete pendulum with fixed position

#2 Pendulum oscillates vibration looks small in a animation video -
The intimal start angular position (what we given) and final angular position(what we got from solving ODE function) of pendulum is in radians not in Degree. When assigning postion of pendulum wrongly given as theta " x1=1*sind(theta2); y1=-1*cosd(theta2);" below changes done in program
below changes done in program to solve this error x1=1*sin(theta2);y1=-1*cos(theta2);