My code is creating an error when I try to evaluate an integral. Could I ask you to reproduce this code and see what is wrong? Thank you.
Here I simply define two variables:
Find SolVm1
:
odeM1 = 1/2*sigma*Vm''[x] + ((delta*a0)/a1 - a1*x)*Vm'[x] - em*Vm[x] == -((2*x - 2*lambda*ep*(a0 + a1*x))/(em - ep));
SolVm1 = DSolveValue[odeM1, Vm[x], x] // FullSimplify
Find SolVp3
:
odeP3 = 1/2*sigma*Vp''[x] + ((delta*a0)/a1 - a1*x)*Vp'[x] - ep*Vp[x] == -((-2*x + 2*em*(a0 + a1*x)* lambda)/(em - ep));
SolGeneralHomoP3 = C[2] Hypergeometric1F1[ep/(2 a1), 1/2, (a1^2 x - a0 delta)^2/(a1^3 sigma)]
odeP3 /. Vp -> (h0 + h1 # &) /. Equal -> Subtract;
eqn = CoefficientList[%, x];
solh = Solve[eqn == 0, {h0, h1}][[1]]
Simplify[odeP3 /. Vp -> (h0 + h1 # &) /. solh]
SolParticularNonHomoP3 = h0 + h1 x /. solh
SolVp3 = SolGeneralHomoP3 + SolParticularNonHomoP3 // FullSimplify
From here on is where I make the mistake:
Rename the constant in SolVp3
and transform SolVm1
and SolVp3
into functions:
Vm[x_] = SolVm1 /. Integrate -> Inactive[NIntegrate];
Vp[x_] = SolVp3 /. C[2] -> C[3];
Find the constants:
Jx[x_] = em*Vm[x] + ep*Vp[x];
Jxx[x_] = em*D[Vm[x], x] + ep*D[Vp[x], x];
Jpi[x_] = Vm[x] + Vp[x];
Jpipi[x_] = D[Vm[x], x] + D[Vp[x], x];
constants = Solve[{Jx[xhat] == 0, Jxx[xhat] == 0, Jpi[xhat] == (2*theta)/((epsilon - 1)*(1 + curlyphi))*xhat}, {C[1], C[2], C[3]}];
SolJx[x_] = Jx[x] /. constants[[1]];
SolJxx[x_] = Jxx[x] /. constants[[1]];
SolJpi[x_] = Jpi[x] /. constants[[1]];
SolJpipi[x_] = Jpipi[x] /. constants[[1]];
Specify parameters:
delta = 2/100;
epsilon = 3/2;
curlyphi = 5;
xi = 5/1000;
lambda = 1/2;
theta = lambda*(epsilon - 1)*(1 + curlyphi) + 0.05;
sigma = (20/100)^2;
muA = 5/100;
sigmaA = 10/100;
rn = delta + muA - sigmaA^2;
em = (delta*theta - Sqrt[delta^2*theta^2 + 4*theta*(epsilon - 1)*(1 + curlyphi)])/(2*theta);
ep = (delta*theta + Sqrt[delta^2*theta^2 + 4*theta*(epsilon - 1)*(1 + curlyphi)])/(2*theta);
a1 = (-delta*theta + Sqrt[delta^2*theta^2 + 4*theta*(epsilon - 1)*(1 + curlyphi)])/(2*theta);
a0 = -((xi + rn - 1/2*sigma - sigmaA*Sqrt[sigma])/(delta + a1))*a1;
a = (-delta*theta + Sqrt[delta^2*theta^2 + 4*lambda*(epsilon - 1)^2*(1 + curlyphi)^2])/(2*lambda*(epsilon - 1)*(1 + curlyphi));
Find xhat (ultimate goal):
Solxhat = NSolve[Activate[SolJpipi[xhat]] == (2*theta)/((epsilon - 1)*(1 + curlyphi)), xhat]
The error:
What I don't understand: why does this error arise? I am setting x=xhat, this should not affect the variable of integration but only the limit.
I can notice something is wrong because this does not compute:
Activate[SolJx[-0.1]]