Matrix transposition: Difference between revisions
Content added Content deleted
(Emacs Lisp: Use cl-lib) |
(Added XPL0 example.) |
||
Line 4,788: | Line 4,788: | ||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
|||
Separate memory for the transposed matrix must be used because of XPL0's |
|||
unusual array configuration. It can't simply reorder the elements stored |
|||
in the original array's memory. |
|||
<lang XPL0>proc Transpose(M, R, C, N); \Transpose matrix M to N |
|||
int M, R, C, N; \rows and columns |
|||
int I, J; |
|||
[for I:= 0 to R-1 do |
|||
for J:= 0 to C-1 do |
|||
N(J,I):= M(I,J); |
|||
]; |
|||
proc ShowMat(M, R, C); \Display matrix M |
|||
int M, R, C; \rows and columns |
|||
int I, J; |
|||
[for I:= 0 to R-1 do |
|||
[for J:= 0 to C-1 do |
|||
RlOut(0, float(M(I,J))); |
|||
CrLf(0); |
|||
]; |
|||
]; |
|||
int M, N(4,3); |
|||
[M:= [[1, 2, 3, 4], \3 rows by 4 columns |
|||
[5, 6, 7, 8], |
|||
[9,10,11,12]]; |
|||
Format(4, 0); |
|||
ShowMat(M, 3, 4); |
|||
CrLf(0); |
|||
Transpose(M, 3, 4, N); |
|||
ShowMat(N, 4, 3); |
|||
]</lang> |
|||
{{out}} |
|||
<pre> |
|||
1 2 3 4 |
|||
5 6 7 8 |
|||
9 10 11 12 |
|||
1 5 9 |
|||
2 6 10 |
|||
3 7 11 |
|||
4 8 12 |
|||
</pre> |
|||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |