1、sympy库的安装(cmd输入pip install sympy)
C:\Users\17865>pip install sympy
2、根号运算的精确表达
小数形式的计算:
import math
print (math.sqrt(8))
PS C:\Users\17865> & C:/Users/17865/AppData/Local/Microsoft/WindowsApps/python3.11.exe d:/Python/sympy1.py
2.8284271247461903
import sympy
print (sympy.sqrt(8))
PS C:\Users\17865> & C:/Users/17865/AppData/Local/Microsoft/WindowsApps/python3.11.exe d:/Python/sympy1.py
2*sqrt(2)
3、符号的表达式运算
from sympy import symbols
x,y,z = symbols('x y z')
expr = x + 2*y +3*z
print(expr*expr)
PS C:\Users\17865> & C:/Users/17865/AppData/Local/Microsoft/WindowsApps/python3.11.exe d:/Python/sympy1.py
(x + 2*y + 3*z)**2
4、因式分解计算
from sympy import symbols,factor
x,y,z = symbols('x y z')
expr = x*x+y*y+z*z+2*x*y+2*y*z+2*x*z
print(factor(expr))
PS C:\Users\17865> & C:/Users/17865/AppData/Local/Microsoft/WindowsApps/python3.11.exe d:/Python/sympy1.py
(x + y + z)**2
5、求导
from sympy import *
x = symbols('x')
print ( diff(sin(x)*exp(x),x) )
PS C:\Users\17865> & C:/Users/17865/AppData/Local/Microsoft/WindowsApps/python3.11.exe d:/Python/sympy1.py
exp(x)*sin(x) + exp(x)*cos(x)
6、求不定积分
from sympy import *
x = symbols('x')
print ( integrate (sin(x)*exp(x),x) )
exp(x)*sin(x)/2 - exp(x)*cos(x)/2
7、求极限
from sympy import *
x = symbols('x')
print ( limit (sin(x)/x,x,0) )
PS C:\Users\17865> & C:/Users/17865/AppData/Local/Microsoft/WindowsApps/python3.11.exe d:/Python/sympy1.py
1
标签:Users,import,17865,symbols,Sympy,sympy,print,符号计算
From: https://www.cnblogs.com/czy363/p/17963113