# I know the lower limit of an integration as well as the integral. How to find the upper limit of the integration?

I used the following code.

NV[x1_, x2_] := NIntegrate[3 x^2, {x, x1, x2}]

FindRoot[NV[0, t] == 3, {t, .001}, PrecisionGoal -> 20]


Output:

NIntegrate::nlim: x = t is not a valid limit of integration. >> {t -> 1.44225}

The output is correct.

However, I want to remove the comment: "x = t is not a valid limit of integration. >>" from the output.

• Use NV[x1_?NumericQ, x2_?NumericQ] := ... instead of NV[x1_,x2_]. – kglr Feb 24 '15 at 11:35
• You can take a look at Quiet if you have faith in the solution. – Yves Klett Feb 24 '15 at 11:38

Nasser gave a fine and simple enough approach. I will propose a different, not that it is better, but just to give another view.

So, if in general you have an integral y[t]==Integrate[f[x],{x,0,t}], it is equivalent to the differential equation: y'[t]=f[t] with the initial condition y==0. You might solve it numerically and then find the solution of the equation y[t]==J, where Jis the integral value you are assumed to know. Its solution yields the upper integral limit being looked for.

Let f[x]=x^2. Then the solution of the differential equation is

nds = NDSolve[{y'[t] == t^2, y == 0}, y, {t, 0, 3}][[1, 1]];


and the upper integral limit is given by the following:

    FindRoot[(y[t] /. nds) == 1, {t, 0.01}] // Quiet

(*  {t -> 1.44225}   *)


I do not see any advantage with respect to the approach of Nasser, but it was interesting to me that one may operate also this way.

Have fun!

If a highly accurate solution is desired, I would follow kguler's comment; otherwise, here is a variation on Alexei Boulbitch's approach:

sol = NDSolveValue[{y'[x] == 3 x^2, y == 0, WhenEvent[y[x] == 3, "StopIntegration"]},
y, {x, 0, 3}];
sol["Domain"][[1, -1]]
(*  1.44225  *)


Or somewhat more directly:

Catch @ NDSolve[{y'[x] == 3 x^2, y == 0, WhenEvent[y[x] == 3, Throw[x]]}, {}, {x, 0, 3}]
(*  1.44225  *)

• Please comment what is "Domain". I like your approach very much. – Alexei Boulbitch Feb 25 '15 at 9:34
• @AlexeiBoulbitch Please see this answer for information about "Domain" and other properties of InterpolatingFunction. Briefly, "Domain" returns a list of intervals, one for each input to the I-Fn specifying its domain. – Michael E2 Feb 25 '15 at 11:18

You can't do numerical integration with upper limit being symbol. Just use Integrate instead

ClearAll[t, x, x1, x2, nv]
nv[x1_, x2_] := Integrate[3 x^2, {x, x1, x2}]
FindRoot[nv[0, t] == 3, {t, .001}] • But i have some integration where I must have to use NIntegrate. Otherwise it cant be solved – Abhijit Saha Feb 24 '15 at 12:57