Project

SOLVING SECOND ORDER ODE BY THE EXAMPLE OF SIMPLE PENDULUM

https://www.youtube.com/watch?v=VJ8XSShfAlw

clear all
close all
clc

g=9.81;
l=1;
m=0.5;
%initial condition
theta_0=[0;5];

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

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

%Extracting the angular displacment
a_disp = results(:,1);

ct = 1;
%animation Plot
for i = 1:length(t_span);
    angle = a_disp(i);
    
    %plot
    x0 = 0;
    y0 = 0;
    x1 = 1*sin(angle);
    y1 = -1*cos(angle);
    
    plot([x0 x1],[y0 y1], \'color\', \'y\')
    hold on
    grid on
    plot(0,0,\'.\', \'color\',\'k\')
    plot(x1,y1,\'-o\',\'markers\',10,\'markerfacecolor\',\'m\',\'color\',\'m\')
    hold off
    title(\'Simulating the motion of pendulum\')
    axis([-2 2 -3 0.5])
    M(ct) = getframe(gcf);
    ct = ct + 1;
    
    
end

movie(M)
videofile=VideoWriter(\'1SimplePendulum.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.