On Tue, Dec 9, 2008 at 5:19 PM, Tim Lahey <[EMAIL PROTECTED]> wrote: > > > On Dec 9, 2008, at 7:55 PM, William Stein wrote: > >>> I ran across this in some timestepping code I wrote for a ODE solver >>> for systems of second order ODEs. The general trick I used is to set >>> the first n-1 terms based upon the formula and set the final one to >>> the endpoint. It means that the final one may be shorter, but that >>> way >>> it always ends at the set endpoint. >> >> Any chance you could dive in and fixe srange? It's a pure Python >> function in >> sage/misc/misc.py >> > > That's an awfully complicated function for what should be fairly simple. > I'm not entirely sure what is being done is some of that code so I don't > know if I want to touch it.
Do it! What's the worst that can happen? It'll be refereed. Maybe you can write something better that is simpler too. William > > What about the other similar functions? > > From my MATLAB code, the timestep loop looks like (using MATLAB > syntax): > > % Iterate over timesteps > while (t<tfinal) & (t + h >t) > > % Ensure we end at tfinal, this may shorten the last timestep > if t + h > tfinal, h = tfinal - t; end > t = t + h; > > end > > Note the trick is checking that that t+h > tfinal. That checks to see if > we pass the endpoint. Also, with the loop, we're also checking to make > sure that the step increases t. This is to prevent looping through if > we're exactly at the endpoint. There is probably a better way of doing > this, > but with floats checking equality is problematic. > > Cheers, > > Tim. > > --- > Tim Lahey > PhD Candidate, Systems Design Engineering > University of Waterloo > http://www.linkedin.com/in/timlahey > > > > -- William Stein Associate Professor of Mathematics University of Washington http://wstein.org --~--~---------~--~----~------------~-------~--~----~ To post to this group, send email to sage-devel@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/sage-devel URLs: http://www.sagemath.org -~----------~----~----~----~------~----~------~--~---