Matrix with two diagonals: Difference between revisions

Content added Content deleted
m (Corrected a typo.)
imported>Maxima enthusiast
No edit summary
Line 2,150: Line 2,150:
(1,7) 1
(1,7) 1
(7,7) 1
(7,7) 1
</pre>

=={{header|Maxima}}==
<syntaxhighlight lang="maxima">
/* Function that returns a square matrix with a diagonal and antidiagonal pattern in their entries */
diags(n):=genmatrix(lambda([x,y],if x=y or x+y=n+1 then 1 else 0),n,n)$

/* Example */
diags(6);
</syntaxhighlight>
{{out}}
<pre>
matrix(
[1, 0, 0, 0, 0, 1],
[0, 1, 0, 0, 1, 0],
[0, 0, 1, 1, 0, 0],
[0, 0, 1, 1, 0, 0],
[0, 1, 0, 0, 1, 0],
[1, 0, 0, 0, 0, 1]
)
</pre>
</pre>