The code is below.
happens with every array:
tmax = 20;
tmin = 1;
patchnum = 5;
xmax = 10;
xcrit = 3;
alpha[1] = 1;
alpha[2] = 1;
alpha[3] = 1;
alpha[4] = 1;
alpha[5] = 1;
betai[1] = 0.05;
betai[2] = 0.04;
betai[3] = 0.03;
betai[4] = 0.02;
betai[5] = 0.01;
lamda[1] = 0.5;
lamda[2] = 0.25;
lamda[3] = 0.166666;
lamda[4] = 0.125;
lamda[5] = 0.1;
Y[1] = 1;
Y[2] = 2;
Y[3] = 3;
Y[4] = 4;
Y[5] = 5;
Array[beh, {19, 10}];
Array[f, {20, 10}];
For[t = tmax, t >= 1, t--,
For[x = xcrit, x <= xmax, x++,
If [t == tmax,
If [x <= xcrit,
f[t, x] = 0, f[t, x] = 1
]];
If [t < tmax,
maxfit = -5;
For[patch = 1, patch <= patchnum, patch++,
x1 = x - alpha[patch] + Y[patch];
x2 = x - alpha[patch];
If [x1 > xmax, x1 = xmax];
If [x1 < xcrit,
x1 = xcrit
];
If [x2 > xmax, x2 = xmax];
If [x2 < xcrit, x2 = xcrit];
tempfit = (1 -
betai[patch])*(lamda[patch]*
f[(t + 1), x1] + (1 - lamda[patch])*f[(t + 1), x2]);
If [x2 <= xcrit,
tempfit = (1 - betai[patch])*(lamda[patch]*f[(t + 1), x1]);] ;
If [tempfit > maxfit,
maxfit = tempfit;
beh[t, x] = patch;
];
f[t, x] = maxfit;
]
]
]
]