Project

Matlab-program that solves the following ODE This ODE represents the equation of motion of a simple pendulum with damping

objective = To write a program that solves the following ODE. This ODE represents the equation of motion of a simple pendulum with damping

In the above equation,

g = gravity in m/s2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient.

Input Values

L=1 metre,

m=0.1 kg,

b=0.05.

g=9.81 m/s2.

STEP1:- Convert 2nd degree ODE order into first degree ODE

Ɵ = Ɵ1

dƟ/dt = dƟ1/dt = Ɵ2

dƟ/dt+b*Ɵ/m+g*sinƟ1/L

STEP2:- Create a function of ODE

function [dtheta_dt] = odefunc(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

STEP3:- Create Simple pendumal program by usinf ODE function

-Initial condition are provided:- pi/2 is displacement and 0 is angular velocity

-Time interval 0 to 50 second in 200steps

-Solving ODE equation by using ode45 function

clear all
close all
clc

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

%Initial condition
theta0 = [pi/2 0];

%Time
t_spane = linspace(0,50,200);

%Solve ODE
[t result] = ode45(@(t,theta)odefunc(t,theta,b,g,l,m),t_spane,theta0);

%Plotting
figure(1)
hold on
plot(t,result(:,1))
plot(t,result(:,2))
xlabel(\'TIME\')
ylabel(\'PLOT\')
hold off
saveas(1,\'Time_plot.png\')

%Animation

x0=0
y0=0
x1=-2
y1=0
x2=2
y2=0
ct=1
for i = 1:length(t)
    x=l*sin(result(i))
    y=-l*cos(result(i))
    
    
    plot([x1,x0,x2],[y1,y0,y2],\'linewidth\',8)
    hold on
    plot([x0,x],[y0 y],\'linewidth\',2)
    hold on
    plot(x,y,\'o\',\'markersize\',15,\'markerfacecolor\',\'b\')
    axis([-3 3 -3 0])
    hold off
    pause(0.1)
    d(ct)=getframe(gcf);
    ct=ct+1;
    
end
movie(d)
videofile=VideoWriter(\"Simple_pendulam.avi\",\"uncompressed AVI\");
open(videofile)
writeVideo(videofile,d)
close(videofile)

PLOTS:-

\"\"

ANIMATION:-

CONCLUSION:-

Plot show how displacement and angular velocity change with respect to time

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.