Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
add comment

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}

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
add comment

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

share|improve this answer
add comment

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
add comment

Your Answer

 
discard

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.