Message Boards Message Boards

1 Reply
0 Total Likes
View groups...
Share this post:

Speed up the solution of a matrix equation

Posted 9 years ago

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.


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 = sj2.Jacob1; sf = LinearSolve[sj1, sj3]; sf], 
CompilationTarget -> "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
POSTED BY: Mostafa Attar

compiling your code is probably a waste of time, since most of the work is being done by LinearSolve.

POSTED BY: Frank Kampas
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
or Discard

Group Abstract Group Abstract