What is the main error in this code and how can it be solved?
2 views (last 30 days)
Show older comments
Here is the code:
a=0; b=1; c=1; d=L;
%initialization
% report pair a,b
% report pair c,d
while ~((c==1)&(d==1))
% test for end
Z = floor((L+b)/d);
e = Z*c-a;
f = Z*d-b;
% report pair e,f
b=d; d=f; a=c; c=e;
end
İt says there's an error at line 1. I ve to declare the variable of L
0 Comments
Answers (1)
Riccardo Scorretti
on 30 Mar 2022
Simply, the variable L is undefined. That is, you must assign a value to it before you use it, for instance by:
L=2; a=0; b=1; c=1; d=L;
Of course the particular value you have to use for L depends on the particular problem you want to solve.
2 Comments
Riccardo Scorretti
on 1 Apr 2022
I cannot see any problem at the line you mentioned: the code runs with no error, provided that a correct value for L is defined (see below). We can help you with Matlab, but it is up to you to define the correct value for the variable L.
L = 2; % <-- This particular value depends on what you want to compute
a = 0; b = 1; c = 1; d = L;
%initialization
% report pair a,b
% report pair c,d
while ~((c==1)&(d==1))
% test for end
Z = floor((L+b)/d);
e = Z*c-a;
f = Z*d-b;
% report pair e,f
b=d; d=f; a=c; c=e;
end
fprintf('Z = %f , e = %f , f = %f\n', Z, e, f);
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!