# How to specify an element of a list when using RecurrenceTable

My problem is that I'm trying to get a list of refraction angles in a multilayer structure (for the sake of this example - with two types of refraction indices and eleven layers of them). The code is as follows:

theta0 = (1.535/2)*(Pi/180)
n = 11
nGaAs = 3.4;
nAlAs = 2.9;
nlayers =
{1, nGaAs, nGaAs, nAlAs, nGaAs, nAlAs, nGaAs,
nAlAs, nGaAs, nAlAs, nGaAs, nAlAs, nGaAs};
RecurrenceTable[
{theta[i] ==
ArcSin[(Extract[nlayers, i]/Extract[nlayers, i + 1])*Sin[theta[i - 1]]],
theta[0] == theta0},
theta, {i, 1, n}]


I'm getting the following error:

Extract::psl1: Position specification i in Extract[{1,3.4,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4,2.9,3.4},i] is not applicable.

Is there any way to use a list of variables in RecurrenceTable? I'm fairly new to this, so maybe I missed something in the desctiption of RecurrenceTable or Extract, but still, does anyone know how to correctly formulate this in Mathematica?

## bumped to the homepage by Community♦yesterday

This question has answers that may be good or bad; the system has marked it active so that they can be reviewed.

• Welcome to MSE! It was already answered here. Do[nl[i]=nlayers[[i]],{i,Length[nlayers]}], then use this nl instead of nlayers. – Alx Sep 15 at 15:17

RecurrenceTable doesn't like Part or its variants. So use indexed variables as @Alx states in a comment to the question. Like so:

theta0 = (1.535/2)(Pi/180);
nGaAs = 3.4;
nAlAs = 2.9;
nlayers =
{1, nGaAs, nGaAs, nAlAs, nGaAs, nAlAs, nGaAs, nAlAs, nGaAs, nAlAs,
nGaAs, nAlAs, nGaAs};
n = Length[nlayers];
Do[nl[i] = nlayers[[i]], {i, n}]
RecurrenceTable[
{theta[i] == ArcSin[nl[i]/nl[i + 1] Sin[theta[i - 1]]],
theta[0] == theta0},
theta, {i, 1, n - 1}]


{0.00393972, 0.00393972, 0.00461898, 0.00393972, 0.00461898, 0.00393972, 0.00461898, 0.00393972, 0.00461898, 0.00393972, 0.00461898, 0.00393972}