Challenge

Week 4.1 - Solving second order ODEs

clear all

close all

clc

b = 0.05;

g = 9.81;

l = 1;

m = 1;

ct=1;

theta_0 = [0;3];

% Initial condition

theta_0 = [0;3];

% Time points

t_span = linspace(0,20,100);

% Solove ode

[t, results] = ode45(@(t,theta) ode_main(t, theta, b,g,l,m),t_span,theta_0);

plot(t,results(:,1))

hold on

plot(t,results(:,2))

ylabel('plot')

xlabel('time')

x0 = 1; y0 = 1;

theta = results(:,1);

for i = 1:length(theta)

figure(2)

x1 = 1-l*sin(theta(i));

y1 = 1-l*cos(theta(i));

plot([0 2],[1 1],'linewidth',3,'color','k')

hold on

plot([1 x1],[1 y1],[x1 x1],[y1 y1],'o','markersize',20,'MarkerFaceColor','r')

hold off

axis([0 2 -0.5 1.5]);

pause(0.03)

M(ct) = getframe(gcf);

ct = ct+1;

end

movie(M)

videofile = VideoWriter('Second_order_ode.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.