Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Give the totals of the entries on the rising diagonals of a square matrix
| ResourceFunction["AntidiagonalTotals"][mat] gives the first n totals along the antidiagonals of the n×n matrix mat. | 
Get the totals for a 3×3 matrix:
| In[1]:= | ![ResourceFunction["AntidiagonalTotals"][Array[a, {3, 3}]]](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/325a0139b6e33237.png) | 
| Out[1]= |  | 
Get the totals for a random matrix:
| In[2]:= | ![mat = RandomInteger[{-10, 10}, {4, 4}]](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/023531537521c5ef.png) | 
| Out[3]= |  | 
| In[4]:= | ![ResourceFunction["AntidiagonalTotals"][mat]](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/498459bceb61bec5.png) | 
| Out[4]= |  | 
The direction of the antidiagonals:
| In[5]:= | ![Table[Style["\[UpperRightArrow]", 24], {m, 3}, {n, 3}] // Grid](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/0588990d30925547.png) | 
| Out[5]= |  | 
AntidiagonalTotals[mat] is equal to AntidiagonalTotals[Transpose[mat]]:
| In[6]:= | ![mat = RandomInteger[{-5, 5}, {3, 3}]](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/4665d6bfad142086.png) | 
| Out[6]= |  | 
| In[7]:= | ![a1 = ResourceFunction["AntidiagonalTotals"][mat]](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/4e17d467a1443420.png) | 
| Out[7]= |  | 
| In[8]:= | ![a2 = ResourceFunction["AntidiagonalTotals"][Transpose[mat]]](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/469f1a7747cd4886.png) | 
| Out[8]= |  | 
| In[9]:= |  | 
| Out[9]= |  | 
Pascal’s triangle:
| In[10]:= | ![(b = Table[Binomial[m, n], {m, 0, 10}, {n, 0, m}]) // Grid](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/6847396b6b3330da.png) | 
| Out[10]= |  | 
The Fibonacci sequence:
| In[11]:= | ![ResourceFunction["AntidiagonalTotals"]@PadRight@b](https://www.wolframcloud.com/obj/resourcesystem/images/8d8/8d848a75-dfd9-4389-9cf5-0ff2f1f1e06f/226ac5a31135b212.png) | 
| Out[11]= |  | 
| In[12]:= |  | 
| Out[12]= |  | 
Wolfram Language 11.3 (March 2018) or above
This work is licensed under a Creative Commons Attribution 4.0 International License