# Save and use results of LinearSolve for symbolic large system (28 equations)

I need to solve system of 28 linear equations, for 28 variables, symbolicly. The coefficient matrix is sparse, and is composed from 8 parameters (symbols).

After that I need to use 6 of the variables in other calculations.

I tried to do that:

expandedMatrix1 = SparseArray[expandedMatrix];
consVector1 = SparseArray[consVector];
SSolution = LinearSolve[expandedMatrix1, -consVector1]


and then I use double brackets to get the specific results I need - for example: SSolution[]

The first stage (solving Eq.) takes very long time, slows down other programs in the computer, and shows nothing in the output at the end!

Where is my mistake?

• The mistake is attemting to invert symbolic matrices at all, in particular matrices of this size. You will get efficient code only if you apply LinearSolve to numerical matrices with machine precision numbers. If you do so, the time for factorization and solving the systems will be neglectible. – Henrik Schumacher Nov 1 '18 at 13:49
• I allready have the numeric solution. I am looking for symbolic one. Is it possible to do it if I reduce the number of parameters to just two and the others will set to be numbers? – SHBR Nov 1 '18 at 14:10
• The only correct answer with this amount of information (almost none) can be: It depends. You should ask yourself why you want to have a symbolic solution. If it is for performance reasons: Forget it. If you expect a human-readible output: That is rather unlikely to obtain. If it is for parameter-studies: Those can be performed also (and more stably) numerically. – Henrik Schumacher Nov 1 '18 at 14:29
• In short: the problem may simply be too large to handle symbolically. – Daniel Lichtblau Nov 1 '18 at 16:14

I had a similar problem for a 24X24 symbolic matrix. Mathematica could not do it and I ended up using Fermats "Redrowech[]". It took only 30 seconds.

The problem is, Fermat's interface is far from optimal and the coding in it is, lets say cumbersome. Here is how I approached it:

1. Create Fermat input with Mathematica (define the array and the variables)
2. Append the created file to "ferstart.txt"
3. Call the "gate to fermat" interface from Mathematica to Fermat (Link to Fermat FLINK)
4. Run from Mathematica FEval["Redrowech[yourMatrix]"] and save the result

The routine I used is tailored towards my particular matrices and I am therefore reluctant to share it. But if you decide to go down that path and have troubles I might be able to help (e.g. the Makefile of gatetofermat needed some editing for my machine).

For Daniel Lichtblau:

The link to the coefficient matrix as a .m file. The defined matrix is $$(A,b)$$ for the linear system $$A x=b$$. The link to the edited ferstart.txt file, which needs to be placed in the installation directory of fermat (for me: ~/ferl6/BACKWARD/). Please note, that you might have to adjust the first number depending on your ram.

The evaluation is done with Mathematica with the following commands:

$$Fermat = "PathTofer64";$$FLink = "PathToFLink64";

link = Install[$$FLink]; FInit[$$Fermat, ""]
FEval["Redrowech([matrix])"];
matSolString = FEval["[matrix]"];
Export["fermatSol.txt", matSolString]
FClose[]
Exit[]


The changes to the Makefile of FLink for my version of Mathematica were mostly including certain libraries and link according to:

ifeq (\$(SYSID), Linux-x86-64)
BIT := 64