Challenge

Week 3 - Solving second order ODEs

clear all
close all
clc

b=0.05;
g=9.81;
l=1;
m=0.1;
ct=1;

%initial conditions
theta_0=[0;3];
%time points
t_span= linspace(0,20,500);

%solve ode

[t,results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
xlabel('plot')
ylabel('time')

for i=1:length(results(:,1))
THETA=(results(i,2));
x0=0;
y0=0;
x1=l*sin(THETA);
y1=l*-cos(THETA);
figure (2)
plot([x0 x1],[y0 y1],'linewidth',1,'color','g')
hold on
plot (x1,y1,'o','markersize',10,'color','r')
hold off
axis([-2 2 -2 2])
M(ct )=getframe(gcf);
ct=ct+1;
end

movie(M)
videofile=VideoWriter('pendulum.avi','uncompressed AVI');
open(videofile)
writeVideo(videofile,M)
close(videofile)

video link-

https://drive.google.com/file/d/1IvWWAJoX5jM4UKI1BwXG0cYrPEevf50w/view?usp=sharing

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.