[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy

Introduction

Use the solve method of sympy to derive analytical solutions for the quadratic equation $ ax ^ 2 + bx + c = 0 $ and the cubic equation $ ax ^ 3 + bx ^ 2 + cx + d = 0 $.

code

(1)Quadratic equation


from sympy import *
x=Symbol('x')                  #letter'x'Is defined as the variable x
"""
Derivation of solution formula
"""
a=Symbol('a')
b=Symbol('b')
c=Symbol('c')
d=Symbol('d')
#Quadratic equation
solve(a*x**2+b*x+c,x)

Result (1)

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


Formula for solving cubic equations

(2)Cubic equation


from sympy import *
x=Symbol('x')                  #letter'x'Is defined as the variable x
"""
Derivation of solution formula
"""
a=Symbol('a')
b=Symbol('b')
c=Symbol('c')
d=Symbol('d')
solve(a*x**3+b*x**2+c*x+d, x)

Result (2)

スクリーンショット 2017-07-31 3.28.20.png


Similarly, the formula for the solution of the quartic equation can be derived.

Recommended Posts

[Scientific / technical calculation by Python] Derivation of analytical solutions for quadratic and cubic equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Solving ordinary differential equations, mathematical formulas, sympy
[Scientific / technical calculation by Python] Analytical solution to find the solution of equation sympy
[Science and technology calculation by Python] Taylor expansion, mathematical formulas, sympy
[Science and technology calculation by Python] Integral, mathematical formula, sympy
[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] Basic operation of arrays, numpy
[Scientific / technical calculation by Python] Numerical solution of second-order ordinary differential equations, initial value problem, numerical calculation
[Scientific and technical calculation by Python] Drawing of fractal figures [Sierpinski triangle, Bernsley fern, fractal tree]
[Scientific / technical calculation by Python] Solving simultaneous linear equations, numerical calculation, numpy
[Science and technology calculation by Python] (Partial) differential, mathematical formula, sympy
Scientific / technical calculation by Python] Drawing and visualization of 3D isosurface and its cross section using mayavi
[Scientific / technical calculation by Python] Sum calculation, numerical calculation
[Scientific / technical calculation by Python] Fitting by nonlinear function, equation of state, scipy
[Scientific / technical calculation by Python] Calculation of matrix product by @ operator, python3.5 or later, numpy
[Scientific / technical calculation by Python] Inverse matrix calculation, numpy
[Scientific / technical calculation by Python] Drawing animation of parabolic motion with locus, matplotlib
[Scientific / technical calculation by Python] Solving second-order ordinary differential equations by Numerov method, numerical calculation
[Scientific / technical calculation by Python] Histogram, visualization, matplotlib
[Scientific / technical calculation by Python] Lagrange interpolation, numerical calculation
[Scientific / technical calculation by Python] Numerical calculation to find the value of derivative (differential)
Calculation of technical indicators by TA-Lib and pandas
[Scientific / technical calculation by Python] Drawing of 3D curved surface, surface, wireframe, visualization, matplotlib
[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] Logarithmic graph, visualization, matplotlib
[Scientific / technical calculation by Python] Polar graph, visualization, matplotlib
[Science / technical calculation by Python] Numerical solution of first-order ordinary differential equations, initial value problem, numerical calculation
[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 / technical calculation by Python] Wave "beat" and group velocity, wave superposition, visualization, high school physics
[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] 3rd order spline interpolation, scipy
Derivation and implementation of update equations for non-negative tensor factorization
[Scientific / technical calculation by Python] Monte Carlo integration, numerical calculation, numpy
Derivation of EM algorithm and calculation example for coin toss
[Scientific / technical calculation by Python] Monte Carlo simulation of thermodynamics of 2D Ising spin system by Metropolis method
[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
[Science / technical calculation by Python] Comparison of convergence speeds of SOR method, Gauss-Seidel method, and Jacobi method for Laplace equation, partial differential equation, boundary value problem
[Scientific / technical calculation by Python] Numerical integration, trapezoidal / Simpson law, numerical calculation, scipy
[Scientific / technical calculation by Python] 1D-3D discrete fast Fourier transform, scipy
[Scientific / technical calculation by Python] 2D random walk (drunk walk problem), numerical calculation
Derivation of multivariate t distribution and implementation of random number generation by python
"Manim" that can draw animation of mathematical formulas and graphs with Python
[Control engineering] Calculation of transfer functions and state space models by Python