I am using Mathematica 9 Student Edition and I am having problems with recursion limit errors. I have written a procedure that works and involves numerical integration. If I run this procedure by itself and plug in the values I want to test, then this procedure works just fine. The procedure is printed below. For anyone interested, it is supposed to transform two random variables, betaone and betazero into two other random variables gamma and rho and then numerically integrate a probability density function using these new random variables:
xtheta = .4; xx = .1;
c = 1/theta /. theta -> xtheta;
gamma = (Log[theta / (1 - theta)] - betazero - x*betaone) /
betaone;
rho = Exp[ betazero + x*betaone] / (1 +
Exp[betazero + x*betaone]);
JMatrix = {{D[gamma, betazero],
D[gamma, betaone]}, {D[rho, betazero], D[rho, betaone]}};
myJacobian = Det[JMatrix] ; gamma =.; rho =.;
betazero = (1/
gamma)*((x + gamma)*Log[rho/(1 - rho)] - x*Log[theta/(1 - theta)]);
betaone = (1/gamma)*(Log[theta/(1 - theta)] - Log[rho/(1 - rho)]);
finalPDF =
c * myJacobian /. {betazero -> (1/
gamma)*((x + gamma)*Log[rho/(1 - rho)] -
x*Log[theta/(1 - theta)]),
betaone -> (1/gamma)*(Log[theta/(1 - theta)] -
Log[rho/(1 - rho)])};
theta = xtheta; finalPDF2 = finalPDF /. {x -> xx};
n = NIntegrate[finalPDF2, {rho, 0, xtheta - .001}, {gamma, 0, 1}];
However, as soon as I add a Print[n] statement right after this procedure the code cannot run and I get the following error "$RecursionLimit::reclim: Recursion depth of 1024 exceeded". Can anyone explain why I get this error and how I can remedy it?
Additionally, I hope to use this procedure in a loop, so that I can run this procedure over and over again and change one of the variables slightly and output my results using the Print statement. I have tried using Do loops and For loops, but I get the same problem as before where I get a "$RecursionLimit::reclim: Recursion depth of 1024 exceeded" error message. Does anyone know if there is an advantage to using one loop over the other and if the problem with the looping is the same as my problem with the Print statement?
Thank you for your help!