What is the main error in this code and how can it be solved?
1 回表示 (過去 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 で Hypothesis Tests についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!