how do i plot number of iteration verses accuracy

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

Jan
Jan am 15 Mai 2019
Both can be done with simple plot() command. So what are your inputs? What have you tried? Which problems do you have with which code?
I know we can plot it using plot(); But problem is how to plot time, since it is constant
Plot can be plot for variable or not.
If you're comparing accuracy between two conditions (55sec and 200sec) why not use a bar plot?
Jan
Jan am 15 Mai 2019
@Manok Kumar: I do not understand the meaning of "Plot can be plot for variable or not".
"loop take 55 sec while another loop takes 200 sec" - does not look like time is constant.
It is not clear what you want to achieve.
you are right Adam, but I want to plot it by plot() funtion only if possible.
First you have to describe to yourself what you want to plot, how the plot should be designed, then if you cannot make that plot, sketch it by hand and attach here. No-one can easily give you a plot with the design you crave if you dont explain what it should look like...
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?
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

Manoj Kumar
Manoj Kumar am 16 Mai 2019
Bearbeitet: Manoj Kumar am 16 Mai 2019
why .^2 is there ? Its not working.
Jan
Jan am 16 Mai 2019
@Manok Kumar: Seriously? Bjorn created some arbitrary test data and [10:5:200].^2 is just an example for any values.
"It is not working" does not tell us anything about the problem you have. Please explain any details. What is not working and how do you see this?
Manoj Kumar
Manoj Kumar am 17 Mai 2019
Bearbeitet: Jan am 17 Mai 2019
My question is if it is iteration then why we square them?
my_function(a,b,c) contain 3 input, however the i/p argument access iteration. Picture of my loop is as like-
M = 1
for r = 1:10
for k = 1: 100
[x, y] = my_function(a(:, :, k), N(r) ,M)
end
end
But Bjorn suggested following
accuracy(i1) = your_optimizationfunction_whatever(i_iterations_to_try(i1),other,input);
which has more argument than the original function contain to plot the Complexity analysis. How this is possible.
@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.
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 Hilfe-Center und File Exchange

Gefragt:

am 15 Mai 2019

Community Treasure Hunt

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

Start Hunting!

Translated by