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 is my code:

f0[y_] := 1/(E^((1 + y)^2/2)*Sqrt[2*Pi])
f1[y_] := 1/(E^((-1 + y)^2/2)*Sqrt[2*Pi])
l[y_] := f1[y]/f0[y]
opts = {Method -> {Automatic, "SymbolicProcessing" -> None}, AccuracyGoal -> 8}
h0[ϵ0_?NumericQ, ϵ1_?NumericQ] := 
  -(ϵ1/(1 - ϵ0)) + 
  NIntegrate[f0[y]*Boole[l[y] < (1 - ϵ0)/(1 - ϵ1)], {y, -∞, ∞}, 
    {Method -> {Automatic, "SymbolicProcessing" -> None},AccuracyGoal -> 8}] - 
  ((1 - ϵ1) * 
    NIntegrate[f1[y]*Boole[l[y] < (1 - ϵ0)/(1 - ϵ1)], {y, -∞,∞}, 
    {Method -> {Automatic, "SymbolicProcessing" -> None}, AccuracyGoal -> 8}])/(1 - ϵ0)
hh0[ϵ0_] := 
  FindRoot[h0[ϵ0, ϵ1] == 0, {ϵ1, 0.5}, 
    StepMonitor :>Print["Step to ϵ0 = ", ϵ0, Evaluate@opts]]
Plot[hh0[ϵ0], {ϵ0, 0, 1}]

I am able to get all the values that are necessery to plot, but the plot doesnt output any graphics. How can I fix this problem?Improved formatting

share|improve this question
    
If you try hh0[x] for some values of x, you will see there is a convergence problem with your integrals. –  Jean-Claude Arbaut May 18 at 20:52
    
@Jean-ClaudeArbaut hh0[0.1] gives me for example 0.77327. hh0[0.5] gives me 0.315573 ... I can get single numbers. Integrals are definitely correct if I havent mistype anything but i tried again. –  Seyhmus Güngören May 18 at 20:55
    
Interesting, I get the same values, but with lots of messages of this kind: NIntegrate::slwcon: Numerical integration converging too slowly; suspect one of the following: singularity, value of the integration is 0, highly oscillatory integrand, or WorkingPrecision too small –  Jean-Claude Arbaut May 18 at 20:57
    
@Jean-ClaudeArbaut it is not only you who gets that message. I get many of them. But eventually there is a result)) –  Seyhmus Güngören May 18 at 20:58
    
Ok, solved. Type Plot[ϵ1 /. hh0[ϵ0], {ϵ0, 0, 1}]. Since you are calling FindRoot, you don't get a value but a list. With /. you can retrieve the value. –  Jean-Claude Arbaut May 18 at 21:02

1 Answer 1

up vote 2 down vote accepted

Here is an answer from my previous comment, as suggested by Öskå.

Since you are calling FindRoot, you don't get a value but a list. With /. you can retrieve the value:

Plot[ϵ1 /. hh0[ϵ0], {ϵ0, 0, 1}]

Mathematica graphics

share|improve this answer
    
thank you very much. –  Seyhmus Güngören May 18 at 23:26
    
I added a picture, I hope you don't mind :) –  Öskå May 18 at 23:29

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.