Solving ODE using MATLAB
- AIM:- SOLVING SECOND ORDER ODE OF MOTION OF SIMPLE PENDULUM USING MATLAB
- THEORY:- Ordinay differential equations is very important mathematical functions which discribes many of system which is dependen upon some variables by using it we can study the lots of natural phenomena occurring around is like vibration, temperature distribution, projectile motion etc. Here,the second order ODE taken to solve is the equation of motion of simple pendulum with damping. Damper is basically type of resistance Which is used for vibrating body it's value decide the types of vibrating motion whether the vibrating system will be damped or undamaged or underdamper.
- FORMULA USED:- The ODE of motion of simple pendulum with damping will be
d^2theta/dt^2+(b/m)*dtheta/DT+g/L*sin(theta) = 0
Where, b = damping factor, m = mass of ball, g= gravitational coefficient, L = length of string
- ASSUMPTION:- To write and solve this 2nd order ODE on MATLAB I am taking some assumptions like (theta =theta1) and (dtheta1/DT = theta2) so on the basis of assumptions (d^2theta2/dt^2 = -b/m*theta2 + g/L* sin(theta 1) ) and second is (theta2 = dtheta1/DT).
- PROCEDURE:-
- To solve the ODE firstly I am going to write all the input value like b,m,g,L and also the initial conditions of the pendulum as we know that theta represent the displacement and dtheta/DT represent the angular velocity so here taking intially it is 0 and 5 and to generate the plot of solution I have to solving it at many of positions with respect to time for that I am using the linspace command (t_span).
- Now to solve the ODE I have to write this ODE with all assumptions in MATLAB for that I have to create a function containing all the assumption, equations and solutions in array form so the programming to create the function will be
function [dtheta_dt] = ode_func(t,theta,b,m,g,L)
theta1 = theta(1);
theta2 = theta(2);
dtheta1_dt = theta2;
dtheta2_dt = -(b/m)*theta2 - g/L*sind(theta1);
%there will be two solution in array form so very important to use semi colon
dtheta_dt = [dtheta1_dt;dtheta2_dt]
end
3. After creating and solving the function to solve it I will use the ode45 solving operator which is by default in MATLAB. It contains the integration of differential equations within the limits with intial conditions.
4. Finally to making the plot of solutions I will use the plot command here in the plot will contain two output displacement and angular velocity both with respect to time.Hence the programming for it will be
clear all
close all
clc
%inputs
b = 0.05;
g = 9.81;
L = 0.5;
m = 0.1;
% intial condition
theta_0 = [0;5];
%time points
t_span = linspace(0,20,500)
% solve ode
[t results] = ode45(@(t,theta)ode_func(t,theta,b,g,L,m),t_span,theta_0);
% plotting
plot(t,results:,1);
hold on
plot(t,results:,2);
xlabel('plot')
ylabel('time')
So, the final result will be