2
$\begingroup$

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[[13]]

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?

$\endgroup$
4
  • $\begingroup$ 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. $\endgroup$ Commented Nov 1, 2018 at 13:49
  • $\begingroup$ 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? $\endgroup$
    – SHBR
    Commented Nov 1, 2018 at 14:10
  • $\begingroup$ 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. $\endgroup$ Commented Nov 1, 2018 at 14:29
  • 1
    $\begingroup$ In short: the problem may simply be too large to handle symbolically. $\endgroup$ Commented Nov 1, 2018 at 16:14

1 Answer 1

2
$\begingroup$

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
#       libs_for_mathlink = -lML64i3 -lm -lpthread -lrt -lstdc++
        static_libs_for_mathlink = -Wl,-Bstatic -lML64i4  -lstdc++
        dynamic_libs_for_mathlink = -Wl,-Bdynamic -lm -lrt -luuid -lpthread -ldl

Notice that you need a Linux machine for FLink to work. Please let me know if the filesharing works. You also edit the path to fermat in gatetofermat.h.

Everything should work without FLink for Windows by directly writing Redrowech[matrix]; in the fermatstart.txt. But I was not able to figure out how to save directly from Fermat without a major headache...

$\endgroup$
5
  • $\begingroup$ I'd be interested to see the input in this case. I won't complain if you post it directly in your response (if this is not familiar, one uses the "edit" right below the response), or provide a link there in case it is huge. $\endgroup$ Commented Nov 2, 2018 at 15:08
  • $\begingroup$ @DanielLichtblau The array definition for Fermat and the mathematica commands to evaluate it? $\endgroup$
    – Armin
    Commented Nov 2, 2018 at 15:21
  • $\begingroup$ Actually I just meant the Mathematica input form of the matrix. $\endgroup$ Commented Nov 2, 2018 at 16:19
  • $\begingroup$ @DanielLichtblau Added it to my answer. $\endgroup$
    – Armin
    Commented Nov 2, 2018 at 16:36
  • $\begingroup$ Thanks, I'll have a look. $\endgroup$ Commented Nov 2, 2018 at 16:55

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.