Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

apply functions iteratively (modified re-post)

(This is a modified re-post of ... since my original question wasn't answered)

I have a few functions R1,R2,R3,R4 which act on vectors. If X = matrix(3,1,(x0,y0,r)) then I have

def R1(X): return matrix(3,1,(X[0,0]/(X[0,0]^2+X[1,0]^2-X[2,0]^2),X[1,0]/(X[0,0]^2+X[1,0]^2-X[2,0]^2),X[2,0]/abs(X[0,0]^2+X[1,0]^2-X[2,0]^2)))

def R2(X): return matrix(3,1,(-X[0,0],X[1,0],X[2,0]))

def R3(X): return matrix(3,1,(-X[0,0]+2,X[1,0],X[2,0]))

def R4(X): return matrix(3,1,(X[0,0],-X[1,0]+2,X[2,0]))

For instance, if v = matrix(3,1,(1,1,1)), then applying R2 to v gives the matrix $(-1,1,1)$.

I'd like to apply about 10 "levels" of iteration of these functions and have the output as a list of vectors. So, the list should be $R1(v), R2(v),R3(v),R4(v),R1^2(v),R2(R1(v)),R3(R1(v)),R4(R1(v)),R1^3(v),...,R1^{10}(v)\,...,R4^{10}(v)$ (as vectors) where $R_j^n = R_j \circ \cdots \circ R_j$ $n$ times.

I know how to apply a single function iteratively, but I don't know how to combine/loop the four together. Thanks.

apply functions iteratively (modified re-post)

(This is a modified re-post of ... Apply Functions Iteratively since my original question wasn't answered)

I have a few functions R1,R2,R3,R4 which act on vectors. If X = matrix(3,1,(x0,y0,r)) then I have

def R1(X): return matrix(3,1,(X[0,0]/(X[0,0]^2+X[1,0]^2-X[2,0]^2),X[1,0]/(X[0,0]^2+X[1,0]^2-X[2,0]^2),X[2,0]/abs(X[0,0]^2+X[1,0]^2-X[2,0]^2)))

def R2(X): return matrix(3,1,(-X[0,0],X[1,0],X[2,0]))

def R3(X): return matrix(3,1,(-X[0,0]+2,X[1,0],X[2,0]))

def R4(X): return matrix(3,1,(X[0,0],-X[1,0]+2,X[2,0]))

For instance, if v = matrix(3,1,(1,1,1)), then applying R2 to v gives the matrix $(-1,1,1)$.

I'd like to apply about 10 "levels" of iteration of these functions and have the output as a list of vectors. So, the list should be $R1(v), R2(v),R3(v),R4(v),R1^2(v),R2(R1(v)),R3(R1(v)),R4(R1(v)),R1^3(v),...,R1^{10}(v)\,...,R4^{10}(v)$ (as vectors) where $R_j^n = R_j \circ \cdots \circ R_j$ $n$ times.

I know how to apply a single function iteratively, but I don't know how to combine/loop the four together. Thanks.