Project

Second Order ODEs

Animation : https://youtu.be/Pqy525hNyWA

clear all
close all
clc

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

%initial condition, distance and velocity
theta_0 = [0 ; 5];

%time span
tspan = linspace(0,20,500);

%SOLVING THE ODE
[t, results] = ode45(@(t,theta) odefun(t,theta,b,g,l,m), tspan, theta_0) ;

figure(1)
hold on
plot(t,results(:,1),\'color\',\'g\');
plot(t,results(:,2),\'color\',\'r\');
xlabel(\'Time\');
legend(\'Displacement\',\'Velocity\');
hold off

figure(2)
x0 = 0;
y0 = 0;
ct = 1;



for i = 1:length(tspan)
    
    y1 = -l*cos(results(i,1)) ;
    x1 = l*sin(results(i,1));
    plot([x0 x1],[y0 y1]);
    viscircles([x1 y1],0.05);
    axis([-1 1.2 -1.2 0.2]);
    grid on
    pause(0.001);
    M(ct) = getframe(gcf); %captures entire interior of FIGURE window
    ct = ct + 1;
    
end

movie(M) %generates a movie with frames compiled from M
videofile = VideoWriter(\'Pendulum(redone)\', \'Uncompressed AVI\'); %Dump out the frames
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.