Two different graphs!!! Difference between Pi and 3.14

3 visualizzazioni (ultimi 30 giorni)
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!!!

Risposta accettata

Azzi Abdelmalek
Azzi Abdelmalek il 24 Set 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 Commenti
!ntel
!ntel il 24 Set 2013
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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su 2-D and 3-D Plots in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by