Skip to content

Commit b089998

Browse files
refactored liouville test examples
1 parent abf7f70 commit b089998

File tree

2 files changed

+54
-46
lines changed

2 files changed

+54
-46
lines changed

sympy/solvers/ode/tests/test_ode.py

Lines changed: 0 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -2556,52 +2556,6 @@ def test_nth_linear_constant_coeff_variation_of_parameters_simplify_False():
25562556
assert checkodesol(eq, sol_simp, order=5, solve_for_func=False) == (True, 0)
25572557

25582558

2559-
def test_Liouville_ODE():
2560-
hint = 'Liouville'
2561-
# The first part here used to be test_ODE_1() from test_solvers.py
2562-
eq1 = diff(f(x), x)/x + diff(f(x), x, x)/2 - diff(f(x), x)**2/2
2563-
eq1a = diff(x*exp(-f(x)), x, x)
2564-
# compare to test_unexpanded_Liouville_ODE() below
2565-
eq2 = (eq1*exp(-f(x))/exp(f(x))).expand()
2566-
eq3 = diff(f(x), x, x) + 1/f(x)*(diff(f(x), x))**2 + 1/x*diff(f(x), x)
2567-
eq4 = x*diff(f(x), x, x) + x/f(x)*diff(f(x), x)**2 + x*diff(f(x), x)
2568-
eq5 = Eq((x*exp(f(x))).diff(x, x), 0)
2569-
sol1 = Eq(f(x), log(x/(C1 + C2*x)))
2570-
sol1a = Eq(C1 + C2/x - exp(-f(x)), 0)
2571-
sol2 = sol1
2572-
sol3 = set(
2573-
[Eq(f(x), -sqrt(C1 + C2*log(x))),
2574-
Eq(f(x), sqrt(C1 + C2*log(x)))])
2575-
sol4 = set([Eq(f(x), sqrt(C1 + C2*exp(x))*exp(-x/2)),
2576-
Eq(f(x), -sqrt(C1 + C2*exp(x))*exp(-x/2))])
2577-
sol5 = Eq(f(x), log(C1 + C2/x))
2578-
sol1s = constant_renumber(sol1)
2579-
sol2s = constant_renumber(sol2)
2580-
sol3s = constant_renumber(sol3)
2581-
sol4s = constant_renumber(sol4)
2582-
sol5s = constant_renumber(sol5)
2583-
assert dsolve(eq1, hint=hint) in (sol1, sol1s)
2584-
assert dsolve(eq1a, hint=hint) in (sol1, sol1s)
2585-
assert dsolve(eq2, hint=hint) in (sol2, sol2s)
2586-
assert set(dsolve(eq3, hint=hint)) in (sol3, sol3s)
2587-
assert set(dsolve(eq4, hint=hint)) in (sol4, sol4s)
2588-
assert dsolve(eq5, hint=hint) in (sol5, sol5s)
2589-
assert checkodesol(eq1, sol1, order=2, solve_for_func=False)[0]
2590-
assert checkodesol(eq1a, sol1a, order=2, solve_for_func=False)[0]
2591-
assert checkodesol(eq2, sol2, order=2, solve_for_func=False)[0]
2592-
assert checkodesol(eq3, sol3, order=2, solve_for_func=False) == {(True, 0)}
2593-
assert checkodesol(eq4, sol4, order=2, solve_for_func=False) == {(True, 0)}
2594-
assert checkodesol(eq5, sol5, order=2, solve_for_func=False)[0]
2595-
not_Liouville1 = classify_ode(diff(f(x), x)/x + f(x)*diff(f(x), x, x)/2 -
2596-
diff(f(x), x)**2/2, f(x))
2597-
not_Liouville2 = classify_ode(diff(f(x), x)/x + diff(f(x), x, x)/2 -
2598-
x*diff(f(x), x)**2/2, f(x))
2599-
assert hint not in not_Liouville1
2600-
assert hint not in not_Liouville2
2601-
assert hint + '_Integral' not in not_Liouville1
2602-
assert hint + '_Integral' not in not_Liouville2
2603-
2604-
26052559
def test_unexpanded_Liouville_ODE():
26062560
# This is the same as eq1 from test_Liouville_ODE() above.
26072561
eq1 = diff(f(x), x)/x + diff(f(x), x, x)/2 - diff(f(x), x)**2/2

sympy/solvers/ode/tests/test_single.py

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,21 @@ def test_1st_linear():
330330
def test_almost_linear():
331331
_ode_solver_test(_get_examples_ode_sol_almost_linear())
332332

333+
334+
def test_Liouville_ODE():
335+
hint = 'Liouville'
336+
not_Liouville1 = classify_ode(diff(f(x), x)/x + f(x)*diff(f(x), x, x)/2 -
337+
diff(f(x), x)**2/2, f(x))
338+
not_Liouville2 = classify_ode(diff(f(x), x)/x + diff(f(x), x, x)/2 -
339+
x*diff(f(x), x)**2/2, f(x))
340+
assert hint not in not_Liouville1
341+
assert hint not in not_Liouville2
342+
assert hint + '_Integral' not in not_Liouville1
343+
assert hint + '_Integral' not in not_Liouville2
344+
345+
_ode_solver_test(_get_examples_ode_sol_liouville())
346+
347+
333348
def test_nth_order_linear_euler_eq_homogeneous():
334349
x, t, a, b, c = symbols('x t a b c')
335350
y = Function('y')
@@ -690,6 +705,45 @@ def _get_examples_ode_sol_almost_linear():
690705
}
691706

692707

708+
def _get_examples_ode_sol_liouville():
709+
return {
710+
'hint': "Liouville",
711+
'func': f(x),
712+
'examples':{
713+
'liouville_01': {
714+
'eq': diff(f(x), x)/x + diff(f(x), x, x)/2 - diff(f(x), x)**2/2,
715+
'sol': [Eq(f(x), log(x/(C1 + C2*x)))],
716+
717+
},
718+
719+
'liouville_02': {
720+
'eq': diff(x*exp(-f(x)), x, x),
721+
'sol': [Eq(f(x), log(x/(C1 + C2*x)))]
722+
},
723+
724+
'liouville_03': {
725+
'eq': ((diff(f(x), x)/x + diff(f(x), x, x)/2 - diff(f(x), x)**2/2)*exp(-f(x))/exp(f(x))).expand(),
726+
'sol': [Eq(f(x), log(x/(C1 + C2*x)))]
727+
},
728+
729+
'liouville_04': {
730+
'eq': diff(f(x), x, x) + 1/f(x)*(diff(f(x), x))**2 + 1/x*diff(f(x), x),
731+
'sol': [Eq(f(x), -sqrt(C1 + C2*log(x))), Eq(f(x), sqrt(C1 + C2*log(x)))],
732+
},
733+
734+
'liouville_05': {
735+
'eq': x*diff(f(x), x, x) + x/f(x)*diff(f(x), x)**2 + x*diff(f(x), x),
736+
'sol': [Eq(f(x), -sqrt(C1 + C2*exp(-x))), Eq(f(x), sqrt(C1 + C2*exp(-x)))],
737+
},
738+
739+
'liouville_06': {
740+
'eq': Eq((x*exp(f(x))).diff(x, x), 0),
741+
'sol': [Eq(f(x), log(C1 + C2/x))],
742+
},
743+
}
744+
}
745+
746+
693747
def _get_examples_ode_sol_nth_algebraic():
694748
M, m, r, t = symbols('M m r t')
695749
phi = Function('phi')

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