Borrar filtros
Borrar filtros

"Vectorization" of a script with a matrix

1 visualización (últimos 30 días)
Hayao
Hayao el 9 de Jul. de 2018
Editada: Hayao el 9 de Jul. de 2018
Dear all,
I am trying to make a code that does certain calculations on a (very large) symbolic matrix as fast as possible.
I know that symbolic calculation is a very costly calculation. Therefore, I resolved to initially substituting the variable (with certain intervals), since I will be doing that after the solution is obtained anyway. However that means I have two options: 1) use parfor (I have parallel computing toolbox), or 2) vectorize. I have problem doing the latter, which I suppose many people will recommend over parfor.
For the parfor method, for example, I can make:
M1 = zeros(s,2000);
parfor t = 1:2000
A1 = randi(1000,s);
A2 = diag(diag(A1));
M1(:,t) = (exp(-A2*0.000002*t)-ones(s)+eye(s))*rand(s,1);
end
M1
where "s" defines the size of the diagonal matrix A2.
This code becomes faster than normal for-loop when "s" is larger than somewhere around 65, and significantly faster on the scale that I plan to work in (certainly more than 10000). By the way, I am running the code in 16-workers parallel computing mode.
However, for the latter vectorization method,
M3 = zeros(s,2000);
t = 1:0.000002:0.004;
A1 = randi(1000,s);
A2 = diag(diag(A1));
M3(:,t) = (exp(-A2*t)-ones(s)+eye(s))*rand(s,1);
M3
Obviously, this is not going to work. You can't substitute an array into a calculation like this. Can anyone suggest me a vectorization method for this case? Is it possible? And do you think this will improve in speed (and memory) over parfor?
Thank you.

Respuestas (0)

Categorías

Más información sobre Matrices and Arrays en Help Center y File Exchange.

Productos


Versión

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by