1

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.

dr.blochwave
  • 8,768
  • 3
  • 42
  • 76
Abhijit Saha
  • 449
  • 1
  • 4
  • 10

3 Answers3

3

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]==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] == 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!

Alexei Boulbitch
  • 39,397
  • 2
  • 47
  • 96
3

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] == 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] == 0, WhenEvent[y[x] == 3, Throw[x]]}, {}, {x, 0, 3}]
(*  1.44225  *)
Michael E2
  • 235,386
  • 17
  • 334
  • 747
1

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

Mathematica graphics

Nasser
  • 143,286
  • 11
  • 154
  • 359