# FindRoot for numerical calculation of integral equation with parameters

I have a problem with a calculation. I was not able to find a corresponding answer. I try to find a numerical calculation of a integral equation with parameters. In general I understand how to solve a simple problem if there isn't a integral. For example:

yy[a_, b_] := x^2 - a + b
gg[a_, b_] := x /. FindRoot[yy[a, b] == 0, {x, 1}]
gg[3, 1]
1.41421 It works with warning in more complicated examples:

 Veffd2i[m_, T_] :=
4 - ((2 E^(-((m + Sqrt[4 + M^2])/
T)) )/((1 + E^(-((m + Sqrt[M^2 + 4])/T))) T \[Sqrt](4 + M)^2))
Veffd2i2[m_, T_] := M /. FindRoot[Veffd2i[m, T] == 0, {M, 0}]
Veffd2i2[1, -2]


The line search decreased the step size to within tolerance specified \ by AccuracyGoal and PrecisionGoal but was unable to find a sufficient \ decrease in the merit function. You may need more than \ MachinePrecision digits of working precision to meet these tolerances.

24992.6


But if I want to add a integration in my example, I face with the next one:

Veffd2i[m_?NumberQ, T_?NumberQ] :=
4 + Integrate[-((
2 E^(-((m + Sqrt[4 + (l + M)^2])/T))
l^2)/((1 + E^(-((m + Sqrt[(l + M)^2 + 4])/T))) T Sqrt[
4 + (l + M)^2])), {l, -100, 100}]
Veffd2i2[m_?NumberQ, T_?NumberQ] :=
M /. FindRoot[Veffd2i[m, T] == 0, {M, 0}]
Veffd2i2[1, -2]


And, Mathematica doesn't want to calculate more simple integral:

yyy[a_?NumberQ,b_?NumberQ]:=Integrate[E^(-E^(a+U^2+x)),{x,-1,0}]+b
ggg[a_?NumberQ, b_?NumberQ] := U /. FindRoot[yyy[a, b] == 0, {U, 0.1}]
ggg[1, -2]


FindRoot::nlnum: The function value {Undefined} is not a list of numbers with dimensions {1} at {U} = {0.1}. ReplaceAll::reps: {FindRoot[yyy[1,-2]==0,{U,0.1}]} is neither a list of replacement rules nor a valid dispatch table, and so cannot be used for replacing.

And I'd like to ask about is it possible to automatize process? That is if I will want to calculate thousand point: Veffd2i2[0,0], Veffd2i2[0,1], Veffd2i2[1, 0], ... rather than one point.

• Does replacing Integrate with NIntegrate in your code produces results you want/like? – Anton Antonov Jan 15 '17 at 14:29
• What's the value of l and M? Are they syntaxic errors ? – Valacar Jan 15 '17 at 14:41
• @AntonAntonov replacing Integrate with NIntegrate leads to greater numbers of errors – illuminates Jan 15 '17 at 15:13
• @Valacar I updated the question, there was "l" in the second example. It was the mistake. In second example I want to obtain a dependence "M" on "m" and "T". – illuminates Jan 15 '17 at 15:34
• Also, in general, make the parameters in your function expressions arguments of the functions. It makes dealing with numeric functions easier, aside from being good programming practice. E.g. Veffd2i[m_?NumberQ, T_?NumberQ, M_?NumberQ] :=... (when using NIntegrate as Anton recommended) eliminates the NIntegrate errors one otherwise gets. – Michael E2 Jan 15 '17 at 16:36

replacing Integrate with NIntegrate leads to greater numbers of errors

Here is how it is done:

In:= ClearAll["Veffd2i*"]
Veffd2i[M_?NumberQ, m_?NumberQ, T_?NumberQ] :=
4 + NIntegrate[-((2 E^(-((m + Sqrt[4 + (l + M)^2])/T)) l^2)/((1 +
E^(-((m + Sqrt[(l + M)^2 + 4])/T))) T Sqrt[
4 + (l + M)^2])), {l, -100, 100},
Method -> {"GlobalAdaptive", "SymbolicProcessing" -> 0}];
Veffd2i2[m_?NumberQ, T_?NumberQ] :=
M /. FindRoot[Veffd2i[M, m, T] == 0, {M, 0}]
Veffd2i2[1, -2]

Out= -2.14841*10^-12

In:= res = Table[Veffd2i2[i, j], {i, 0, 10}, {j, 0, 10}];

In:= Chop[Map[# /. {x_ /; (! NumberQ[x]) :> 0} &, res, {2}]]

Out= {{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 1.69524, 0, 0, 0,
0, 0, 0, 0, 0}, {0, 0, -2.85528, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0,
0, -1.69382, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 2.77715, 0, 0, 0, 0, 0,
0, 0}, {0, 0, 0, -3.78568, -1.28138, 1.16415*10^-10, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, 0, 0, 3.44355, 0, 0,
0, 0, 0, 1.16414*10^-10}, {0, 0, 0, 7.33208, 0, 1.92166, 0, 0, 0, 0,
0}, {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}, {0, 0, -26.4683, 0,
0, -3.87403, -0.631233, 1.16357*10^-10, 0, 0, 0}}

• Thank you very much for answer. I'd like to ask you about the initial approximation. When one uses FindRoot, then one needs to know about the initial approximation for U. And it is the nontrivial approximation: if for an equation without an integral I can plot a graph and know about initial approxiation, then for an integral equation I cannot plot a graph. It turns out that I must select U by hand. Can Mathematica help me in this problem? – illuminates Jan 17 '17 at 11:04

Many questions with a basic problem: Do the equations have roots that FindRoot can find? The plot of your first example shows, there is no root.

Veffd2i[m_, T_] =
4 - ((2 E^(-((m + Sqrt[4 + M^2])/T)))/((1 + E^(-((m + Sqrt[M^2 + 4])/T))) T \[Sqrt](4 + M)^2)) // Simplify

Limit[Veffd2i[1, -2], M -> ∞]
{4}

Plot[Veffd2i[1, -2], {M, -100000, 100000}] In your 2. example is "l" undefined.

• I appologize for the mistake. In reality there needs -4-… instead of 4-… – illuminates Jan 17 '17 at 9:52