How should i get start with this?

25 ビュー (過去 30 日間)
Alex Degaga
Alex Degaga 2015 年 4 月 1 日
編集済み: Alex Degaga 2015 年 4 月 26 日
The Pythagorean theorem states that a^2 + b^2 = c^2 • Write a MATLAB program in a script file that finds all the combinations of triples a, b, and c that are positive integers all smaller or equal to 50 that satisfy the Pythagorean theorem. Display the results in a three-column table in which every row corresponds to one triple. The first three rows of the table are:
3 4 5
5 12 13
6 8 10
  2 件のコメント
James Tursa
James Tursa 2015 年 4 月 1 日
Repeated Question:
"The Pythagorean theorem states that a^2 + b^2 = c^2 • Write a MATLAB program in a script file that finds all the combinations of triples a, b, and c that are positive integers all smaller or equal to 50 that satisfy the Pythagorean theorem. Display the results in a three-column table in which every row corresponds to one triple. The first three rows of the table are:
3 4 5
5 12 13
6 8 10
"
Why are you posting this here? You already had a Question for this with Answers:
Alex Degaga
Alex Degaga 2015 年 4 月 5 日
編集済み: Alex Degaga 2015 年 4 月 26 日
Thank you Joep

サインインしてコメントする。

採用された回答

Joep
Joep 2015 年 4 月 1 日
編集済み: Joep 2015 年 4 月 1 日
You can start by writing down the Pythagorean therm in matlab. The second is start a loop from 1 to 50. You could use a for loop for that.
n=1;
for a_ = 1:50
for b_ = 1:50
c_=sqrt(a_^2+b_^2);
if c_==round(c_)
if c_<=50
a(n)=a_;
b(n)=b_;
c(n)=c_;
n=n+1;
end
end
clear c_
end
end
Pyth=[a',b',c'];
disp(Pyth)
With this code you have still some double solutions. I let it to you to solve this bug. A solution could be found to let b>a and c>b but I didn't test it, so I could be wrong.
Update: I found by the way this for answer (without the bug):
3 4 5
5 12 13
6 8 10
7 24 25
8 15 17
9 12 15
9 40 41
10 24 26
12 16 20
12 35 37
14 48 50
15 20 25
15 36 39
16 30 34
18 24 30
20 21 29
21 28 35
24 32 40
27 36 45
30 40 50
  2 件のコメント
Alex Degaga
Alex Degaga 2015 年 4 月 2 日
編集済み: Alex Degaga 2015 年 4 月 5 日
Thank you, I had the FOLLOWING, but what you did make sense a lot!
if length(a)==1
if length(b)==1
if length(c)==1
if a==abs(a)
if b==abs(b)
if c==abs(c)
for a=1:1:50
b=1:1:50
c=sqrt(a^2+b^2)
if a<=50&&b<=50&&c<=50
fprintf(' %i %i %i\n', a,b,c)
elseif a>50&&b>50&&c>50
disp('error')
elseif length(a)~=1,length(b)~=1, length(c)~=1
Joep
Joep 2015 年 4 月 7 日
編集済み: Joep 2015 年 4 月 7 日
if a<=50&&b<=50&&c<=50
is this necessary? is
if c<=50
not enough? because a en b already are from 1 to 50.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeGraphics Object Programming についてさらに検索

製品

Community Treasure Hunt

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

Start Hunting!

Translated by