Let's solve simultaneous linear equations with Python sympy!

What is Sympy

SymPy is a library for computer algebra in Python (free!) Something like Mathematica!

Official page

Here

let's try it

environment

$ python3 -V
Python 3.7.3

Building a virtual environment

$ mkdir algebra-homework
$ cd algebra-homework
$ python3 -m venv venv
$ source ./venv/bin/activate

sympy installation


$ pip install sympy
Collecting sympy
  Downloading https://files.pythonhosted.org/packages/ce/5b/acc12e3c0d0be685601fc2b2d20ed18dc0bf461380e763afc9d0a548deb0/sympy-1.5.1-py2.py3-none-any.whl (5.6MB)
    100% |████████████████████████████████| 5.6MB 1.2MB/s 
Collecting mpmath>=0.19 (from sympy)
  Downloading https://files.pythonhosted.org/packages/ca/63/3384ebb3b51af9610086b23ea976e6d27d6d97bf140a76a365bd77a3eb32/mpmath-1.1.0.tar.gz (512kB)
    100% |████████████████████████████████| 522kB 1.6MB/s 
Installing collected packages: mpmath, sympy
  Running setup.py install for mpmath ... done
Successfully installed mpmath-1.1.0 sympy-1.5.1
You are using pip version 19.0.3, however version 20.1 is available.
You should consider upgrading via the 'pip install --upgrade pip' command.

Try to solve simultaneous equations

-7x +2y +10 = 0 3x +5y +9 = 0

$ python
Python 3.7.3 (default, Mar  6 2020, 22:34:30) 
[Clang 11.0.3 (clang-1103.0.32.29)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import sympy
>>> x=sympy.Symbol('x')
>>> y=sympy.Symbol('y')
>>> sympy.solve([-7*x+2*y+10,3*x+5*y+9])
{x: 32/41, y: -93/41}

Try to solve x by hand

-7x +2y +10 = 0 3x +5y +9 = 0

-35x+10y+50=0 6x+10y+18=0

-41x+0y+32=0

x=32/41


There seems to be something! It was good

Recommended Posts

Let's solve simultaneous linear equations with Python sympy!
Solve simultaneous ordinary differential equations with Python and SymPy.
How to solve simultaneous linear equations
Solve AtCoder 167 with python
Solve Sudoku with Python
Solve POJ 2386 with python
Solve simultaneous equations in an instant using Python
Solve AtCoder ABC166 with python
Let's run Excel with Python
Let's write python with cinema4d.
UDP simultaneous connection with Python
[Python] Linear regression with scikit-learn
Let's build git-cat with Python
Solve AtCoder ABC 186 with Python
[Circuit x Python] How to solve circuit equations symbolically using sympy
solver> Link> Solve Excel Solver with python
Solve ABC163 A ~ C with Python
Let's make a GUI with python.
Solve ABC166 A ~ D with Python
Let's play with Excel with Python [Beginner]
Solve AtCoder Problems Recommendation with python (20200517-0523)
Solve ABC168 A ~ C with Python
Let's do image scraping with Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Let's make a graph with python! !!
Multiple integrals with Python and Sympy
Solve ordinary differential equations in Python
Let's analyze voice with Python # 1 FFT
[Scientific / technical calculation by Python] Solving simultaneous linear equations, numerical calculation, numpy
Solving simultaneous linear equations in Python (sweeping method and fractional representation)
Let's make a shiritori game with Python
Algorithm learned with Python 9th: Linear search
Let's solve the portfolio with continuous optimization
Let's create a free group with Python
I wanted to solve ABC160 with Python
[Introduction to Python] Let's use foreach with Python
Let's read the RINEX file with Python ①
Let's make a voice slowly with Python
[AtCoder] Solve ABC1 ~ 100 A problem with Python
[Python] Let's make matplotlib compatible with Japanese
Solve AtCoder ABC168 with python (A ~ D)
Let's do MySQL data manipulation with Python
Let's calculate Godel's β function with SymPy
Let's make a web framework with Python! (1)
Let's make a Twitter Bot with Python!
Solve Lake Counting (POJ NO.2386) with Python3
I wanted to solve ABC172 with Python
Let's develop an investment algorithm with Python 1
Let's get along with Python # 0 (Environment construction)
Let's make a web framework with Python! (2)
[Blender x Python] Let's get started with Blender Python !!
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Python hand play (let's get started with AtCoder?)
Solving ordinary differential equations with Python ~ Universal gravitation
I wanted to solve NOMURA Contest 2020 with Python
Let's write FizzBuzz with an error: Python Version
Try to solve the man-machine chart with Python
Solve A ~ D of yuki coder 247 with python
Let's control EV3 motors and sensors with Python