how do i plot number of iteration verses accuracy

3 Ansichten (letzte 30 Tage)
Manoj Kumar
Manoj Kumar am 15 Mai 2019
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 Kommentare
Manoj Kumar
Manoj Kumar am 16 Mai 2019
Bearbeitet: Manoj Kumar am 16 Mai 2019
If this is the case then how to plot it. How we collect the number of iteration for these two cases?
Jan
Jan am 17 Mai 2019
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

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Bjorn Gustavsson
Bjorn Gustavsson am 16 Mai 2019
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 Kommentare
Jan
Jan am 17 Mai 2019
@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 am 17 Mai 2019
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.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Loops and Conditional Statements 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