What is the main error in this code and how can it be solved?
2 次查看(过去 30 天)
显示 更早的评论
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 个评论
回答(1 个)
Riccardo Scorretti
2022-3-30
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 个评论
Riccardo Scorretti
2022-4-1
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);
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Logical 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!