Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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. >>

share|improve this question
h[t_?NumericQ] := NIntegrate[f[x] - 0.1 g[x], {x, 0, t}]

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

{t -> 2.353038699}

share|improve this answer
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. – murray Dec 16 '12 at 16:07
@murray Have you actually tried that? It generates a whole bunch of messages before giving the same answer. – Sjoerd C. de Vries Dec 16 '12 at 16:42
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! – murray Dec 16 '12 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

share|improve this answer

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.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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