Project

A program in Matlab that will simulate the pendulum motion

clear all
close all
clc

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

%initial condition
theta_0=[0;3];

%time points
t_span=linspace(0,20,500);

%ode solver
[t,results]=ode45(@(t,theta) ode_func(t,theta,b,g,l,m), t_span, theta_0);


%storing t & results in different matrices
array1 = results(:,1);

ct = 1;

for i= 1:length(results(:,1))
    
         result=results(i);   
x0 = 0;
y0 = 0;

x1 = l*sind(result);
y1 = l*-cosd(result);
 figure(1)
 title(\'Second ODE pendulum Graph\')
        plot([x0 x1],[y0 y1])
        axis([-0.05 0.05 -1.1 1])
        M(ct)=getframe(gcf)
        ct=ct+1;
end
movie(M)
videofile = VideoWriter(\'Second ODE pendulum Graph.avi\',\'uncompressed AVI\');
open(videofile)
writeVideo(videofile,M)
close(videofile)

figure(2)
   title(\'Second ODE pendulum Graph\')
plot(t,results(:,1));
hold on
plot(t,results(:,2));
xlabel(\'plot\');
ylabel(\'results\');

%LINK FOR THE ANIMATED VIDEO

https://youtu.be/kz_2nIfDqXA

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.