Challenge

Week 3 - Solving second order ODEs

AIM:

To sloves the ODE which respresents the equation of motion of a simple pendulum with damping.

Objective:

To write a program that solves the following ODE which respresents the equations of motion of a simple pendulum with damping and create an animated video of the output obtains by solving this ODE.

d^2`theta`/dt^2 +b/md`theta`+g/Lsin`theta`=0

Theory:

The motion of a simple pendulum is a basic classical example of simple harmonic motion, consisting of a small bob and a massless string.movement of the pendulum depends on newton's second law. when this law is written down, a second -order ordinary differential equation is formed that describes the position of the end the pendulum w.r.t time .

EQUATION OF MOTION IS:

d^2`theta`/dt^2 +b/md`theta`+g/Lsin`theta`=0

In the above equation,

* g=gravity in m/s^2

* L= length of the pendulum in the meter.

* m=mass of the ball in kg.

*b= damping coefficient.

Since the given function is in the second -order differential equation we will convert it into first order to solve the ODE.

Let

`theta`=`theta`1

d`theta`1/dt=`theta`2

d`theta`^2/dt^2=d`theta`2/dt

INPUT:

*L=1meter

*m=1kg

*b=0.05

*g=9.81m/s^2

*Time span =0-20sec

*angular displacement =0

*angular velocity=3 rad/sec2 at time

t=0

CODE:

%Program to simulate the transient behavior of a simple pendulum

clear all
close all
clc


b=0.05;
g=9.81;
l=1
m=0.1

%initial condition 
theta_0=[0;5];

% time points 
t_span =linspace(0,20,500);
%slove ODE
[t,results]= ode45(@ (t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
figure(1)
plot(t,results(:,1))
hold on 
plot(t,results(:,2))
xlabel('time')
ylabel('plot')
% creating animation of the pendulum
ct=1;
theta_1=results(:,1);
for i=1:length(results(:,1))
    %initial co-ordinates 
    x_start=0;
    y_start=0;
    theta_2=theta_1(i);
    %final co-ordinates 
    x_end=1*sin(theta_2);
    y_end=-1*cos(theta_2);

    %ploting for animation
    figure(2)
    %base of pendulum 
    plot([-1,1],[0,0],'lineWidth',4,'Color','b')
    hold on 
    %starting of pendulum 
    line ([x_start x_end],[y_start y_end],'linewidth',6,'color','b')
    hold on
    %bob of pendulum 
    plot(x_end,y_end,'Marker','o','markersize',28,'MarkerFaceColor','r')
    axis([-2 2 -2 2])
    pause(0.03)
    hold off 
    M(ct) = getframe(gcf);
    ct = ct+1;
end
%Animation of the pendulum
%creating movie from captured frames
movie(M)
videofile=VideoWriter('pendulum Animation.avi','Uncompressed AVI');
open (videofile);
writeVideo(videofile,M);
close(videofile);


Detail explanation each step of the program:

1.in the first step inputs and initial condition of a simple pendulum are fed.

2. Then the program is written to slove the ode in which matlab inbulit function (ode45) is used with constant theta,t, and another function is used ,which is defined separately in function program .

3.In the next step results of solved ODE is plotted .wr.t time using plot command .

4.Now iteration of co-ordinate is fed using for loop to create animation.

5. Then plot command is used to plot pendulum string and bob.

6.in the next step,the move command is used to create an animated video of the oscilating pendulum .

out put :

1. the output obtained is graphical respresentation velocity curve and displacement curve w.r.t time.

*Angular displacement and angular velocity plots were generated for a time range of 20 secs.

results:

The displacement(bule colour and angular velocity (red color) is decreasing by the increased time, this is due to the introduction of damper i.e damping coefficient which absorbs the vibrations to make the body in equillibrium position.

Animated file:

https://drive.google.com/file/d/1kZpEyxBeZup-Cejw_Xs2q6_B8rdZu6o_/view?usp=sharing

conclusion:

*The graph of displacement and angular velocity is plotted in velocity v/s time diagram.

* Animation of simple pendulum is created.

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.