python求方程解析解和数值解

解一元方程:

1
2
3
from sympy import *
x, a, b, c = symbols('x a b c')
solve(a * x**2 + b * x + c, x)

解多元方程:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
from sympy import *
x, y, z = symbols('x y z')
solve([y + x - 1, 3 * x + 2 * y - 5], [x, y])
limit(sin(x) / x, x, 0)
simplify(sin(x)**2 + cos(x)**2)
expand((x + 1)**2)
factor(x**2 + 2*x + 1)
collect(x*y + x - 3 + 2*x**2 - z*x**2 + x**3, x)
trigsimp(cosh(x)**2 + sinh(x)**2)
expand_trig(sin(x + y)) 
 
x, y = symbols('x y', positive=True)
n = symbols('n', real=True)
expand_log(log(x*y))
logcombine(n*log(x))
 
E**(I*pi)+1
expand(exp(I*x), complex=True)
 
tmp = series(exp(I*x), x, 0, 10)
pprint(tmp)
re(tmp)
series(sinh(x), x, 0, 10)
 
integrate(x*sin(x), x)
integrate(x*sin(x), (x, 0, 2*pi))
diff(x**2)
 
r = symbols('r', positive=True)
circle_area = 2 * integrate(sqrt(r**2-x**2), (x, -r, r))
circle_area.subs(r, x)

求数值解

1
2
3
s = solve(a * x**2 + b * x + c, x)
val = s.evalf(subs = {a:1, b:2, c:1})
print(str(val))

Fourier,

from sympy import *
from sympy.abc import x
s = fourier_series(x**2, (x, -pi, pi))
s.truncate(4)

refer to:
https://blog.csdn.net/shuangguo121/article/details/86611948
https://www.cnblogs.com/coshaho/p/9653460.html
https://baike.baidu.com/item/%E5%8F%8C%E6%9B%B2%E5%87%BD%E6%95%B0/8704306?fr=aladdin
https://www.cnblogs.com/FrostyForest/p/16660154.html

Leave a Comment