1
$\begingroup$

I am very new to Mathematica (started two weeks ago), and I am trying to solve a system of linear equations consisting of nine equation. My matrices A and B are given below.

A = {{I a - I b + c, 0, 0, -I d, -I E^((2 I π)/3) f, 0, -I d, -I f, 0},
 {0, I a + c, 0, -I E^(-((2 I π)/3)) f, -I d, -I E^((2 I π)/3)f, -I f, -I d, -I f}, 
 {0, 0, I a + I b + c,  0, -I E^(-((2 I π)/3)) f, -I d, 0, -I f, -I d},
 {-I d, -I E^((2 I π)/3) f, 0, I a - I b + c, 0, 0, -I d, -I E^(-((2 I π)/3)) f, 0}, 
 {-I E^(-((2 I π)/3)) f, -I d, -I E^((2 I π)/3) f, 0, I a + c, 0, -I E^((2 I π)/3)f, -I d, -I E^(-((2 I π)/3)) f}, 
 {0, -I E^(-((2 I π)/3)) f, -I d, 0, 0, I a + I b + c, 0, -I E^((2 I π)/3) f, -I d}, 
 {-I d, -I f, 0, -I d, -I E^(-((2 I π)/3)) f, 0, I a - I b + c, 0, 0},
 {-I f, -I d, -I f, -I E^((2 I π)/3) f, -I d, -I E^(-((2 I π)/3)) f, 0, I a + c, 0}, 
 {0, -I f, -I d, 0, -I E^((2 I π)/3) f, -I d, 0, 0, I a + I b + c}}

B = {0, I q, 0, 0, 0, 0, 0, 0, 0}

I is iota and other variables are a, b, c, d, f, q.

I am using LinearSolve, but it is taking forever. How can I solve my system of equations?

$\endgroup$
9
  • $\begingroup$ The code is ill-edited it seems. I am trying to make it better but the first line doesn't seems to turn in code. Any suggestion is welcome. $\endgroup$
    – SiPh
    Commented Jan 15 at 16:43
  • $\begingroup$ Welcome to Mathematica StackExchange! I have edited your question to improve on the formatting (and the title). Just to be sure: your capital letter I stands for the imaginary unit $i$, right? (I haven't heard it being called by the greek letter iota ...) $\endgroup$
    – Domen
    Commented Jan 15 at 17:06
  • $\begingroup$ Hi @Domen Yes, I stands for sqrt(-1) and thanks for the editing :) $\endgroup$
    – SiPh
    Commented Jan 15 at 17:08
  • $\begingroup$ Great! How long did you wait for the result? I get the result in approximately a minute in version 13.3. $\endgroup$
    – Domen
    Commented Jan 15 at 17:08
  • $\begingroup$ What? It was running for six hours and then I stopped it! I am using Mathematica 9.0.1.0. $\endgroup$
    – SiPh
    Commented Jan 15 at 17:10

1 Answer 1

1
$\begingroup$

All available methods one might use for this give results in under a minute on my desktop, using version 13.3.

Timing[ls1 = LinearSolve[mat, bvec];]
ls1 // LeafCount

(* Out[902]= {43.9821, Null}

Out[903]= 807546 *)

Timing[
 ls2 = LinearSolve[mat, bvec, Method -> "OneStepRowReduction"];]
ls2 // LeafCount

(* Out[904]= {41.8555, Null}

Out[905]= 305563 *)

Timing[
 ls3 = LinearSolve[mat, bvec, Method -> "CofactorExpansion"];]
ls3 // LeafCount

(* Out[906]= {1.22199, Null}

Out[907]= 1333058 *)

Timing[
 ls4 = LinearSolve[mat, bvec, Method -> "DivisionFreeRowReduction"];]
ls4 // LeafCount

(* Out[908]= {44.0486, Null}

Out[909]= 809934 *)

It is a bit mysterious why the Automatic1 setting delivers a result different from all the others. Possibly some heuristic simplification is used. I had thought that setting would just choose "OneStepRowReduction" and run with that, but apparently that's not the case.

The (by far) fastest in this case also gives the largest result. But only by a factor of 4 or so vs. the smallest. And we can reduce it substantially in size using Together, again in reasonable time.

Timing[ls3T = Together[ls3];]
LeafCount[ls3T]

(* Out[914]= {5.94691, Null}

Out[915]= 94294 *)

Of course one has to actually do the computations to get the results. (Stated differently, there's no convenient way to predict in advance what method might work best, so we predict after the fact.)

$\endgroup$

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.