Project

ODE

clear all
close all
clc

g=9.81; 
l=1; 
m= 0.1; 
w=g/(l*m);

%initial condition
theta_0=[ 0;100];

%time span
t_span=linspace(0,50,100);

%integration
[t , results]=ode45(@(t,theta) ode_func(t,theta,w), t_span , theta_0);

%plotting
figure(1)
plot(t,results(:,1))
hold on
plot(t,results(:,2))
ylabel(\'VELOCITY/DISPLACEMENT\')
xlabel(\'TIME\')

%animation
ct=1;
for i=1:length(t_span)
    THETA=results(i,1);
 
    %string
    x0=0;
    y0=0;
    x=x0-l*sind(THETA);
    y=y0-l*cosd(THETA);
    
figure(2)
    plot([x0 x],[y0 y],\'color\',\'g\',\'linewidth\',2)
    axis([ -1.3 1.3 -1.3 1.3]);
    
    %ball
    centre=[x y];
    circle=viscircles(centre,0.2)
    M(ct)=getframe(gcf);
       ct=ct+1;
end
movie(M)
videofile=VideoWriter(\'Pendulum_matlab.avi\',\'Uncompressed AVI\');
open(videofile)
writeVideo(videofile,M)
close(videofile)

% The code attached below is to call the function ode_func
function [dtheta_dt]=ode_func(t,theta,w)
theta1=theta(1)
theta2=theta(2)
dtheta1_dt=theta2;
dtheta2_dt= -(w^2)*sind(theta1);
dtheta_dt=[dtheta1_dt;dtheta2_dt]
end

\"Plot\"

Animation video link: https://drive.google.com/file/d/1Odfj8zYwuxeQ24aiofJN6HHkmrIXQvpq/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.