#6479 closed defect (fixed)
desolve for 2nd order ODE with initial condition gives wrong answer
Reported by: | gmhossain | Owned by: | burcin |
---|---|---|---|
Priority: | major | Milestone: | sage-4.3 |
Component: | calculus | Keywords: | |
Cc: | hamptonio@… | Merged in: | sage-4.3.alpha1 |
Authors: | Robert Mařík | Reviewers: | David Joyner |
Report Upstream: | N/A | Work issues: | |
Branch: | Commit: | ||
Dependencies: | Stopgaps: |
Description
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.
Attachments (4)
Change History (23)
comment:1 Changed 12 years ago by
Changed 12 years ago by
comment:2 Changed 12 years ago by
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.
comment:3 Changed 12 years ago by
- Cc hamptonio@… added
- Reviewers set to hamptonio@gmail.com
comment:4 Changed 12 years ago by
- Summary changed from desolve for 2nd order ODE with initial condition gives wrong answer to [with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer
comment:5 Changed 12 years ago by
- Status changed from needs_review to needs_work
- Summary changed from [with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer to desolve for 2nd order ODE with initial condition gives wrong answer
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.
comment:6 Changed 12 years ago by
- Status changed from needs_work to needs_review
- Summary changed from desolve for 2nd order ODE with initial condition gives wrong answer to [with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer
comment:7 Changed 12 years ago by
- Milestone set to sage-4.1.3
Changed 12 years ago by
Apply on the top of the patch trac_6479_marik_revised.patch and on the top pf the patch for Ticket #385 http://trac.sagemath.org/sage_trac/ticket/385
comment:8 Changed 12 years ago by
- Reviewers hamptonio@gmail.com deleted
comment:9 Changed 12 years ago by
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
comment:10 follow-up: ↓ 11 Changed 12 years ago by
- Status changed from needs_review to needs_work
- Summary changed from [with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer to [with patch, needs work] desolve for 2nd order ODE with initial condition gives wrong answer
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...).
comment:11 in reply to: ↑ 10 ; follow-up: ↓ 12 Changed 12 years ago by
Replying to wdj:
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.
comment:12 in reply to: ↑ 11 Changed 12 years ago by
Replying to robert.marik:
Replying to wdj:
...
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!
Changed 12 years ago by
this replaces previous patches and installs on the top of patch for trac #385
comment:13 Changed 12 years ago by
- Status changed from needs_work to needs_review
comment:14 Changed 12 years ago by
- Summary changed from [with patch, needs work] desolve for 2nd order ODE with initial condition gives wrong answer to [with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer
comment:15 Changed 12 years ago by
- Status changed from needs_review to positive_review
- Summary changed from [with patch, needs review] desolve for 2nd order ODE with initial condition gives wrong answer to [with patch, positive review] desolve for 2nd order ODE with initial condition gives wrong answer
Great patch. Passes sage -testall and is very well-documented.
Thanks Robert!!
comment:16 Changed 12 years ago by
- Merged in set to sage-4.3.alpha1
- Report Upstream set to N/A
- Resolution set to fixed
- Reviewers set to David Joyner
- Status changed from positive_review to closed
comment:17 Changed 12 years ago by
- Summary changed from [with patch, positive review] desolve for 2nd order ODE with initial condition gives wrong answer to desolve for 2nd order ODE with initial condition gives wrong answer
comment:18 Changed 12 years ago by
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.
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:
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?