Re: LogLog plot of NDSolve solution
- To: mathgroup at smc.vnet.net
- Subject: [mg52792] Re: [mg52557] LogLog plot of NDSolve solution
- From: Adam Getchell <agetchell at physics.ucdavis.edu>
- Date: Mon, 13 Dec 2004 04:22:58 -0500 (EST)
- References: <200412020721.CAA05780@smc.vnet.net> <opsidom8sxiz9bcq@monster.cox-internet.com>
- Sender: owner-wri-mathgroup at wolfram.com
Thanks very much for your detailed answers. Unfortunately, I cannot replicate your results (Mathematica 5.0.1.0 on Windows). In[1]:= << "Graphics`Graphics`" Off[General::spell1] << "Graphics`Legend`" In[4]:= Dodelson := Derivative[1][\[CapitalChi]][x] - (x/H)*(255/(Subscript[\[Tau], n]*x5))*(12 + 6*x + x2)*(E^(-x) - \[CapitalChi][x]* (1 + E^(-x))) f = \[CapitalChi] /. First[NDSolve[ {Dodelson == 0 /. {H -> 1.13, Subscript[\[Tau], n] -> 886.7}, \[CapitalChi][1.293] == 0.25}, \[CapitalChi], {x, 0.1, 1.3}, MaxSteps -> 106]]; plot = LogLogPlot[f[x], {x, 0.1, 1.3}]; Yields: From In[4]:= \!\(\*FormBox[ RowBox[{\(NDSolve::"ndnum"\), ":", "\<\"Encountered non-numerical value for a derivative at \ \\!\\(TraditionalForm\\`x\\) == \\!\\(TraditionalForm\\`1.293`\\). \ \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\ \\\", ButtonFrame->None, ButtonData:>\\\"NDSolve::ndnum\\\"]\\)\"\>"}], \ TraditionalForm]\) From In[4]:= \!\(\*FormBox[ RowBox[{\(ReplaceAll::"reps"\), ":", "\<\"\\!\\(TraditionalForm\\`\\({\\(\\(\\(\\(\\(\\(\\(\\(\\*\ SuperscriptBox[\\\"\[CapitalChi]\\\", \\\"\[Prime]\\\", \ Rule[MultilineFunction, None]]\\)\\)(x)\\)\\) - \\(0.2544983836857554`\\\\ x \ \\(\\(\[LeftSkeleton] 1 \[RightSkeleton]\\)\\) \\(\\(\[LeftSkeleton] 1 \ \[RightSkeleton]\\)\\)\\\\ \\(\\((\\(\[LeftSkeleton] 1 \ \[RightSkeleton]\\))\\)\\)\\)\\/x5\\)\\) \[Equal] 0\\)\\), \\(\\(\\(\\(\ \[CapitalChi](1.293`)\\)\\) \[Equal] 0.25`\\)\\)}\\)\\) is neither a list of \ replacement rules nor a valid dispatch table, and so cannot be used for \ replacing. \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", \ ButtonStyle->\\\"RefGuideLinkText\\\", ButtonFrame->None, \ ButtonData:>\\\"ReplaceAll::reps\\\"]\\)\"\>"}], TraditionalForm]\) And pages and pages of more stuff. Whereas this: In[10]:= Dodelson := Derivative[1][y][ x] - (x/H)*(255/ (Subscript[\[Tau], n]*x^5))* (12 + 6*x + x^2)* (E^(-x) - y[x]* (1 + E^(-x))) In[11]:= ans = NDSolve[ {Dodelson == 0 /. {H -> 1.13, Subscript[\[Tau], n] -> 886.7}, y[1.293] == 0.25}, y, {x, 0.88, 1.3}, MaxSteps -> 10^6] In[12]:= LogLogPlot[y[x] /. ans, {x, 0.88, 1.3}, PlotStyle -> {Hue[0.7]}, AxesLabel -> {"x (MeV)", "y"}, PlotLabel -> "y[x]", PlotRange -> All] Still generates garbage of a different sort: From In[12]:= \!\(\*FormBox[ RowBox[{\(ParametricPlot::"pptr"\), ":", "\<\"\\!\\(TraditionalForm\\`\\({\\(log(x)\\)\\/\\(log(10)\\), \ \\(log(\\(\\(\\(\\(y(x)\\)\\)/.\[InvisibleSpace]ans\\)\\))\\)\\/\\(log(10)\\)}\ \\)\\) does not evaluate to a pair of real numbers at \ \\!\\(TraditionalForm\\`x\\) = \\!\\(TraditionalForm\\`0.8800000175`\\). \ \\!\\(\\*ButtonBox[\\\"More\[Ellipsis]\\\", ButtonStyle->\\\"RefGuideLinkText\ \\\", ButtonFrame->None, ButtonData:>\\\"ParametricPlot::pptr\\\"]\\)\"\>"}], \ TraditionalForm]\) DrBob wrote: > > Third, here's a working LogLogPlot: > > Dodelson := Derivative[1][\[CapitalChi]][ > x] - (x/H)*(255/ > (Subscript[\[Tau], n]*x^5))* > (12 + 6*x + x^2)*(E^(-x) - > \[CapitalChi][x]*(1 + E^(-x))) > f = \[CapitalChi] /. First[NDSolve[ > {Dodelson == 0 /. > {H -> 1.13, > Subscript[\[Tau], n] -> > 886.7}, \[CapitalChi][1.293] == > 0.25}, \[CapitalChi], {x, 0.1, > 1.3}, MaxSteps -> 10^6]]; > plot = LogLogPlot[f@x, {x, 0.1, 1.3}]; > > It gives error messages, but only because Log[f[x]] isn't real for x < > 0.88 or so, when f[x] is negative. Here's the first data point on the > graph above: > > E^First[Cases[plot, Line[a_] -> a, Infinity]]; > First[%] > > {0.8838322898494186, 0.08540796127338049} > > This gives no errors: > > LogLogPlot[f@x, {x, 0.88, 1.3}]; > > But these may be more informative: > > Plot[f@x, {x, 0.5, 0.7}, PlotRange -> All] > Plot[f@x, {x, 0.6, 0.8}, PlotRange -> All] > Plot[f@x, {x, 0.8, 1.3}, PlotRange -> All] > Plot[Exp@f@x, {x, .3, 1.3}, PlotRange -> All]; > > We might call the last one an ExpPlot, rather than a LogPlot. > > And here's a little more detail: > > Plot[f@x, {x, 0.7, 0.8}, PlotRange -> All]; > FindRoot[f@x, {x, 0.75}] > LogPlot[Abs@f@x, {x, 0.3, 1.3}, PlotRange -> All] > {x -> 0.751965} > > (That's a LogAbsPlot, I guess.) > > The last two plots, along with the result of FindRoot, may be all you > need. > > Bobby > > On Thu, 2 Dec 2004 02:21:06 -0500 (EST), Adam Getchell > <agetchell at physics.ucdavis.edu> wrote: > >> Hello all, >> >> I'm solving an ODE via NDSolve (neutron abundance for Big Bang >> Nucleosynthesis -- from "Modern Cosmology", S. Dodelson). The result >> comes out as an InterpolatingFunction, which plots fine using Plot. >> However, if I wish to do a Log-Log plot, neither LogLogPlot nor >> LogLogListPlot work. What am I missing? >> >> \!\(Dodelson := \(\[CapitalChi]'\)[ >> x] - \(x\/H\) \(255\/\(\(\[Tau]\_n\) x\^5\)\) \((12 + 6 x + >> x\^2)\) \((\[ExponentialE]\^\(-x\) - \[CapitalChi][ >> x] \((1 + \[ExponentialE]\^\(-x\))\))\)\) >> >> In[329]:= >> \!\(\(\(\[IndentingNewLine]\)\(ans = >> NDSolve[{Dodelson \[Equal] >> 0 /. {H \[Rule] 1.13, \[Tau]\_n \[Rule] 886.7}, >> \[CapitalChi][ >> 1.293] \[Equal] .25}, \[CapitalChi], {x, .1, 1.3}, >> MaxSteps \[Rule] 10\^6]\)\)\) >> >> Using the Evaluate trick suggested by >> http://www.nhn.ou.edu/~morrison/Mathematica/TipSheets/2Dgraphics.pdf >> doesn't work. >> >> This example doesn't cover LogLogPlots: >> http://documents.wolfram.com/v4/MainBook/3.8.2.html >> >> Other search results on Google haven't turned up anything so far. >> >> Thanks, >> >> --Adam Getchell >> >> >> >> >> > > >
- References:
- LogLog plot of NDSolve solution
- From: Adam Getchell <agetchell@physics.ucdavis.edu>
- LogLog plot of NDSolve solution