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
dsolve doesn't know order-reducing substitutions #15881
Comments
Hi, I 'm interested in fixing this bug but I' will have to see how to convert my math to symbolic computations. |
Even if you try this eq using dsolve => f(x).diff(x, 1) + x * f(x).diff(x)**2=0 it gives only the constant solution but not the other one. Whereas solve gives the other solution that too in f'(x) form not f(x). Definitely needs a lot of fixes. |
Hi @XtremeGood. If you want to work on this you'll need to use the latest master version of SymPy. The equation you show has two solutions under current master: In [2]: f(x).diff(x, 1) + x * f(x).diff(x)**2
Out[2]:
2
⎛d ⎞ d
x⋅⎜──(f(x))⎟ + ──(f(x))
⎝dx ⎠ dx
In [3]: dsolve(_)
Out[3]: [f(x) = C₁, f(x) = C₁ - log(x)] In terms of how to code this the method could be roughly as simple as eq = f(x).diff(x, 2) + x * f(x).diff(x)**2
new_eq = eq.subs(f(x).diff(x), g(x))
if new_eq.has(f): # if new_eq has f then f appears outside of derivatives
raise NotImplementedError
sol = dsolve(new_eq, g(x))
sol_f = Eq(f(x), integrate(sol.rhs, x)) The more complicated part is working out how to slot that into Then the solver part has to be a function called |
Hi @oscarbenjamin |
Hi @oscarbenjamin |
Hi again @XtremeGood. If you add the code to match this type of ODE where I suggested then Perhaps you should open a new issue about the Liouville solver. The type of ODE referred to by this issue is more general than Liouville: it could be of any order. |
Hi @oscarbenjamin |
Hi @oscarbenjamin Check my github for the current code which would work for the function which we were expecting: |
This method should not be used if f(x) appears outside of derivatives. In dsolve it's not actually necessary to return NotImplementedError. We just need to test for this when deciding if the method matches the ODE. I recommend just to test |
Done it, please see,I do have a github account but 'm not familiar to merge,pull requests etc. If you see it good can you please tell me how to ask them for changes. |
Okay that looks like a good start. What we need to do now is get it into the SymPy codebase and get it up as a pull request. For this you'll need to install git. Let's not worry right now about making it perfect. Once you have a pull request we can make comments on how to improve it and we can see what happens when running the tests. I'll describe the steps but you'll probably want to read some guides. Here's the SymPy guide to contributing: https://github.com/sympy/sympy/wiki/introduction-to-contributing In terms of git the steps you need to follow are:
Then we can talk about the rewriting the code so it fits into |
Thanks a lot! I will try to do it as fast as I can. |
Done it.I have opened a pull request named "Sympyedit1". Please see it.It is showing error in spacing. |
I would like to work on this issue. Is there any lead on the way it should be worked upon? |
This is mostly done in #15992 |
Am I a part of this merge? |
Yes, if you look the first commit on that pull request is your commit. |
Thanks @asmeurer, @oscarbenjamin and @smichr for the great help in first merge!! |
Thanks @XtremeGood for your help! There are many more issue with dsolve if you look... |
If an ODE only involves derivatives of the dependent variable then it is possible to use a substitution to to reduce the order of the ODE. This usually makes it easier to solved but
dsolve
doesn't know how to do it yet.Here's an example:
Since
f(x)
only appears as a derivative we can use the substitutiong(x) = f(x).diff(x)
to obtain a first order ODE:This is a solution of the original ODE since
It would be good to add a new solver in sympy/solvers.ode.py. The idea would be that the solver matches ODEs that only include on derivatives of the dependent variable. It would generate the ODE by substitution
Then the solver should recursively call
dsolve
to solve that ODE and (if that works) integrate the result to get the solution to the original ODE.This solver should appear in the matching order after all of the methods for linear ODEs but before the nonlinear methods (e.g. Liouville) here :https://github.com/sympy/sympy/blob/master/sympy/solvers/ode.py#L309.
The text was updated successfully, but these errors were encountered: