MathGroup Archive 2003

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

Search the Archive

Re: Immediate or Delayed Definitions in NDSolve?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg45076] Re: Immediate or Delayed Definitions in NDSolve?
  • From: Jens-Peer Kuska <kuska at informatik.uni-leipzig.de>
  • Date: Tue, 16 Dec 2003 06:21:00 -0500 (EST)
  • Organization: Universitaet Leipzig
  • References: <brchoh$2nt$1@smc.vnet.net>
  • Reply-to: kuska at informatik.uni-leipzig.de
  • Sender: owner-wri-mathgroup at wolfram.com

Hi,

evaluate it when you *have* a numerical value for
a

eq[a_?NumericQ] := y''[x] + a^2*y[x] == 0

sol[a_?NumericQ] := NDSolve[{eq[a], y[0] == 1, y'[0] == -1}, y, {x, 0,
10}]

and 

sol[15]

will work.

Regards
  Jens

extrabyte wrote:
> 
> Hi everyone!
> I have a serious problem with NDSolve.
> 
> Method 1 (Delayed Definition)
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> In[1]: eq[a_] := y''[x] + a^2*y[x] == 0;
> 
> In[2]: sol[a_] := NDSolve[{eq[a], y[0] == 1, y'[0] == -1}, y, {x, 0, 10}]
> 
> In[3]: sol[a]
> 
>  NDSolve::"ndnum": "Encountered non-numerical value for a derivative at \
> \!\(x\) == \!\(5.840380984046049`*^-301\)."
> 
> Out[3]:{{y -> InterpolatingFunction[{{0., 0.}}, "<>"]}}
> 
> In[4]: f[x_, a_] := y[x] /. sol[a][[1]]
> 
> In[5]: f[1, 1]
> 
> In[6]:Plot[f[x, 2], {x, 0, 10}]
> 
> [PLOT HERE]
> Out[6] - Graphics -
> 
> In[7] f[x, a]
> 
> NDSolve::"ndnum": "Encountered non-numerical value for a derivative at \
> \!\(x\) == \!\(5.840380984046049`*^-301\)."
> 
> Out[7] InterpolatingFunction[{{0., 0.}}, "<>"][x]
> 
> In[8] Table[{x, f[x, 1]}, {x, 0, 10}]
> 
> General::"ivar": "\!\(0\) is not a valid variable."
> NDSolve::"dsvar": "\!\(0\) cannot be used as a variable."
> 
> [SNIPPED]
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> Example 2 (Immediate Definition)
> 
> In[1]: eq[a_] := y''[x] + a^2*y[x] == 0;
> 
> In[2]: sol[a_] := NDSolve[{eq[a], y[0] == 1, y'[0] == -1}, y, {x, 0, 10}]
> 
> In[3]: sol[a]
> 
>  NDSolve::"ndnum": "Encountered non-numerical value for a derivative at \
> \!\(x\) == \!\(5.840380984046049`*^-301\)."
> 
> Out[3]:{{y -> InterpolatingFunction[{{0., 0.}}, "<>"]}}
> 
> In[4]: f[x_, a_] = y[x] /. sol[a][[1]]
> 
> NDSolve::"ndnum": "Encountered non-numerical value for a derivative at \
> \!\(x\) == \!\(5.840380984046049`*^-301\)."
> 
> Out[5]: InterpolatingFunction[{{0., 0.}}, "<>"][x]
> 
> In[6]: f[1, 1]
> 
> InterpolatingFunction::"dmval": "Input value \!\({1}\) lies outside the
> range \
> of data in the interpolating function. Extrapolation will be used."
> 
> Out[6]: 0
> 
> In[7]: Table[{x, f[x, 1]}, {x, 0, 10}]
> InterpolatingFunction::"dmval": "Input value \!\({1}\) lies outside the
> range \
> of data in the interpolating function. Extrapolation will be used."
> InterpolatingFunction::"dmval": "Input value \!\({2}\) lies outside the
> range \
> of data in the interpolating function. Extrapolation will be used."
> [snip]
> 
> Out[7]: {{0, 1.}, {1, 0.}, {2, -1.}, {3, -2.}, {4, -3.}, {5, -4.}, {6, -5.},
> {7, -6.}, {8, \
> -7.}, {9, -8.}, {10, -9.}}
> 
> ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
> 
> Immediate or Delayed Definitions in NDSolve??
> 
> thx in advance
> 
> --
> extrabyte
> http://extrabyte.splinder.it
> http://www.hardwarenonsolo.3go.it


  • Prev by Date: NETLink - CREATING a new class?
  • Next by Date: Re: Slide show presentations
  • Previous by thread: Re: Immediate or Delayed Definitions in NDSolve?
  • Next by thread: Re: Immediate or Delayed Definitions in NDSolve?