Challenge

Week 3 - Solving second order ODEs

https://drive.google.com/drive/folders/1bbBog-Cv7E1r0KSPIRgsvtqRd25C1nNX?usp=sharing

Introduction:

A second order ordinary differential equation is an ordinary differential equation in which any derivatives with respect to the independent variable have order no greater than 2">2.

Ordinary differential equations helps us to solve the many engineering systems. Such as harmonic motions, vibrarions, damping,etc.

Second-order linear differential equations are used to model many systems in engineering.

A simple pendulum consists of a mass ‘m’ hanging from a string of length ‘l’ and fixed at a pivot point . When displaced to an initial angle ’θ’ and released, the pendulum will swing back and forth with periodic motion.

The equation is given by:

Explanation of the code :

Inputs are taken as given in the problem

L=1 metre,

m=1 kg,

b=0.05.

g=9.81 m/s2

Initial conditions are taken as

Angular displacement = 0, Angular Velocity = 3 rad/sec, at time t = 0

The motion is simulated between 0-20sec

Solving ODE

Ode solver ode45 is used in this matlab program. The results are stored in an array of row atrix of two coloumns, for the values of displacement and velocity at different time periods.

Ode_func is the function made to solve the given equation . where the asumptions are made in the from of code .

Figure 1: plotting

Here the graph is plotted to get the wave form of the displacement and the velocity from the initial condtions.

Figure 2: plotting

Animating the transient motion of the simple pendulum:

Here we use the concept of the for loop . as the the bob moves with a velocity ,and displaces for the different time period. And recorded it and animated the path of the oscillations

Errors faced:

Not using the hold on & hold off command at the proper step.

Giving the proper value for the pause

Determining the x and y values

Steps To Overcome those errors:

Make sure the use of hold on and hold off commands after the proper plot command or the graph wont be as per requirement and to avoid the path trace to left in the graph

Use of proper value for the pause (in this case 0.0001) to get the proper animation form

In the motion of the simple pendulum the coridnates x, y are interchanges like

X=l*sinθ and Y=-l*cosθ

clear all
close all
clc

b = 0.05;
g = 9.81;
l = 1;
m = 0.2;

% initial condition
theta_0 = [0;5];

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

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

plot(t, results(:,1))
hold on
plot(t, results(:,2))

%Animating the transient motion of the simple pendulum

figure(2)
ct=1;

for i=1:length(results(:,1))
    x0=0;
    y0=0;
    
    x1=l*sin(results(i,1));
    y1=-l*cos(results(i,1));
    plot([0 0],[-1.5 0.5])
    hold on
    plot([x0 x1],[y0 y1],'linewidth',1,'color','b')
    axis([-1.5 1.5 -1.5 0.5])
    plot(x1, y1,'o','MarkerSize',20,'color','r')
    pause(0.0001)
    M(ct)=getframe(gcf)
   hold off
   ct=ct+1
   
end%making the video file

movie(M)
videofile=VideoWriter('simple_pendulum.avi')
open(videofile)
writeVideo(videofile,M)
close(videofile)
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.