Project

Simple Pendulum animation using MATLAB

https://youtu.be/m-trexRaji4

clear all
close all
clc
%constants
b=0.5
g=9.81
l=1
m=1
%intial condition
theta_0=[0;5]
%time
t_span=linspace(0,20,100);
%solve ode
[t,x] = ode45(@(t1,theta) exam(t1,theta,b,g,l,m),t_span,theta_0);
%origin
O=[0,0];
axis(gca,\'equal\');
%ascpet ratio
axis ([-1 1 -1.5 1])
grid on
hold on
for i=1:length(t)
P=l*[sin(x(i,1)) -cos(x(i,1))];
%circle origin
o_circle=viscircles(O,0.05);
%pendulum
pend = line([O(1) P(1)],[O(2) P(2)]);
%ball
ball=viscircles(P,0.1);
%time
pause(0.06)
if(i<length(t))
delete (pend);
delete(ball);
delete(o_circle);
end
end
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.