Why is the string below the first conditional not printed?
조회 수: 2 (최근 30일)
이전 댓글 표시
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
dpb
2021년 11월 13일
(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).
답변 (1개)
Cris LaPierre
2021년 11월 14일
편집: Cris LaPierre
2021년 11월 14일
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
dpb
2021년 12월 2일
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.
참고 항목
카테고리
Help Center 및 File Exchange에서 Environment and Settings에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!