[Python] Solve equations with sympy

Introduction

I want to solve the cubic equation easily ... The formula for the solution of the cubic equation is extremely long. If you are interested here When I searched for a programmatic solution to this, there was a module called sympy in Python. Really awesome.

environment

Both worked

How to use

Installation

It's already installed in Anaconda's environment, but if not, install it with pip

pip install sympy

Solve the equation

I want to solve the equation for the time being! Click here You can define characters with Symbol and solve equations withsolve (). Solve the following cubic equation.

3x^3 + 2x^2 + x + 10 = 0

Exponentiation can be written in Python's standard exponentiation style.

x**3 #x cubed

The following is the program.

from sympy import *

x = Symbol('x')

sol = solve(3*x**3 + 2*x**2 + x + 10)

print(sol)

Output result. Three solutions are passed in list.

[-5/3, 1/2 - sqrt(7)*I/2, 1/2 + sqrt(7)*I/2]

This is the same as below.

[\frac{-5}{3}, \frac{1}{2} - \frac{{\sqrt{7}}i}{2}, \frac{1}{2} + \frac{{\sqrt{7}}i}{2}]

Various other functions

~ Under investigation ~ Append

Recommended Posts

[Python] Solve equations with sympy
Let's solve simultaneous linear equations with Python sympy!
Solve simultaneous ordinary differential equations with Python and SymPy.
Solve AtCoder 167 with python
Solve Sudoku with Python
Solve POJ 2386 with python
Solve AtCoder ABC166 with python
Solve AtCoder ABC 186 with Python
solver> Link> Solve Excel Solver with python
Solve ABC163 A ~ C with Python
Solve ABC166 A ~ D with Python
Solve AtCoder Problems Recommendation with python (20200517-0523)
Solve ABC168 A ~ C with Python
Solve ABC162 A ~ C with Python
Solve ABC167 A ~ C with Python
Solve ABC158 A ~ C with Python
Multiple integrals with Python and Sympy
Solve ordinary differential equations in Python
[Circuit x Python] How to solve circuit equations symbolically using sympy
FizzBuzz with Python3
Scraping with Python
Statistics with python
Scraping with Python
Python with Go
Twilio with Python
Integrate with Python
I wanted to solve ABC160 with Python
Play with 2016-Python
AES256 with python
Tested with Python
python starts with ()
[AtCoder] Solve ABC1 ~ 100 A problem with Python
with syntax (Python)
Solve AtCoder ABC168 with python (A ~ D)
Bingo with python
Zundokokiyoshi with python
Solve Lake Counting (POJ NO.2386) with Python3
I wanted to solve ABC172 with Python
Excel with Python
Microcomputer with Python
Cast with python
[AtCoder] Solve A problem of ABC101 ~ 169 with Python
Solving ordinary differential equations with Python ~ Universal gravitation
I wanted to solve NOMURA Contest 2020 with Python
Try to solve the man-machine chart with Python
Solve A ~ D of yuki coder 247 with python
I want to solve APG4b with Python (Chapter 2)
Solve simultaneous equations in an instant using Python
Solve "AtCoder version! Ant book (beginner)" with Python!
Serial communication with Python
Zip, unzip with python
Django 1.11 started with Python3.6
Primality test with Python
Python with eclipse + PyDev.
Socket communication with Python
Data analysis with python 2
Scraping with Python (preparation)
Try scraping with Python.
Solve ABC168D in Python
Learning Python with ChemTHEATER 03
Sequential search with Python