Challenge

Week 3 - Solving second order ODEs

Aim :-

To solve second order Ordinary Differential Equation for simple pendulum

Objective :-

1) To find out pivot positon

2) TO animate motion of simple harmonic motion of pendulum.

Theroy:-

Simple pendulum is type of simpe pendulum in which it consists of a point mass suspended by means of light inextensible string of length from a fixed support.The motion occurs in a vertical plane and is driven by a gravitational force.The tangential component of the gravitational force, mg sin θ, always acts towards the mean position θ = 0 opposite to the displacement, restoring force acting tangent to the arc

Matlab code :-

Functional code :-

% Function code

function [dtheta_dt] = ode_func(t, theta, b, g, l, m)
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

Main code :-

clear all
close all
clc

% Input variables
b=0.05;
g=9.81,
l=1;
m=1;

%Inital condition
theta_0 = [0;5];

%time span
t_span = linspace(0,20,200);

% ODE equation
[t, results] = ode45(@(t,theta) ode_func(t,theta,b,g,l,m),t_span,theta_0);

% To find position of fixed point
x0 = 0;
y0 = 0;
plot (x0, y0,'marker','O')

% To extract the first column of a result and assigned it to 'y'
y = results(:,1);

% To create images for each time value and stored it in array 'M'
ct=1;
for i=1:length(t_span)
    Y1=y(i)
    x1 = l*sin(Y1);
    y1 = -l*cos(Y1);
    plot([x0 x1],[y0 y1],'LineWidth',3,'Marker','o')
    hold on
    plot(x1,y1,'marker','o','Color','g','MarkerSize',30,'MarkerFaceColor','g')
    hold off
    title({'simple harmonic motion';'of a pendulum'},'color','r')
    axis([-1 1 -2 2])
    pause(0.01)
    M(ct)= getframe(gcf)
    ct=ct+1;
end

%to create animation
movie(M)
videofile = VideoWriter('pendulum.avi','Uncompressed AVI')
open(videofile)
writeVideo(videofile,M)
close(videofile)

Problems Facing during write a code :-

1) Not having idea about how to find location of fixed point

Solution :- Take a reference program from matlab group and understand the comcept to find find location of fixed program

2) Getting error while plot fixed point

3) Getting error while creating images for each time value and stored it in array 'M'

Rssult :-

Google Drice Link :-

https://drive.google.com/file/d/1suPctzhUS4I0h_SIQtwnu8uoTUFOGzgp/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.