Just a simple visualizer for the sum of the first n Natural numbers.
Also coded a version without borders, as the colors get messed up for large n with borders on the squares.
Also coded a version without borders, as the colors get messed up for large n with borders on the squares.
Sum of First n Numbers
Sum of First n Numbers
In[]:=
sumOfFirstNNums[n_]:=ListAnimate[{Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}]}]],"Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,n,2*n-1-j}]}]],"2*Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Red,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,n,2*n-1-j}]}]],"2*Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Red,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,2*n-1-j,2*n-1}]}]],"2*Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Red,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,n-j,n}]}]],ToString[n]<>"*("<>ToString[n]<>"+1)"],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n}]}]],"2*Σ from 1 to "<>ToString[n]<>" = "<>ToString[n]<>"*("<>ToString[n]<>"+1)"],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}]}]],"Σ from 1 to "<>ToString[n]<>" = "<>ToString[n]<>"*("<>ToString[n]<>"+1)/2"],Labeled[Graphics[Flatten[{EdgeForm[Thick],LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}]}]],"Σ from 1 to "<>ToString[n]<>" = "<>ToString[n]<>"*("<>ToString[n]<>"+1)/2 = "<>ToString[n*(n+1)/2]]}]
In[]:=
sumOfFirstNNums[5]
Out[]=
In[]:=
sumOfFirstNNums[10]
Out[]=
Sum of First n Numbers (no border, to make visuals for large n better)
Sum of First n Numbers (no border, to make visuals for large n better)
In[]:=
sumOfFirstNNumscolors[n_]:=ListAnimate[{Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}]}]],"Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,n,2*n-1-j}]}]],"2*Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Red,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,n,2*n-1-j}]}]],"2*Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Red,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,2*n-1-j,2*n-1}]}]],"2*Σ from 1 to "<>ToString[n]],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}],Red,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,n-j,n}]}]],ToString[n]<>"*("<>ToString[n]<>"+1)"],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n}]}]],"2*Σ from 1 to "<>ToString[n]<>" = "<>ToString[n]<>"*("<>ToString[n]<>"+1)"],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}]}]],"Σ from 1 to "<>ToString[n]<>" = "<>ToString[n]<>"*("<>ToString[n]<>"+1)/2"],Labeled[Graphics[Flatten[{LightBlue,Table[Rectangle[{i,j}],{j,n-1,0,-1},{i,0,n-1-j}]}]],"Σ from 1 to "<>ToString[n]<>" = "<>ToString[n]<>"*("<>ToString[n]<>"+1)/2 = "<>ToString[n*(n+1)/2]]}]
In[]:=
sumOfFirstNNumscolors[100]
Out[]=
Approaches a right triangle as we’d expect for large n.
limofasn->∞=
n(n+1)
2
1
2
2
n
Which is the formula for an isosceles right triangle.