Bug introduced in 5.0 and fixed in 11.0
LinearSolveFunction
is new in 5.0
Consider the following set of equations and corresponding variables:
eqns1 ={2 x == 2 - 4 y, 3 y == 4 z, 2 z + 4 t == 3, 3 t + 2 z == 5};
vars = {x, y, z, t};
We can use CoefficientArrays
to get the array of coefficient of the variables, and use that to solve the set of equations:
{v1, m1} = CoefficientArrays[eqns1, vars];
LinearSolve[m1][-v1] (* This creates a LinearSolveFunction then applies it to -v1 *)
$ \{-\frac{41}{3}, \frac{22}{3}, \frac{11}{2}, -2\} $
Now we make the set of equations symbolic and repeat the process:
eqns2 = {b x == 2 - c y, a y == c z, b z + c t == 3, a t + b z == 5};
{v2, m2} = CoefficientArrays[eqns2, vars];
Now we solve the equations:
LinearSolve[m2][-v2]
And Mathematica just crashes as if you typed Quit[]
.
Note that LinearSolveFunction
is the culprit because you can still get the answer without crashing Mathematica by just using regular LinearSolve
(without first creating a LinearSolveFunction
) as follows:
LinearSolve[m2, -v2]
$\{\frac{2 a^2 b - 2 a b c - 3 a c^2 + 5 c^3}{a b^2 (a - c)}, \frac{ 3 a c - 5 c^2}{a b (a - c)}, \frac{3 a - 5 c}{b (a - c)}, \frac{2}{a - c}\}$
Also, note that if we pass the vector as a List
, it also works fine
ls = LinearSolve[m2]; (* create a LinearSolveFunction *)
ls[{2, 0, 3, 5}] // ExpandAll // Together
Can anyone reproduce this? I get the same behavior on both Mathematica 10.3.1 and 10.4. OS is Windows 10 64-bit.
Normal[]
tov2
. The simplerLinearSolve[m2][SparseArray[1 -> 1, 4]]
also crashes, so I'm inclined to think that theLinearSolveFunction[]
chokes on sparse vectors for some reason. $\endgroup$Normal
works which is why I stated that just using a normalList
doesn't crash Mathematica. About Sparse vectors, that was my initial title, maybe I should include that back. $\endgroup$LinearSolveFunction[]
chokes on sparse vectors in that version as well. Clearly an old problem. Even the (now deprecated and undocumented) functionLUBackSubstitution[]
chokes if given a sparse vector. $\endgroup$