Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

desolve for 2nd order ODE with initial condition gives wrong answer #6479

Closed
golam-m-hossain opened this issue Jul 8, 2009 · 20 comments
Closed

Comments

@golam-m-hossain
Copy link

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)

It seems desolve instead of using the given initial
value of y at x=0, it literally passes "y(0)" to maxima.

CC: @sagetrac-mhampton

Component: calculus

Author: Robert Mařík

Reviewer: David Joyner

Merged: sage-4.3.alpha1

Issue created by migration from https://trac.sagemath.org/ticket/6479

@wdjoyner
Copy link

wdjoyner commented Jul 8, 2009

comment:1

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.

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:

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)'

Hope this helps.

An additional problem is that the syntax for desolve and desolve_laplace are different. Perhaps this could be fixed at the same time?

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 6, 2009

Attachment: trac_6479_marik.patch.gz

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 6, 2009

comment:2

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.

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.

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 6, 2009

Reviewer: hamptonio@gmail.com

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 7, 2009

comment:5

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.

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 7, 2009

Attachment: trac_6479_marik_revised.patch.gz

Apply only this patch

@robert-marik robert-marik mannequin added this to the sage-4.2 milestone Oct 12, 2009
@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 13, 2009

Attachment: trac_6479_marik_revised_2.patch.gz

Apply on the top of the patch trac_6479_marik_revised.patch and on the top pf the patch for Ticket #385 #385

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 13, 2009

Changed reviewer from hamptonio@gmail.com to none

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 13, 2009

comment:9

I attached second patch which should be applied after the previous trac_6479_marik_revised.patch and after a patch for Ticket #385.

With this new patch

  • we can solve more differential equations (clairot, lagrange, ...)

  • desolve Laplace does not return string and the initial conditions do not persist in the system

  • added a simple interface to runge kutta methods from maxima

@wdjoyner
Copy link

comment:10

The improvements are fantastic!

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.

I hope you can please fix these.

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...).

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 25, 2009

comment:11

Replying to @wdjoyner:

The improvements are fantastic!

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.

I hope you can please fix these.

Thanks. I will try to fix it. Sorry, I am newbie in Python.

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...).

what about this:

endpoints=a .... integrate from ics[0] to a

endpoints=[a] .... integrate from ics[0] to a

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.

I think that this is possible and I can try within a week.

@wdjoyner
Copy link

comment:12

Replying to @robert-marik:

Replying to @wdjoyner:

...

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...).

what about this:

endpoints=a .... integrate from ics[0] to a

endpoints=[a] .... integrate from ics[0] to a

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.

I think that this is possible and I can try within a week.

This sounds excellent - thanks!

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 27, 2009

this replaces previous patches and installs on the top of patch for trac #385

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Oct 27, 2009

comment:13

Attachment: trac_6479_marik_revision3.patch.gz

@wdjoyner
Copy link

comment:15

Great patch. Passes sage -testall and is very well-documented.

Thanks Robert!!

@mwhansen
Copy link
Contributor

Author: Robert Marik

@mwhansen
Copy link
Contributor

Reviewer: David Joyner

@mwhansen
Copy link
Contributor

Merged: sage-4.3.alpha1

@robert-marik
Copy link
Mannequin

robert-marik mannequin commented Apr 7, 2010

comment:18

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.

@fchapoton
Copy link
Contributor

Changed author from Robert Marik to Robert Mařík

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

5 participants