how do i plot number of iteration verses accuracy

4 ビュー (過去 30 日間)
Manoj Kumar
Manoj Kumar 2019 年 5 月 15 日
コメント済み: Bjorn Gustavsson 2019 年 5 月 17 日
I want to plot following two complexity comparision graph
1) How do I plot time vs number of iteration in matlab. Since one loop take 55 sec while another loop takes 200 sec.
2) Number of iteration vs accuracy(10^-5 to 0.1)
  8 件のコメント
Manoj Kumar
Manoj Kumar 2019 年 5 月 16 日
編集済み: Manoj Kumar 2019 年 5 月 16 日
If this is the case then how to plot it. How we collect the number of iteration for these two cases?
Jan
Jan 2019 年 5 月 17 日
What does "if this is the case" mean? You post the screenshot of a plot. This does not explain, what you want to plot. Without seeing your code, we cannot guess how you can collect the numbers. But actually it works like this:
x = zeros(1, 100); % Pre-allocation
for k = 1:100
x(k) = sin(1 / k); % Insert your calculation here
end

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

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 5 月 16 日
Something like this should be doable:
i_iterations_to_try = [10:5:200].^2; % Some array with number of iterations to run through
for i1 = 1:numel(i_iterations)
accuracy(i1) = your_optimizationfunction_whatever(i_iterations_to_try(i1),other,input);
end
semilogx(accuracy,i_iterations_to_try,'d--')
HTH
  5 件のコメント
Jan
Jan 2019 年 5 月 17 日
@Manoj Kumar: Bjorn gave you an example of how to collect data. Because you did not tell us any details about your code, he had to invent an example. So it is not meaningful if you ask for explanations of this example, e.g. why he as square the data. He could set it to the power or sqrt(17) also, because they are arbitrary inputs, which must replaced by your values in the real code. E.g.:
M = 1
x = zeros(100, 10); % Pre-allocation for speed
y = zeros(100, 10); % Pre-allocation for speed
for r = 1:10
for k = 1: 100
[x(k, r), y(k, r)] = my_function(a(:, :, k), N(r), M);
end
end
Collecting the values works by using an index and storing them in an array.
Bjorn Gustavsson
Bjorn Gustavsson 2019 年 5 月 17 日
Manoj: Oh, your function wasn't named "your_optimizationfunction_whatever"? When you complained about my arbitrary selection of number of iterations to try and not the function-name I thought that I had made a very lucky guess of your function-name!
Read that as: How could I or anyone else give you your selected number of iterations or any other details like function-name or the input arguments to your function when you haven't given us any information about any of those details? When trying to use the replies try to think about how the reply leads _towards_ your goal, and what you might have to change or expand to reach your goal, also consider the amount of information the responders have to work from when doing this.

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

カテゴリ

Help Center および File ExchangeLoops and Conditional Statements についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by