Project

simple pendulum second order ode

youtubelink https://youtu.be/QRVvJpRDQCQ

\"\"

\"\"

clc
clear all
close all
%inputs
l=1.00; m =1.0; g = 9.81;
k = (g/(l*m))^2;
% ODE funtion
f = @(t,y)  [y(2); -k*sin(y(1))];
% initial values for Disp
y_ini= [pi/2;0];
%time points
t_span = linspace(0,10,500);
%Solve ODE
[t,y] = ode45(f,t_span,y_ini);
%Plot of Results
figure(201)
plot(t,y(:,1))
hold on
plot(t,y(:,2))
ylabel(\'blue: Displacment, Orange: Velocity\')
xlabel(\'Time response\')
%animation Plot
mt=1;
figure(mt)
grid on
axis([-2.0 2.0 -2.0 2.0]);    
O = [0 0];
for i=1: length(t)
   % Position of Ball
   P = l*[sin(y(i,1)) -cos(y(i,1))];
   %circle origin
   o_cric = viscircles(O, 0.01);
   pend = line([O(1) P(1)],[O(2) P(2)]);
   %Ball
   ball = viscircles(P,0.05);
   %time interval to update plot
   pause(0.001);
   M(mt)=getframe(gcf);
   mt=mt+1;
    % delete previous plot
   if i<length(t)
      delete(pend);
        delete(ball);
        delete(o_cric);
    end
end
   movie(M)
   videofile=VideoWriter(\'SimplePendulum.avi\',\'Uncompressed AVI\');
   open(videofile)
   writeVideo(videofile,M)
   close(videofile)
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.