Two different graphs!!! Difference between Pi and 3.14
3 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Azzi Abdelmalek
on 24 Sep 2013
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 Comments
More Answers (0)
See Also
Categories
Find more on 2-D and 3-D 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!