sparse matrix operations to gain efficiency
6 views (last 30 days)
I've never really used sparse matrices before but I was wondering if it would be useful in my case to imporve efficiency. My code is as follows
a=randi([1 3],1,5);b=randi([1 spec],1,5);
c=randi([1 3],1,5);d=randi([1 spec],1,5);
I've used an example of reac=25 and spec=20 but in reality I could have reac up to 1500 and spec up to 500. I use the values of rate in differential equations which I solve using ode15s. This is the part of my code that takes the longest, where fwd and bcwd are sparse matrices. Would truning them into sparse matrices using sparse help me? if so, how can I rewrite my code?
An help is appreciated,
John D'Errico on 16 Jul 2019
Are those matrices mostly zero? No. It looks like they are 50% zeros. Sparse will not gain anything, because thre is also overhead in working with computations on sparse matrices.
Next, sparse matrices gain when you are doing matrix multiplications, and solving linear systems of eequations, but mainly only then if they are really sparse. 50% zeros does not cut it.