Project

a new title

clear all
close all
clc

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


%initial conditiom
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);

angular_disp=results(:,1);
ct=1;

for i=1:length(t_span)
THETA=angular_disp(i);
%coordinates of pendulum
x0=0;
y0=0;
x1=l*sin(THETA);
y1=-l*cos(THETA);
plot([-0.5 0.5],[0 0], [-0.5 -0.5], [0 0.08],[-0.5 0.5], [0.08 0.08], [0.5 0.5], [0.08 0],'color','r');
hold on
plot([x0 x1],[y0 y1],'color','r');
plot(x1,y1,'O','markers',30,'markerfacecolor','b','color','y');
axis([-1.5 1.5 -1.5 0.1])
hold off
pause(0.01)
%animation
p(ct)=getframe(gcf);
ct=ct+1;
end
movie(p)
videofile=VideoWriter('pendulum_animation.avi','uncompressed avi');
open(videofile)
writeVideo(videofile,p)
close(videofile)

%plots
plot(t,results(:,1));
hold on
plot(t,results(:,2));
xlabel('time in seconds');
ylabel('plot');
legend('Displacement','velocity');

Video link:https://youtu.be/ozu9Kt2ia5U

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.