0
|
9972 Views
|
2 Replies
|
1 Total Likes
View groups...
Share

# Problem with conditionals

Posted 9 years ago
 Hi everyone, I am having some problems with the if statment in Mathematica. I following code the program is taking the t value from the for loop statment (tmax) and doing the calculation. But I use the if statment to tell the program to do the calculations only for 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] if [x1 > xmax, x1 = xmax] if [x1 < xcrit, x1 = xcrit; x2 = x - alpha[patch]; ] 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; ] ] ] ] `
2 Replies
Sort By:
Posted 9 years ago
 Thanks, solved the problem!
Posted 9 years ago
 Oh function names in Mathematica begin with capital letters. In fact, they are all written in what is called a CamelCase.All of your if the statements should be If statements. Make that change and perhaps then your code will work as expected.