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.

I am new to Mathematica. I am trying to numerically solve for C in the following equation:

$\begin{equation} \begin{array}{lcl} -\int_0^\infty (5000000+100000 x+ C)^{-1} \frac{1}{0.20x \sqrt{20 \pi}} exp(-0.5 (\frac{log(x/50)-0.10*10}{0.20\sqrt{10}})^2)dx=\\ -\int_0^\infty (5000000+100000 x+ 10000 *Max(x-50,0))^{-1} \frac{1}{0.20x \sqrt{20 \pi}} exp(-0.5 (\frac{log(x/50)-0.10*10}{0.20\sqrt{10}})^2)dx \end{array} \end{equation}$

I know a solution is: C=152300.

However, when I write the following code:

f[C_?NumericQ] := NIntegrate[(-(5000000 + 100000*x + 
     10000*Max[0, x - 50])^(-1) + (5000000 + 100000*x + 
    C)^(-1))*1/(x*0.20*(10*2 Pi )^(0.5))* Exp (-0.5*((Log[x/50] - 0.10*10)/(0.20*(10)^(0.5)))^2), {x, 0, Infinity}] 

{FindRoot[f[C] = 0, {C, 150000}]}

I have an error message and cannot find the root. In addition, there are other similar equations I want to solve for which I don't have an initial guess for the solution. Is there a good procedure for finding the root in such cases? Thank you very much for any advice!

share|improve this question
Defined symbols show in black font.You have a lot of blue symbols here –  belisarius Dec 18 '13 at 18:24
thanks for the reply. I just edited the formula, and corrected for the syntax. However, I still cannot solve for the equation. Any recommendation? Thanks in advance. –  Aurel Dec 18 '13 at 19:32
Exp needs square brackets? Double equals for FindRoot? –  cormullion Dec 18 '13 at 19:40
Also, watch out for upper-case variables... eg –  cormullion Dec 18 '13 at 19:52
add comment

closed as off-topic by bobthechemist, Michael E2, m_goldberg, rm -rf Dec 19 '13 at 16:47

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "This question arises due to a simple mistake such as a trivial syntax error, incorrect capitalization, spelling mistake, or other typographical error and is unlikely to help any future visitors, or else it is easily found in the documentation." – bobthechemist, Michael E2, m_goldberg, rm -rf
If this question can be reworded to fit the rules in the help center, please edit the question.

1 Answer

g[x_] := 1/(1/5 x Sqrt[20 Pi]) Exp [-1/ 2 ((Log[x/50] - 1)/(1/5 Sqrt@10))^2]
i1[c_?NumericQ] := NIntegrate[1/( 5 10^6 + 10^5 x + c) g@x, {x, 0, Infinity}, 
                              Method -> {Automatic, "SymbolicProcessing" -> None}]
i2 = NIntegrate[ 1/( 5 10^6 + 10^5 x + 10^4 Max[x - 50, 0]) g@x, {x, 0, Infinity}];

Let's take a look at the behavior:

Plot[{i2, i1[c]}, {c, 10, 10^6}, PlotRange -> All]

Mathematica graphics

So we expect only one solution. Being just a straight line, FindRoot[] will find the solution no matter the initial point used:

FindRoot[i1[c] - i2, {c, 10}]
 {c -> 504481.}
share|improve this answer
Thank you very much! It is very strange. I know R better than Mathematica. But if I follow your steps in R, i2=3.819418e-08; and graphically ,the two lines have no intersection on the same domain. Perhaps, the two programs use different methods to estimate the integrals. In addition, the example I took was derived from a paper whose author reported a solution equal to 152300. I don't really know what to think. –  Aurel Dec 19 '13 at 17:15
add comment

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