Reduce the compiling time with 1000x1000 matrix

4 Ansichten (letzte 30 Tage)
salad9996
salad9996 am 14 Dez. 2019
Beantwortet: Image Analyst am 14 Dez. 2019
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 Kommentare
John D'Errico
John D'Errico am 14 Dez. 2019
Did you mean computing time? Or are you trying to compile this?
salad9996
salad9996 am 14 Dez. 2019
yea, the running time, it take too long to run

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 14 Dez. 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.

Kategorien

Mehr zu Data Type Identification finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by