Challenge

Week 3 - Solving second order ODEs

Video Link

clear all
close all 
clc

%inputs
b = 0.05;
g = 9.81;
l = 1;
m = 1;

%initial condition
theta_0 =[0;3];

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

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

ct=1;
for i =1:length(results)
    a=results(i);
    x1=l+l*cos((3*pi/2)+a);
    y1=l+l*sin((3*pi/2)+a);
    plot([l x1],[l y1],'-o','linewidth',1.5,'color',[0 0 0],'markerfacecolor','r','markersize',10)
    axis([0 2 0 2])
    pause(0.03)
    m=getframe(gcf);
    c(ct)=m;
    ct=ct+1;
end
movie(c)
video = VideoWriter('Pendulum.avi','Uncompressed AVI')
open(video)
writeVideo(video,c)
close(video)
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.