Message Boards Message Boards

0
|
1094 Views
|
3 Replies
|
0 Total Likes
View groups...
Share
Share this post:

Create AffineTransform with ArrayFlatten

Posted 1 year ago

I want to obtain the same result given by AffineTransform but use ArrayFlatten. I tried the following example, but it didn't produce the desired results:

In[81]:= aa = {IdentityMatrix[3], {2, 3, 4}};
AffineTransform[{aa[[1]], aa[[2]]}] // TransformationMatrix
ArrayFlatten[{{aa[[1]], {{0, 0, 0}}}, {{aa[[2]]} // Transpose, 1}}]

Out[82]= {{1, 0, 0, 2}, {0, 1, 0, 3}, {0, 0, 1, 4}, {0, 0, 0, 1}}

During evaluation of In[81]:= ArrayFlatten::match: ArrayFlatten[{{{{1,0,0},{0,1,0},{0,0,1}},{{0,0,0}}},{{{2},{3},{4}},1}}] fails the matching condition for ArrayFlatten[a,n]: if b = a[[i_1,i_2,...,i_n]], c = a[[j_1,j_2,...,j_n]], Head[a] == Head[b] == Head[c], Length[Dimensions[b]] >= n, Length[Dimensions[c]] >= n, and i_k = j_k, then Dimensions[b][[k]] must equal Dimensions[c][[k]]. Here the condition fails for k = 1 and i_k = j_k = 1.

Out[83]= ArrayFlatten[{{{{1, 0, 0}, {0, 1, 0}, {0, 0, 1}}, {{0, 0, 
     0}}}, {{{2}, {3}, {4}}, 1}}]

Any hints for solving this problem?

Regards, Zhao

POSTED BY: Hongyi Zhao
3 Replies
Posted 1 year ago

Here are some further examples:

ArrayFlatten[{
   {IdentityMatrix[2]}, {1}
   }] // MatrixForm
ArrayFlatten[{
      {IdentityMatrix[2], 1}
      }] // MatrixForm
ArrayFlatten[{
         {Array[a, {1, 2}], Array[b, {1, 3}]},
   {Array[c, {4, 2}], Array[d, {4, 3}]}
         }] // MatrixForm

enter image description here

In short, the key points are as follows: the dimensions of the rows and columns of the corresponding matrix block must correspond to each other.

POSTED BY: Hongyi Zhao
Posted 1 year ago

The following method does the trick:

In[128]:= aa = {IdentityMatrix[3], {2, 3, 4}};
AffineTransform[{aa[[1]], aa[[2]]}] // TransformationMatrix
ArrayFlatten[{
  {aa[[1]], {aa[[2]]} // Transpose}, {{{0, 0, 0}}, 1}
  }]
% == %%

Out[129]= {{1, 0, 0, 2}, {0, 1, 0, 3}, {0, 0, 1, 4}, {0, 0, 0, 1}}

Out[130]= {{1, 0, 0, 2}, {0, 1, 0, 3}, {0, 0, 1, 4}, {0, 0, 0, 1}}

Out[131]= True
POSTED BY: Hongyi Zhao
Posted 1 year ago

This seems like a sort of awkward thing to do, but here's one attempt:

ArrayPad[ArrayPad[aa[[1]], {{0, 1}, {0, 0}}], {{0, 0}, {0, 1}}, List /@ Append[aa[[2]], 1]]
POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract