What is the main error in this code and how can it be solved?
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Antworten (1)
Riccardo Scorretti
am 30 Mär. 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 Kommentare
Riccardo Scorretti
am 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);
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!