-3

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

enter image description here 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.

illuminato
  • 299
  • 2
  • 9
  • 1
    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 – illuminato 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". – illuminato Jan 15 '17 at 15:34
  • For yyy, use Integrate[E^(-E^(a + U^2 + x)), {x, -1, 0}, Assumptions -> {a, U} \[Element] Reals], or perhaps Integrate[E^(-E^(a + U^2 + x)), {x, -1, 0}, GenerateConditions -> False]; also, to save time, use = instead of :=. – Michael E2 Jan 15 '17 at 16:30
  • 1
    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
  • @MichaelE2 Thank you! What you mean by "save time, use = instead of := " the calculated time? And do you know why if I write Assumptions -> {a, U} in last example, Mathematica tells that it is "Unknown option Assumptions in NIntegrate..."? – illuminato Jan 17 '17 at 09:29
  • (1) The basic difference between Set/= and SetDelayed/:= is that = evaluated the RHS (your Integrate, for instance) once and for all time when the definition is made; whereas := will evaluate the RHS every time the function is invoked (see link). So with := you reevaluate the integral every time, which is a time-consuming operation. Since the general integral can be found, it will be faster to do it only once.... – Michael E2 Jan 17 '17 at 11:59
  • ...(2) NIntegrate does not have an option Assumptions (but Integrate does). In general, numerical functions will not have an Assumptions option because such problems are numerically explicit/definite. Symbolic functions sometimes have the option Assumptions for giving assumptions about symbolic parameters. – Michael E2 Jan 17 '17 at 12:04

2 Answers2

2

From the comments:

replacing Integrate with NIntegrate leads to greater numbers of errors

Here is how it is done:

In[67]:= 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[70]= -2.14841*10^-12

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

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

Out[72]= {{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}}
Anton Antonov
  • 37,787
  • 3
  • 100
  • 178
  • 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? – illuminato Jan 17 '17 at 11:04
1

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}]

enter image description here

In your 2. example is "l" undefined.