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 CenterFile Exchange에서 Data Type Identification에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by