Challenge

Week 3 - Solving second order ODEs

clear all
close all
clc
b=0.05;
g=9.81;
l=1;
m=0.1;
% initial condition
theta_0 = [0;5];
% time points
t_span = linspace(0,10,500)
% solve ODE
[t,results] = ode45(@(t,theta) ode_func(t, theta, b,g,l,m),t_span, theta_0);
plot(t,results(:,1))
xlabel('time')
ylabel('displacement')
figure(2)
title('velocity Vs Time plot')
plot(t,results(:,2))
ylabel('velocity')
xlabel('time')
figure(3)
title('Parameter Variation w.r.t. Time plot')
plot(t,results(:,1))
hold on
plot (t,results(:,2))
xlabel('Time')
ylabel('Parameters')
legend('Displacement','Velocity')
ct = 1
for i = 1:length(angle)
angle = theta(i);
figure(4)
title('simple pendulum animation')
x0 = 0;
y0 = 0;
x1 = 1*cos(((3*pi)/2)+angle);
y1 = 1*sin(((3*pi)/2)+angle);
plot([x0 x1],[y0 y1],'linewidth',4)
hold on
plot(x1,y1,'.','markers',50)
hold on
plot([-5,5],[0,0],'linewidth',5)
hold off
axis([-9,9,-4,4])
pause(0.09)
G(ct) = getframe(gcf)
ct = ct+1;
end
movie(G)
VideoFile = VideoWriter('pendulum Animation.avi','Uncompressed AVI');
open(VideoFile)
writeVideo(VideoFile,G)
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.