No Output for loop?

4 Ansichten (letzte 30 Tage)
Steven Thies
Steven Thies am 18 Feb. 2021
Kommentiert: Rena Berman am 6 Mai 2021
% I want to create a loop for all number combination from 1 to 10^4 for a^3+b^3=c^3
% My Script does not work. There is no Output and no errror code.
% When i change i to 2 then it works but why not when i use 3 for i
% Please help me to fix my problem
% Thank you
n = 10^4;
i = 3;
for a = 1:n
for b = 1:n
for c = 1:n
if (((a^i)+(b^i)) == (c^i))
result = ['Bingo ' 'For a: ' num2str(a) ' For b: ' num2str(b) ' For c: ' num2str(c)];
disp(result)
end
end
end
end
  2 Kommentare
Stephen23
Stephen23 am 19 Feb. 2021
Bearbeitet: Stephen23 am 19 Feb. 2021
Original question by Steven Thies retrieved from Google Cache:
Many deleted comments are also shown in the archive.
"No Output for loop?"
% I want to create a loop for all number combination from 1 to 10^4 for a^3+b^3=c^3
% My Script does not work. There is no Output and no errror code.
% When i change i to 2 then it works but why not when i use 3 for i
% Please help me to fix my problem
% Thank you
n = 10^4;
i = 3;
for a = 1:n
for b = 1:n
for c = 1:n
if (((a^i)+(b^i)) == (c^i))
result = ['Bingo ' 'For a: ' num2str(a) ' For b: ' num2str(b) ' For c: ' num2str(c)];
disp(result)
end
end
end
end
Rena Berman
Rena Berman am 6 Mai 2021
(Answers Dev) Restored edit

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Cris LaPierre
Cris LaPierre am 18 Feb. 2021
Bearbeitet: Cris LaPierre am 18 Feb. 2021
You could could potentially display 1.000000000000000e+12 values. I would seriously reconsider doing that.
The reason nothing is displayed is because none of the values tested meet the condition of your if statement. In fact, the only integer solution to this equation is a=b=c=0 (proved by Fermat and perhaps Euler).
  12 Kommentare
Cris LaPierre
Cris LaPierre am 19 Feb. 2021
So @Cris LaPierre if i use n=10^4 instead n=2 is it right like that for my task?
n=10^4;
i=3;
for a = 0:n
for b = 0:n
for c = 0:n
if a^i+b^i == c^i
result = ['Bingo ' 'For a: ' num2str(a) ' For b: ' num2str(b) ' For c: ' num2str(c)]; disp(result)
end
end
end
end
Cris LaPierre
Cris LaPierre am 19 Feb. 2021
@Cris LaPierre now i think i understand my task. i already created my script which is right for the task. he does not want any solution only the script.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Loops and Conditional Statements 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!

Translated by