I'm trying to write a function (A) which calls another function (B) (in my case KroneckerProduct
) where the number and the position of the arguments of function (B) depend on the arguments of function (A).
Here an example of what I mean:
I have two matrices (1 and 2) and I want to do the KroneckerProduct
of them n
times (in the example n=5
) where in position a
and b
(in the example 1
and 3
) I have matrix2
, in all the other (2
,4
,5
) I have matrix1
.
matrix1 = IdentityMatrix[2];
matrix2 = {{2,2},{2,2}};
function[1, 3, 5] = KronekerProduct[
matrix2, matrix1, matrix2, matrix1, matrix1
]
I can think several ways of doing that but none of them is elegant or short, while I think there is a compact way of doing it and I can't see it/
Thanks
matrix1
andmatrix2
? Don't you want them as a part of the input. Is it always be aboutmatrix2
being in exactly two spots? If not, please elaborate on what do you want to be able to input in general. $\endgroup$