Challenge

Solving second order ODEs

Here in this programm we are going to study the motion of simple pendulum using higher order ODE.

Firstly we have to decide input parameters such as

b=damping coefficient

g=gravitational force

l=length of rod

m=mass of ball or dead weight attached to the end of rod

Programm for ode function:-

function[dtheta_dt]=ode_func(t,theta,b,g,l,m)
theta1=theta(1);
theta2=theta(2);
dtheta1_dt=theta2;
dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end

In above programm we have transformed second order ODE into first order ODE

here we gwt two ODE's i.e.

dtheta1_dt=theta2;
dtheta2_dt=-(b/m)*theta2-(g/l)*sin(theta1);

By using this two equations we are going to create animation of pendulum

Programm for second order ODE:-

% SECOND ORDER ODE
close all
clc

%INPUTS
b=0.05;   
g=9.81;   
l=1;
m=1;



%INITIAL CONDITIONS
theta_0=[0,3];

%TIME POINTS
t_span=linspace(0,20,100);

%SOLVE 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))
ylabel('PLOT')
xlabel('TIME')
title('DISPLACEMENT AND VELOCITY VS TIME')
legend('DISPLACEMENT','VELOCITY')
ct=1;
for i=1:length(results)
    x0=0;
    y0=0;
    x1=l*sin(results(i,1));
    y1=-l*cos(results(i,1));
    figure(2) 
    plot([-0.5 0.5],[0 0],[x0 x1],[y0 y1],'linewidth',3);
    line(x1,y1,'color','g','LineWidth',18,'marker','o');
    title('SIMPLE PENDULUM');
    pause(0.03)
    axis([-1 1 -2 0.5])
    M(ct)=getframe(gcf);
    ct=ct+1;
end
movie(M)
videofile=VideoWriter('Pendulum_animation.avi','Uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

In above program we have stated initial coditions i.e.

Displacement=0

and Velocity=3

then by using linspace we have time range 0-20sec

Explanation for ODE 45:- By using ODE 45 command we have calculated values of 't' and 'results'

Then we have plotted plot for diaplacement and velocity vs time

for creating animation we have used for loop.

Then we have calculated the values of x1 and y1

By using marker command we have created ball for the pendulum, then we have created movie of that pendulum.

Below is the link for animation.

Youtube link:-https://youtu.be/9DMX5lTQBqo

Errors-

errors were occured while creating ball of pendulum

i had used plot command instead of line command

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.