Recently, I have been working on my code to optimize the run time. In that code, I have several linear system of equations which start from small ones (5 equations- 5 unknowns) to large ones (5000 equations - 5000 unknowns). I have used the Solve command for finding the solution of these systems.

It may worth mentioning that the systems are sparse and ill conditioned (the condition number of the coefficient matrix is fairly large).

Now, I am wondering that if there is any other command which solve these systems faster? Any other hints for improving the run time is appreciated.

  • 1
    $\begingroup$ Try Root or, if appropriate, FindInstance. Simplify and FullSimplify can be of use too. $\endgroup$ Jun 4, 2017 at 22:37
  • 4
    $\begingroup$ Or how about LinearSolve? $\endgroup$
    – bill s
    Jun 4, 2017 at 22:37
  • $\begingroup$ @bills: Does that perform faster than solve? I thought that solve may call that function itself. $\endgroup$ Jun 5, 2017 at 5:51
  • $\begingroup$ @bills: Do you know what solution methods in LinearSolve are appropriate for large sparse ill conditioned systems? $\endgroup$ Jun 8, 2017 at 8:09
  • $\begingroup$ @DavidG.Stork: How Simplify and FullSimplify can be useful!? Do you any further experience with Root and FindInstance? $\endgroup$ Jun 8, 2017 at 8:11

1 Answer 1


As suggested in the comments, using LinearSolve is a good option. I could reduce the run time from 1.9 minutes to 0.6 minutes. Here is a simple procedure which uses LinearSolve and give an output in the format of rules which can be used for further substitution of the solution. Also, one can play around with the method of solution. In my case, Method -> "Multifrontal" was the best.

LinSol[Eqs_, Vars_] := Module[{b, A, Sol, SolRule},
  {b, A} = CoefficientArrays[Eqs, Vars];
  Sol = LinearSolve[A, -b, Method -> "Multifrontal"];
  SolRule = {};
  Do[SolRule = Union[SolRule, {Vars[[i]] -> Sol[[i]]}], {i,1,Length[Vars]}];
  • 1
    $\begingroup$ SolRule = {}; Do[SolRule = Union[SolRule, {Vars[[i]] -> Sol[[i]]}], {i,1,Length[Vars]}]; SolRule can be simplified to SolRule = Thread[Vars -> Sol] $\endgroup$
    – xzczd
    Jun 5, 2017 at 10:24
  • $\begingroup$ @xzczd: Wow, thanks, I didn't know that. :) $\endgroup$ Jun 5, 2017 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.