문제

Is there a Python 2.7 package that contains a Gauss-Siedel solver for systems with more than 3 linear algebraic equations containing more than 3 unknowns? A simple example of the sort of problem I would like to solve is given below. If there are no templates or packages available, is it possible to solve this in python? If so please could you advise on the best way of going about it. Thanks.

An example of three linear algebraic equations with three unknowns (x,y,z):

x - 3y + z = 10

2x + 5y + z = 4

-x + y - 2z = -13

도움이 되었습니까?

해결책

After a bit of searching around I found the solution was to use the numpy.linalg.solve command. The command uses the LAPACK gesv routine to solve the problem; however I am not sure what iterative technique this uses.

Here is the code to solve the problem if anyone is interested:

a = np.array([[1,-3,1],[2,5,1],[-1,1,-2]])
b = np.array([10,4,-13])

x = np.linalg.solve(a, b)

print x

print np.allclose(np.dot(a, x), b)      # To check the solution is found
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top