0
$\begingroup$

The Table function works fine and return a nice list of values

n = 200000`200;
k = 2 n - 50`200;
\[Mu] = 10`200^-5;
\[Nu] = 10`200^-5;
qhat = k/(2 n);

Table[Log[(
  E^(4 n qhat s) (1 - qhat)^(-1 + 4 n \[Mu]) qhat^(-1 + 4 n \[Nu]))/
  NIntegrate[
   E^(4 n qhat s) (1 - qhat)^(-1 + 4 n \[Mu]) qhat^(-1 + 
       4 n \[Nu]), {qhat, 1/(4 n + 1), 1 - 1/(4 n + 1)}, 
   MaxRecursion -> 12]], {s, 0, 1, 0.01}]

but the Plot function shows an empty plot.

Plot[Log[(
  E^(4 n qhat s) (1 - qhat)^(-1 + 4 n \[Mu]) qhat^(-1 + 4 n \[Nu]))/
  NIntegrate[
   E^(4 n qhat s) (1 - qhat)^(-1 + 4 n \[Mu]) qhat^(-1 + 
       4 n \[Nu]), {qhat, 1/(4 n + 1), 1 - 1/(4 n + 1)}, 
   MaxRecursion -> 12]], {s, 0, 1}, AxesLabel -> {"s", "P(qhat | s)"}, PlotRange -> All]

Why?

$\endgroup$
  • $\begingroup$ what version are you running? It works fine on the latest sources. $\endgroup$ – rcollyer Jan 21 '15 at 18:02
  • $\begingroup$ Version 10.0.1.0 (Mac OSX). I tried to restart the Kernel and to restart Mathematica but it still does not work. Can you really see the function on the plot? Note that other plots work fine for me. For example Plot[2 x^2, {x, 0, 1}] works fine. $\endgroup$ – Remi.b Jan 21 '15 at 18:04
1
$\begingroup$

as I can see the problem is that in NIntegrate s is localised. define a function for your expression

f[s_] := Log[(E^(4 n qhat s) (1 - qhat)^(-1 + 4 n \[Mu]) qhat^(-1 + 
    4 n \[Nu]))/NIntegrate[E^(4 n qhat s) (1 - qhat)^(-1 + 4 n \[Mu]) qhat^(-1 + 
    4 n \[Nu]), {qhat, 1/(4 n + 1), 1 - 1/(4 n + 1)}, MaxRecursion -> 12]]

and then the plot works normally

Plot[f[s], {s, 0, 1}, AxesLabel -> {"s", "P(qhat | s)"}, PlotRange -> All]
$\endgroup$
  • $\begingroup$ It is the solution indeed! Thanks. +1. Can you tell me a bit more of why this happens? Why is s localized in the Plot case but not in the Table case? And what does it exactly mean? Does it mean that in the Plot case shas no value associated to it in the NIntegrate function? Why does it work using a function? $\endgroup$ – Remi.b Jan 21 '15 at 18:15
  • $\begingroup$ I just can suppose that it happens becouse of NIntegrate can't process undefined variables like "s". It contributes all the vars to be numerically defined or to be integrating parameters. If you try to evaluate NIntegrate expression separately you will see the message of non-numerick evaluation $\endgroup$ – k_v Jan 21 '15 at 18:32
  • $\begingroup$ the difference between Table and Plot looks like Table firstly defines the list of "s" values and then calculates expression on this list, but Plot works inside some another way $\endgroup$ – k_v Jan 21 '15 at 18:39

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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