MathGroup Archive 1998

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

Search the Archive

Re: Can't take a value from an InterpolatingFunction.

  • To: mathgroup at smc.vnet.net
  • Subject: [mg13643] Re: Can't take a value from an InterpolatingFunction.
  • From: Paul Abbott <paul at physics.uwa.edu.au>
  • Date: Fri, 07 Aug 1998 18:46:05 +0800
  • Organization: University of Western Australia
  • References: <6qbqv3$a71@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

I. Ioannou wrote:

> I've set up and solved a system of two differential equations, according
> to the following prescription;
> 
>   solution =
>     NDSolve[{r'[t] == .....equation1......,
>              p'[t] == .....equation2......,
>              r[0] == 0.,p[0] == p0}, {r, p}, {t, 0, 0.2},
>              MaxSteps \[Rule] 300000, Method \[Rule] Automatic]
> 
> All has worked very nicely. However, I need now to take the value of r
> at t=0.2 and I can't seem to be able to do it.
> 
> I should point out that the Book suggestion r[0.2] /. % doesn't work,
> because the above statement is within a For loop and is run many times.

Fine -- but do you record each solution?  If so, surely 

	r[0.2] /. solution

(or, if the solutions are indexed, say solution[1]) will do what you
want.  For example, 

	In[1]:= p0 = 1; 

	In[2]:= solution[1] = NDSolve[{r'[t] == p[t]+r[t],
              p'[t] == r[t]-p[t],
              r[0] == 0,p[0] == p0}, {r, p}, {t, 0, 0.2}];

	In[3]:= r[0.2] /. solution[1] // First
	Out[3]= 0.202677

Also, personally, I tend to use constructs such as Table (for a list of
solutions) or Nest (for iterative computations) to construct a set of
solutions.

Cheers,
	Paul 

____________________________________________________________________ 
Paul Abbott                                   Phone: +61-8-9380-2734
Department of Physics                           Fax: +61-8-9380-1014
The University of Western Australia            Nedlands WA  6907       
mailto:paul at physics.uwa.edu.au  AUSTRALIA                       
http://www.physics.uwa.edu.au/~paul

            God IS a weakly left-handed dice player
____________________________________________________________________


  • Prev by Date: Re: What is the fastest machine for Mathematica?
  • Next by Date: Re: operator overloading with UpValues (eg, for shifting graphics)
  • Previous by thread: Re: Can't take a value from an InterpolatingFunction.
  • Next by thread: A couple of curious outputs from Integrate[]