Matrix with two diagonals: Difference between revisions

Content deleted Content added
Aspen138 (talk | contribs)
→‎{{header|Matlab}}: "Matlab"=>"MATLAB"
m [Uiua] ⇌ works on the rows of the array by default, so ≡ isn't needed.
(3 intermediate revisions by 3 users not shown)
Line 1,023:
0 1 0 0 0 0 0 0 1 0
1 0 0 0 0 0 0 0 0 1</pre>
 
=={{header|EasyLang}}==
{{trans|Nim}}
<syntaxhighlight>
proc matrix side . .
for i to side
for j to side
if i = j or i = side - j + 1
write "1 "
else
write "0 "
.
.
print ""
.
.
matrix 6
</syntaxhighlight>
{{out}}
<pre>
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>
 
=={{header|Excel}}==
Line 2,110 ⟶ 2,137:
0 1 0 1 0
1 0 0 0 1)</pre>
 
=={{header|Mathematica}}/{{header|Wolfram Language}}==
<syntaxhighlight lang="Mathematica">
ClearAll[CreateMatrixWithTwoDiagonals];
CreateMatrixWithTwoDiagonals[n_Integer] :=
IdentityMatrix[n] + Reverse[IdentityMatrix[n]] -
If[OddQ[n], SparseArray[{{(n + 1)/2, (n + 1)/2} -> 1}, {n, n}], 0];
CreateMatrixWithTwoDiagonals[7] // MatrixForm
</syntaxhighlight>
{{out}}
 
<math>
\left(
\begin{array}{ccccccc}
1 & 0 & 0 & 0 & 0 & 0 & 1 \\
0 & 1 & 0 & 0 & 0 & 1 & 0 \\
0 & 0 & 1 & 0 & 1 & 0 & 0 \\
0 & 0 & 0 & 1 & 0 & 0 & 0 \\
0 & 0 & 1 & 0 & 1 & 0 & 0 \\
0 & 1 & 0 & 0 & 0 & 1 & 0 \\
1 & 0 & 0 & 0 & 0 & 0 & 1 \\
\end{array}
\right)
</math>
 
 
=={{header|MATLAB}}==
Line 2,978 ⟶ 3,030:
1 0 0 0 0 1
</pre>
=={{header|Uiua}}==
 
<syntaxhighlight lang="Uiua">
DoubleMatrix ← ↥⇌.⊞=.⇡
DoubleMatrix 4
</syntaxhighlight>
{{out}}
<pre>
╭─
╷ 1 0 0 1
0 1 1 0
0 1 1 0
1 0 0 1
</pre>
=={{header|V (Vlang)}}==
{{trans|go}}