4
$\begingroup$

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

$\endgroup$
1

3 Answers 3

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

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

{t -> 2.353038699}

$\endgroup$
3
  • $\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
    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$ 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
    Dec 16, 2012 at 22:03
4
$\begingroup$

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

Output

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

$\endgroup$
1
$\begingroup$

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.

$\endgroup$
0

Your Answer

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

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