Efficient way for solving a matrix equation - Mathematica Stack Exchange most recent 30 from mathematica.stackexchange.com 2019-09-18T06:18:52Z https://mathematica.stackexchange.com/feeds/question/85432 https://creativecommons.org/licenses/by-sa/4.0/rdf https://mathematica.stackexchange.com/q/85432 1 Efficient way for solving a matrix equation mak maak https://mathematica.stackexchange.com/users/2376 2015-06-08T09:31:07Z 2015-06-08T13:56:52Z <p>I am looking for a more effcient method to perform the following analysis. I did my best, but running the following code on my machine takes 9.766s. I need to perform this analysis several times.</p> <pre><code>ClearAll["Global`*"]; Jfunction = Compile[{{NOunknownPar, _Integer, 0}, {dt, _Real, 0}, {Kgeneral, _Real, 2}, {Jacob1, _Real, 2}}, Module[{Ident, sj1, sj2, sj3, sf}, Ident = IdentityMatrix[2*NOunknownPar]; sj1 = Ident - (0.5*dt)*Kgeneral; sj2 = Ident + (0.5*dt)*Kgeneral; sj3 = Dot @@ {sj2, Jacob1}; sf = LinearSolve[sj1, sj3]; sf], CompilationTarget -&gt; "C"]; NoVar = 79; NoRep = 6001; deltaT = 0.0001; Jmat = IdentityMatrix[2*NoVar]; KK = ConstantArray[0, NoRep - 1]; Do[KK[[i]] = RandomReal[1, {2*NoVar, 2*NoVar}], {i, NoRep - 1}]; Do[Jmat = Jfunction[NoVar, deltaT, KK[[jJa]], Jmat], {jJa, NoRep - 1}] // Timing </code></pre>