我目前需要一个课程,该课程必须能够显示和解决这样的方程组:
| 2x-4y+4z=8 |
| 34x+3y-z=30 |
| x+y+z=108 |
我认为写一个类将方程系统的左侧转换为类似矩阵的对象是个好主意,这里是用于该系统的自制矩阵:
/2 -4 4\
|34 3 -1|
\1 1 1/
我目前写下了如下内容:
class mymatrix(object):
def __init__(self):
o11 = None
o12 = None
o12 = None
o21 = None
o22 = None
o23 = None
o31 = None
o32 = None
o33 = None
def set(row, column, value):
string = 'o'+str(row)+str(column)+' = '+str(value)
exec(string)
def solve(self, listwithrightsidethings):
#Here I want to solve the system. This code should read the three
#values out of the list and solves the system It should return the
#values for x, y and z in a tuple: (x, y, z)
pass
我正在寻找解决线性代数问题的模块,然后我发现了numpy。我在手册中搜索但没有找到完全解决我的问题的方法。
我该如何编写solve
函数?
编辑:
Python应该这样解释它
/o11, o21, o31\ 123
|o21, o22, o32| = 456
\o31, o32, o33/ 789
编辑:我想用准确的三个变量解决它,并将其作为元组返回。
tuple(x)
。 - zaphodef