Why is the string below the first conditional not printed?
1 visualización (últimos 30 días)
Mostrar comentarios más antiguos
I need help understanding why the string below the first conditional is not printed when AA, BB, CC are clearly equal. See attachment below
2 comentarios
dpb
el 13 de Nov. de 2021
(AA==BB) == 1 && (CC) == 1
is not good syntax.
if AA==1 & BB==1 & CC==1
will work; more succinct forms can be written if you would use arrays for variables instead of indivdually naming the variables (generally a bad practice to use MATLAB efficiently to have mulitple similarly-named/functionally equivalent variables as above).
Respuestas (1)
Cris LaPierre
el 14 de Nov. de 2021
Editada: Cris LaPierre
el 14 de Nov. de 2021
Because the result of the dot products is not exactly 1.
A = [2 2 -1+4i]/5;
B = circshift(A,-1);
C = circshift(B,-1);
AA = dot(A,A)
BB = dot(B,B)
CC = dot(C,C)
% now subtract 1. Result is not 0
AA-1
BB-1
CC-1
2 comentarios
dpb
el 2 de Dic. de 2021
Floating point arithmetic is only an approximation to algebra...see <Goldberg - What Every Computer Scientist Should Know> for detailed explanation. There are some other discussions and examples in the documentation as well.
Ver también
Categorías
Más información sobre Matrices and Arrays en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!