TVP

# 用Python来学高数？解方程组？简直不敢相信！简直不可思议！

from sympy import *def fangchengzu(): """求解方程组""" #定义变量 x,y = symbols('x y') # 使用solve()函数求解x，y的值 result = solve((2*x-y-3,3*x+y),(x,y)) print(result)if __name__ == '__main__': fangchengzu()

from sympy import *def qiujixain(): x = symbols('x') expr = x**2/exp(x) # 无穷用两个o表示 result = limit(expr,x,oo) print('被求函数为：') pprint(expr) print('结果为：') pprint(result)if __name__ == '__main__': qiujixain()

from sympy import *def qiuweifen(): """求微分""" f = Function('f') x = symbols('x') f = exp(tan(1/x)) * sin(1/x) result = diff(f,x) print('被求函数为') pprint(f) print('结果为:') pprint(result)if __name__ == '__main__': qiuweifen()

diff()函数第一个参数存放表达式，第二个参数存放对哪个变量求微分，如需要计算高阶导数，可在后面加数字，没写默认求一阶导数。输出结果如下：

diff()函数也可以用来求偏导，例如求以下的偏导：

from sympy import *from sympy.abc import x,ydef qiuweifen(): """求偏导""" # 定义一个函数f，它是x，y的函数 f = Function('f')(x,y) f = x**2 * sin(2*y) # 对x求偏导 fx = f.diff(x) # 对y求偏导 fy = f.diff(y) print('所求函数为：') pprint(f) print('对x偏导为：') pprint(fx) print('对y偏导为：') pprint(fy)if __name__ == '__main__': qiuweifen()

from sympy import *def budingjifen(): """求不定积分""" x = symbols('x') expr = (x**2)/(x**2 + 1) result = integrate(expr,x) print("被积函数为：") pprint(expr) print('不定积分结果为：') pprint(result)if __name__ == '__main__': budingjifen()

from sympy import *def dingjifen(): """求定积分""" f = Function('f') x = symbols('x') f = exp(-x**2) expr_1 = diff(f,x) expr_2 = diff(f,x,2) expr = expr_1 * expr_2 result = integrate(expr,(x,0,1)) print('被积函数为：') pprint(expr) print('结果为：') pprint(result)if __name__ == '__main__': dingjifen()

from sympy import *def weifenfangcheng(): """常微分方程""" f = Function('f') x = symbols('x') expr = diff(f(x),x,2) + 2*diff(f(x),x) + 3*f(x) result = dsolve(expr,f(x)) pprint(result)if __name__ == '__main__': weifenfangcheng()

from sympy import *from sympy.abc import x,ydef weifenfangcheng(): """偏微分方程求解""" f = Function('f') # 表示z为x，y的函数 z = f(x,y) zx = z.diff(x) zy = z.diff(y) eq = Eq(1 + (2*(zx/z)) + (3*(zy/z))) result = pdsolve(eq) print('微分方程为：') pprint(eq) print('求得函数为：') pprint(result)if __name__ == '__main__': weifenfangcheng()

• 发表于:
• 原文链接https://kuaibao.qq.com/s/20181008A0335600?refer=cp_1026
• 腾讯「腾讯云开发者社区」是腾讯内容开放平台帐号（企鹅号）传播渠道之一，根据《腾讯内容开放平台服务协议》转载发布内容。
• 如有侵权，请联系 cloudcommunity@tencent.com 删除。

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22

2024-04-22