Challenge

Week 3 - Solving second order ODEs

Aim: Solving a second order ordinary differential equation of simple pendulum and showing the effect of damping by an animatio

Objective:

• To convert second order ordinary differential equation to 1st order ordinary differential equation.

• To create the function using MATLAB in-built function for solving ordinary differential equation

• To plot the displacement and velocity damping through the time stipulated time of simulation.

• To make the animation of simple pendulum.

Description & Governing equation

The differential equation is mostly used to define the complex physics phenomenon in the mathematical way. Differential equation is divided in two different classity as ordinary differential equation and partial differential equation. Solving a 1 order differential is quite easy and require only one constant to define the equation, also it can be also programmed easily. The main effort is taken while solving 2nd order differential equation. Most of the fluid equation and some structural phenomenon are defined in the 2nd order differential equation which need to solve eventually to simulated the flow or study the structural behavior.

A simple pendulum consists of mass which is attached by the string of length L from a pivot point P. when displaced by initial force the mass gets moved back and forth performing periodic motion. By applying the Newton's second law motion we can obtain the equation of motion for simple pendulum which is given as

The code is given as:

clear all

close all

clc

%Given data

b = 0.05: mping coefficient g = 9.81; Acceleration due to gravity

I = 1;

Length of Pendulum in meters

m = 1;

Mass

%Time duration for simulation t_span= linspace(0.20, 100);

*Providing Initial Condition as Angular displacement & velocity y initial [0,3])

*Calculation using ODE45

a = e(t,y)ode_second_order_pendulum(y,b,m,1,g);

[ty] ode45(a,t_span,y_initial);

*Plot of Angular displacement & Velocity with respect to Time function.

figure(1);

grid on subplot(1,2,1)

plot(t,y(.1)); title('Displacement vs Time');

xlabel('Time in seconds');

ylabel('Angular displacement in rad');

subplot(1.2.2)

plot(t,y(2));

title('Angular velocity Vs Time")

xlabel( "Time in seconds");

ylabel('Angular velocity in rad/sec");

grid off

saveas (figure(1), 'subplot', 'jpg')

Polar Co-ordinate To Cartesian Co-ordinate

y1 = -1*cos(y(:,1));

x1 = 1*sin(y(:,1));

%Video for Pendulum motion

for 1 = 1:100

figure(2)

plot([0 x1(1)], [0 yt(1)], 'linewidth",3, "color","r");

hold on

plot(x(i),y(1), 'marker. 'o', 'linewidth", 10, marker facecolor","g");

plot([-1.2 1.2],[0 0], linewidth",3, 'color', 'b');

axis([-1.2 1.2 1.2 1.23);:

title(['Time: num2str(t_span(1))]): M(1) getframe(gcf);

close(2)

end

movie(M)

videofile VideoWriter('singlependulum.avi". "Uncompressed AVI');

open(videofile);

writevideo (videofile,M) close(videofile)

The Function is given as:

function ydot = ode_second_order_pendulum(y,b,m,1,g) ydot [y(2):-(b/m) y(2)-(g/l) sin(y(1))]:

end

Inference of Plot:

As we can see from the plots the displacement is getting reduce as we

move further in to time because of damping factor. From the plot we can clearly observe displacement is starting from 0 as initial condition. In the angular velocity vs time plot it has started from 3 rad/sec and then further get decrease.

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.