Filter löschen
Filter löschen

What is the main error in this code and how can it be solved?

2 Ansichten (letzte 30 Tage)
Baris Unsal
Baris Unsal am 30 Mär. 2022
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

Antworten (1)

Riccardo Scorretti
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
Baris Unsal
Baris Unsal am 30 Mär. 2022
İt gives an another problem too, in line 7. What s the main problem, what can be the main thing about
Z= floor((L+b)/d)
Riccardo Scorretti
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);
Z = 1.000000 , e = 1.000000 , f = 1.000000

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by