Reduce the compiling time with 1000x1000 matrix

4 ビュー (過去 30 日間)
salad9996
salad9996 2019 年 12 月 14 日
回答済み: Image Analyst 2019 年 12 月 14 日
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 件のコメント
John D'Errico
John D'Errico 2019 年 12 月 14 日
Did you mean computing time? Or are you trying to compile this?
salad9996
salad9996 2019 年 12 月 14 日
yea, the running time, it take too long to run

サインインしてコメントする。

回答 (1 件)

Image Analyst
Image Analyst 2019 年 12 月 14 日
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.

カテゴリ

Help Center および File ExchangeData Type Identification についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by