- "(2*pi*f0*t)" interpreted by MATLAB as ((2*pi)*f0)*t
- "2*pi*(f0*t)" interpreted by MATLAB as (2*pi)*(f0*t)
How parentheses effects multiplication with pi ?
    9 Ansichten (letzte 30 Tage)
  
       Ältere Kommentare anzeigen
    
    Emre Doruk
 am 4 Aug. 2020
  
    
    
    
    
    Bearbeitet: Bruno Luong
      
      
 am 5 Aug. 2020
            Hi, 
I am trying to generate sine wave. I am usning following two code lines. But they are slightly different (about e-15). Why is it happenning ? What is the differences of two lines;
f0=5e2;
fs=500e2;
len=3e3;
dt=1/fs;
t=0:dt:(len-1);
sing1= sin (2*pi*f0*t);
sing2= sin(2*pi*(f0*t));
isequal(sing1,sing2)
Thanks for your help,
0 Kommentare
Akzeptierte Antwort
  Bruno Luong
      
      
 am 5 Aug. 2020
        
      Bearbeitet: Bruno Luong
      
      
 am 5 Aug. 2020
  
      From wikipedia
"While floating-point addition and multiplication are both commutative (a + b = b + a and a × b = b × a), they are not necessarily associative. That is, (a + b) + c is not necessarily equal to a + (b + c). ... "
As floating-point multiplication is NOT ASSOCIATIVE, both results might be different.
5 Kommentare
  Bruno Luong
      
      
 am 5 Aug. 2020
				Sometime this non-associativity is a real headeach, such as finding a limits of a sign- alternate series by partial sum, or integral of an oscillated signal (any wave propagation SW might encounters this). There is a real challenge to know what really the limits and the order of the sum can make the result change widely.
Weitere Antworten (1)
  madhan ravi
      
      
 am 4 Aug. 2020
        In the first the order of operation is from left to right.
In the second the order of operation is inside the parenthesis and then the outer.
7 Kommentare
Siehe auch
Kategorien
				Mehr zu Performance and Memory finden Sie in Help Center und File Exchange
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!



