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

Stephen23
Stephen23 on 19 Feb 2021
Edited: Stephen23 on 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
(Answers Dev) Restored edit

Sign in to comment.

 Accepted Answer

Cris LaPierre
Cris LaPierre on 18 Feb 2021
Edited: Cris LaPierre on 18 Feb 2021

0 votes

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 Comments

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
how can i change my script to run correctly
https://en.m.wikipedia.org/wiki/Fermat%27s_Last_Theorem
No solutions are possible in integers for i higher than 2
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.
please can you help me
Walter Roberson
Walter Roberson on 18 Feb 2021
Edited: Walter Roberson on 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 on 18 Feb 2021
Edited: Cris LaPierre on 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 on 18 Feb 2021
Edited: Cris LaPierre on 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 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.

Sign in to comment.

More Answers (0)

Categories

Community Treasure Hunt

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

Start Hunting!