Re: Finding only final values in NDSolve
- To: mathgroup at smc.vnet.net
- Subject: [mg91249] Re: Finding only final values in NDSolve
- From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
- Date: Mon, 11 Aug 2008 06:07:34 -0400 (EDT)
- Organization: The Open University, Milton Keynes, UK
- References: <g7lvmq$fdj$1@smc.vnet.net>
zakseidov2 at gmail.com wrote: > 1. I use NDSolve for integration from some t0 to some tf, but I'm > interested only in FINAL VALUES y(tf),y'(tf). > How to do it (I mean: avoiding InterpolatingFunction and saving all > intermediate values)? As long as one uses NDSolve, one will always get an InterpolatingFunction object (if the process is successful, of course), because NDSolve builds an InterpolatingFunction to represent a function that solve numerically the differential equation(s). If you do not want these interpolating functions, you must use some other methods/approaches to get your integration done. > 2. I use WorkingPrecision -> 32(or larger). Final values y(tf),y'(tf) > are of lesser Precision than 32D so i can't use them directly for > further integrations. I do some manupulations to take more artificial > digits... > But what's the best way for doing it automatically not manually? Coercing Mathematica to use subsequently fixed-size arbitrary-precision arithmetic can be achieve with a construct such as Block[{$MinPrecision = $MaxPrecision = 30}, ...] For instance, In[1]:= sol = NDSolve[{y''[x] + Sin[y[x]] y[x] == 0, y[0] == 1, y'[0] == 0}, y, {x, 0, 30}, WorkingPrecision -> 30]; In[2]:= Block[{$MinPrecision = $MaxPrecision = 30}, {y[1], y'[1]} /. sol[[1]] ] Precision /@ % Out[2]= {0.624400364233472054920976458678, \ -0.668045563872908903982164732251} Out[3]= {30., 30.} In[4]:= {y[1], y'[1]} /. sol[[1]] Precision /@ % Out[4]= {0.62440036423347205492097645868, \ -0.668045563872908903982164732} Out[5]= {29.3405, 27.1661} In[6]:= {y[1.`30], y'[1.`30]} /. sol[[1]] Precision /@ % Out[6]= {0.62440036423347205492097645868, \ -0.668045563872908903982164732} Out[7]= {29.1601, 26.9857} > 3. In other words: I need only values of y(t), y'(t) in fixed t_i with > fixed interval d. > How to do it using NDSolve economically without InterpolatingFunction > (which I guess takes a lot of time if MaxSteps -> 10^8(or larger))? You cannot avoid InterpolatingFunction when using NDSolve. If you do not want these interpolating functions, you must use some other methods/approaches to get your integration done. Hope this helps, -- Jean-Marc