Two different graphs!!! Difference between Pi and 3.14
3 次查看(过去 30 天)
显示 更早的评论
Hello i am a learner of matlab and i had a doubt
I have written a code to plot a cosine graph as followed
clear all
close all
t=-5:0.001:5;
y1=cos(2*pi*1000*t);
y2=cos(2*3.14*1000*t);
subplot(2,1,1);
plot(t,y1);
subplot(2,1,2);
plot(t,y2);
I have expected the same graph would be plotted for both the variables y and y1 in my code
but to my surprise i have got both of them different and i guess the first graph (i.e, y graph) must be correct and i dont know why the second graph has turned out as this
Please help me out in this...
Thanks in advance!!!
0 个评论
采纳的回答
Azzi Abdelmalek
2013-9-24
We can explain this: the variation of t is
For the first case
v=2*pi*0.001*1000;
mod(v,pi)=0 % which means the cos will not change
For the second case
v=2*3.14*0.001*1000
mod(v,pi)
=3.1384
%which means the cos will change
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!