comparing between two identical variables returns logic 0?

10 vues (au cours des 30 derniers jours)
Mohamed Salah
Mohamed Salah le 5 Mai 2020
Commenté : Mohamed Salah le 5 Mai 2020
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?

Réponse acceptée

Stephen23
Stephen23 le 5 Mai 2020
Modifié(e) : Stephen23 le 5 Mai 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:

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Produits


Version

R2018a

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by