Solve simultaneous ordinary differential equations with Python and SymPy.

Here, I would like to install sympy in Python and solve simultaneous ordinary differential equations.

sympy site

https://docs.sympy.org/latest/index.html

Warming up

First, I will write an example of the differentiation of a basic function using sympy.

python


import sympy as sym
x = sym.Symbol('x')
h = x**3 + 3*x + 1
h.diff(x,1)

Simultaneous first-order ordinary differential equations

Let's solve the simultaneous first-order ordinary differential equations.

python


x = sym.Symbol('x')
f = sym.Function('f')
g = sym.Function('g')
h = sym.Function('h')
eq1 = sym.Eq(f(x).diff(x,1),g(x)+h(x))
eq2 = sym.Eq(g(x).diff(x,1),h(x)+f(x))
eq3 = sym.Eq(h(x).diff(x,1),f(x)+g(x))
sym.dsolve([eq1, eq2, eq3])

Doesn't it correspond to partial differential equations?

Let's get along and solve the PDE.

The partial differential calculation itself is possible.

python


x = sym.Symbol('x')
y = sym.Symbol('y')
u = x**2 - y**2
u.diff(x,1)

However, even if I try to do the following calculation, the answer does not come out well.

python


x = sym.Symbol('x')
y = sym.Symbol('y')
u = x**2 - y**2
v = sym.Function('v')
eq1 = sym.Eq(u.diff(x,1), v(x,y).diff(y,1))
eq2 = sym.Eq(u.diff(y,1), -v(x,y).diff(x,1) )
sym.dsolve([eq1, eq2])

Hmm ... It corresponds to the equivalent of the second year of university, but it is not possible to correspond a little when it is equivalent to the third grade or higher. (; ^ _ ^ A

Recommended Posts

Solve simultaneous ordinary differential equations with Python and SymPy.
[Python] Solve equations with sympy
Let's solve simultaneous linear equations with Python sympy!
Solve ordinary differential equations in Python
Solving ordinary differential equations with Python ~ Universal gravitation
Multiple integrals with Python and Sympy
Numerical analysis of ordinary differential equations with Scipy's odeint and ode
Solve the initial value problem of ordinary differential equations with JModelica
[Scientific / technical calculation by Python] Solving ordinary differential equations, mathematical formulas, sympy
I tried Jacobian and partial differential with python
Solve simultaneous equations in an instant using Python
Solve Sudoku with Python
Solve POJ 2386 with python
Make ordinary tweets fleet-like with AWS Lambda and Python
Programming with Python and Tkinter
Encryption and decryption with Python
UDP simultaneous connection with Python
python with pyenv and venv
Solve AtCoder ABC 186 with Python
Works with Python and R
[Numerical calculation method, python] Solving ordinary differential equations by Eular method
Solve with Ruby and Python AtCoder ABC133 D Cumulative sum
Solve the spiral book (algorithm and data structure) with python!
Communicate with FX-5204PS with Python and PyUSB
Shining life with Python and OpenCV
solver> Link> Solve Excel Solver with python
Robot running with Arduino and python
Install Python 2.7.9 and Python 3.4.x with pip.
AM modulation and demodulation with python
[Python] font family and font with matplotlib
Scraping with Python, Selenium and Chromedriver
I want to solve APG4b with Python (only 4.01 and 4.04 in Chapter 4)
Solve ABC166 A ~ D with Python
[Science and technology calculation by Python] (Partial) differential, mathematical formula, sympy
Play with Poincare series and SymPy
How to solve simultaneous linear equations
Scraping with Python and Beautiful Soup
JSON encoding and decoding with python
Solve AtCoder Problems Recommendation with python (20200517-0523)
Hadoop introduction and MapReduce with Python
[GUI with Python] PyQt5-Drag and drop-
Solve ABC168 A ~ C with Python
Solving simultaneous linear equations in Python (sweeping method and fractional representation)
Reading and writing NetCDF with Python
I played with PyQt5 and Python3
Solve with Ruby, Python and Java AtCoder ARC104 B Cumulative sum
Solve ABC162 A ~ C with Python
Solve the Python knapsack problem with a branch and bound method
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Reading and writing CSV with Python
Coexistence of Python2 and 3 with CircleCI (1.0)
Easy modeling with Blender and Python
Sugoroku game and addition game with python
FM modulation and demodulation with Python
Solve with Python [100 past questions that beginners and intermediates should solve] (028 --033 breadth-first search)
Solve with Ruby, Perl, Java and Python AtCoder ABC 047 C Regular Expression
Communicate between Elixir and Python with gRPC
Data pipeline construction with Python and Luigi
Monitor Mojo outages with Python and Skype
FM modulation and demodulation with Python Part 3