% 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 Commenti

Stephen23
Stephen23 il 19 Feb 2021
Modificato: Stephen23 il 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 il 6 Mag 2021
(Answers Dev) Restored edit

Accedi per commentare.

 Risposta accettata

Cris LaPierre
Cris LaPierre il 18 Feb 2021
Modificato: Cris LaPierre il 18 Feb 2021

0 voti

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 Commenti

n = 10^4;
i = 3;
for a = 1:n
for b = 1:n
for c = 1:n
if (a^i) = (b^i) = (c^i) = 0
result = ['Bingo ' 'For a: ' num2str(a) ' For b: ' num2str(b) ' For c: ' num2str(c)];
disp(result)
end
end
end
end
Steven Thies
Steven Thies il 18 Feb 2021
how can i change my script to run correctly
Walter Roberson
Walter Roberson il 18 Feb 2021
https://en.m.wikipedia.org/wiki/Fermat%27s_Last_Theorem
No solutions are possible in integers for i higher than 2
Steven Thies
Steven Thies il 18 Feb 2021
then how can i write a script to show all possible combination of numbers for a^3+b^3=c^3
if a^i + b^i == c^i
You were not using a bad test before: you were simply asking for a mathematical impossibility.
Steven Thies
Steven Thies il 18 Feb 2021
please can you help me
Walter Roberson
Walter Roberson il 18 Feb 2021
Modificato: Walter Roberson il 18 Feb 2021
Except for a b c all 0, no solutions exist in positive integers. Can solutions exist if the integers can be negative?
Sometimes the point of homework is to show that something does not exist
I think you misunderstood my answer. Your script is fine. You are trying to find integer solutions for an equation that does not have them in the range of numbers you are looking at.
You could start your loops at 0 instead of 1 to get some results. Then you get the trivial solutions (e.g. when all 3 are 0, or, if a=0, then when b=c, etc)
n=2;
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
Bingo For a: 0 For b: 0 For c: 0 Bingo For a: 0 For b: 1 For c: 1 Bingo For a: 0 For b: 2 For c: 2 Bingo For a: 1 For b: 0 For c: 1 Bingo For a: 2 For b: 0 For c: 2
Cris LaPierre
Cris LaPierre il 18 Feb 2021
Modificato: Cris LaPierre il 19 Feb 2021
This reply is a response to the following comment @Steven Thies deleted
maybe i understand my task false. The task is: Leonard Euler proved the following special form of Fermat's great theorem: there are no natural numbers for the coefficients a, b and c that satisfy the equation a^3 + b^3 = c^3. Create a Matlab script that checks all number combinations between 1 and 10 ^ 4 for all three coefficients for the equation a^3 + b^3 = c^3. . If the equation is correct for a certain combination of numerical values, the message "Bingo", followed by the associated numerical values, should be sent via disp. A user query is not necessary here.
i really dont know how to continue.please help me
You've created the script. However, the answer is in the first sentence:
"there are no natural numbers for the coefficients a, b and c that satisfy the equation a^3 + b^3 = c^3."
Your script confirms that.
Cris LaPierre
Cris LaPierre il 18 Feb 2021
Modificato: Cris LaPierre il 19 Feb 2021
This reply is a response to the following comment @Steven Thies deleted
@Cris LaPierre is your script correct for my task which i posted here? Thank you so much guys.
No, it's not. It should be obvious why not. Mine is checking numbers from 0-2, not 1-10^4. However, you should have more confidence in your own work. I only modified your original script.
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 il 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.

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Loops and Conditional Statements in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by