フィルターのクリア

Big O notation for complexity of a program

7 ビュー (過去 30 日間)
Hazim Nasir
Hazim Nasir 2020 年 4 月 19 日
コメント済み: Hazim Nasir 2020 年 4 月 20 日
Hello,
I am writing a paper and have written a program where I have to calculate the time complexity for it. the program has to find the summation of a vector of elements
v=sum(x) where x=[x1^2,x2^,…….,x(n^2)]; where n could be 1,10,100,1000,10000. each element has random value. I have used (tic toc) to find the calculation time but I got strange results; I expect that the time will be increase linearly while changing n from 1 to 10000 but I got graphs as shown in the attachment where results differ for each run. I would like to ask: is the time of summation process varies with respect to the values; for example sum[1.2^+2.3^] is differ from sum[11546.233665^2+9866.89^2] ?
Also, I have did the following test:
d=1000;
VarMin = -10;
VarMax = 10;
VarSize=[1 d];
x=unifrnd(VarMin,VarMax,VarSize);
tic
sum(x);
toc
disp('%%%%%%%%%%%%%%%%%%%5')
tic
sum(x);
toc
the results is:
Elapsed time is 0.000100 seconds.
%%%%%%%%%%%%%%%%%%%5
Elapsed time is 0.000056 seconds.
So what is the best way is this case to find the compelxity. Thank you in advance
Hazim
  2 件のコメント
Tommy
Tommy 2020 年 4 月 19 日
Hazim Nasir
Hazim Nasir 2020 年 4 月 20 日
Thank you very much

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

回答 (0 件)

カテゴリ

Help Center および File ExchangeMathematics についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by