Plotting with an array in an equation

2 views (last 30 days)
If I had an array of angles (the phi value), and I wanted to use them to plot m against iterations of the simulation (N) (as shown in the attached image), then how do it?
I tried this before but since the angles are in an array and I'm trying to add all of them together and multiply them by 1/N, I can't seem to be able to plot them.
I think I need to make an array for the m values to them lnspace and plot against N, but I've not had much success in getting it to work.
Sorry for the poor explanation.
  6 Comments
Walter Roberson
Walter Roberson on 3 May 2021
Are there N phi values or is the division by a value that is unrelated to the number of phi values?
Oliver  Ford
Oliver Ford on 3 May 2021
So essentially it's 1/(number of iterations) multiplied by the sum of the angles at that iteration. If that makes any sense?

Sign in to comment.

Accepted Answer

Walter Roberson
Walter Roberson on 4 May 2021
Let theta be an N by number_of_angles array (so each row refers to a different time step)
m_temp = sum(cos(theta),2);
At this point, you need to decide whether the division is by the number of iterations that had occurred up to that point, or if it is by the total number of iterations. If it is by the total number of iterations, then
m = m_temp / N;
plot(m)
If it is by the number of iterations to that point, then
m = m_temp ./ (1:N);
plot(m)

More Answers (0)

Community Treasure Hunt

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

Start Hunting!