Skip to content

Commit e578d97

Browse files
refactor(test_ode.py): 1st_exact examples
1 parent 87a885b commit e578d97

File tree

2 files changed

+48
-30
lines changed

2 files changed

+48
-30
lines changed

sympy/solvers/ode/tests/test_ode.py

Lines changed: 0 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -813,35 +813,6 @@ def test_old_ode_tests():
813813
assert checkodesol(eq11, sol11, order=1, solve_for_func=False)[0]
814814

815815

816-
@slow
817-
def test_1st_exact1():
818-
# Type: Exact differential equation, p(x,f) + q(x,f)*f' == 0,
819-
# where dp/df == dq/dx
820-
eq1 = sin(x)*cos(f(x)) + cos(x)*sin(f(x))*f(x).diff(x)
821-
eq2 = (2*x*f(x) + 1)/f(x) + (f(x) - x)/f(x)**2*f(x).diff(x)
822-
eq3 = 2*x + f(x)*cos(x) + (2*f(x) + sin(x) - sin(f(x)))*f(x).diff(x)
823-
eq4 = cos(f(x)) - (x*sin(f(x)) - f(x)**2)*f(x).diff(x)
824-
eq5 = 2*x*f(x) + (x**2 + f(x)**2)*f(x).diff(x)
825-
sol1 = [Eq(f(x), -acos(C1/cos(x)) + 2*pi), Eq(f(x), acos(C1/cos(x)))]
826-
sol2 = Eq(f(x), exp(C1 - x**2 + LambertW(-x*exp(-C1 + x**2))))
827-
sol2b = Eq(log(f(x)) + x/f(x) + x**2, C1)
828-
sol3 = Eq(f(x)*sin(x) + cos(f(x)) + x**2 + f(x)**2, C1)
829-
sol4 = Eq(x*cos(f(x)) + f(x)**3/3, C1)
830-
sol5 = Eq(x**2*f(x) + f(x)**3/3, C1)
831-
assert dsolve(eq1, f(x), hint='1st_exact') == sol1
832-
assert dsolve(eq2, f(x), hint='1st_exact') == sol2
833-
assert dsolve(eq3, f(x), hint='1st_exact') == sol3
834-
assert dsolve(eq4, hint='1st_exact') == sol4
835-
assert dsolve(eq5, hint='1st_exact', simplify=False) == sol5
836-
assert checkodesol(eq1, sol1, order=1, solve_for_func=False)[0]
837-
# issue 5080 blocks the testing of this solution
838-
# FIXME: assert checkodesol(eq2, sol2, order=1, solve_for_func=False)[0]
839-
assert checkodesol(eq2, sol2b, order=1, solve_for_func=False)[0]
840-
assert checkodesol(eq3, sol3, order=1, solve_for_func=False)[0]
841-
assert checkodesol(eq4, sol4, order=1, solve_for_func=False)[0]
842-
assert checkodesol(eq5, sol5, order=1, solve_for_func=False)[0]
843-
844-
845816
@slow
846817
@XFAIL
847818
def test_1st_exact2_broken():

sympy/solvers/ode/tests/test_single.py

Lines changed: 48 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
3434
"""
3535
from sympy import (acos, asin, atan, cos, Derivative, Dummy, diff,
36-
E, Eq, exp, I, log, pi, Piecewise, Rational, S, sin, sinh, tan,
36+
E, Eq, exp, I, LambertW, log, pi, Piecewise, Rational, S, sin, sinh, tan,
3737
sqrt, symbols, Ei, erfi)
3838

3939
from sympy.core import Function, Symbol
@@ -318,6 +318,11 @@ def test_nth_algebraic():
318318
_ode_solver_test(_get_examples_ode_sol_nth_algebraic())
319319

320320

321+
@slow
322+
def test_slow_examples_1st_exact():
323+
_ode_solver_test(_get_examples_ode_sol_1st_exact(), run_slow_test=True)
324+
325+
321326
@slow
322327
def test_slow_examples_nth_order_reducible():
323328
_ode_solver_test(_get_examples_ode_sol_nth_order_reducible(), run_slow_test=True)
@@ -1284,6 +1289,48 @@ def _get_examples_ode_sol_separable():
12841289
}
12851290

12861291

1292+
def _get_examples_ode_sol_1st_exact():
1293+
# Type: Exact differential equation, p(x,f) + q(x,f)*f' == 0,
1294+
# where dp/df == dq/dx
1295+
return {
1296+
'hint': "1st_exact",
1297+
'func': f(x),
1298+
'examples':{
1299+
'1st_exact_01': {
1300+
'eq': sin(x)*cos(f(x)) + cos(x)*sin(f(x))*f(x).diff(x),
1301+
'sol': [Eq(f(x), -acos(C1/cos(x)) + 2*pi), Eq(f(x), acos(C1/cos(x)))],
1302+
'slow': True,
1303+
},
1304+
1305+
'1st_exact_02': {
1306+
'eq': (2*x*f(x) + 1)/f(x) + (f(x) - x)/f(x)**2*f(x).diff(x),
1307+
'sol': [Eq(f(x), exp(C1 - x**2 + LambertW(-x*exp(-C1 + x**2))))],
1308+
'slow': True,
1309+
},
1310+
1311+
'1st_exact_03': {
1312+
'eq': 2*x + f(x)*cos(x) + (2*f(x) + sin(x) - sin(f(x)))*f(x).diff(x),
1313+
'sol': [Eq(f(x)*sin(x) + cos(f(x)) + x**2 + f(x)**2, C1)],
1314+
'slow': True,
1315+
},
1316+
1317+
'1st_exact_04': {
1318+
'eq': cos(f(x)) - (x*sin(f(x)) - f(x)**2)*f(x).diff(x),
1319+
'sol': [Eq(x*cos(f(x)) + f(x)**3/3, C1)],
1320+
'slow': True,
1321+
},
1322+
1323+
'1st_exact_05': {
1324+
'eq': 2*x*f(x) + (x**2 + f(x)**2)*f(x).diff(x),
1325+
'sol': [Eq(x**2*f(x) + f(x)**3/3, C1)],
1326+
# 'sol':[Eq(f(x), 2**Rational(1, 3)*(x**2/(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3) - 2**Rational(1, 3)*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)/2)), Eq(f(x), 2**Rational(1, 3)*(2*x**2/((-1 - sqrt(3)*I)*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)) + 2**Rational(1, 3)*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)/4 + 2**Rational(1, 3)*sqrt(3)*I*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)/4)),
1327+
# Eq(f(x), 2**Rational(1, 3)*(2*x**2/((-1 + sqrt(3)*I)*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)) + 2**Rational(1, 3)*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)/4 - 2**Rational(1, 3)*sqrt(3)*I*(-3*C1 + sqrt(9*C1**2 + 4*x**6))**Rational(1, 3)/4))],
1328+
'slow': True,
1329+
},
1330+
}
1331+
}
1332+
1333+
12871334
def _get_all_examples():
12881335
all_solvers = [_get_examples_ode_sol_euler_homogeneous(),
12891336
_get_examples_ode_sol_euler_undetermined_coeff(),

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy