Why is does the y axis of the graph have the same value all the way down?

조회 수: 3 (최근 30일)
Hello, I am very new to Matlab and I have just started learning to produce graphs. I tried to run the code:
y =@(t) 1.11*cos(2*pi*100000*t) + 0.5*cos(2*pi*98000*t) + 0.5*cos(2*pi*102000*t); x = -1*pi:0.1:pi; plot(x,y(x));
The graph produced is:
As you can see, it has -0.145 all the way down the y axis and I have no idea why. Is this a problem with the code? Thank you very much in advance!

채택된 답변

Konstantinos Sofos
Konstantinos Sofos 2015년 3월 4일
편집: Konstantinos Sofos 2015년 3월 4일
Are you sure that your formula is correct? You pass into cosine function not pi but pi^2 when you plot. You pass into variable t the vector x when you plot and this vector x is already the range of pi.
if you use instead
y =@(t) 1.11*cos(100000*t) + 0.5*cos(98000*t) + 0.5*cos(102000*t); x = -2*pi:0.1:2*pi;
plot(x,y(x))
you take
if the function is correct you have to take another interval
x = -pi:pi/180:pi
Regards

추가 답변 (1개)

Giorgos Papakonstantinou
Giorgos Papakonstantinou 2015년 3월 4일
편집: Giorgos Papakonstantinou 2015년 3월 4일
Because y(x) barely changes in the interval 1*pi:0.1:pi.
Try a more densely spaced vector: i.e.
x = -1*pi:pi/180:pi;

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by