I encountered an error when I was hoping for some Mathematica (8.0.4) magic sparing me to code up numerical integration, function approximation and root-finding myself. The broader context and the reference functions here come from a previous question:
k=10/3;
H = ParetoDistribution[1.18709*10^6, 0.938482];
Hstar = H;
u[c_,l_]=Log[c]-Log[1+l^(1+k)/(1+k)];
T[z_]=(1-0.84/1.3) * z;
lType[n_]=ArgMax[{u[n l-T[n l],l],l>=0},l];
zType[n_] = n lType[n];
where u
is the utility function as in Saez 2001 allowing for income effects, T
the actual tax schedule (approximate). Note that lType
and zType
only makes sense numerically. The original problem with
Type=InverseFunction[zType]
was solved with not SetDelayed
but Set
everywhere. But the following nested (numerical) integration does not work (for any H distribution you give it). Have I defined it wrong?
g[z_]:=NSolve[T'[z]/(1-T'[z])-(k SurvivalFunction[H,z]/(z PDF[Hstar,z]))
Integrate[(1-g)Exp[Integrate[1-\[Xi]u[zzz]/\[Xi]c[zzz],{zzz,z,zz}]]
PDF[H,zz]/SurvivalFunction[H,z],{zz,z,\[Infinity]}],g,Reals];
N[g[2000000], 10]
Error:
NIntegrate::nlim: zzz = zz is not a valid limit of integration.
EDIT: More interestingly, when I simply specify numeric arguments for the inner integral, the computation starts, though does not finish in an hour:
tmp[z_?NumericQ, zz_?NumericQ] := NIntegrate[1 - \[Xi]u[zzz]/\[Xi]c[zzz], {zzz, z, zz}]
g[z_] := NSolve[T'[z]/(1 - T'[z]) - (k SurvivalFunction[H,z]/(z PDF[Hstar, z]))
NIntegrate[(1 - g) Exp[tmp[z, zz]] PDF[H, zz]/SurvivalFunction[H, z], {zz,z,
\[Infinity]}], g, Reals]
But the same gives me an error if I compile first. Why? Because the limit at infinity? How should I proceed?
tmp = Compile[{{z, _Real}, {zz, _Real}},NIntegrate[1 - \[Xi]u[zzz]/\[Xi]c[zzz],
{zzz, z, zz}],Parallelization -> True, CompilationTarget -> "C"]
Then I run g[2000000] and get the error:
CompiledFunction::cfsa: "Argument zz at position 2 should be a !(\"machine-size real number\")."