Skip to content

Commit 802a3ef

Browse files
committed
sym_integrate
1 parent e7747c7 commit 802a3ef

1 file changed

Lines changed: 34 additions & 4 deletions

File tree

SymPy/sympy_0.py

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,17 +21,47 @@ def Taylor_Expand():
2121
tmp = series(exp(I*x), x, 0, 10)
2222
return tmp
2323

24+
def expand_cos():
25+
# 对cos(x)进行Taylor展开对比exp(i*x)
26+
cos_e = series(cos(x), x, 0, 10)
27+
com_e = series(exp(I*x), x, 0, 10)
28+
print(re(com_e))
29+
print(im(com_e))
30+
return cos_e
31+
32+
# SymPy中进行不定积分运算
33+
def integrate_E():
34+
return integrate(x*sin(x), x)
35+
36+
# 通过定积分得到半圆的面积
37+
def semi_circle():
38+
# 定义运算符号
39+
x, y, r = symbols('x, y, r')
40+
# 这里直接返回了原表达式,因为不知道r的正负关系
41+
temp = 2*integrate(sqrt(r**2-x**2), (x, -r, r))
42+
# 对r进行重新定义
43+
r = symbols('r', positive=True)
44+
circle_area = 2 * integrate(sqrt(r**2-x**2), (x, -r, r))
45+
# 对circle_area进行定积分就可以得到球的体积
46+
# 利用subs特性进行替换
47+
circle_area = circle_area.subs(r, sqrt(r**2-x**2))
48+
# 对circle_area在-r到r区间上进行定积分
49+
return integrate(circle_area,(x, -r, r))
50+
51+
# 测试Latex中的功能
2452
import numpy as np
2553
def latex_E():
2654
# 在python中使用Latex,将表达式转为Latex格式
2755
return latex(exp(I*x+cos(x)))
2856

29-
3057
def main():
3158
ex_num = Expand_E()
32-
print(ex_num)
33-
print(Taylor_Expand())
34-
print(latex_E())
59+
# print(ex_num)
60+
# print(Taylor_Expand())
61+
# print(latex_E())
62+
# print(expand_cos())
63+
# print(integrate_E())
64+
print(semi_circle())
3565

3666
if __name__ == "__main__":
3767
main()

0 commit comments

Comments
 (0)