Equal condition issue _ I will become crazy
Show older comments
Hi I have been struggling with Matlab and I think I am going to become crazy. It seems that 2 is no longer equal to 2... I am probably just blind and I don't see the problem so please help me!
I run a code and after some iterations the condition at line 30 stops working when the terms are equal. HELP! Here is the code:
clear all; close all;
ndef=10; nsinus=10; Amax=2.0; Astep=Amax/ndef;
x0=0; y0=0;
A0=y0:(Amax-y0)/nsinus:Amax;
Ak=0; iAk=1;
%the goal of the following is to find in what cell between y0 and Amax are located
%the different elements of A0
for j=1:nsinus+1
if A0(1,j)~=0
while 1
%I asked for these variables so you can see the problem
A0(1,j)
Ak
%after some time this stops working properly
%as you can see it looks like Matlab stops recognizing that
%the variables are equal
% WTF?
if Ak==A0(1,j)
j
disp('working')
end
if Ak>=A0(1,j)
i0=iAk;
break
end
iAk=iAk+1;
Ak=Ak+Astep;
end
end
end
%this should stop when Ak=Amax=2, unstead it stops when Ak=2.2 because it doesn't realize that at %some point Ak=Amax=2. PLEASE HELP
Accepted Answer
More Answers (0)
Categories
Find more on MATLAB 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!