Reduce the compiling time with 1000x1000 matrix
2 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
clear
clc
K=10^3;
N=10^3;
f=10^3;
po=10;
ch=5;
pmax=20;
noise=1;
h=sqrt(1/2)*[randn(K,N)+1i*randn(K,N)];
v=var(h);
g=transpose(vecnorm(h))*vecnorm(h);
inv_g=1./g;
%EPA
for i=1:length(g)
for j=1:length(g)
p1(i,j)=pmax/N;
pt1=sum(sum(p1));
r1=f*log2(1+((p1(i,j)*g/noise)));
rt1=sum(sum(r1))/K;
EE1=rt1/((K*po)+(ch*pt1));
end
end
Can I use something like Root finding algorithm to reduce the compiling time? How do i apply it?? Any other method to reduce the compiling time?
2 comentarios
Respuestas (1)
Image Analyst
el 14 de Dic. de 2019
So you mean "run time" instead of compilation time, since you're not compiling this into a standalone executable - it's just an m-file script.
You don't even need the loop. You can simply do this:
clear
clc
K=10^3;
N=10^3;
f=10^3;
po=10;
ch=5;
pmax=20;
noise=1;
h=sqrt(1/2)*[randn(K,N)+1i*randn(K,N)];
v=var(h);
g=transpose(vecnorm(h))*vecnorm(h);
p1 = (pmax / N) * ones(size(g));
inv_g=1./g;
% [rows, columns] = size(g)
pt1 = (pmax / N) * numel(g)
gOverNoise = g ./ noise;
% Do the matrix multiplication.
matrixMultiplication = p1 * gOverNoise;
% Or maybe you want p1 .* gOverNoise to do an element by element multiplication.
% I'm not sure.
% EPA
r1 = f*log2(1+(matrixMultiplication));
rt1 = sum(r1(:))/K;
EE1 = rt1 / ((K*po)+(ch*pt1));
but I really question whether you want a matrix multiplication with p1 * gOverNoise, OR an element-by-element multiplication with p1 .* gOverNoise. It was the matrix multiplication of a 1000 by 1000 matrix being done a million times inside your inner loop that was taking all the time.
0 comentarios
Ver también
Categorías
Más información sobre Data Type Identification en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!