On Sun, Nov 29, 2009 at 7:11 AM, ryan_n <rnelsonc...@gmail.com> wrote:
> Hello all, > > I've just started using Sage, and I'm currently trying to use the > ode_solver class to solve some simple differential equations. I was > having some problems setting up my own program based on this class > until I realized that the number of points in the solution does not > match the number of points requested by the t_span variable. For > example, when I run this script: > _________ > #!/usr/bin/env sage-python > from sage.all import ode_solver > > def f(t, y): > return [y[1], -y[0]] > T = ode_solver() > T.function=f > T.y_0=[1, 1] > T.ode_solve(t_span=[0, 10], num_points=100) > print len(T.solution) > T.ode_solve(t_span=[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]) > print len(T.solution) > _________ > > I get returned values of 101 and 10, where I would expect 100 and 11. > > I don't know about the first case, but for the second case, the > solution for the last value (10) is missing. I was able to circumvent > this problem by appending a dummy variable to the end of t_span, but > I'm wondering if this is the expected behavior. Is there something > about the solution that I'm missing? I am currently using Sage 4.2.1 > that I built from source in a Gentoo Linux distro. > Hi Ryan The second case certainly looks like a bug > > In a slightly related aside, I know that y_0 are the initial > conditions, but what if you know the conditions somewhere in the > middle or outside your range of interest (t_span)? Would it be > possible to input known y values as (y,t) tuples that are not > necessarily the first values (and possibly may not get returned in the > solution)? I've tried running the above script and getting the > solution for a particular t value (say t=2), changing y_0 to the > values I got for t=2, and rearrange the t_span list with 2 as the > first value, and the results I get are not what I would expect... Is > there something about solving these types of systems that does not > permit using arbitrary set conditions? (I apologize if this is a > really dumb question. I know very little about ode solving > algorithms.) > > In my case running my model to validate its behaviour, I ran it to steady state and then used the y vector as the new y_0. In the subsequent runm I then added an if statement to f - using your example: def f(t, y): if (t == 5): y[0] = 5 return [y[1], -y[0]] > Thanks > > Ryan > > P.S. As this is my first post, I want to thank all of you who started/ > maintain/develop Sage. I've only been using it for a short time, but > I'm extremely happy with what I've seen so far. I look forward to > finding other ways to apply this tool to as many problems as possible. > > It is awesome isn't it. Anthony -- To post to this group, send email to sage-support@googlegroups.com To unsubscribe from this group, send email to sage-support-unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/sage-support URL: http://www.sagemath.org