Download as pdf or txt
Download as pdf or txt
You are on page 1of 4

30/10/21, 04:02 Solving Second Order Differential Equations in Python - ePythonGuru

HOME ABOUT US CONTACT US PRIVACY POLICY

 INTRODUCTION  CALCULUS  MULTIVARIATE CALCULUS  ODE  NUMERICAL METHODS MISC PROGRAM

Home / Second order Differential Equations / Solving Second Order Differential Equations in Python Social Counter

Solving Second Order Differential  900 Follow

Equations in Python
 Second order Differential Equations
Tags
Solving Second Order Differential Equations 
In many real-life modeling situations, a differential equation for a variable of interest Basics of Python

depends not only on the first derivative but also on the higher ones.  Complex numbers

Creation of matrix
For something more than a second derivative, the question will almost certainly direct
Differentiation
you through some special trick that is very specific to the problem at hand. 

First Order Differentia

Also read, Reason behind the huge Demand of Python Developers Framework Great

Growth Model Int


For second-order differential equations, you have to know how to deal with them in
Introduction Intro
general. Fortunately, the technology involved is straightforward, and this article guides
Lagrange's theorem
you through all that you need to know with a useful example!

Limits and Continuity

Numerical Methods
Homogeneous Second Order Differential Equations
Polynomial Polyn


Program Python
The first major type of second-order differential equations that you need to learn to
Rolle's theorem
solve are the ones that can be written for our dependent variable y and the
Second order Differen
independent variable t:

Different equations are solved in Python using Scipy.integrate package with the
Popular Posts
ODEINT function. Another Python package that solves different equations is GEKKO. 

solving polynomia
python

Also read, Reason behind the huge Demand of Python Developers Solving polynomial eq
this section, we'll discu

equations in python. H
polynomi...

5 imp
ODEINT requires three inputs:
begin

5 imp
beginners in Python If
to program then this a
lot and many people s
y = odeint (model, y0, t)

Why Google Use Py
1. model: A function name that returns values based on y. you should use Pyth
Why Google Use Pytho

should use Python In g
companies are involve
2. y0: Initial condition. as product d...

3. t: Points for the time when the solution should be reported. 


https://www.epythonguru.com/2020/07/second-order-differential-equation.html 1/4
30/10/21, 04:02 Solving Second Order Differential Equations in Python - ePythonGuru


Solvi
The Python code starts importing the required Numpy, Scipy, and Matplotlib packs. Diffe

Model, initial conditions, and time points are defined as the inclusion in ODEINT in Py
Solving Second Order
arithmetic. In many real-life mode
differential equation f

interest de...
An example of using odeint with the following differential equation.
Reason Behind the

Python Developers
Example 1: The reason behind the
for Python Developers
the IT industry: Python
early 1980s...

Contact Form

Python Code:
Name

from matplotlib import pyplot as plt

from scipy.integrate import odeint


Email
*

import numpy as np

def f(u,x):
Message
*

return (u[1],-2*u[1]-2*u[0]+np.cos(2*x))

y0 = [0,0]

xs = np.linspace(1,10,200)

us = odeint(f,y0,xs)
Send

ys = us[:,0]

plt.plot(xs,ys,'-')
plt.plot(xs,ys,'r*')

plt.xlabel('x values')

plt.ylabel('y values')

plt.title('(D**2+2*D+2)y = cos(2*x)')

plt.show()

Output:

Also read, Reason behind the huge Demand of Python Developers


Example 2:

Python Code:

from matplotlib import pyplot as plt

from scipy.integrate import odeint

https://www.epythonguru.com/2020/07/second-order-differential-equation.html 2/4
30/10/21, 04:02 Solving Second Order Differential Equations in Python - ePythonGuru

import numpy as np

def f(u,x):

return (u[1],-5 * u[1]-7)

y0 = [21,12]
xs = np.arange(0,5,0.1)

us = odeint(f,y0,xs)

ys = us[:,0]

plt.plot(xs,ys,'-')
plt.plot(xs,ys,'ro')
plt.xlabel('x values')

plt.ylabel('y values')

plt.title('(D**2+ 5*D+7)y=0')

plt.show()

Output:

Solving Second Order Differential Equations 

Example: 3

Python code:

from matplotlib import pyplot as plt

from scipy.integrate import odeint

import numpy as np

def f(u,x):

return (u[1],-x**2*np.sin(u[0]))

u0 = [1,0]

xs = np.arange(0,3,0.5)

us = odeint(f,u0,xs)

ys = us[:,0]

plt.plot(xs,ys,'-')
plt.plot(xs,ys,'ro')
plt.xlabel('x values')

plt.ylabel('y values')

plt.title('(D**2+x**2.sin(y))')

plt.show()

https://www.epythonguru.com/2020/07/second-order-differential-equation.html 3/4
30/10/21, 04:02 Solving Second Order Differential Equations in Python - ePythonGuru

Summary: In this, we discuss how to solving Second-order Differential equations in


Python Programming. So, in this very first step is importing the libraries that are
necessary. You can also Check this Python Libraries if you read in detail about the
Libraries. Matplotlib is a library for Python programming language. Pyplot is a
Matplotlib module that is used for plotting. Scipy provides a routine for performing
numerical integration. Sometimes a function is complicated to integrate so in that
case it can be solved by numerical integration method. The Scipy.integrate used in
that case because it contains most of the required function. 

SHARE THIS  Facebook


 Twitter

SECOND ORDER DIFFERENTIAL


EQUATIONS

Solving Second Order


Differential Equations in Python

PREVIOUS NEXT
Reason Behind the Huge Demand of Python Developers Program to find the sum of elements in Python

ABOUT PAGES FOLLOWERS

Home Seguidores (3)


About us
Contact us
Disclaimer Seguir
ePythonGURU -Python is Programming language which is used today in Privacy Policy
Web Development and in schools and colleges as it cover only basic
concepts.ePythoGURU is a platform for those who want to learn Terms and Conditions
FOLLOW US
programming related to python and cover topics related to calculus,
Multivariate Calculus, ODE, Numericals Methods Concepts used in
Python Programming.This website is focused on the concept of
Instagram
Mathematics used in programming by using various mathematical
equations. Pin It

Copyright © 2019-2020 ePythonguru.com All Right Reseved

https://www.epythonguru.com/2020/07/second-order-differential-equation.html 4/4

You might also like