rm(list=ls()) # clear all variable values # set up matrices and define a complete cell: Mf = matrix(c( 1, 0, 0, -1/25, 1, 0 , 0, 0, 1), byrow=TRUE, ncol=3) Md = matrix(c( 1, 0, 0, 1/25, 1, 0 , 0, 0, 1), byrow=TRUE, ncol=3) Mo = matrix(c( 1, 15, 0, 0 , 1, 0 , 0, 0, 1), byrow=TRUE, ncol=3) Mb = matrix(c( 1, 0, 0, 0 , 1, 0.032, 0, 0, 1), byrow=TRUE, ncol=3) # this last element is a "bend" by an angle of 32 mrad cell = list( Mf, Mo, Mb, Mo, Md, Mo, Mb, Mo) ds = c( 0, 15, 0, 15, 0, 15, 0, 15) s = cumsum(ds) # find the matrix of a complete cell: Mcell = diag(1,3) i = 0 while(i