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!!!

采纳的回答

Azzi Abdelmalek
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
  2 个评论
!ntel
!ntel 2013-9-24
Thanks for your answer Azzi,
so you say that because of approximation of pi to 3.14 and multiplying it with '1000' is amplyfing the error of approximation and thus we get such non zero value for modulus in second case.

请先登录,再进行评论。

更多回答(0 个)

类别

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