Plotting Cos complete stupidity

3 visualizaciones (últimos 30 días)
Robert
Robert el 28 de Sept. de 2016
Comentada: Robert el 28 de Sept. de 2016
I have been plotting trig functions like this for years in matlab with zero problem Now all of a sudden it no longer works.
x = [0:.1:20]
y = .5*cos(2*pi*60.*x)
plot(x,y)
Now today all i get is a constant value. What is going on here
Doing the following makes no difference
x = [0:.1:20]
plot(x,.5*cos(2*pi*60.*x))
Someone please tell me why in the holy land of matlab multiplying the vector X by a constant of 2*pi*60 completely ruins the plot and turns it into a constant. It makes zero sense!
but yet somehow this works
plot(x,cos(x))
All I'm doing is multiplying the foreign X by a constant of 2*pi*60 This is ridiculous
Also just to add the following works
y = cos(2*x) y = cos(2*pi*x)
But for some insane reason the plot goes nuts when you plot
y = cos(2*pi*60*x) and says the plot is a constant .5
Also just to add to the infuriation of this if you plot
plot(x,.5*cos(120*pi*x)) %you get a constant of .5
plot(x,.5*cos(119*pi*x)) %you get a proper oscillating cos

Respuesta aceptada

Massimo Zanetti
Massimo Zanetti el 28 de Sept. de 2016
Editada: Massimo Zanetti el 28 de Sept. de 2016
This is not ridiculous, this is math.
Try refine the step of x:
x = 0:.01:20;
y = .5*cos(2*pi*60*x);
plot(x,y)
Your "weird" phenomenon is due to the fact that all cosine crests fall into the discretized interval you choose, which is too coarse to make you see them.
  1 comentario
Robert
Robert el 28 de Sept. de 2016
great so i loose an hour worth of work today because a 1 in million chance my interval falls exactly on a constant Awesome!

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Graphics Objects en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by