Spiral Matrix Procedure in Maple -


I want to write a process to take square matrix and want to output it to a spiral matrix.

For example;

  M: = matrix (3, [[1,2,3], [4,5,6], [7,8,9]]);   

will start

  S: = matrix (3, [[1,2,3], [8 9 4], [7, 6 , 5]]);   

is starting in the upper left corner and by the time you do not reach the middle, every line is clockwise.

My first thought was that I should be able to call each element (M_i, j) from a matrix and tell where to go. I can write a different process for each class matrix where each of the elements of the given matrix should be moved. Since I could not work for it n.

What do I have for 3x3 metrics here

  spiral: = proc (a1, a2, a3, b1, b2, b3, c1, c2 , C3) Local M, S; M: = matrix (3, [[A1, A2, A3], [B1, B2, B3], [C1, C2, C3]]); S: = Matrix (3, [[A1, A2, A3], [C2, C3, B1], [C1, B3, B2]]); Print (m); Print (s); End spiral (1,2,3,4,5,6,7,8,9);   

It is very difficult for me to get information about the matrix in the maple. Any sign will be given if you use maple. Thank you.

I do not think this problem is a particularly compact solution. Here is a solution with which I have come. It moves in the form of a square matrix and gives another matrix which is the spiral of the input matrix.

  spiral: = proc (M :: Matrix) local size, spiralCount, currentRow, currentCol, Mindex, K; Local spiral matrix; Size: = numelems (m [1]); Spiral number: = size; CurrentRow: = 1; CurrentCol: = 0; Mindex: = 0; Spiral matrix: = matrix (size, shape); While spiral count & gt; From 0 to 1 to spiral; Make current call: = currentCol + 1; Spiral matrix [current, current calculation]: = m [iquo (mindex, size) + 1, (mindex modern shape) + 1]; Mindex: = Mindex + 1; The end is: Calculate 1 to spiral from 1 to currentRow: = currentRow + 1; Spiral matrix [current, current calculation]: = m [iquo (mindex, size) + 1, (mindex modern shape) + 1]; Mindex: = Mindex + 1; End: For 1 to spiral, do -1 - current coil: = current call - 1; Spiral matrix [current, current calculation]: = m [iquo (mindex, size) + 1, (mindex modern shape) + 1]; Mindex: = Mindex + 1; End: To turn 1 to spiral, turn on the Country 2 to turn on: = current-row -1; Spiral matrix [current, current calculation]: = m [iquo (mindex, size) + 1, (mindex modern shape) + 1]; Mindex: = Mindex + 1; Ending: spiral count: = spiral number - 2; End: Return spiral matrix; End proc: & gt; Meters: = matrix ([[1,2,3], [4,5,6], [7,8,9]]); [1 2 3] [] m: = [4 5 6] [] [7 8 9] & gt; Spiral (m); [1 2 3] [] [8 9 4] [] [7 6 5]   

Let me type this implementation and / or how I use the matrix.

Comments

Popular posts from this blog

ios - Adding an SKSpriteNode to SKScene from a child SKSpriteNode -

Matlab transpose a table vector -

c# - Textbox not clickable but editable -