Immediate or Delayed Definitions in NDSolve?
- To: mathgroup at smc.vnet.net
- Subject: [mg44993] Immediate or Delayed Definitions in NDSolve?
- From: "extrabyte" <extrabyte22 at libero.it>
- Date: Fri, 12 Dec 2003 04:41:36 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
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