0% found this document useful (0 votes)
242 views

Sympy Ode Example 12

This document discusses solving a second order differential equation with given initial conditions using the Sympy Python module. It presents the differential equation and initial conditions, then outlines 7 steps to solve it symbolically: 1) import modules and define variables, 2) define the dependent variable symbolically, 3) use Sympy.dsolve to solve the DE, 4) solve constants using initial conditions, 5) substitute constants back into the solution, 6) convert the solution to a numerical form, 7) plot the numerical solution versus the independent variable. The output of the full process is a plot of the solution function over a range of the independent variable values.

Uploaded by

Hemant Kuralkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
242 views

Sympy Ode Example 12

This document discusses solving a second order differential equation with given initial conditions using the Sympy Python module. It presents the differential equation and initial conditions, then outlines 7 steps to solve it symbolically: 1) import modules and define variables, 2) define the dependent variable symbolically, 3) use Sympy.dsolve to solve the DE, 4) solve constants using initial conditions, 5) substitute constants back into the solution, 6) convert the solution to a numerical form, 7) plot the numerical solution versus the independent variable. The output of the full process is a plot of the solution function over a range of the independent variable values.

Uploaded by

Hemant Kuralkar
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

Author: Brian Mungo 03/02/2018

Email: mungoengineering@gmail.com Rev 1

SOLVE A SECOND ORDER DIFFERENTIAL EQUATION WITH GIVEN


INITIAL CONDITIONS USING SYMPY

This discussion will solve the following differential equation (DE) with given initial conditions using a
Python module called Sympy.

𝑦̈ + 𝑦̇ + 𝑦 = 0 ; 𝑦(0) = 1 ; 𝑦̇ (0) = 0 (1)

Step 1: Import all modules and define the independent variable ‘t’.

Step 2: Define your dependent variable in symbol form [2].

Step 3: Using Sympy.dsolve solve the DE.

Output:

The output above is the solution to (1). The output looks confusing however and could use some context
before moving forward. y1’s data type is called a ‘sympy.core.relational.Equality’ [2]. That’s a fancy
term for stating that the 1st index of y1 is equal to the 2nd index. Or,
𝑦(𝑡) = 𝐶1𝑠𝑖𝑛 …

1
Author: Brian Mungo 03/02/2018
Email: mungoengineering@gmail.com Rev 1

If we type the following,

Output:

The (.lhs) means Left Hand Side, while (.rhs) means Right Hand Side.

Step 4: Solve the constants using the given initial conditions. I have not found an easy way to do this yet.
Apparently, this concept is not fully implemented yet. The following seems to work well though [3]. To
solve for the constants, we must solve a system of equations by setting the value of the independent
variable and bringing over the equality condition to one side. The first index below is the equation y1
equal to one, while the second is y1’s derivative equal to zero. [Do not put the = sign in; Move to one
side]

Step 5: Substitute the constants back into y1.

Step 6: Turn the y1 function into an equation that can be numerically solved [3]. This will allow you to
graph y1 in terms of an array of independent values. I do not know why ‘numpy’ is used below.

Step 7: Create an array of ‘t’ values and plot y1 in terms of ‘t’ using matplotlib.pyplot.

2
Author: Brian Mungo 03/02/2018
Email: mungoengineering@gmail.com Rev 1

Output:

References:
[1] http://docs.sympy.org/latest/index.html
[2] http://docs.sympy.org/latest/modules/solvers/ode.html
[3] http://www.eg.bucknell.edu/physics/ph329/jupyter/ode_sympy.ipynb.pdf

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy