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

dsolve hangs #11131

Closed
proy87 opened this issue May 18, 2016 · 2 comments
Closed

dsolve hangs #11131

proy87 opened this issue May 18, 2016 · 2 comments

Comments

@proy87
Copy link

proy87 commented May 18, 2016

Looks like a simple DE
y=Function('y')(x)
dsolve(diff(y,x,x)-8*cos(x)+sec(x)**2)

skirpichev added a commit to skirpichev/diofant that referenced this issue Apr 10, 2017
skirpichev added a commit to skirpichev/diofant that referenced this issue Aug 4, 2018
@sidhantnagpal
Copy link
Member

This issue seems to have been fixed on master:

In [29]: y = Function('y')(x)                                                     

In [30]: dsolve(diff(y, x, x) - 8*cos(x) + sec(x)**2)                                 
Out[30]: y(x) = C+ C₂⋅x + log(cos(x)) - 8cos(x)

Perhaps @oscarbenjamin will know if there's a need to add a test for this, if it wasn't already.

@oscarbenjamin
Copy link
Collaborator

I've checked and it is slow in 1.3 (doesn't hang) but it's slow in integrals. It faster in master because it is now solved by nth_algebraic:

In [8]: y=Function('y')(x) 
   ...: eq=diff(y,x,x)-8*cos(x)+sec(x)**2                                                                                                                     

In [9]: classify_ode(eq)                                                                                                                                      
Out[9]: 
('nth_algebraic',
 'nth_linear_constant_coeff_variation_of_parameters',
 'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters',
 'nth_algebraic_Integral',
 'nth_linear_constant_coeff_variation_of_parameters_Integral',
 'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters_Integral')

The other solvers don't hang but they are slow and give suboptimal results:

In [1]: y=Function('y')(x) 
   ...: eq=diff(y,x,x)-8*cos(x)+sec(x)**2                                                                                                                     

In [2]: dsolve(eq, hint='nth_linear_euler_eq_nonhomogeneous_variation_of_parameters')                                                                         
Out[2]: 
                                           ⌠                          
                                           ⎮   ⎛              2y(x) = C₁ + C₂x + 8xsin(x) - xtan(x) - ⎮ x8cos(x) - sec (x)⎠ dx
                                           ⌡                          

In [3]: dsolve(eq, hint='nth_linear_constant_coeff_variation_of_parameters')                                                                                  
Out[3]: 
                                                           ⌠              
              ⎛                sin(x)⎞   ⌠                 ⎮       2      
y(x) = C₁ + x⎜C₂ + 8sin(x) - ──────⎟ -8xcos(x) dx --xsec (x) dx
              ⎝                cos(x)⎠   ⌡                 ⌡  

This is because each method ends up with an integral like:

In [11]: integrate(x*(cos(x)-sec(x)**2), x)                                                                                                                   
Out[11]: 
⌠                        
⎮   ⎛            2   ⎞   
⎮ x⋅⎝cos(x) - sec (x)⎠ dx
⌡                        

which takes a while and doesn't evaluate anyway.

It could be worth opening a separate issue in integrals about that but I think this is all fixed as far as dsolve is concerned. Simple ODEs like this are now handled in a simple way by nth_algebraic.

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

3 participants