MATLAB 2016a and 2017a give different results when multiplying by the complex conjugate
    1 visualización (últimos 30 días)
  
       Mostrar comentarios más antiguos
    
    CJ Werner
 el 15 de Dic. de 2017
  
    
    
    
    
    Comentada: CJ Werner
 el 18 de Dic. de 2017
            I am running some code and found that multiplying a complex vector x by x' gives me slightly different results between MATLAB2016a (gives me answer I am looking for) and 2017a (has a complex component on the diagonal when I am not expecting it). If I troubleshoot with randn(3)+randn(3)*i I have no problems (with rng seeded). Is it due to precision? An example x vector that will give me trouble is below.
x=
4.07165372227704e-09 - 1.57176600601260e-08i
-1.39876117489891e-07 - 1.17688977471939e-07i
2.19114480796579e-07 + 1.33125665568044e-08i
3.68460108310824e-08 + 9.08472574818831e-08i
This gives me further trouble even if I run the result of Rxx=x*x' from 2016a on 2017a when I use the eig() function, eig(Rxx), so I am hoping it's a parameter I can change that will fix both results in MATLAB.
Thanks, CJ
0 comentarios
Respuesta aceptada
  Christine Tobler
    
 el 15 de Dic. de 2017
        This is wrong behavior: the diagonal of matrix Rxx should have zero imaginary part. We will work on fixing this for a future release. Thank you very much for letting us know about this.
Note the issue specifically happens when computing the outer product of a vector with itself. For matrices, the diagonal is still real:
 >> X = [x, zeros(4, 1)];
 >> isreal(diag(x*x'))
 ans =
   logical
    0
 >> isreal(diag(X*X'))
 ans =
   logical
    1
As a workaround, remove the imaginary part of the diagonal elements explicitly:
 Rxx = Rxx - 1i*diag(imag(diag(Rxx)));
This should also resolve the issue in EIG: The problem there would have been that EIG uses a different algorithm when the input matrix is hermitian, and ishermitian(A) requires the diagonal of A to be real.
2 comentarios
  Christine Tobler
    
 el 15 de Dic. de 2017
				A colleague is looking into this, and suggested a simpler workaround for R2017a:
 if iscolumn(x)
     Rxx = x.*x';  % Uses implicit expansion behavior
 else
     Rxx = x*x';
 end
Más respuestas (0)
Ver también
Categorías
				Más información sobre Creating and Concatenating Matrices en Help Center y File Exchange.
			
	Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

