comparing between two identical variables returns logic 0?
6 views (last 30 days)
Show older comments

clc
clear
n=0:63;
x1=0:7;
x=[x1 x1 x1 x1 x1 x1 x1 x1];
y=((-1).^n).*x;
[msg,N1]=find_period(x);
disp(msg);
[msg,N2]=find_period(y);
disp(msg);
%Taking 1 period of Y
y1=zeros(1,N2);
for i = 1:N2
y1(i)=y(i);
end
if N1==N2
fprintf('N1=N2=%d \n', N1);
end
ak=our_fourier_series(x1);
bk=our_fourier_series(y1);
for i =1:4
if (bk(i)==ak(4+i))
disp('bk=ak-N/2')
end
end
bk(6)==ak(2)
bk(6)
ak(2)
as you can see in the command window bk(6) equals ak(2)
but comparing between them returns logic 0
how is that even possible?
0 Comments
Accepted Answer
Stephen23
on 5 May 2020
Edited: Stephen23
on 5 May 2020
"as you can see in the command window bk(6) equals ak(2)"
Nope. Just looking at some floating point values displayed in the command window (or variable viewer, etc.) is not a valid way to determine their exact values (and hence is not valid to decide if they are equal). Those values are certainly not equal, which you will see when you view them at a higher precision, e.g. dowload this:
"but comparing between them returns logic 0 how is that even possible?"
Simply because the values are not equal. Read these to know why they are not equal:
This is worth reading as well:
More Answers (0)
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!