Challenge

Week 3 - Solving second order ODEs

SIMPLE PENDULAM

AIM :Create an image that represents the position of the pendulum;

Create an animation of a simple pendulam by matlab programming.

INTRODUCTION : In mathematics, an ordinary differential equation (ODE) is a differential equation containing one or more functions of one independent variable and the derivatives of those functions. The term ordinary is used in contrast with the term partial differential equation which may be with respect to more than one independent variable.

In mechanics and physics, simple harmonic motion is a special type of periodic motion where the restoring force on the moving object is directly proportional to, and opposite of, the object's displacement vector. It results in an oscillation which, if uninhibited by friction or any other disipation of energy,continues indefinitely.

Simple harmonic motion can serve as a mathematical modell for a variety of motions, but is typified by the oscillation of a mass on a spring when it is subject to the linear elastic restoring force given by hooke's law he motion is sinusoidal in time and demonstrates a single resonant frequency. Other phenomena can be modeled by simple harmonic motion, including the motion of a simple pendulam, although for it to be an accurate model, the netforce on the object at the end of the pendulum must be proportional to the displacement.

HERE IS THE LINK OF YOUTUBE VIDEO

https://youtu.be/QTA9xdwp6ro

THIS IS THE PICTURE OF SIMPLE PENDULAM MOTION:

CODE IN MATLAB :

clear all
close all
clc

% Inputs
l = 1;
m = 1;
b = 0.05;
g = 9.81;

% initial conditions
theta_0 = [0;3];

%time points
t_span = linspace(0,20,500);


%solve ode
[t, result] = ode45(@(t,theta) ode_fun(t,theta,l,m,b,g),t_span, theta_0);

%plotting
figure(1)
hold on
plot(t,result(:,1));
plot(t,result(:,2));
xlabel('plot')
ylabel('time')
legend('angular displacement','angular velocity');
title('damped oscillation of a simple pendulam');
hold off

figure(2)
ct = 1;
for i = 1:length(result(:,1))
    x0 = 0;
    y0 = 0;
    
    x1 = l*sin(result(i,1));
    y1 = -l*cos(result(i,1));
    plot([0 x1],[0 y1],'linewidth',5)
     
     % Plot Support
     rectangle('Position',[-0.5 0 1 0],'EdgeColor','k','LineWidth',3)
      grid on
      axis([-2 2 -2 1])
      title('Simple Harmonic Motion of Pendulum')
      pause(0.03)
      M(ct)=getframe(gcf);
      ct=ct+1;
      xlabel('plot') 
end

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

SIMPLE PENDULAM FUNCTION CODE

function [dtheta_dt] = ode_fun(t,theta,l,m,b,g)
    theta1 = theta(1);
    theta2 = theta(2);
    dtheta1_dt = theta2;
    dtheta2_dt = -(b/m)*theta2-(g/l)*sin(theta1);
    dtheta_dt = [dtheta1_dt; dtheta2_dt];
    
end


RESULTING GRAPHS:

ERRORS FACED :

i have faced many errors like naming function name wrong and paranthesis mistakes. mistakes at ode45, and counter typing mistake .

and i made mistake at plotting graphs .

and i verified these mistakes by help center and by skill lynk support members.

REFERENCES :

https://en.wikipedia.org/wiki/Ordinary_differential_equation

https://en.wikipedia.org/wiki/Simple_harmonic_motion

CONCLUSION :

finally the motion was created by matlab program. and these are used in many real life situations.

here is the animated youtube link

https://youtu.be/QTA9xdwp6ro

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.