[ 3 / biz / cgl / ck / diy / fa / ic / jp / lit / sci / vr / vt ] [ index / top / reports ] [ become a patron ] [ status ]
2023-11: Warosu is now out of extended maintenance.

/sci/ - Science & Math


View post   

File: 776 KB, 1920x1200, 1293994857892.jpg [View same] [iqdb] [saucenao] [google]
5104644 No.5104644 [Reply] [Original]

I have to write a code in Mathematica that goes through the numbers from 1 to 50 and prints out the numbers that are the sum of two perfect squares.
For each n between 1 and 50, which ones can be expressed as n = (a^2) + (b^2), 1<=n<=50
Any ideas? I really can't figure this one out.

>> No.5104657

any takers?

>> No.5104674 [DELETED] 
File: 70 KB, 852x480, cutey_Emma-superbad_plain.jpg [View same] [iqdb] [saucenao] [google]
5104674

Well depending on what it's for, I'd just compute all the values...

Table[a^2 + b^2, {a, 1, Sqrt[50]}, {b, 1, Sqrt[50]}]
Select[Union[Flatten[%]], # < 50 &]

>> No.5104679
File: 1.02 MB, 1334x1832, cutey_Emma_pocket.jpg [View same] [iqdb] [saucenao] [google]
5104679

Well depending on what it's for, I'd just compute all the values...

Table[a^2 + b^2, {a, 1, Sqrt[50]}, {b, 1, Sqrt[50]}]
Select[Union[Flatten[%]], # < 51 &]

>> No.5104698

>>5104679
I think that would just end up limiting the a and b values to between 1 and 50. I want all the values where the sum of the squares is between 1 and 50.

>> No.5104718

So you want the n output value to be limited to between 1 and 50?

>> No.5104719 [DELETED] 

>>5104679
No, you're wrong, this gives all the numbers.
If a or b reaches sqrt(50)>7 then the sum a^2+b^2 goes over 50, that's why I cut it off there.

You can requite it as

n := 50
Table[a^2 + b^2, {a, 1, Sqrt[n]}, {b, 1, Sqrt[n]}];
Select[Union[Flatten[%]], # <= n &]

if you don't want magic numbers in your code.

>> No.5104727

>>5104698
No, you're wrong, this gives all the numbers.
If a or b reaches sqrt(50)>7 then the sum a^2+b^2 goes over 50, that's why I cut it off there.

You can requite it as

n := 50
Table[a^2 + b^2, {a, 1, Sqrt[n]}, {b, 1, Sqrt[n]}];
Select[Union[Flatten[%]], # <= n &]

if you don't want magic numbers in your code.