Sage: Ticket #6479: desolve for 2nd order ODE with initial condition gives wrong answer
https://trac.sagemath.org/ticket/6479
<pre class="wiki">sage: y(x) = function('y',x)
sage: desolve( y(x).diff(x,2) == 0, y(x))
k2*x + k1
sage: desolve( y(x).diff(x,2) == 0, y(x), [0,0,1])
x + y(0)
sage: desolve( y(x).diff(x,2) == 0, y(x), [0,1,1])
x + y(0)
</pre><p>
It seems desolve instead of using the given initial
value of y at x=0, it literally passes "y(0)" to maxima.
</p>
en-usSagehttps://trac.sagemath.org/chrome/site/logo_sagemath_trac.png
https://trac.sagemath.org/ticket/6479
Trac 1.1.6wdjWed, 08 Jul 2009 13:07:39 GMT
https://trac.sagemath.org/ticket/6479#comment:1
https://trac.sagemath.org/ticket/6479#comment:1
<p>
I'm not sure if this is a duplicate or not but Robert Bradshaw definitely knows about this bug. (I wrote a crappy version of the original solver, Robert wrote the new and improved one. However, Marshall Hampton and I spend several hours at SD15 trying to figure out how to patch this bug and couldn't.) BTW, it is actually documented to behave this way if you read the docstrings carefully.
</p>
<p>
Here is, at Robert Bradshaw's request, a *maxima* session solving a 2nd order ODE with 2 initial conditions and a 2nd order ODE with 2 boundary conditions:
</p>
<pre class="wiki">sage: maxima.eval("de:'diff(y,x,2) + y*'diff(y,x)^3 = 0")
"'diff(y,x,2)+y*('diff(y,x,1))^3=0"
sage: maxima.eval("ode2(de,y,x)")
'(y^3+6*%k1*y)/6=x+%k2'
sage: maxima.eval("soln:ode2(de,y,x)")
'(y^3+6*%k1*y)/6=x+%k2'
sage: maxima.eval("bc2(soln,x=0,y=1,x=1,y=3)")
'(y^3-10*y)/6=x-3/2'
sage: maxima.eval("de:'diff(y,x,2) + 4*y = 0")
"'diff(y,x,2)+4*y=0"
sage: maxima.eval("soln:ode2(de,y,x)")
'y=%k1*sin(2*x)+%k2*cos(2*x)'
sage: maxima.eval("bc2(soln,x=0,y=1,x=1,y=3)")
'y=cos(2*x)-(cos(2)-3)*sin(2*x)/sin(2)'
sage: maxima.eval("ic2(soln,x=0,y=1,'diff(y,x)=3)")
'y=3*sin(2*x)/2+cos(2*x)'
</pre><p>
Hope this helps.
</p>
<p>
An additional problem is that the syntax for desolve and desolve_laplace are different. Perhaps this could be fixed at the same time?
</p>
Ticketrobert.marikTue, 06 Oct 2009 16:43:27 GMTattachment set
https://trac.sagemath.org/ticket/6479
https://trac.sagemath.org/ticket/6479
<ul>
<li><strong>attachment</strong>
set to <em>trac_6479_marik.patch</em>
</li>
</ul>
Ticketrobert.marikTue, 06 Oct 2009 16:51:00 GMT
https://trac.sagemath.org/ticket/6479#comment:2
https://trac.sagemath.org/ticket/6479#comment:2
<p>
The patch which fixes ic2 and bc2 commands is attached. With this patch, the ode2 runs two times - the first pass is kept to ensure that Maxima is able to solve the system.
</p>
<p>
Test for bc2 has been added.
The problem related to desolve_laplace has not been solved - perhaps need more work. As I understand, the corresponding command in Maxima allows to solve systems of equations and the function in Maxima is designed for one equation only.
</p>
Ticketrobert.marikTue, 06 Oct 2009 16:52:28 GMTcc, reviewer set
https://trac.sagemath.org/ticket/6479#comment:3
https://trac.sagemath.org/ticket/6479#comment:3
<ul>
<li><strong>cc</strong>
<em>hamptonio@…</em> added
</li>
<li><strong>reviewer</strong>
set to <em>hamptonio@gmail.com</em>
</li>
</ul>
Ticketrobert.marikTue, 06 Oct 2009 17:01:08 GMTsummary changed
https://trac.sagemath.org/ticket/6479#comment:4
https://trac.sagemath.org/ticket/6479#comment:4
<ul>
<li><strong>summary</strong>
changed from <em>desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>[with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
Ticketrobert.marikWed, 07 Oct 2009 04:56:19 GMTstatus, summary changed
https://trac.sagemath.org/ticket/6479#comment:5
https://trac.sagemath.org/ticket/6479#comment:5
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>summary</strong>
changed from <em>[with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
<p>
Patch hass been posted, but it assumes that the solution of second order ODE is found in the explicit form, i.e. y=f(x) which is not allways true. From this reason the patch does not solve all related issues and needs more work. I hope to post new patch within a week.
</p>
Ticketrobert.marikWed, 07 Oct 2009 13:22:58 GMTattachment set
https://trac.sagemath.org/ticket/6479
https://trac.sagemath.org/ticket/6479
<ul>
<li><strong>attachment</strong>
set to <em>trac_6479_marik_revised.patch</em>
</li>
</ul>
<p>
Apply only this patch
</p>
Ticketrobert.marikWed, 07 Oct 2009 13:24:57 GMTstatus, summary changed
https://trac.sagemath.org/ticket/6479#comment:6
https://trac.sagemath.org/ticket/6479#comment:6
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
<li><strong>summary</strong>
changed from <em>desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>[with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
Ticketrobert.marikMon, 12 Oct 2009 09:38:23 GMTmilestone set
https://trac.sagemath.org/ticket/6479#comment:7
https://trac.sagemath.org/ticket/6479#comment:7
<ul>
<li><strong>milestone</strong>
set to <em>sage-4.1.3</em>
</li>
</ul>
Ticketrobert.marikTue, 13 Oct 2009 13:48:30 GMTattachment set
https://trac.sagemath.org/ticket/6479
https://trac.sagemath.org/ticket/6479
<ul>
<li><strong>attachment</strong>
set to <em>trac_6479_marik_revised_2.patch</em>
</li>
</ul>
<p>
Apply on the top of the patch trac_6479_marik_revised.patch and on the top pf the patch for Ticket <a class="closed ticket" href="https://trac.sagemath.org/ticket/385" title="enhancement: [with patch, positive review] implement at for symbolics (closed: fixed)">#385</a> <a class="ext-link" href="http://trac.sagemath.org/sage_trac/ticket/385"><span class="icon"></span>http://trac.sagemath.org/sage_trac/ticket/385</a>
</p>
Ticketrobert.marikTue, 13 Oct 2009 13:49:12 GMTreviewer deleted
https://trac.sagemath.org/ticket/6479#comment:8
https://trac.sagemath.org/ticket/6479#comment:8
<ul>
<li><strong>reviewer</strong>
<em>hamptonio@gmail.com</em> deleted
</li>
</ul>
Ticketrobert.marikTue, 13 Oct 2009 13:55:00 GMT
https://trac.sagemath.org/ticket/6479#comment:9
https://trac.sagemath.org/ticket/6479#comment:9
<p>
I attached second patch which should be applied after the previous trac_6479_marik_revised.patch and after a patch for Ticket <a class="closed ticket" href="https://trac.sagemath.org/ticket/385" title="enhancement: [with patch, positive review] implement at for symbolics (closed: fixed)">#385</a>.
</p>
<p>
With this new patch
</p>
<ul><li>we can solve more differential equations (clairot, lagrange, ...)
</li></ul><ul><li>desolve Laplace does not return string and the initial conditions do not persist in the system
</li></ul><ul><li>added a simple interface to runge kutta methods from maxima
</li></ul>
TicketwdjSat, 17 Oct 2009 20:11:11 GMTstatus, summary changed
https://trac.sagemath.org/ticket/6479#comment:10
https://trac.sagemath.org/ticket/6479#comment:10
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>needs_work</em>
</li>
<li><strong>summary</strong>
changed from <em>[with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>[with patch, needs work] desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
<p>
The improvements are *fantastic*!
</p>
<p>
However, some of the docstrings do not follow proper format.
For example, in your desolve_rk4 function, you do not indent
the Sage code in the EXAMPLES section correctly. Also, if a
function can produce different types of output (eg, a plot or
a list of points, depending on the optional parameters), both
should be illustrated in the examples. I don't know if this
improper formatting screws up the sage -test script or not.
There is also some improper indentation in other sections,
such as OUTPUT, for functions such as desolve_rk4, for example.
</p>
<p>
I hope you can please fix these.
</p>
<p>
A request: in your new functions desolve_rk4 and desolve_system_rk4
there is an option called endpoint, with default value 10. I would
prefer an option called endpoints with a default value of [0,10]
(or something), so that a range can be plotted other than from
ics[0] to endpoint. If it is too much hassle, fine (you can just add
plots together to get that anyway...).
</p>
Ticketrobert.marikSun, 25 Oct 2009 19:22:16 GMT
https://trac.sagemath.org/ticket/6479#comment:11
https://trac.sagemath.org/ticket/6479#comment:11
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/6479#comment:10" title="Comment 10">wdj</a>:
</p>
<blockquote class="citation">
<p>
The improvements are *fantastic*!
</p>
<p>
However, some of the docstrings do not follow proper format.
For example, in your desolve_rk4 function, you do not indent
the Sage code in the EXAMPLES section correctly. Also, if a
function can produce different types of output (eg, a plot or
a list of points, depending on the optional parameters), both
should be illustrated in the examples. I don't know if this
improper formatting screws up the sage -test script or not.
There is also some improper indentation in other sections,
such as OUTPUT, for functions such as desolve_rk4, for example.
</p>
<p>
I hope you can please fix these.
</p>
</blockquote>
<p>
Thanks. I will try to fix it. Sorry, I am newbie in Python.
</p>
<blockquote class="citation">
<p>
A request: in your new functions desolve_rk4 and desolve_system_rk4
there is an option called endpoint, with default value 10. I would
prefer an option called endpoints with a default value of [0,10]
(or something), so that a range can be plotted other than from
ics[0] to endpoint. If it is too much hassle, fine (you can just add
plots together to get that anyway...).
</p>
</blockquote>
<p>
what about this:
</p>
<p>
endpoints=a .... integrate from ics[0] to a
</p>
<p>
endpoints=[a] .... integrate from ics[0] to a
</p>
<p>
endpoints=[a,b] .... integrate from ics[0] to b, then integrate back from ics[0] to a, reverse the second list and join both lists together /without repeating the point (ics[0],ics[1])/. If ics[0] is bigger than b or smaller than a, raise error.
</p>
<p>
I think that this is possible and I can try within a week.
</p>
TicketwdjSun, 25 Oct 2009 20:15:47 GMT
https://trac.sagemath.org/ticket/6479#comment:12
https://trac.sagemath.org/ticket/6479#comment:12
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/6479#comment:11" title="Comment 11">robert.marik</a>:
</p>
<blockquote class="citation">
<p>
Replying to <a class="ticket" href="https://trac.sagemath.org/ticket/6479#comment:10" title="Comment 10">wdj</a>:
</p>
</blockquote>
<p>
...
</p>
<blockquote class="citation">
<blockquote class="citation">
<p>
A request: in your new functions desolve_rk4 and desolve_system_rk4
there is an option called endpoint, with default value 10. I would
prefer an option called endpoints with a default value of [0,10]
(or something), so that a range can be plotted other than from
ics[0] to endpoint. If it is too much hassle, fine (you can just add
plots together to get that anyway...).
</p>
</blockquote>
<p>
what about this:
</p>
<p>
endpoints=a .... integrate from ics[0] to a
</p>
<p>
endpoints=[a] .... integrate from ics[0] to a
</p>
<p>
endpoints=[a,b] .... integrate from ics[0] to b, then integrate back from ics[0] to a, reverse the second list and join both lists together /without repeating the point (ics[0],ics[1])/. If ics[0] is bigger than b or smaller than a, raise error.
</p>
<p>
I think that this is possible and I can try within a week.
</p>
</blockquote>
<p>
This sounds excellent - thanks!
</p>
Ticketrobert.marikTue, 27 Oct 2009 20:22:59 GMTattachment set
https://trac.sagemath.org/ticket/6479
https://trac.sagemath.org/ticket/6479
<ul>
<li><strong>attachment</strong>
set to <em>trac_6479_marik_revision3.patch</em>
</li>
</ul>
<p>
this replaces previous patches and installs on the top of patch for trac <a class="closed ticket" href="https://trac.sagemath.org/ticket/385" title="enhancement: [with patch, positive review] implement at for symbolics (closed: fixed)">#385</a>
</p>
Ticketrobert.marikTue, 27 Oct 2009 20:23:47 GMTstatus changed
https://trac.sagemath.org/ticket/6479#comment:13
https://trac.sagemath.org/ticket/6479#comment:13
<ul>
<li><strong>status</strong>
changed from <em>needs_work</em> to <em>needs_review</em>
</li>
</ul>
Ticketrobert.marikWed, 28 Oct 2009 21:07:14 GMTsummary changed
https://trac.sagemath.org/ticket/6479#comment:14
https://trac.sagemath.org/ticket/6479#comment:14
<ul>
<li><strong>summary</strong>
changed from <em>[with patch, needs work] desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>[with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
TicketwdjSat, 31 Oct 2009 15:50:10 GMTstatus, summary changed
https://trac.sagemath.org/ticket/6479#comment:15
https://trac.sagemath.org/ticket/6479#comment:15
<ul>
<li><strong>status</strong>
changed from <em>needs_review</em> to <em>positive_review</em>
</li>
<li><strong>summary</strong>
changed from <em>[with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>[with patch, positive review] desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
<p>
Great patch. Passes sage -testall and is very well-documented.
</p>
<p>
Thanks Robert!!
</p>
TicketmhansenSun, 29 Nov 2009 10:10:24 GMTstatus changed; author, upstream, reviewer, resolution, merged set
https://trac.sagemath.org/ticket/6479#comment:16
https://trac.sagemath.org/ticket/6479#comment:16
<ul>
<li><strong>status</strong>
changed from <em>positive_review</em> to <em>closed</em>
</li>
<li><strong>author</strong>
set to <em>Robert Marik</em>
</li>
<li><strong>upstream</strong>
set to <em>N/A</em>
</li>
<li><strong>reviewer</strong>
set to <em>David Joyner</em>
</li>
<li><strong>resolution</strong>
set to <em>fixed</em>
</li>
<li><strong>merged</strong>
set to <em>sage-4.3.alpha1</em>
</li>
</ul>
TicketmvnguSat, 26 Dec 2009 18:21:33 GMTsummary changed
https://trac.sagemath.org/ticket/6479#comment:17
https://trac.sagemath.org/ticket/6479#comment:17
<ul>
<li><strong>summary</strong>
changed from <em>[with patch, positive review] desolve for 2nd order ODE with initial condition gives wrong answer</em> to <em>desolve for 2nd order ODE with initial condition gives wrong answer</em>
</li>
</ul>
Ticketrobert.marikWed, 07 Apr 2010 11:10:57 GMT
https://trac.sagemath.org/ticket/6479#comment:18
https://trac.sagemath.org/ticket/6479#comment:18
<p>
Thanks for including the patch to Sage.
The work on this patch has been supported by the grant GA201/07/0145 of the Czech Grant Agency.
</p>
TicketchapotonSun, 07 Aug 2016 20:15:38 GMTauthor changed
https://trac.sagemath.org/ticket/6479#comment:19
https://trac.sagemath.org/ticket/6479#comment:19
<ul>
<li><strong>author</strong>
changed from <em>Robert Marik</em> to <em>Robert Mařík</em>
</li>
</ul>
Ticket