# Solving Integrals

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

NIntegrate::nlim:

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

• Aug 3, 2016 at 15:27

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

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


{t -> 2.353038699}

• 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. Dec 16, 2012 at 16:07
• @murray Have you actually tried that? It generates a whole bunch of messages before giving the same answer. Dec 16, 2012 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! 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$

f[x_]:=Exp[Cos[3*x]]
g[x_]:=(1/3)*x^3-x^2+2
h[x_]:=f[x]-0.1g[x]
Clear[hP]
hP=hP/.First@NDSolve[{hP==0,hP'[t]==h[t]},hP,{t,0,10}];


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}];
Manipulate[
(* Start looking for solution near supplied x *)
root = t /. FindRoot[hP[t] == 3, {t, x, 0, 10}];
(* Display the discovered root *)
Column@{
Row@{"Starting at Subscript[t, 0]=",x},
Row@{"Root at t=", root},
Show[{
plot,
Graphics[{
{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.