#7560: len(t_span) > 2 case creates len(t_span) - 1 solutions
-------------------------------------------------+--------------------------
Reporter: adavid | Owner: jkantor
Type: defect | Status: needs_work
Priority: minor | Milestone: sage-5.6
Component: numerical | Resolution:
Keywords: ode_solver, ode_solve, t_span | Work issues:
Report Upstream: N/A | Reviewers:
Authors: Jan Medlock | Merged in:
Dependencies: | Stopgaps:
-------------------------------------------------+--------------------------
Old description:
> From: Ryan
>
> {{{
> 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.
> }}}
New description:
From: Ryan
{{{
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.
}}}
Apply:
1. attachment:trac_7560_ode_off-by-one+doc.patch
--
Comment (by tkluck):
This is a very clear explanation in the doctext, thanks.
This part is not entirely right, though:
{{{
* If ``t_span`` is a tuple with more than 2 values, then (...)
* If ``t_span`` is a tuple with just 2 time values, then (...) the
user must also specify
``num_points``.
}}}
In the code, the distinction is made based on whether `num_points` is
specified, and not based on the length of `t_span`. That's a good thing.
(remember how your matlab code always breaks when you pass 1x1 matrices to
your generic code for NxN matrices.)
I would also be tempted to change the name of the parameter `num_points`
to `num_intervals`, raising a `DeprecationWarning` for `num_points`. How
do you feel about that?
--
Ticket URL: <http://trac.sagemath.org/sage_trac/ticket/7560#comment:8>
Sage <http://www.sagemath.org>
Sage: Creating a Viable Open Source Alternative to Magma, Maple, Mathematica,
and MATLAB
--
You received this message because you are subscribed to the Google Groups
"sage-trac" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/sage-trac?hl=en.