Amit Kumar : Life Is Learning!

GSoC : This week in SymPy #1


Hi there! The First week of the coding period has came to an end, this week has been very hectic for me due to my practicals and Minor project submission at college, though I mananged to reach the goal for this week.

This week, I worked on Linear system solver linsolve in the solveset Module, as I mentioned in my last post, about my goals for Week 1.

Progress of Week 1

I implemented the following two functions:

PR : #9438. It’s almost good to merge after a final review by flacjacket & hargup.

  • linear_eq_to_matrix : method to convert system of linear Equations to Matrix Form.

  • linsolve: It’s the General Linear System solver.

Thanks to Jason for reviewing my initial implementation & suggesting useful changes.

Algorithm Used

The algorithm used in linsolve is Gauss-Jordan elimination, which results, after elimination, in an reduced row echelon form matrix. (used rref() method of matrices)

Capabilities of Linsolve

linsolve is a powerful linear system solver, It can solve all types of linear systems, accepted in all input forms, hence providing a user friendly Public API.

  • under-determined:
In []: A = Matrix([[1, 2, 3], [4, 5, 6], [7, 8, 9]])

In []: b = Matrix([3, 6, 9])

In []: linsolve((A, b), [x, y, z])
Out[]:{(z - 1, -2*z + 2, z)}
  • well-behaved:
In []: Eqns = [3*x + 2*y - z - 1, 2*x - 2*y + 4*z + 2, - x + S(1)/2*y - z]

In []: linsolve(Eqns, x, y, z)
Out[]:{(1, -2, -2)}
  • over-determined:
# Parametrized solution
In []: A = Matrix([[1, 5, 3], [2, 10, 6], [3, 15, 9], [1, 4, 3]])

In []: b = Matrix([0, 0, 0, 1])

In []: linsolve((A, b), [x, y, z])
Out[]:{(-3*z + 5, -1, z)}

# No solution
In []: A = Matrix([[1, 5, 3], [2, 1, 6], [1, 7, 9], [1, 4, 3]])

In []: b = Matrix([0, 0, 0, 1])

In []: linsolve((A, b), [x, y, z])
Out[]: ....
ValueError: Linear system has no solution

The input formats supported:

(as mentioned in my last post)

  • Augmented Matrix Form
  • List Of Equations Form
  • Input A & b Matrix Form (from Ax = b)

Plan for Week 2:

This week I plan to work on Complex Sets.

That’s all for now, looking forward for week #2.