Plotting Cos complete stupidity

6 views (last 30 days)
Robert
Robert on 28 Sep 2016
Commented: Robert on 28 Sep 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

Accepted Answer

Massimo Zanetti
Massimo Zanetti on 28 Sep 2016
Edited: Massimo Zanetti on 28 Sep 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 Comment
Robert
Robert on 28 Sep 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!

Sign in to comment.

More Answers (0)

Categories

Find more on Line Plots in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!