Project

Solving second order derivative ODE function for simple oscillating pendulum using MATLAB.

%input
b=0.5;
g=9.81;
l=1;
m=1;

%initial condition
theta_0 = [0;3];

%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);

figure(1)
plot(t,results(:,1),'color','b');
hold on
plot (t,results(:,2),'color','r');
hold off
xlabel('position');
ylabel('angular velocity');

ct=1;
for i=1:length(results(:,1))
    x0=0;
    y0=0;
    x1=1*sin(results(i,1));
    y1=-1*cos(results(i,1));
    
    figure(2)
    plot([-1 1],[0 0],'linewidth',5,'color','g');
    hold on
    plot([x0 x1],[y0 y1],'linewidth',3,'color','b');
    hold on
    plot(x1,y1,'marker','.','markerfacecolor','r','markersize',25);

    axis([-1.5 1.5 -1.75 0])
    
    hold off
    M(ct)=getframe(gcf);
    ct = ct + 1;
end

movie(M)
videofile=VideoWriter('ode_func.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)
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

Solving second order derivative ODE function for simple oscillating pendulum using MATLAB.

AIM:

to solve the differential equation of simple harmonic motion of a pendulum and to make a simulation of the pendulum using MATLAB.

This differential is solved to find out the value for theta, resulting in the prediction of the pendulum bob at a particular position at a particular time.

a graph is also ploted for identifying the relation between angular displacement and velocity with respect to time.

thus, a second order derivative ODE function for simple oscillating pendulum is solved using MATLAB.

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.