[Scientific / technical calculation by Python] Analytical solution to find the solution of equation sympy

Contents

Use sympy's solve method to solve the following three problems.

(1) Find the root of the quadratic equation, $ x ^ 2 + 5x + 3 = 0 $. (2) Solve the cubic equation, $ 3x ^ 3 + 3x-5 = 0 $. Imaginary solution comes out. (3) Solve the two-dimensional simultaneous equations, $ x ^ 2 + y ^ 2 = 4, y = 2x + 1 $.


Code (1)

Example(1)


from sympy import *
x=Symbol('x')                  #letter'x'Is defined as the variable x

"""
equation: solve
Example: 2 * x **2 +5*x+3=Find the root of 0
"""
sol=solve(2 * x **2 +5*x+3, x) #Store the solution in sol
print(sol)

Result: Example (1)

スクリーンショット 2017-07-18 14.51.46.png


Code (2)

Example(2)


from sympy import *
x=Symbol('x')                  #letter'x'Is defined as the variable x

"""
equation: solve
Example: 2 * x **3 +3*x-5=Find the root of 0
"""
sol=solve(2 * x **3 +3*x-5, x)
print(sol)

Result: Example (2)

スクリーンショット 2017-07-18 14.57.38.png


Code (3)

example(3)


from sympy import *
x=Symbol('x')    #letter'x'Is defined as the variable x
y=Symbol('y')    #letter'x'Is defined as the variable x

"""
equation: solve
Simultaneous equations x**2+y**2=4, y=2x+Find the solution of 1
"""
b= solve ([x*2+y**2-4, y-2*x+1],[x,y])  #Solve simultaneous equations
print(b)

Result: Example (3)

[(1/4 + sqrt(13)/4, -1/2 + sqrt(13)/2), (-sqrt(13)/4 + 1/4, -sqrt(13)/2 - 1/2)]

Recommended Posts

[Scientific / technical calculation by Python] Analytical solution to find the solution of equation sympy
Find the solution of the nth-order equation in python
[Scientific / technical calculation by Python] Fitting by nonlinear function, equation of state, scipy
[Scientific / technical calculation by Python] Solving one-dimensional Newton equation by the 4th-order Runge-Kutta method
[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Basic operation of arrays, numpy
[Scientific / technical calculation by Python] Sum calculation, numerical calculation
[Scientific / technical calculation by Python] Numerical solution of second-order ordinary differential equations, initial value problem, numerical calculation
[Scientific / technical calculation by Python] Numerical solution of one-dimensional harmonic oscillator problem by velocity Verlet method
[Scientific / technical calculation by Python] Numerical solution of eigenvalue problem of matrix by power method, numerical linear algebra
[Scientific / technical calculation by Python] Calculation of matrix product by @ operator, python3.5 or later, numpy
[Scientific / technical calculation by Python] Solving ordinary differential equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Inverse matrix calculation, numpy
[Scientific / technical calculation by Python] Histogram, visualization, matplotlib
[Scientific / technical calculation by Python] Drawing animation of parabolic motion with locus, matplotlib
[Scientific / technical calculation by Python] Drawing of 3D curved surface, surface, wireframe, visualization, matplotlib
[Scientific / technical calculation by Python] Numerical solution of two-dimensional Laplace-Poisson equation by Jacobi method for electrostatic potential, elliptic partial differential equation, boundary value problem
[Scientific / technical calculation by Python] Numerical solution of one-dimensional unsteady heat conduction equation by Crank-Nicholson method (implicit method) and FTCS method (positive solution method), parabolic partial differential equation
[Scientific / technical calculation by Python] Logarithmic graph, visualization, matplotlib
[Scientific / technical calculation by Python] Polar graph, visualization, matplotlib
[Scientific / technical calculation by Python] Solving the boundary value problem of ordinary differential equations in matrix format, numerical calculation
[Scientific / technical calculation by Python] Plot, visualization, matplotlib of 2D data read from file
[Scientific / technical calculation by Python] Drawing, visualization, matplotlib of 2D (color) contour lines, etc.
[Scientific / technical calculation by Python] Numerical solution of one-dimensional and two-dimensional wave equations by FTCS method (explicit method), hyperbolic partial differential equations
[Scientific / technical calculation by Python] 3rd order spline interpolation, scipy
I tried to find the entropy of the image with python
[Scientific / technical calculation by Python] Monte Carlo integration, numerical calculation, numpy
Debug by attaching to the Python process of the SSH destination
Find the diameter of the graph by breadth-first search (Python memory)
[Scientific / technical calculation by Python] List of matrices that appear in Hinpan in numerical linear algebra
[Scientific / technical calculation by Python] List of usage of (special) functions used in physics by using scipy
[Scientific and technical calculation by Python] Drawing of fractal figures [Sierpinski triangle, Bernsley fern, fractal tree]
[Scientific / technical calculation by Python] Numerical integration, trapezoidal / Simpson law, numerical calculation, scipy
[Scientific / technical calculation by Python] Solving simultaneous linear equations, numerical calculation, numpy
[Scientific / technical calculation by Python] Vector field visualization example, electrostatic field, matplotlib
[Scientific / technical calculation by Python] 2D random walk (drunk walk problem), numerical calculation
Find the numerical solution of the second-order ordinary differential equation with scipy
[Python] A simple function to find the center coordinates of a circle
[Scientific / technical calculation by Python] Monte Carlo simulation of thermodynamics of 2D Ising spin system by Metropolis method
Scientific / technical calculation by Python] Drawing and visualization of 3D isosurface and its cross section using mayavi
Find the white Christmas rate by prefecture with Python and map it to a map of Japan
What is Newton's method? ?? Approximate solution of equation to be solved by Newton's method
I tried to find the optimal path of the dreamland by (quantum) annealing
Pandas of the beginner, by the beginner, for the beginner [Python]
I tried to verify and analyze the acceleration of Python by Cython
[Scientific / technical calculation by Python] Solving one-dimensional Schrodinger equation in stationary state by shooting method (1), well-type potential, quantum mechanics
[Scientific / technical calculation by Python] Solving (generalized) eigenvalue problem using numpy / scipy, using library
[Circuit x Python] How to find the transfer function of a circuit using Lcapy
[Scientific / technical calculation by Python] Solving second-order ordinary differential equations by Numerov method, numerical calculation
[python] How to sort by the Nth Mth element of a multidimensional array
How to find the coefficient of the trendline that passes through the vertices in Python
[Scientific / technical calculation by Python] Plot, visualize, matplotlib 2D data with error bars
How to find the area of the Voronoi diagram
Combinatorial optimization to find the hand of "Millijan"
Find the divisor of the value entered in python
Calculation of technical indicators by TA-Lib and pandas
How to erase the characters output by Python
Solving the equation of motion in Python (odeint)
Find the geometric mean of n! Using Python
[Introduction to Algorithm] Find the shortest path [Python3]
[Scientific / technical calculation by Python] Solving the Schrodinger equation in the steady state in the 3D isotropic harmonic oscillator potential by the matrix method, boundary value problem, quantum mechanics