Matlab equality problem. Please help.
이전 댓글 표시
Hi, this is my code.
theta(k) = 45
l = x.*cosd(theta(k))+y.*sind(theta(k));
l(1,1) == l(3,3);
x(1,1)*cosd(45)+ y(1,1)*sind(45) == x(3,3)*cosd(45)+ y(3,3)*sind(45);
x(1,1)+ y(1,1)==x(3,3)+ y(3,3);
However, matlab it saying
l(1,1) == l(3,3)
is false,
x(1,1)*cosd(45)+ y(1,1)*sind(45) == x(3,3)*cosd(45)+ y(3,3)*sind(45)
is false, and
x(1,1)+ y(1,1)==x(3,3)+ y(3,3)
is true. I am wondering why because I believe l(1,1) == l(3,3) is true.
댓글 수: 2
Rik
2018년 10월 3일
Your code is not self-contained (i.e. we cannot run it independently of the code you have before this), and I don't understand what you mean with your code/notation.
A wild guess would be that you are checking equality on a non-integer data type, which means you might be encountering float rounding errors. If you run the code below, you can clearly see that 1.0000 does not equal 1.0000
a=1+eps*2;%very close to 1
b=sqrt(a);b=b^2;%do an operation and reverse it
clc,isequal(a,b)
disp(a)
disp(b)
Jenny Chen
2018년 10월 3일
편집: Stephen23
2018년 10월 4일
채택된 답변
추가 답변 (1개)
Image Analyst
2018년 10월 3일
0 개 추천
카테고리
도움말 센터 및 File Exchange에서 Linear Algebra에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!