Here's a problem that I don't understand.

f[x_] := Exp[Cos[3*x]]
g[x_] := (1/3)*x^3 - x^2 + 2 

When I try to find the limit:

Solve[NIntegrate[f[x] - 0.1 g[x], {x, 0, t}] == 3, t] 

I get these errors x3


Solve::inex: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >>


3 Answers 3

h[t_?NumericQ] := NIntegrate[f[x] - 0.1 g[x], {x, 0, t}]

FindRoot[h[t] == 3, {t, 1}]

{t -> 2.353038699}

  • $\begingroup$ Just note that if you include the NIntegrate expression directly within the FindRoot expression (instead of definning a function h), then you don't need the ?NumericQ qualification. $\endgroup$
    – murray
    Commented Dec 16, 2012 at 16:07
  • $\begingroup$ @murray Have you actually tried that? It generates a whole bunch of messages before giving the same answer. $\endgroup$ Commented Dec 16, 2012 at 16:42
  • $\begingroup$ I had tried it and didn't get messages, but when I tried it again just now I get them. Not sure what in my environment earlier suppressed the messages! $\endgroup$
    – murray
    Commented Dec 16, 2012 at 22:03

When solving integral equations numerically it's usually good to interpolate the integral since they tend to be slow to calculate, here I use NDSolvetoget an approximation hP[t] $\approx \int_0^t h(x)dx$


And when solving equations you don't always have unique solutions so where you start your search affects which solution you'll find

plot = Plot[{hP[t], 3}, {t, 0, 10}];
 (* Start looking for solution near supplied x *)
 root = t /. FindRoot[hP[t] == 3, {t, x, 0, 10}];
 (* Display the discovered root *)
   Row@{"Starting at Subscript[t, 0]=",x},
   Row@{"Root at t=", root},
       {Blue, Point[{x, hP[x]}]},
       Disk[{root, hP[root]}, 0.1]
 , {{x, 0, "First search position"}, 0, 10}]


Update: It might seem predictable which root it will find but try starting at $t_0$ = 0.74 or 1.3 and you'll see that it finds the root at 5.7


If what you really need is to know the $t$ value where equality occurs, you can do it interactively:

 Manipulate[NIntegrate[f[x] - 0.1` g[x], {x, 0, t}], {t, 0, 10}]

Just move the slider until the answer is 3. In this case, it's about t=2.3535.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.