# Solving an equation containing an integral numerically

my problem is: I get the result of definite integral and now I need to find the upper limit for the same integral but with opposite sign value so f2=-f1.

   f[x_]:=(E^x m (-1 + x - x0) + E^(b x) n (1 + b (-x + x0)))^2 /
( (a E^(b x) + E^x K1) (E^x m -E^(b x) n)^2 (x - x0) )


The values of the parameters are:

    m = 2.017100;
n= 0.87100;
K1 = 1;
a = 21.57100;
x0 = -1.53100;
b = 0.56827100;
x1 = 7.810;
x2 = 10;


I was able to calculate the value of the following definite integral:

firstIntegral = NIntegrate[f[x],{x,x1,x2}]

(*Out: 0.0019499644501301185 *)


I am now trying to find the indefinite integral first and then find the upper limit by this:

    f1[x1_, x2_] := Integrate[f[x], {x, x1, x2}]
FindRoot[ nv[10, x3] == -firstIntegral, {x3, .001}]


A first version of this question was put on hold due to simple syntax mistakes; I re-edited the question to include and clarify this second part of my problem.

• Try adding a colon in your function definition, i.e. f[x_] := – MarcoB May 19 '15 at 12:49
• After adding the semicolon, evaluate NIntegrate[f[x], {x, x1, x2}] – Dr. belisarius May 19 '15 at 12:52
• Could you tell me, how to solve this problem: we need to get the upper limit for the same integral but the opposite sign value, so the upper limit of the first integral becomes lower for the required integral : firstIntegral=NIntegrate[ f[x], {x, x1, x2}]; upperLimit = Solve[NIntegrate[ f[x], {x, x2, x3}] = firstIntegral, x3] – Elka May 19 '15 at 13:23
• @ElviraKadaub there might be a solution for x3<0, but there's a singularity there around -1.53 which maybe has a principal value, so the task at hand isn't exactly trivial. – LLlAMnYP May 19 '15 at 14:33
• Hey @Marco, integral-equation actually means something kinda different from what the OP seems to have, so I removed it. – J. M.'s technical difficulties May 19 '15 at 15:56

Elvira, I am going to put here what I had put together for an answer to your question. There is still something puzzling about your question though, and that is the fact that you are essentially recalculating the same integral twice, it seems to me.

Here is what I mean:

$$\text{firstIntegral}=\int_{x1}^{x2} \! f(x) \, \mathrm{d}x$$

Then you are looking for $x3$ such that

$$\int_{x2}^{x3} \! f(x) \, \mathrm{d}x = -\int_{x1}^{x2} \! f(x) \, \mathrm{d}x$$

but, considering that if you swap the limits of integration, the integral value changes sign, we can write:

$$\int_{x2}^{x3} \! f(x) \, \mathrm{d}x = -\int_{x1}^{x2} \! f(x) \, \mathrm{d}x = \int_{x2}^{x1} \! f(x) \, \mathrm{d}x$$

... so the $x3$ value you are looking for is $x1$! I wonder if I am misreading your question this second time around...

In any case, I'd like to present some machinery that I think might come in handy for you to solve further questions like this one. In the absence of further clarifications, I will use what we learned above about $x3$to check that the numerical results are correct.

As you said, this is the value of your first integral:

firstIntegral = NIntegrate[f[x], {x, x1, x2}]

(* Out: 0.00194996 *)


Symbolic integration of your function f[x] doesn't get very far, at least on my computer and for reasonable waiting time. So I'll tackle your your problem numerically instead.

To do so , I will define a function that calculates your second integral numerically, but that attempts to do so only when it is fed a numerical value for the integration limits, otherwise the NIntegrate function won't be able to complete its task.

secondIntegral[a_?NumericQ, b_?NumericQ] := NIntegrate[f[x], {x, a, b}]


See this FAQ for further explanation on the topic of NumericQ.

Let's take a look at the value of this integral, using $x2$ as the lower integration limit, as you requested:

Plot[secondIntegral[x2, x3], {x3, 5, x2},
GridLines -> {None, {-firstIntegral}}, GridLinesStyle -> {Thick, Red}
] In that plot, I put a $y$-axis grid line indicating the value of -firstIntegral, so that gives us an idea of a) whether a solution exists (it does); b) what a rough estimate for $x3$ might be (somewhere around 8).

I will then use FindRoot to solve the equation numerically, using the rough estimate for $x3$ I got from the plot.

FindRoot[secondIntegral[x2, x3] == -firstIntegral, {x3, 8}]

(* Out: {x3 -> 7.8} *)


Notice that we recover the value of $x1$ you had set at the beginning as expected from the discussion above. Do let me know if I am misunderstanding your problem though.

• Thank you @MarcoB. This is my friend's problem I am trying to help with so I'm not that strong in the problem and its analytical solution. But I'll definetly get back to your answer later as soon as she'll take a look on it. – Elka May 19 '15 at 16:52
• @ElviraKadaub I wonder if your friend had a chance to take a look at my answer to see whether I am misunderstanding their problem. – MarcoB May 20 '15 at 20:47
• You do understand it right, @MarcoB. I'll try to explain her problem: she's investigating the system with duck trajectory, so x1 belongs to the stable part, then it goes to x2 - discontinuity point and then it should move to the unstable condition, so x3 must differ from x1. According to your solution, those limits we used before were not right and she gives new limits х1= 4,35708; х2=7 should be correct but now she couldnt compute the integral due to singularity problem which nable to solve for now. Thanks again. – Elka May 20 '15 at 21:22
• @Elvira OK good to know. Well, hopefully my answer can help in some way. Otherwise you/she could always post another question with the new requirements. – MarcoB May 20 '15 at 21:24