Plotting Cos complete stupidity

10 ビュー (過去 30 日間)
Robert
Robert 2016 年 9 月 28 日
コメント済み: Robert 2016 年 9 月 28 日
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

採用された回答

Massimo Zanetti
Massimo Zanetti 2016 年 9 月 28 日
編集済み: Massimo Zanetti 2016 年 9 月 28 日
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 件のコメント
Robert
Robert 2016 年 9 月 28 日
great so i loose an hour worth of work today because a 1 in million chance my interval falls exactly on a constant Awesome!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLine Plots についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by