Improving the performance of solving linear equations

42 views
Skip to first unread message

tvn

unread,
Jun 28, 2013, 2:20:24 PM6/28/13
to sage-s...@googlegroups.com

Hi, I am wondering if there's some way to speed up the process of solving linear equations for a lot unknowns (200+). For Current I just apply solve() directly over 200+ linear equations and let it solve for the unknowns, e.g., solve([2c_0 + 2c_1 + 3= 0 ,  4.2c_0 + 5c_1 + 1 = 0  ... ] , solution_dict=True).  This takes lots of time when I have hundreds of equations with hundreds of unknowns c_i.    

I do know that most (over 70%) of the unknown coefficients will be 0 and most of the non-zero coefficients will be related.  That is,  among the non-zero coefficients, some of them will get independent values r_i and other non-zero coefficients will depend on these. For example, c_10 = r1 , c_9 = 2*r1+3 , c_8=r2 , c_1 = 1/2*r2 .  Given these information, is there something that I can do to speed up the process ?   Could I use some special data structure, sparse matrix or something ?  

Volker Braun

unread,
Jun 28, 2013, 2:45:28 PM6/28/13
to sage-s...@googlegroups.com
Don't use the general-purpose solve() for linear equations. Write your system of linear equations in matrix form and then use the solve_left() / solve_right() method of matrices. Solving something in the order of 200 equations should be almost instantaneous.

tvn

unread,
Jun 28, 2013, 5:33:59 PM6/28/13
to sage-s...@googlegroups.com
I can convert my data to a matrix M but M.solve_left() will give 0 to *all* coefficients in my matrix. This is not the results given by solve(), which is something like c_10 = r1 , c_9 = 2*r1+3 , c_8=r2 , c_1 = 1/2*r2.  I have tried using the reduced row echelon form and M.rref() seems to give what I want (equiv to the answer from sol(). The problem is that this method rref() also takes long time, seem to be even longer than calling solve()  itself.

Volker Braun

unread,
Jun 28, 2013, 9:16:20 PM6/28/13
to sage-s...@googlegroups.com
As usual, the most general solution is a particular solution plus something from the kernel.

Whats the base ring of the matrix that you are constrcuting?
Reply all
Reply to author
Forward
0 new messages