Project

SOLVING A ODE AND CREATING ANIMATION OF PENDULOM

close all
clear all
clc

%solving pendulam ode

% defining the fixed or the pivot point from which pendulam hangs

x_0=0;
y_0=0;

%inputs
g=9.81; %in m/s*2
l=2; %in metre
m=0.5; %in kg

dtheta=[0;8];

t_span=linspace(0,10,500);

%solving the ode
[t,results]=(ode45(@(t,theta) ode_function(t,theta,g,l,m) ,t_span,dtheta));

c=results(:,1); %extracting the values of displacement from the result matrix..

ct=1;

for i=(1:length(t_span))
theta_=c(i);
x0=0;
y0=0;
x1=l*sin(theta_);
y1=-l*cos(theta_);


%plotting
plot([-2 2],[0 0],\'color\',\'k\',\'linewidth\',3);
hold on
plot([x0 x1],[y0 y1],\'color\',\'r\',\'linewidth\',2);
hold off


axis([-2 2 -2 2])
grid on
pause(0.01);
q(ct)=getframe(gcf);
ct=ct+1;

end
movie(q)
videofile=VideoWriter(\'animation.avi\',\'uncompressed avi\');
open(videofile)
writeVideo(videofile,q)
close(videofile)

function part

function[dtheta_dt,t]=ode_function(t,theta,g,l,m)
w=(g/(l*m));
%the function iis to determine aND CALL VARUIABLES
theta1=theta(1);
theta2=theta(2);
dtheta1_dt=theta2;
dtheta2_dt=-(w^2)*sin(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt];
end

ANIMATION link

https://drive.google.com/drive/folders/1-XKD22lA7DCU7hgZ0NXeLpErUYArbXrg

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.