Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2004
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Plotting a function of an interpolated function

  • To: mathgroup at smc.vnet.net
  • Subject: [mg52984] Re: [mg52925] Plotting a function of an interpolated function
  • From: DrBob <drbob at bigfoot.com>
  • Date: Sat, 18 Dec 2004 04:00:23 -0500 (EST)
  • References: <200412171018.FAA16026@smc.vnet.net>
  • Reply-to: drbob at bigfoot.com
  • Sender: owner-wri-mathgroup at wolfram.com

I'll take the last problem first -- the Plot:

Plot[W[\[Phi]], {t, 0, 100/m}]

It can't be evaluated until Phi is computed, but regardless of what Phi turns out to be, the plot is determined anyway:

Clear[m, mp, G, P, \[Rho], \[Phi], W,
   Inflaton]
V = Function[x, (1/2)*m^2*x^2];
\[Rho] = Function[x, D[x, t]^2/2 + V[x]];
H = Function[x, Sqrt[((8*Pi*G)/3)*
       \[Rho][x]]];
P = Function[x, D[x, t]^2/2 - V[x]];
Inflaton = Derivative[2][\[Phi]][t] +
     3*H[\[Phi][t]]*Derivative[1][\[Phi]][t] +
     Derivative[1][V][\[Phi][t]];
W = Function[x, P[x]/\[Rho][x]];
W[\[Phi]]

-1

W is constant, so the Plot should show -1 across the board (if it works at all).

Now for the problem with Phi. Your definition of Phi isn't the best, but if you must use it, the Plot needs Evaluate:

m = 10^16;
mp = 1.2211*10^19;
G = mp^(-2);
Clear[\[Phi]]
\[Phi] = \[Phi][t] /. First[NDSolve[
      {Inflaton == 0, Derivative[1][\[Phi]][
         0] == 0, \[Phi][0] == 1}, \[Phi][t],
      {t, 0, 100/m}, MaxSteps -> 10^6]];
Plot[Evaluate[W[\[Phi]]], {t, 0, 100/m}]

But I don't see the expected constant -1. Instead, I see a Sin wave, I think due to noise.

(W simplified to -1 when its argument was a symbol, but when the argument is numeric, the fraction P[x]/rho[x] appears to be vulnerable to numerical problems.)

Define Phi this way, and I get a much more reasonable result:

Clear[\[Phi]]
\[Phi] = \[Phi] /. First[NDSolve[
      {Inflaton == 0, Derivative[1][\[Phi]][
         0] == 0, \[Phi][0] == 1}, \[Phi],
      {t, 0, 100/m}, MaxSteps -> 10^6]];
Plot[W[\[Phi][t]], {t, 0, 100/m}]

The curve wavers, but it's -1 to machine precision, as expected.

Bobby

On Fri, 17 Dec 2004 05:18:38 -0500 (EST), Adam Getchell <agetchell at physics.ucdavis.edu> wrote:

> I've solved a function using NDSolve, expressed it as a pure function,
> and plotted it in the attached notebook. Now I'd like to define other
> functions in terms of this pure function and plot them. I haven't seen
> this come up in the archives, hence the post here.
>
> If phi is my interpolating function and W is my newly defined function, ie:
>
> In[291]:=
> V = Function[x, (1/2)*m^2*
>      x^2];
> \[Rho] = Function[x,
>     D[x, t]^2/2 + V[x]];
> H = Function[x, Sqrt[
>      ((8*Pi*G)/3)*\[Rho][x]]];
>
> In[294]:=
> V[\[Phi][t]]
> Derivative[1][V][\[Phi][t]]
> \[Rho][\[Phi][t]]
> H[\[Phi][t]]
> Out[294]=
> (1/2)*m^2*\[Phi][t]^2
> Out[295]=
> m^2*\[Phi][t]
> Out[296]=
> (1/2)*m^2*\[Phi][t]^2 +
>   (1/2)*Derivative[1][\[Phi]][t]^
>     2
> Out[297]=
> 2*Sqrt[(2*Pi)/3]*
>   Sqrt[G*((1/2)*m^2*
>       \[Phi][t]^2 + (1/2)*
>       Derivative[1][\[Phi]][t]^
>        2)]
>
> In[298]:=
> Inflaton = Derivative[2][\[Phi]][
>     t] + 3*H[\[Phi][t]]*
>     Derivative[1][\[Phi]][t] +
>    Derivative[1][V][\[Phi][t]]
> Out[298]=
> \[Phi][t]*m^2 + Derivative[2][
>     \[Phi]][t] + 2*Sqrt[6*Pi]*
>    Derivative[1][\[Phi]][t]*
>    Sqrt[G*((1/2)*m^2*
>        \[Phi][t]^2 + (1/2)*
>        Derivative[1][\[Phi]][t]^
>         2)]
>
> In[299]:=
> m = 10^16;
> mp = 1.2211*10^19;
> G = mp^(-2);
>
> In[302]:=
> \[Phi] = \[Phi][t] /. First[
>     NDSolve[{Inflaton == 0,
>       Derivative[1][\[Phi]][
>         0] == 0, \[Phi][0] ==
>        1}, \[Phi][t], {t, 0,
>       100/m}, MaxSteps ->
>       10^6]]
> Out[302]=
> InterpolatingFunction[][t]
>
> In[303]:=
> P = Function[x, D[x, t]^2/2 -
>     V[x]]
> \[Rho]
> W = Function[x, P[x]/\[Rho][x]]
> \[Phi]
> Out[303]=
> Function[x, (1/2)*D[x, t]^2 -
>    V[x]]
> Out[304]=
> Function[x, (1/2)*D[x, t]^2 +
>    V[x]]
> Out[305]=
> Function[x, P[x]/\[Rho][x]]
> Out[306]=
> InterpolatingFunction[][t]
>
> Then this doesn't work:
>
> In[307]:=
> TestPlot = Plot[W[\[Phi]],
>     {t, 0, 100/m}];
>
> I've tried a symbolic solution to avoid the interpolating function, but
> my workstation hasn't produced one yet.
>
> I'm reading the Functions notebook from "Essential Mathematica for
> Students of Science", but as far as I can tell I should be using pure
> functions of the interpolating function.
>
> Any pointers appreciated, as always. Thanks for help in the past,
> especially Dr. Bob.
>
> --Adam
>
>
>
>
>
>



-- 
DrBob at bigfoot.com
www.eclecticdreams.net


  • Prev by Date: Re: Mathematica language issues
  • Next by Date: Re: Re: Re: Integrate in version 5.1
  • Previous by thread: Plotting a function of an interpolated function
  • Next by thread: Re: Plotting a function of an interpolated function