用Python解方程

用Python解方程_第1张图片

# -*- coding:utf-8 -*-
import sympy

x,y = sympy.symbols("x y")   # 申明未知数"x"和"y"
b = sympy.solve([3*x -2*y-3,x+2*y-5],[x,y])
print(b)

运行结果:{x: 2, y: 3/2}

2、已知 x+y=0.2,x+3y=1,则代数式 x*x +4xy+4y*y 的值为()

# -*- coding:utf-8 -*-
import sympy

x,y = sympy.symbols("x y")
c = sympy.solve([x+y-0.2,x+3*y-1],[x,y])
print(c)
m = c[x]
n = c[y]
print(m*m+4*m*n+4*n*n)

运行结果:0.360000000000000

 

用Python解方程_第2张图片

# -*- coding:utf-8 -*-
import sympy

x = sympy.symbols("x")
a = sympy.solve([((x+1)/x + 1/(x-2))-1],[x])
print(a)

运行结果:{x: 1}

你可能感兴趣的:(python学习笔记)