In some simulations I have been doing with Mathematica, I first set up a
large symbolic sparse matrix (4000 x 4000).
I don't have a simple set of array rules to do this. The matrix is generated
by a somewhat complicated symbolic pattern matching. This takes around 5-10
seconds.
The point is that, once it is set up I replace the symbolic values with
different numerical values and compute quantities related to Eigenvalues and
LinearSolve.
My problem is that the replacement from symbolic to numeric also takes
around 5 to 10 seconds.
I was wondering if you guys had any advice on how to speed this up. I tried
using Dispatch but it doesn't make a difference because the number of
symbolic values to replace is small (usually 6).
So my question is: starting with a sparse symbolic matrix dependent on a
small number of parameters, what is the fastest way to generate a numerical
matrix from it?
Thanks in advance,
Gabriel
Next problem: Replace[] does not work on SparseArray[]'s. However, you can use BlockRules[] (code below) to do the replacement.
Code for BlockRules[] by Andrew Moylen at Wolfram, from an earlier posting on this group that I can't find right now:
SetAttributes[BlockRules, HoldRest];
BlockRules[rules_, expr_] := Block @@ Append[Apply[Set, Hold[rules], {2}],
Unevaluated[expr]]
Enjoy,
Daniel
Thank you for the reply. My matrix is constructed from a system of
polynomial equations using CoefficientArrays.
Indeed, replacement does not work. What I was doing was (sadly)
SparseArray[Normal@matrix /.rules].
Gabriel