Message Boards Message Boards

0
|
5535 Views
|
5 Replies
|
2 Total Likes
View groups...
Share
Share this post:

How do I cross reference a set of rules against pythagorean triples?

Posted 9 years ago
POSTED BY: Jeffery Cole
5 Replies
Posted 9 years ago
POSTED BY: Paul Cleary
Posted 9 years ago

Thanks!

Yes I believe this is what I want. However I am having trouble understanding it (extremely new to mathematica). I put the excessive rules just to be careful so as to avoid confusion, sorry if they had the opposite effect. Is it possible that you could give me the same code with step by comments explaining what is happening? Sorry if I’m asking too much.

Thanks anyway!

POSTED BY: Updating Name

Oops! The last four matter some because

a1 + b2 = b1 + a4 = a2 + b3 = a3 + b4

POSTED BY: Jeffery Cole

When you're starting off, avoid using Print or Do. Print just causes something to appear on the screen. You don't want to use print. You almost never want to actually use Print in Mathematica. You want to return the actual values so that you can use them for later. Instead of these, let's use Table:

Let's break your code down into some simpler pieces. This will make it easier to maintain and understand. Here's a function that generates a list of the values you are interested in:

generateValues[m_, n_] := {m^2 - n^2, 2 m n, m^2 + n^2,  m^2 - n^2 - 2 m n};
Table[generateValues[m, n], {n, 1, 5}, {m, n + 1, 5}]

Now let's make a function that returns True only when the first three elements of a list satisfy a^2+b^2=c^2.

 isItPythagorean[list_] := (list[[1]]^2 + list[[2]]^2 == list[[3]]^2)

Let's test that it works:

isItPythagorean[{3, 4, 5}]
True

We can apply it inside the Table:

Table[isItPythagorean[generateValues[m, n]], {n, 1, 5}, {m, n + 1, 5}]
{{True, True, True, True}, {True, True, True}, {True, True}, {True}, {}}
POSTED BY: Sean Clarke

Thank You Soo Much! You have been extremely helpful. :-)

However the rules that I am using are to find multiple triplets (Sorry for not being clear enough in the original post).

The rules are the following:

a12+b12=c12

a22+b22=c22

a32+b32=c32

a42+b42=c42

a1=b4

b1=a2

b2=a3

b3=a4

a1+b2=L

b1+a4=L

a2+b3=L

a3+b4=L

When all values for a, b, c, and L are whole numbers. Obviously we’re using m & n to determine the triplets and not a, b, and c, but do I need to define a, b & c from the table? What you gave me is really helpful, but I don’t know how to test with different triples simultaneously. Sorry if I’m incoherent. Thanks once again!

p.s.

the last four equations just want to determine that a+b is an integer, otherwise L doesn’t matter

POSTED BY: Jeffery Cole
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract