Challenge

Week 3 - Solving second order ODEs

Aim:

To solve the second order ODEs function by using Matlab

objective:

  • To write matlab program by using ode45 sover for second order differential equation
  • Plot the graph
  • To create animation for simple pendulum

Introduction

Second-Order Differential Equation A differential equation is an equation of a function and one or more derivatives which may be of first degree or more. Differential Equations are of the form:

d2y/dx2 + p dy/dx + qy = 0.

for example

dy/dx + y2 = 5x First Order Differential Equation.

d2y/dx2 + xy = sin(x) Second Order Differential Equation.

d3y/dx3 + x dy/dx + y = ex Third Order Differential Equation.

Differential Equations might be of different orders i.e. th

Second-Order Differential Equation Examples

In several real-world situations, First Order Differential Equation does not suffice properly and there is a need to implement Second Order Differential Equation. For a degree greater than one, there’s always a specific trick that is particular to the type of situation you are handling. For you to know how to handle the 2nd order Differential Equation, make sure you go through the concept completely as it will show you some examples and the technique involved in solving 2nd Order Differential Equation.

Difference Between 1st and 2nd Order Differential Equations

In the unknown y(x) Equation (1) is 1st order seeing that the highest derivative that seems in it is a 1st order derivative. Similarly, equation (2) is a 2nd order because also y appears. They are both linear, since y, y and y are not squared or cubed etc and their product is not appearing.

e highest degree of the derivative.

Simple Pendulum:

  • SHM. SHM or simple harmonic motion is the type of periodic motion in which the magnitude of restoring force on the body...
  • Effect of Gravity. The time period of simple pendulum is inversely proportional do the square root of acceleration due...
  • Physical Pendulum. For simple pendulum we consider the mass of the string to be negligible as compared to the Bob
  • Summary. A simple pendulum is a mechanical system which consist of a light inextensible string and small bob

Equation of simple pendulum;

g = gravity in m/s2,

L = length of the pendulum in m,

m = mass of the ball in kg,

b=damping coefficient

Programe for pendulum motion

% SOLVING 2ND ORDER ODE
clear all
close all
clc
l=1
m=1
b=0.05
g=9.81
%initial condition
theta_0 = [0;5];
%time point
t_span = linspace(0,10,250);
[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))
ylabel('plot')
xlabel('time')
%ANIMATION
x0=0;
y0=0;
ct=1;
for i=length(t)
x1=l*sin(results(i,l));
y1=l*cos(results(i,l));
plot([-1 1],[0 0],'linewidth',6,'Color','g');
axis([-2 2 -2 2]);
line([x0 x1],[y0 y1],'linewidth',2,'color','b');
hold on;
plot(x0,y0,'o','markersize',2,'markerfacecolor','r');
plot(x1,y1,'o','markersize',10,'markerfacecolor','b');
title('simple pendulum');
grid on;
hold off;
ct = ct+1;
M(ct) = getframe(gcf);
end
movie(m);
videofile=VideoWriter('simple_pendulum','uncompressed AVI');
open(videofile);
writeVideo(videofile,m);
close(videofile);
Code for ODE Function:
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
Result:
As which have required for solve second order ODEs by using matlab has been successfuly completed as per the give equation and results are attached with the program
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.