m2m模型翻译
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

2892 lines
98 KiB

6 months ago
  1. #
  2. # The main tests for the code in single.py are currently located in
  3. # sympy/solvers/tests/test_ode.py
  4. #
  5. r"""
  6. This File contains test functions for the individual hints used for solving ODEs.
  7. Examples of each solver will be returned by _get_examples_ode_sol_name_of_solver.
  8. Examples should have a key 'XFAIL' which stores the list of hints if they are
  9. expected to fail for that hint.
  10. Functions that are for internal use:
  11. 1) _ode_solver_test(ode_examples) - It takes a dictionary of examples returned by
  12. _get_examples method and tests them with their respective hints.
  13. 2) _test_particular_example(our_hint, example_name) - It tests the ODE example corresponding
  14. to the hint provided.
  15. 3) _test_all_hints(runxfail=False) - It is used to test all the examples with all the hints
  16. currently implemented. It calls _test_all_examples_for_one_hint() which outputs whether the
  17. given hint functions properly if it classifies the ODE example.
  18. If runxfail flag is set to True then it will only test the examples which are expected to fail.
  19. Everytime the ODE of a particular solver is added, _test_all_hints() is to be executed to find
  20. the possible failures of different solver hints.
  21. 4) _test_all_examples_for_one_hint(our_hint, all_examples) - It takes hint as argument and checks
  22. this hint against all the ODE examples and gives output as the number of ODEs matched, number
  23. of ODEs which were solved correctly, list of ODEs which gives incorrect solution and list of
  24. ODEs which raises exception.
  25. """
  26. from sympy.core.function import (Derivative, diff)
  27. from sympy.core.mul import Mul
  28. from sympy.core.numbers import (E, I, Rational, pi)
  29. from sympy.core.relational import (Eq, Ne)
  30. from sympy.core.singleton import S
  31. from sympy.core.symbol import (Dummy, symbols)
  32. from sympy.functions.elementary.complexes import (im, re)
  33. from sympy.functions.elementary.exponential import (LambertW, exp, log)
  34. from sympy.functions.elementary.hyperbolic import (acosh, asinh, cosh, sinh, tanh)
  35. from sympy.functions.elementary.miscellaneous import (cbrt, sqrt)
  36. from sympy.functions.elementary.piecewise import Piecewise
  37. from sympy.functions.elementary.trigonometric import (acos, asin, atan, cos, sec, sin, tan)
  38. from sympy.functions.special.error_functions import (Ei, erfi)
  39. from sympy.functions.special.hyper import hyper
  40. from sympy.integrals.integrals import (Integral, integrate)
  41. from sympy.polys.rootoftools import rootof
  42. from sympy.core import Function, Symbol
  43. from sympy.functions import airyai, airybi, besselj, bessely, lowergamma
  44. from sympy.integrals.risch import NonElementaryIntegral
  45. from sympy.solvers.ode import classify_ode, dsolve
  46. from sympy.solvers.ode.ode import allhints, _remove_redundant_solutions
  47. from sympy.solvers.ode.single import (FirstLinear, ODEMatchError,
  48. SingleODEProblem, SingleODESolver, NthOrderReducible)
  49. from sympy.solvers.ode.subscheck import checkodesol
  50. from sympy.testing.pytest import raises, slow, ON_TRAVIS
  51. import traceback
  52. x = Symbol('x')
  53. u = Symbol('u')
  54. _u = Dummy('u')
  55. y = Symbol('y')
  56. f = Function('f')
  57. g = Function('g')
  58. C1, C2, C3, C4, C5, C6, C7, C8, C9, C10 = symbols('C1:11')
  59. hint_message = """\
  60. Hint did not match the example {example}.
  61. The ODE is:
  62. {eq}.
  63. The expected hint was
  64. {our_hint}\
  65. """
  66. expected_sol_message = """\
  67. Different solution found from dsolve for example {example}.
  68. The ODE is:
  69. {eq}
  70. The expected solution was
  71. {sol}
  72. What dsolve returned is:
  73. {dsolve_sol}\
  74. """
  75. checkodesol_msg = """\
  76. solution found is not correct for example {example}.
  77. The ODE is:
  78. {eq}\
  79. """
  80. dsol_incorrect_msg = """\
  81. solution returned by dsolve is incorrect when using {hint}.
  82. The ODE is:
  83. {eq}
  84. The expected solution was
  85. {sol}
  86. what dsolve returned is:
  87. {dsolve_sol}
  88. You can test this with:
  89. eq = {eq}
  90. sol = dsolve(eq, hint='{hint}')
  91. print(sol)
  92. print(checkodesol(eq, sol))
  93. """
  94. exception_msg = """\
  95. dsolve raised exception : {e}
  96. when using {hint} for the example {example}
  97. You can test this with:
  98. from sympy.solvers.ode.tests.test_single import _test_an_example
  99. _test_an_example('{hint}', example_name = '{example}')
  100. The ODE is:
  101. {eq}
  102. \
  103. """
  104. check_hint_msg = """\
  105. Tested hint was : {hint}
  106. Total of {matched} examples matched with this hint.
  107. Out of which {solve} gave correct results.
  108. Examples which gave incorrect results are {unsolve}.
  109. Examples which raised exceptions are {exceptions}
  110. \
  111. """
  112. def _add_example_keys(func):
  113. def inner():
  114. solver=func()
  115. examples=[]
  116. for example in solver['examples']:
  117. temp={
  118. 'eq': solver['examples'][example]['eq'],
  119. 'sol': solver['examples'][example]['sol'],
  120. 'XFAIL': solver['examples'][example].get('XFAIL', []),
  121. 'func': solver['examples'][example].get('func',solver['func']),
  122. 'example_name': example,
  123. 'slow': solver['examples'][example].get('slow', False),
  124. 'simplify_flag':solver['examples'][example].get('simplify_flag',True),
  125. 'checkodesol_XFAIL': solver['examples'][example].get('checkodesol_XFAIL', False),
  126. 'dsolve_too_slow':solver['examples'][example].get('dsolve_too_slow',False),
  127. 'checkodesol_too_slow':solver['examples'][example].get('checkodesol_too_slow',False),
  128. 'hint': solver['hint']
  129. }
  130. examples.append(temp)
  131. return examples
  132. return inner()
  133. def _ode_solver_test(ode_examples, run_slow_test=False):
  134. for example in ode_examples:
  135. if ((not run_slow_test) and example['slow']) or (run_slow_test and (not example['slow'])):
  136. continue
  137. result = _test_particular_example(example['hint'], example, solver_flag=True)
  138. if result['xpass_msg'] != "":
  139. print(result['xpass_msg'])
  140. def _test_all_hints(runxfail=False):
  141. all_hints = list(allhints)+["default"]
  142. all_examples = _get_all_examples()
  143. for our_hint in all_hints:
  144. if our_hint.endswith('_Integral') or 'series' in our_hint:
  145. continue
  146. _test_all_examples_for_one_hint(our_hint, all_examples, runxfail)
  147. def _test_dummy_sol(expected_sol,dsolve_sol):
  148. if type(dsolve_sol)==list:
  149. return any(expected_sol.dummy_eq(sub_dsol) for sub_dsol in dsolve_sol)
  150. else:
  151. return expected_sol.dummy_eq(dsolve_sol)
  152. def _test_an_example(our_hint, example_name):
  153. all_examples = _get_all_examples()
  154. for example in all_examples:
  155. if example['example_name'] == example_name:
  156. _test_particular_example(our_hint, example)
  157. def _test_particular_example(our_hint, ode_example, solver_flag=False):
  158. eq = ode_example['eq']
  159. expected_sol = ode_example['sol']
  160. example = ode_example['example_name']
  161. xfail = our_hint in ode_example['XFAIL']
  162. func = ode_example['func']
  163. result = {'msg': '', 'xpass_msg': ''}
  164. simplify_flag=ode_example['simplify_flag']
  165. checkodesol_XFAIL = ode_example['checkodesol_XFAIL']
  166. dsolve_too_slow = ode_example['dsolve_too_slow']
  167. checkodesol_too_slow = ode_example['checkodesol_too_slow']
  168. xpass = True
  169. if solver_flag:
  170. if our_hint not in classify_ode(eq, func):
  171. message = hint_message.format(example=example, eq=eq, our_hint=our_hint)
  172. raise AssertionError(message)
  173. if our_hint in classify_ode(eq, func):
  174. result['match_list'] = example
  175. try:
  176. if not (dsolve_too_slow):
  177. dsolve_sol = dsolve(eq, func, simplify=simplify_flag,hint=our_hint)
  178. else:
  179. if len(expected_sol)==1:
  180. dsolve_sol = expected_sol[0]
  181. else:
  182. dsolve_sol = expected_sol
  183. except Exception as e:
  184. dsolve_sol = []
  185. result['exception_list'] = example
  186. if not solver_flag:
  187. traceback.print_exc()
  188. result['msg'] = exception_msg.format(e=str(e), hint=our_hint, example=example, eq=eq)
  189. if solver_flag and not xfail:
  190. print(result['msg'])
  191. raise
  192. xpass = False
  193. if solver_flag and dsolve_sol!=[]:
  194. expect_sol_check = False
  195. if type(dsolve_sol)==list:
  196. for sub_sol in expected_sol:
  197. if sub_sol.has(Dummy):
  198. expect_sol_check = not _test_dummy_sol(sub_sol, dsolve_sol)
  199. else:
  200. expect_sol_check = sub_sol not in dsolve_sol
  201. if expect_sol_check:
  202. break
  203. else:
  204. expect_sol_check = dsolve_sol not in expected_sol
  205. for sub_sol in expected_sol:
  206. if sub_sol.has(Dummy):
  207. expect_sol_check = not _test_dummy_sol(sub_sol, dsolve_sol)
  208. if expect_sol_check:
  209. message = expected_sol_message.format(example=example, eq=eq, sol=expected_sol, dsolve_sol=dsolve_sol)
  210. raise AssertionError(message)
  211. expected_checkodesol = [(True, 0) for i in range(len(expected_sol))]
  212. if len(expected_sol) == 1:
  213. expected_checkodesol = (True, 0)
  214. if not (checkodesol_too_slow and ON_TRAVIS):
  215. if not checkodesol_XFAIL:
  216. if checkodesol(eq, dsolve_sol, func, solve_for_func=False) != expected_checkodesol:
  217. result['unsolve_list'] = example
  218. xpass = False
  219. message = dsol_incorrect_msg.format(hint=our_hint, eq=eq, sol=expected_sol,dsolve_sol=dsolve_sol)
  220. if solver_flag:
  221. message = checkodesol_msg.format(example=example, eq=eq)
  222. raise AssertionError(message)
  223. else:
  224. result['msg'] = 'AssertionError: ' + message
  225. if xpass and xfail:
  226. result['xpass_msg'] = example + "is now passing for the hint" + our_hint
  227. return result
  228. def _test_all_examples_for_one_hint(our_hint, all_examples=[], runxfail=None):
  229. if all_examples == []:
  230. all_examples = _get_all_examples()
  231. match_list, unsolve_list, exception_list = [], [], []
  232. for ode_example in all_examples:
  233. xfail = our_hint in ode_example['XFAIL']
  234. if runxfail and not xfail:
  235. continue
  236. if xfail:
  237. continue
  238. result = _test_particular_example(our_hint, ode_example)
  239. match_list += result.get('match_list',[])
  240. unsolve_list += result.get('unsolve_list',[])
  241. exception_list += result.get('exception_list',[])
  242. if runxfail is not None:
  243. msg = result['msg']
  244. if msg!='':
  245. print(result['msg'])
  246. # print(result.get('xpass_msg',''))
  247. if runxfail is None:
  248. match_count = len(match_list)
  249. solved = len(match_list)-len(unsolve_list)-len(exception_list)
  250. msg = check_hint_msg.format(hint=our_hint, matched=match_count, solve=solved, unsolve=unsolve_list, exceptions=exception_list)
  251. print(msg)
  252. def test_SingleODESolver():
  253. # Test that not implemented methods give NotImplementedError
  254. # Subclasses should override these methods.
  255. problem = SingleODEProblem(f(x).diff(x), f(x), x)
  256. solver = SingleODESolver(problem)
  257. raises(NotImplementedError, lambda: solver.matches())
  258. raises(NotImplementedError, lambda: solver.get_general_solution())
  259. raises(NotImplementedError, lambda: solver._matches())
  260. raises(NotImplementedError, lambda: solver._get_general_solution())
  261. # This ODE can not be solved by the FirstLinear solver. Here we test that
  262. # it does not match and the asking for a general solution gives
  263. # ODEMatchError
  264. problem = SingleODEProblem(f(x).diff(x) + f(x)*f(x), f(x), x)
  265. solver = FirstLinear(problem)
  266. raises(ODEMatchError, lambda: solver.get_general_solution())
  267. solver = FirstLinear(problem)
  268. assert solver.matches() is False
  269. #These are just test for order of ODE
  270. problem = SingleODEProblem(f(x).diff(x) + f(x), f(x), x)
  271. assert problem.order == 1
  272. problem = SingleODEProblem(f(x).diff(x,4) + f(x).diff(x,2) - f(x).diff(x,3), f(x), x)
  273. assert problem.order == 4
  274. problem = SingleODEProblem(f(x).diff(x, 3) + f(x).diff(x, 2) - f(x)**2, f(x), x)
  275. assert problem.is_autonomous == True
  276. problem = SingleODEProblem(f(x).diff(x, 3) + x*f(x).diff(x, 2) - f(x)**2, f(x), x)
  277. assert problem.is_autonomous == False
  278. def test_linear_coefficients():
  279. _ode_solver_test(_get_examples_ode_sol_linear_coefficients)
  280. @slow
  281. def test_1st_homogeneous_coeff_ode():
  282. #These were marked as test_1st_homogeneous_coeff_corner_case
  283. eq1 = f(x).diff(x) - f(x)/x
  284. c1 = classify_ode(eq1, f(x))
  285. eq2 = x*f(x).diff(x) - f(x)
  286. c2 = classify_ode(eq2, f(x))
  287. sdi = "1st_homogeneous_coeff_subs_dep_div_indep"
  288. sid = "1st_homogeneous_coeff_subs_indep_div_dep"
  289. assert sid not in c1 and sdi not in c1
  290. assert sid not in c2 and sdi not in c2
  291. _ode_solver_test(_get_examples_ode_sol_1st_homogeneous_coeff_subs_dep_div_indep)
  292. _ode_solver_test(_get_examples_ode_sol_1st_homogeneous_coeff_best)
  293. @slow
  294. def test_slow_examples_1st_homogeneous_coeff_ode():
  295. _ode_solver_test(_get_examples_ode_sol_1st_homogeneous_coeff_subs_dep_div_indep, run_slow_test=True)
  296. _ode_solver_test(_get_examples_ode_sol_1st_homogeneous_coeff_best, run_slow_test=True)
  297. @slow
  298. def test_nth_linear_constant_coeff_homogeneous():
  299. _ode_solver_test(_get_examples_ode_sol_nth_linear_constant_coeff_homogeneous)
  300. @slow
  301. def test_slow_examples_nth_linear_constant_coeff_homogeneous():
  302. _ode_solver_test(_get_examples_ode_sol_nth_linear_constant_coeff_homogeneous, run_slow_test=True)
  303. def test_Airy_equation():
  304. _ode_solver_test(_get_examples_ode_sol_2nd_linear_airy)
  305. @slow
  306. def test_lie_group():
  307. _ode_solver_test(_get_examples_ode_sol_lie_group)
  308. @slow
  309. def test_separable_reduced():
  310. df = f(x).diff(x)
  311. eq = (x / f(x))*df + tan(x**2*f(x) / (x**2*f(x) - 1))
  312. assert classify_ode(eq) == ('factorable', 'separable_reduced', 'lie_group',
  313. 'separable_reduced_Integral')
  314. _ode_solver_test(_get_examples_ode_sol_separable_reduced)
  315. @slow
  316. def test_slow_examples_separable_reduced():
  317. _ode_solver_test(_get_examples_ode_sol_separable_reduced, run_slow_test=True)
  318. @slow
  319. def test_2nd_2F1_hypergeometric():
  320. _ode_solver_test(_get_examples_ode_sol_2nd_2F1_hypergeometric)
  321. def test_2nd_2F1_hypergeometric_integral():
  322. eq = x*(x-1)*f(x).diff(x, 2) + (-1+ S(7)/2*x)*f(x).diff(x) + f(x)
  323. sol = Eq(f(x), (C1 + C2*Integral(exp(Integral((1 - x/2)/(x*(x - 1)), x))/(1 -
  324. x/2)**2, x))*exp(Integral(1/(x - 1), x)/4)*exp(-Integral(7/(x -
  325. 1), x)/4)*hyper((S(1)/2, -1), (1,), x))
  326. assert sol == dsolve(eq, hint='2nd_hypergeometric_Integral')
  327. assert checkodesol(eq, sol) == (True, 0)
  328. @slow
  329. def test_2nd_nonlinear_autonomous_conserved():
  330. _ode_solver_test(_get_examples_ode_sol_2nd_nonlinear_autonomous_conserved)
  331. def test_2nd_nonlinear_autonomous_conserved_integral():
  332. eq = f(x).diff(x, 2) + asin(f(x))
  333. actual = [Eq(Integral(1/sqrt(C1 - 2*Integral(asin(_u), _u)), (_u, f(x))), C2 + x),
  334. Eq(Integral(1/sqrt(C1 - 2*Integral(asin(_u), _u)), (_u, f(x))), C2 - x)]
  335. solved = dsolve(eq, hint='2nd_nonlinear_autonomous_conserved_Integral', simplify=False)
  336. for a,s in zip(actual, solved):
  337. assert a.dummy_eq(s)
  338. # checkodesol unable to simplify solutions with f(x) in an integral equation
  339. assert checkodesol(eq, [s.doit() for s in solved]) == [(True, 0), (True, 0)]
  340. def test_2nd_linear_bessel_equation():
  341. _ode_solver_test(_get_examples_ode_sol_2nd_linear_bessel)
  342. @slow
  343. def test_nth_algebraic():
  344. eqn = f(x) + f(x)*f(x).diff(x)
  345. solns = [Eq(f(x), exp(x)),
  346. Eq(f(x), C1*exp(C2*x))]
  347. solns_final = _remove_redundant_solutions(eqn, solns, 2, x)
  348. assert solns_final == [Eq(f(x), C1*exp(C2*x))]
  349. _ode_solver_test(_get_examples_ode_sol_nth_algebraic)
  350. @slow
  351. def test_slow_examples_nth_linear_constant_coeff_var_of_parameters():
  352. _ode_solver_test(_get_examples_ode_sol_nth_linear_var_of_parameters, run_slow_test=True)
  353. def test_nth_linear_constant_coeff_var_of_parameters():
  354. _ode_solver_test(_get_examples_ode_sol_nth_linear_var_of_parameters)
  355. @slow
  356. def test_nth_linear_constant_coeff_variation_of_parameters__integral():
  357. # solve_variation_of_parameters shouldn't attempt to simplify the
  358. # Wronskian if simplify=False. If wronskian() ever gets good enough
  359. # to simplify the result itself, this test might fail.
  360. our_hint = 'nth_linear_constant_coeff_variation_of_parameters_Integral'
  361. eq = f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x) - 2*x - exp(I*x)
  362. sol_simp = dsolve(eq, f(x), hint=our_hint, simplify=True)
  363. sol_nsimp = dsolve(eq, f(x), hint=our_hint, simplify=False)
  364. assert sol_simp != sol_nsimp
  365. assert checkodesol(eq, sol_simp, order=5, solve_for_func=False) == (True, 0)
  366. assert checkodesol(eq, sol_simp, order=5, solve_for_func=False) == (True, 0)
  367. @slow
  368. def test_slow_examples_1st_exact():
  369. _ode_solver_test(_get_examples_ode_sol_1st_exact, run_slow_test=True)
  370. @slow
  371. def test_1st_exact():
  372. _ode_solver_test(_get_examples_ode_sol_1st_exact)
  373. def test_1st_exact_integral():
  374. eq = cos(f(x)) - (x*sin(f(x)) - f(x)**2)*f(x).diff(x)
  375. sol_1 = dsolve(eq, f(x), simplify=False, hint='1st_exact_Integral')
  376. assert checkodesol(eq, sol_1, order=1, solve_for_func=False)
  377. @slow
  378. def test_slow_examples_nth_order_reducible():
  379. _ode_solver_test(_get_examples_ode_sol_nth_order_reducible, run_slow_test=True)
  380. @slow
  381. def test_slow_examples_nth_linear_constant_coeff_undetermined_coefficients():
  382. _ode_solver_test(_get_examples_ode_sol_nth_linear_undetermined_coefficients, run_slow_test=True)
  383. @slow
  384. def test_slow_examples_separable():
  385. _ode_solver_test(_get_examples_ode_sol_separable, run_slow_test=True)
  386. def test_nth_linear_constant_coeff_undetermined_coefficients():
  387. #issue-https://github.com/sympy/sympy/issues/5787
  388. # This test case is to show the classification of imaginary constants under
  389. # nth_linear_constant_coeff_undetermined_coefficients
  390. eq = Eq(diff(f(x), x), I*f(x) + S.Half - I)
  391. our_hint = 'nth_linear_constant_coeff_undetermined_coefficients'
  392. assert our_hint in classify_ode(eq)
  393. _ode_solver_test(_get_examples_ode_sol_nth_linear_undetermined_coefficients)
  394. def test_nth_order_reducible():
  395. F = lambda eq: NthOrderReducible(SingleODEProblem(eq, f(x), x))._matches()
  396. D = Derivative
  397. assert F(D(y*f(x), x, y) + D(f(x), x)) == False
  398. assert F(D(y*f(y), y, y) + D(f(y), y)) == False
  399. assert F(f(x)*D(f(x), x) + D(f(x), x, 2))== False
  400. assert F(D(x*f(y), y, 2) + D(u*y*f(x), x, 3)) == False # no simplification by design
  401. assert F(D(f(y), y, 2) + D(f(y), y, 3) + D(f(x), x, 4)) == False
  402. assert F(D(f(x), x, 2) + D(f(x), x, 3)) == True
  403. _ode_solver_test(_get_examples_ode_sol_nth_order_reducible)
  404. @slow
  405. def test_separable():
  406. _ode_solver_test(_get_examples_ode_sol_separable)
  407. @slow
  408. def test_factorable():
  409. assert integrate(-asin(f(2*x)+pi), x) == -Integral(asin(pi + f(2*x)), x)
  410. _ode_solver_test(_get_examples_ode_sol_factorable)
  411. @slow
  412. def test_slow_examples_factorable():
  413. _ode_solver_test(_get_examples_ode_sol_factorable, run_slow_test=True)
  414. def test_Riccati_special_minus2():
  415. _ode_solver_test(_get_examples_ode_sol_riccati)
  416. @slow
  417. def test_1st_rational_riccati():
  418. _ode_solver_test(_get_examples_ode_sol_1st_rational_riccati)
  419. def test_Bernoulli():
  420. _ode_solver_test(_get_examples_ode_sol_bernoulli)
  421. def test_1st_linear():
  422. _ode_solver_test(_get_examples_ode_sol_1st_linear)
  423. def test_almost_linear():
  424. _ode_solver_test(_get_examples_ode_sol_almost_linear)
  425. def test_Liouville_ODE():
  426. hint = 'Liouville'
  427. not_Liouville1 = classify_ode(diff(f(x), x)/x + f(x)*diff(f(x), x, x)/2 -
  428. diff(f(x), x)**2/2, f(x))
  429. not_Liouville2 = classify_ode(diff(f(x), x)/x + diff(f(x), x, x)/2 -
  430. x*diff(f(x), x)**2/2, f(x))
  431. assert hint not in not_Liouville1
  432. assert hint not in not_Liouville2
  433. assert hint + '_Integral' not in not_Liouville1
  434. assert hint + '_Integral' not in not_Liouville2
  435. _ode_solver_test(_get_examples_ode_sol_liouville)
  436. def test_nth_order_linear_euler_eq_homogeneous():
  437. x, t, a, b, c = symbols('x t a b c')
  438. y = Function('y')
  439. our_hint = "nth_linear_euler_eq_homogeneous"
  440. eq = diff(f(t), t, 4)*t**4 - 13*diff(f(t), t, 2)*t**2 + 36*f(t)
  441. assert our_hint in classify_ode(eq)
  442. eq = a*y(t) + b*t*diff(y(t), t) + c*t**2*diff(y(t), t, 2)
  443. assert our_hint in classify_ode(eq)
  444. _ode_solver_test(_get_examples_ode_sol_euler_homogeneous)
  445. def test_nth_order_linear_euler_eq_nonhomogeneous_undetermined_coefficients():
  446. x, t = symbols('x t')
  447. a, b, c, d = symbols('a b c d', integer=True)
  448. our_hint = "nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients"
  449. eq = x**4*diff(f(x), x, 4) - 13*x**2*diff(f(x), x, 2) + 36*f(x) + x
  450. assert our_hint in classify_ode(eq, f(x))
  451. eq = a*x**2*diff(f(x), x, 2) + b*x*diff(f(x), x) + c*f(x) + d*log(x)
  452. assert our_hint in classify_ode(eq, f(x))
  453. _ode_solver_test(_get_examples_ode_sol_euler_undetermined_coeff)
  454. def test_nth_order_linear_euler_eq_nonhomogeneous_variation_of_parameters():
  455. x, t = symbols('x, t')
  456. a, b, c, d = symbols('a, b, c, d', integer=True)
  457. our_hint = "nth_linear_euler_eq_nonhomogeneous_variation_of_parameters"
  458. eq = Eq(x**2*diff(f(x),x,2) - 8*x*diff(f(x),x) + 12*f(x), x**2)
  459. assert our_hint in classify_ode(eq, f(x))
  460. eq = Eq(a*x**3*diff(f(x),x,3) + b*x**2*diff(f(x),x,2) + c*x*diff(f(x),x) + d*f(x), x*log(x))
  461. assert our_hint in classify_ode(eq, f(x))
  462. _ode_solver_test(_get_examples_ode_sol_euler_var_para)
  463. @_add_example_keys
  464. def _get_examples_ode_sol_euler_homogeneous():
  465. r1, r2, r3, r4, r5 = [rootof(x**5 - 14*x**4 + 71*x**3 - 154*x**2 + 120*x - 1, n) for n in range(5)]
  466. return {
  467. 'hint': "nth_linear_euler_eq_homogeneous",
  468. 'func': f(x),
  469. 'examples':{
  470. 'euler_hom_01': {
  471. 'eq': Eq(-3*diff(f(x), x)*x + 2*x**2*diff(f(x), x, x), 0),
  472. 'sol': [Eq(f(x), C1 + C2*x**Rational(5, 2))],
  473. },
  474. 'euler_hom_02': {
  475. 'eq': Eq(3*f(x) - 5*diff(f(x), x)*x + 2*x**2*diff(f(x), x, x), 0),
  476. 'sol': [Eq(f(x), C1*sqrt(x) + C2*x**3)]
  477. },
  478. 'euler_hom_03': {
  479. 'eq': Eq(4*f(x) + 5*diff(f(x), x)*x + x**2*diff(f(x), x, x), 0),
  480. 'sol': [Eq(f(x), (C1 + C2*log(x))/x**2)]
  481. },
  482. 'euler_hom_04': {
  483. 'eq': Eq(6*f(x) - 6*diff(f(x), x)*x + 1*x**2*diff(f(x), x, x) + x**3*diff(f(x), x, x, x), 0),
  484. 'sol': [Eq(f(x), C1/x**2 + C2*x + C3*x**3)]
  485. },
  486. 'euler_hom_05': {
  487. 'eq': Eq(-125*f(x) + 61*diff(f(x), x)*x - 12*x**2*diff(f(x), x, x) + x**3*diff(f(x), x, x, x), 0),
  488. 'sol': [Eq(f(x), x**5*(C1 + C2*log(x) + C3*log(x)**2))]
  489. },
  490. 'euler_hom_06': {
  491. 'eq': x**2*diff(f(x), x, 2) + x*diff(f(x), x) - 9*f(x),
  492. 'sol': [Eq(f(x), C1*x**-3 + C2*x**3)]
  493. },
  494. 'euler_hom_07': {
  495. 'eq': sin(x)*x**2*f(x).diff(x, 2) + sin(x)*x*f(x).diff(x) + sin(x)*f(x),
  496. 'sol': [Eq(f(x), C1*sin(log(x)) + C2*cos(log(x)))],
  497. 'XFAIL': ['2nd_power_series_regular','nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients']
  498. },
  499. 'euler_hom_08': {
  500. 'eq': x**6 * f(x).diff(x, 6) - x*f(x).diff(x) + f(x),
  501. 'sol': [Eq(f(x), C1*x + C2*x**r1 + C3*x**r2 + C4*x**r3 + C5*x**r4 + C6*x**r5)],
  502. 'checkodesol_XFAIL':True
  503. },
  504. #This example is from issue: https://github.com/sympy/sympy/issues/15237 #This example is from issue:
  505. # https://github.com/sympy/sympy/issues/15237
  506. 'euler_hom_09': {
  507. 'eq': Derivative(x*f(x), x, x, x),
  508. 'sol': [Eq(f(x), C1 + C2/x + C3*x)],
  509. },
  510. }
  511. }
  512. @_add_example_keys
  513. def _get_examples_ode_sol_euler_undetermined_coeff():
  514. return {
  515. 'hint': "nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients",
  516. 'func': f(x),
  517. 'examples':{
  518. 'euler_undet_01': {
  519. 'eq': Eq(x**2*diff(f(x), x, x) + x*diff(f(x), x), 1),
  520. 'sol': [Eq(f(x), C1 + C2*log(x) + log(x)**2/2)]
  521. },
  522. 'euler_undet_02': {
  523. 'eq': Eq(x**2*diff(f(x), x, x) - 2*x*diff(f(x), x) + 2*f(x), x**3),
  524. 'sol': [Eq(f(x), x*(C1 + C2*x + Rational(1, 2)*x**2))]
  525. },
  526. 'euler_undet_03': {
  527. 'eq': Eq(x**2*diff(f(x), x, x) - x*diff(f(x), x) - 3*f(x), log(x)/x),
  528. 'sol': [Eq(f(x), (C1 + C2*x**4 - log(x)**2/8 - log(x)/16)/x)]
  529. },
  530. 'euler_undet_04': {
  531. 'eq': Eq(x**2*diff(f(x), x, x) + 3*x*diff(f(x), x) - 8*f(x), log(x)**3 - log(x)),
  532. 'sol': [Eq(f(x), C1/x**4 + C2*x**2 - Rational(1,8)*log(x)**3 - Rational(3,32)*log(x)**2 - Rational(1,64)*log(x) - Rational(7, 256))]
  533. },
  534. 'euler_undet_05': {
  535. 'eq': Eq(x**3*diff(f(x), x, x, x) - 3*x**2*diff(f(x), x, x) + 6*x*diff(f(x), x) - 6*f(x), log(x)),
  536. 'sol': [Eq(f(x), C1*x + C2*x**2 + C3*x**3 - Rational(1, 6)*log(x) - Rational(11, 36))]
  537. },
  538. #Below examples were added for the issue: https://github.com/sympy/sympy/issues/5096
  539. 'euler_undet_06': {
  540. 'eq': 2*x**2*f(x).diff(x, 2) + f(x) + sqrt(2*x)*sin(log(2*x)/2),
  541. 'sol': [Eq(f(x), sqrt(x)*(C1*sin(log(x)/2) + C2*cos(log(x)/2) + sqrt(2)*log(x)*cos(log(2*x)/2)/2))]
  542. },
  543. 'euler_undet_07': {
  544. 'eq': 2*x**2*f(x).diff(x, 2) + f(x) + sin(log(2*x)/2),
  545. 'sol': [Eq(f(x), C1*sqrt(x)*sin(log(x)/2) + C2*sqrt(x)*cos(log(x)/2) - 2*sin(log(2*x)/2)/5 - 4*cos(log(2*x)/2)/5)]
  546. },
  547. }
  548. }
  549. @_add_example_keys
  550. def _get_examples_ode_sol_euler_var_para():
  551. return {
  552. 'hint': "nth_linear_euler_eq_nonhomogeneous_variation_of_parameters",
  553. 'func': f(x),
  554. 'examples':{
  555. 'euler_var_01': {
  556. 'eq': Eq(x**2*Derivative(f(x), x, x) - 2*x*Derivative(f(x), x) + 2*f(x), x**4),
  557. 'sol': [Eq(f(x), x*(C1 + C2*x + x**3/6))]
  558. },
  559. 'euler_var_02': {
  560. 'eq': Eq(3*x**2*diff(f(x), x, x) + 6*x*diff(f(x), x) - 6*f(x), x**3*exp(x)),
  561. 'sol': [Eq(f(x), C1/x**2 + C2*x + x*exp(x)/3 - 4*exp(x)/3 + 8*exp(x)/(3*x) - 8*exp(x)/(3*x**2))]
  562. },
  563. 'euler_var_03': {
  564. 'eq': Eq(x**2*Derivative(f(x), x, x) - 2*x*Derivative(f(x), x) + 2*f(x), x**4*exp(x)),
  565. 'sol': [Eq(f(x), x*(C1 + C2*x + x*exp(x) - 2*exp(x)))]
  566. },
  567. 'euler_var_04': {
  568. 'eq': x**2*Derivative(f(x), x, x) - 2*x*Derivative(f(x), x) + 2*f(x) - log(x),
  569. 'sol': [Eq(f(x), C1*x + C2*x**2 + log(x)/2 + Rational(3, 4))]
  570. },
  571. 'euler_var_05': {
  572. 'eq': -exp(x) + (x*Derivative(f(x), (x, 2)) + Derivative(f(x), x))/x,
  573. 'sol': [Eq(f(x), C1 + C2*log(x) + exp(x) - Ei(x))]
  574. },
  575. 'euler_var_06': {
  576. 'eq': x**2 * f(x).diff(x, 2) + x * f(x).diff(x) + 4 * f(x) - 1/x,
  577. 'sol': [Eq(f(x), C1*sin(2*log(x)) + C2*cos(2*log(x)) + 1/(5*x))]
  578. },
  579. }
  580. }
  581. @_add_example_keys
  582. def _get_examples_ode_sol_bernoulli():
  583. # Type: Bernoulli, f'(x) + p(x)*f(x) == q(x)*f(x)**n
  584. return {
  585. 'hint': "Bernoulli",
  586. 'func': f(x),
  587. 'examples':{
  588. 'bernoulli_01': {
  589. 'eq': Eq(x*f(x).diff(x) + f(x) - f(x)**2, 0),
  590. 'sol': [Eq(f(x), 1/(C1*x + 1))],
  591. 'XFAIL': ['separable_reduced']
  592. },
  593. 'bernoulli_02': {
  594. 'eq': f(x).diff(x) - y*f(x),
  595. 'sol': [Eq(f(x), C1*exp(x*y))]
  596. },
  597. 'bernoulli_03': {
  598. 'eq': f(x)*f(x).diff(x) - 1,
  599. 'sol': [Eq(f(x), -sqrt(C1 + 2*x)), Eq(f(x), sqrt(C1 + 2*x))]
  600. },
  601. }
  602. }
  603. @_add_example_keys
  604. def _get_examples_ode_sol_riccati():
  605. # Type: Riccati special alpha = -2, a*dy/dx + b*y**2 + c*y/x +d/x**2
  606. return {
  607. 'hint': "Riccati_special_minus2",
  608. 'func': f(x),
  609. 'examples':{
  610. 'riccati_01': {
  611. 'eq': 2*f(x).diff(x) + f(x)**2 - f(x)/x + 3*x**(-2),
  612. 'sol': [Eq(f(x), (-sqrt(3)*tan(C1 + sqrt(3)*log(x)/4) + 3)/(2*x))],
  613. },
  614. },
  615. }
  616. @_add_example_keys
  617. def _get_examples_ode_sol_1st_rational_riccati():
  618. # Type: 1st Order Rational Riccati, dy/dx = a + b*y + c*y**2,
  619. # a, b, c are rational functions of x
  620. return {
  621. 'hint': "1st_rational_riccati",
  622. 'func': f(x),
  623. 'examples':{
  624. # a(x) is a constant
  625. "rational_riccati_01": {
  626. "eq": Eq(f(x).diff(x) + f(x)**2 - 2, 0),
  627. "sol": [Eq(f(x), sqrt(2)*(-C1 - exp(2*sqrt(2)*x))/(C1 - exp(2*sqrt(2)*x)))]
  628. },
  629. # a(x) is a constant
  630. "rational_riccati_02": {
  631. "eq": f(x)**2 + Derivative(f(x), x) + 4*f(x)/x + 2/x**2,
  632. "sol": [Eq(f(x), (-2*C1 - x)/(x*(C1 + x)))]
  633. },
  634. # a(x) is a constant
  635. "rational_riccati_03": {
  636. "eq": 2*x**2*Derivative(f(x), x) - x*(4*f(x) + Derivative(f(x), x) - 4) + (f(x) - 1)*f(x),
  637. "sol": [Eq(f(x), (C1 + 2*x**2)/(C1 + x))]
  638. },
  639. # Constant coefficients
  640. "rational_riccati_04": {
  641. "eq": f(x).diff(x) - 6 - 5*f(x) - f(x)**2,
  642. "sol": [Eq(f(x), (-2*C1 + 3*exp(x))/(C1 - exp(x)))]
  643. },
  644. # One pole of multiplicity 2
  645. "rational_riccati_05": {
  646. "eq": x**2 - (2*x + 1/x)*f(x) + f(x)**2 + Derivative(f(x), x),
  647. "sol": [Eq(f(x), x*(C1 + x**2 + 1)/(C1 + x**2 - 1))]
  648. },
  649. # One pole of multiplicity 2
  650. "rational_riccati_06": {
  651. "eq": x**4*Derivative(f(x), x) + x**2 - x*(2*f(x)**2 + Derivative(f(x), x)) + f(x),
  652. "sol": [Eq(f(x), x*(C1*x - x + 1)/(C1 + x**2 - 1))]
  653. },
  654. # Multiple poles of multiplicity 2
  655. "rational_riccati_07": {
  656. "eq": -f(x)**2 + Derivative(f(x), x) + (15*x**2 - 20*x + 7)/((x - 1)**2*(2*x \
  657. - 1)**2),
  658. "sol": [Eq(f(x), (9*C1*x - 6*C1 - 15*x**5 + 60*x**4 - 94*x**3 + 72*x**2 - \
  659. 33*x + 8)/(6*C1*x**2 - 9*C1*x + 3*C1 + 6*x**6 - 29*x**5 + 57*x**4 - \
  660. 58*x**3 + 28*x**2 - 3*x - 1))]
  661. },
  662. # Imaginary poles
  663. "rational_riccati_08": {
  664. "eq": Derivative(f(x), x) + (3*x**2 + 1)*f(x)**2/x + (6*x**2 - x + 3)*f(x)/(x*(x \
  665. - 1)) + (3*x**2 - 2*x + 2)/(x*(x - 1)**2),
  666. "sol": [Eq(f(x), (-C1 - x**3 + x**2 - 2*x + 1)/(C1*x - C1 + x**4 - x**3 + x**2 - \
  667. 2*x + 1))],
  668. },
  669. # Imaginary coefficients in equation
  670. "rational_riccati_09": {
  671. "eq": Derivative(f(x), x) - 2*I*(f(x)**2 + 1)/x,
  672. "sol": [Eq(f(x), (-I*C1 + I*x**4 + I)/(C1 + x**4 - 1))]
  673. },
  674. # Regression: linsolve returning empty solution
  675. # Large value of m (> 10)
  676. "rational_riccati_10": {
  677. "eq": Eq(Derivative(f(x), x), x*f(x)/(S(3)/2 - 2*x) + (x/2 - S(1)/3)*f(x)**2/\
  678. (2*x/3 - S(1)/2) - S(5)/4 + (281*x**2 - 1260*x + 756)/(16*x**3 - 12*x**2)),
  679. "sol": [Eq(f(x), (40*C1*x**14 + 28*C1*x**13 + 420*C1*x**12 + 2940*C1*x**11 + \
  680. 18480*C1*x**10 + 103950*C1*x**9 + 519750*C1*x**8 + 2286900*C1*x**7 + \
  681. 8731800*C1*x**6 + 28378350*C1*x**5 + 76403250*C1*x**4 + 163721250*C1*x**3 \
  682. + 261954000*C1*x**2 + 278326125*C1*x + 147349125*C1 + x*exp(2*x) - 9*exp(2*x) \
  683. )/(x*(24*C1*x**13 + 140*C1*x**12 + 840*C1*x**11 + 4620*C1*x**10 + 23100*C1*x**9 \
  684. + 103950*C1*x**8 + 415800*C1*x**7 + 1455300*C1*x**6 + 4365900*C1*x**5 + \
  685. 10914750*C1*x**4 + 21829500*C1*x**3 + 32744250*C1*x**2 + 32744250*C1*x + \
  686. 16372125*C1 - exp(2*x))))]
  687. }
  688. }
  689. }
  690. @_add_example_keys
  691. def _get_examples_ode_sol_1st_linear():
  692. # Type: first order linear form f'(x)+p(x)f(x)=q(x)
  693. return {
  694. 'hint': "1st_linear",
  695. 'func': f(x),
  696. 'examples':{
  697. 'linear_01': {
  698. 'eq': Eq(f(x).diff(x) + x*f(x), x**2),
  699. 'sol': [Eq(f(x), (C1 + x*exp(x**2/2)- sqrt(2)*sqrt(pi)*erfi(sqrt(2)*x/2)/2)*exp(-x**2/2))],
  700. },
  701. },
  702. }
  703. @_add_example_keys
  704. def _get_examples_ode_sol_factorable():
  705. """ some hints are marked as xfail for examples because they missed additional algebraic solution
  706. which could be found by Factorable hint. Fact_01 raise exception for
  707. nth_linear_constant_coeff_undetermined_coefficients"""
  708. y = Dummy('y')
  709. a0,a1,a2,a3,a4 = symbols('a0, a1, a2, a3, a4')
  710. return {
  711. 'hint': "factorable",
  712. 'func': f(x),
  713. 'examples':{
  714. 'fact_01': {
  715. 'eq': f(x) + f(x)*f(x).diff(x),
  716. 'sol': [Eq(f(x), 0), Eq(f(x), C1 - x)],
  717. 'XFAIL': ['separable', '1st_exact', '1st_linear', 'Bernoulli', '1st_homogeneous_coeff_best',
  718. '1st_homogeneous_coeff_subs_indep_div_dep', '1st_homogeneous_coeff_subs_dep_div_indep',
  719. 'lie_group', 'nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients',
  720. 'nth_linear_constant_coeff_variation_of_parameters',
  721. 'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters',
  722. 'nth_linear_constant_coeff_undetermined_coefficients']
  723. },
  724. 'fact_02': {
  725. 'eq': f(x)*(f(x).diff(x)+f(x)*x+2),
  726. 'sol': [Eq(f(x), (C1 - sqrt(2)*sqrt(pi)*erfi(sqrt(2)*x/2))*exp(-x**2/2)), Eq(f(x), 0)],
  727. 'XFAIL': ['Bernoulli', '1st_linear', 'lie_group']
  728. },
  729. 'fact_03': {
  730. 'eq': (f(x).diff(x)+f(x)*x**2)*(f(x).diff(x, 2) + x*f(x)),
  731. 'sol': [Eq(f(x), C1*airyai(-x) + C2*airybi(-x)),Eq(f(x), C1*exp(-x**3/3))]
  732. },
  733. 'fact_04': {
  734. 'eq': (f(x).diff(x)+f(x)*x**2)*(f(x).diff(x, 2) + f(x)),
  735. 'sol': [Eq(f(x), C1*exp(-x**3/3)), Eq(f(x), C1*sin(x) + C2*cos(x))]
  736. },
  737. 'fact_05': {
  738. 'eq': (f(x).diff(x)**2-1)*(f(x).diff(x)**2-4),
  739. 'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x), Eq(f(x), C1 + 2*x), Eq(f(x), C1 - 2*x)]
  740. },
  741. 'fact_06': {
  742. 'eq': (f(x).diff(x, 2)-exp(f(x)))*f(x).diff(x),
  743. 'sol': [
  744. Eq(f(x), log(C1/(cos(C1*sqrt(-1/C1)*(C2 + x)) - 1))),
  745. Eq(f(x), log(C1/(cos(C1*sqrt(-1/C1)*(C2 - x)) - 1))),
  746. Eq(f(x), C1)
  747. ],
  748. 'slow': True,
  749. },
  750. 'fact_07': {
  751. 'eq': (f(x).diff(x)**2-1)*(f(x)*f(x).diff(x)-1),
  752. 'sol': [Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2*x)),Eq(f(x), sqrt(C1 + 2*x)), Eq(f(x), C1 + x)]
  753. },
  754. 'fact_08': {
  755. 'eq': Derivative(f(x), x)**4 - 2*Derivative(f(x), x)**2 + 1,
  756. 'sol': [Eq(f(x), C1 - x), Eq(f(x), C1 + x)]
  757. },
  758. 'fact_09': {
  759. 'eq': f(x)**2*Derivative(f(x), x)**6 - 2*f(x)**2*Derivative(f(x),
  760. x)**4 + f(x)**2*Derivative(f(x), x)**2 - 2*f(x)*Derivative(f(x),
  761. x)**5 + 4*f(x)*Derivative(f(x), x)**3 - 2*f(x)*Derivative(f(x),
  762. x) + Derivative(f(x), x)**4 - 2*Derivative(f(x), x)**2 + 1,
  763. 'sol': [
  764. Eq(f(x), C1 - x), Eq(f(x), -sqrt(C1 + 2*x)),
  765. Eq(f(x), sqrt(C1 + 2*x)), Eq(f(x), C1 + x)
  766. ]
  767. },
  768. 'fact_10': {
  769. 'eq': x**4*f(x)**2 + 2*x**4*f(x)*Derivative(f(x), (x, 2)) + x**4*Derivative(f(x),
  770. (x, 2))**2 + 2*x**3*f(x)*Derivative(f(x), x) + 2*x**3*Derivative(f(x),
  771. x)*Derivative(f(x), (x, 2)) - 7*x**2*f(x)**2 - 7*x**2*f(x)*Derivative(f(x),
  772. (x, 2)) + x**2*Derivative(f(x), x)**2 - 7*x*f(x)*Derivative(f(x), x) + 12*f(x)**2,
  773. 'sol': [
  774. Eq(f(x), C1*besselj(2, x) + C2*bessely(2, x)),
  775. Eq(f(x), C1*besselj(sqrt(3), x) + C2*bessely(sqrt(3), x))
  776. ],
  777. 'slow': True,
  778. },
  779. 'fact_11': {
  780. 'eq': (f(x).diff(x, 2)-exp(f(x)))*(f(x).diff(x, 2)+exp(f(x))),
  781. 'sol': [
  782. Eq(f(x), log(C1/(cos(C1*sqrt(-1/C1)*(C2 + x)) - 1))),
  783. Eq(f(x), log(C1/(cos(C1*sqrt(-1/C1)*(C2 - x)) - 1))),
  784. Eq(f(x), log(C1/(1 - cos(C1*sqrt(-1/C1)*(C2 + x))))),
  785. Eq(f(x), log(C1/(1 - cos(C1*sqrt(-1/C1)*(C2 - x)))))
  786. ],
  787. 'dsolve_too_slow': True,
  788. },
  789. #Below examples were added for the issue: https://github.com/sympy/sympy/issues/15889
  790. 'fact_12': {
  791. 'eq': exp(f(x).diff(x))-f(x)**2,
  792. 'sol': [Eq(NonElementaryIntegral(1/log(y**2), (y, f(x))), C1 + x)],
  793. 'XFAIL': ['lie_group'] #It shows not implemented error for lie_group.
  794. },
  795. 'fact_13': {
  796. 'eq': f(x).diff(x)**2 - f(x)**3,
  797. 'sol': [Eq(f(x), 4/(C1**2 - 2*C1*x + x**2))],
  798. 'XFAIL': ['lie_group'] #It shows not implemented error for lie_group.
  799. },
  800. 'fact_14': {
  801. 'eq': f(x).diff(x)**2 - f(x),
  802. 'sol': [Eq(f(x), C1**2/4 - C1*x/2 + x**2/4)]
  803. },
  804. 'fact_15': {
  805. 'eq': f(x).diff(x)**2 - f(x)**2,
  806. 'sol': [Eq(f(x), C1*exp(x)), Eq(f(x), C1*exp(-x))]
  807. },
  808. 'fact_16': {
  809. 'eq': f(x).diff(x)**2 - f(x)**3,
  810. 'sol': [Eq(f(x), 4/(C1**2 - 2*C1*x + x**2))],
  811. },
  812. # kamke ode 1.1
  813. 'fact_17': {
  814. 'eq': f(x).diff(x)-(a4*x**4 + a3*x**3 + a2*x**2 + a1*x + a0)**(-1/2),
  815. 'sol': [Eq(f(x), C1 + Integral(1/sqrt(a0 + a1*x + a2*x**2 + a3*x**3 + a4*x**4), x))],
  816. 'slow': True
  817. },
  818. # This is from issue: https://github.com/sympy/sympy/issues/9446
  819. 'fact_18':{
  820. 'eq': Eq(f(2 * x), sin(Derivative(f(x)))),
  821. 'sol': [Eq(f(x), C1 + Integral(pi - asin(f(2*x)), x)), Eq(f(x), C1 + Integral(asin(f(2*x)), x))],
  822. 'checkodesol_XFAIL':True
  823. },
  824. # This is from issue: https://github.com/sympy/sympy/issues/7093
  825. 'fact_19': {
  826. 'eq': Derivative(f(x), x)**2 - x**3,
  827. 'sol': [Eq(f(x), C1 - 2*x**Rational(5,2)/5), Eq(f(x), C1 + 2*x**Rational(5,2)/5)],
  828. },
  829. 'fact_20': {
  830. 'eq': x*f(x).diff(x, 2) - x*f(x),
  831. 'sol': [Eq(f(x), C1*exp(-x) + C2*exp(x))],
  832. },
  833. }
  834. }
  835. @_add_example_keys
  836. def _get_examples_ode_sol_almost_linear():
  837. from sympy.functions.special.error_functions import Ei
  838. A = Symbol('A', positive=True)
  839. f = Function('f')
  840. d = f(x).diff(x)
  841. return {
  842. 'hint': "almost_linear",
  843. 'func': f(x),
  844. 'examples':{
  845. 'almost_lin_01': {
  846. 'eq': x**2*f(x)**2*d + f(x)**3 + 1,
  847. 'sol': [Eq(f(x), (C1*exp(3/x) - 1)**Rational(1, 3)),
  848. Eq(f(x), (-1 - sqrt(3)*I)*(C1*exp(3/x) - 1)**Rational(1, 3)/2),
  849. Eq(f(x), (-1 + sqrt(3)*I)*(C1*exp(3/x) - 1)**Rational(1, 3)/2)],
  850. },
  851. 'almost_lin_02': {
  852. 'eq': x*f(x)*d + 2*x*f(x)**2 + 1,
  853. 'sol': [Eq(f(x), -sqrt((C1 - 2*Ei(4*x))*exp(-4*x))), Eq(f(x), sqrt((C1 - 2*Ei(4*x))*exp(-4*x)))]
  854. },
  855. 'almost_lin_03': {
  856. 'eq': x*d + x*f(x) + 1,
  857. 'sol': [Eq(f(x), (C1 - Ei(x))*exp(-x))]
  858. },
  859. 'almost_lin_04': {
  860. 'eq': x*exp(f(x))*d + exp(f(x)) + 3*x,
  861. 'sol': [Eq(f(x), log(C1/x - x*Rational(3, 2)))],
  862. },
  863. 'almost_lin_05': {
  864. 'eq': x + A*(x + diff(f(x), x) + f(x)) + diff(f(x), x) + f(x) + 2,
  865. 'sol': [Eq(f(x), (C1 + Piecewise(
  866. (x, Eq(A + 1, 0)), ((-A*x + A - x - 1)*exp(x)/(A + 1), True)))*exp(-x))],
  867. },
  868. }
  869. }
  870. @_add_example_keys
  871. def _get_examples_ode_sol_liouville():
  872. n = Symbol('n')
  873. _y = Dummy('y')
  874. return {
  875. 'hint': "Liouville",
  876. 'func': f(x),
  877. 'examples':{
  878. 'liouville_01': {
  879. 'eq': diff(f(x), x)/x + diff(f(x), x, x)/2 - diff(f(x), x)**2/2,
  880. 'sol': [Eq(f(x), log(x/(C1 + C2*x)))],
  881. },
  882. 'liouville_02': {
  883. 'eq': diff(x*exp(-f(x)), x, x),
  884. 'sol': [Eq(f(x), log(x/(C1 + C2*x)))]
  885. },
  886. 'liouville_03': {
  887. '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(),
  888. 'sol': [Eq(f(x), log(x/(C1 + C2*x)))]
  889. },
  890. 'liouville_04': {
  891. 'eq': diff(f(x), x, x) + 1/f(x)*(diff(f(x), x))**2 + 1/x*diff(f(x), x),
  892. 'sol': [Eq(f(x), -sqrt(C1 + C2*log(x))), Eq(f(x), sqrt(C1 + C2*log(x)))],
  893. },
  894. 'liouville_05': {
  895. 'eq': x*diff(f(x), x, x) + x/f(x)*diff(f(x), x)**2 + x*diff(f(x), x),
  896. 'sol': [Eq(f(x), -sqrt(C1 + C2*exp(-x))), Eq(f(x), sqrt(C1 + C2*exp(-x)))],
  897. },
  898. 'liouville_06': {
  899. 'eq': Eq((x*exp(f(x))).diff(x, x), 0),
  900. 'sol': [Eq(f(x), log(C1 + C2/x))],
  901. },
  902. 'liouville_07': {
  903. 'eq': (diff(f(x), x)/x + diff(f(x), x, x)/2 - diff(f(x), x)**2/2)*exp(-f(x))/exp(f(x)),
  904. 'sol': [Eq(f(x), log(x/(C1 + C2*x)))],
  905. },
  906. 'liouville_08': {
  907. 'eq': x**2*diff(f(x),x) + (n*f(x) + f(x)**2)*diff(f(x),x)**2 + diff(f(x), (x, 2)),
  908. 'sol': [Eq(C1 + C2*lowergamma(Rational(1,3), x**3/3) + NonElementaryIntegral(exp(_y**3/3)*exp(_y**2*n/2), (_y, f(x))), 0)],
  909. },
  910. }
  911. }
  912. @_add_example_keys
  913. def _get_examples_ode_sol_nth_algebraic():
  914. M, m, r, t = symbols('M m r t')
  915. phi = Function('phi')
  916. k = Symbol('k')
  917. # This one needs a substitution f' = g.
  918. # 'algeb_12': {
  919. # 'eq': -exp(x) + (x*Derivative(f(x), (x, 2)) + Derivative(f(x), x))/x,
  920. # 'sol': [Eq(f(x), C1 + C2*log(x) + exp(x) - Ei(x))],
  921. # },
  922. return {
  923. 'hint': "nth_algebraic",
  924. 'func': f(x),
  925. 'examples':{
  926. 'algeb_01': {
  927. 'eq': f(x) * f(x).diff(x) * f(x).diff(x, x) * (f(x) - 1) * (f(x).diff(x) - x),
  928. 'sol': [Eq(f(x), C1 + x**2/2), Eq(f(x), C1 + C2*x)]
  929. },
  930. 'algeb_02': {
  931. 'eq': f(x) * f(x).diff(x) * f(x).diff(x, x) * (f(x) - 1),
  932. 'sol': [Eq(f(x), C1 + C2*x)]
  933. },
  934. 'algeb_03': {
  935. 'eq': f(x) * f(x).diff(x) * f(x).diff(x, x),
  936. 'sol': [Eq(f(x), C1 + C2*x)]
  937. },
  938. 'algeb_04': {
  939. 'eq': Eq(-M * phi(t).diff(t),
  940. Rational(3, 2) * m * r**2 * phi(t).diff(t) * phi(t).diff(t,t)),
  941. 'sol': [Eq(phi(t), C1), Eq(phi(t), C1 + C2*t - M*t**2/(3*m*r**2))],
  942. 'func': phi(t)
  943. },
  944. 'algeb_05': {
  945. 'eq': (1 - sin(f(x))) * f(x).diff(x),
  946. 'sol': [Eq(f(x), C1)],
  947. 'XFAIL': ['separable'] #It raised exception.
  948. },
  949. 'algeb_06': {
  950. 'eq': (diff(f(x)) - x)*(diff(f(x)) + x),
  951. 'sol': [Eq(f(x), C1 - x**2/2), Eq(f(x), C1 + x**2/2)]
  952. },
  953. 'algeb_07': {
  954. 'eq': Eq(Derivative(f(x), x), Derivative(g(x), x)),
  955. 'sol': [Eq(f(x), C1 + g(x))],
  956. },
  957. 'algeb_08': {
  958. 'eq': f(x).diff(x) - C1, #this example is from issue 15999
  959. 'sol': [Eq(f(x), C1*x + C2)],
  960. },
  961. 'algeb_09': {
  962. 'eq': f(x)*f(x).diff(x),
  963. 'sol': [Eq(f(x), C1)],
  964. },
  965. 'algeb_10': {
  966. 'eq': (diff(f(x)) - x)*(diff(f(x)) + x),
  967. 'sol': [Eq(f(x), C1 - x**2/2), Eq(f(x), C1 + x**2/2)],
  968. },
  969. 'algeb_11': {
  970. 'eq': f(x) + f(x)*f(x).diff(x),
  971. 'sol': [Eq(f(x), 0), Eq(f(x), C1 - x)],
  972. 'XFAIL': ['separable', '1st_exact', '1st_linear', 'Bernoulli', '1st_homogeneous_coeff_best',
  973. '1st_homogeneous_coeff_subs_indep_div_dep', '1st_homogeneous_coeff_subs_dep_div_indep',
  974. 'lie_group', 'nth_linear_constant_coeff_undetermined_coefficients',
  975. 'nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients',
  976. 'nth_linear_constant_coeff_variation_of_parameters',
  977. 'nth_linear_euler_eq_nonhomogeneous_variation_of_parameters']
  978. #nth_linear_constant_coeff_undetermined_coefficients raises exception rest all of them misses a solution.
  979. },
  980. 'algeb_12': {
  981. 'eq': Derivative(x*f(x), x, x, x),
  982. 'sol': [Eq(f(x), (C1 + C2*x + C3*x**2) / x)],
  983. 'XFAIL': ['nth_algebraic'] # It passes only when prep=False is set in dsolve.
  984. },
  985. 'algeb_13': {
  986. 'eq': Eq(Derivative(x*Derivative(f(x), x), x)/x, exp(x)),
  987. 'sol': [Eq(f(x), C1 + C2*log(x) + exp(x) - Ei(x))],
  988. 'XFAIL': ['nth_algebraic'] # It passes only when prep=False is set in dsolve.
  989. },
  990. # These are simple tests from the old ode module example 14-18
  991. 'algeb_14': {
  992. 'eq': Eq(f(x).diff(x), 0),
  993. 'sol': [Eq(f(x), C1)],
  994. },
  995. 'algeb_15': {
  996. 'eq': Eq(3*f(x).diff(x) - 5, 0),
  997. 'sol': [Eq(f(x), C1 + x*Rational(5, 3))],
  998. },
  999. 'algeb_16': {
  1000. 'eq': Eq(3*f(x).diff(x), 5),
  1001. 'sol': [Eq(f(x), C1 + x*Rational(5, 3))],
  1002. },
  1003. # Type: 2nd order, constant coefficients (two complex roots)
  1004. 'algeb_17': {
  1005. 'eq': Eq(3*f(x).diff(x) - 1, 0),
  1006. 'sol': [Eq(f(x), C1 + x/3)],
  1007. },
  1008. 'algeb_18': {
  1009. 'eq': Eq(x*f(x).diff(x) - 1, 0),
  1010. 'sol': [Eq(f(x), C1 + log(x))],
  1011. },
  1012. # https://github.com/sympy/sympy/issues/6989
  1013. 'algeb_19': {
  1014. 'eq': f(x).diff(x) - x*exp(-k*x),
  1015. 'sol': [Eq(f(x), C1 + Piecewise(((-k*x - 1)*exp(-k*x)/k**2, Ne(k**2, 0)),(x**2/2, True)))],
  1016. },
  1017. 'algeb_20': {
  1018. 'eq': -f(x).diff(x) + x*exp(-k*x),
  1019. 'sol': [Eq(f(x), C1 + Piecewise(((-k*x - 1)*exp(-k*x)/k**2, Ne(k**2, 0)),(x**2/2, True)))],
  1020. },
  1021. # https://github.com/sympy/sympy/issues/10867
  1022. 'algeb_21': {
  1023. 'eq': Eq(g(x).diff(x).diff(x), (x-2)**2 + (x-3)**3),
  1024. 'sol': [Eq(g(x), C1 + C2*x + x**5/20 - 2*x**4/3 + 23*x**3/6 - 23*x**2/2)],
  1025. 'func': g(x),
  1026. },
  1027. # https://github.com/sympy/sympy/issues/13691
  1028. 'algeb_22': {
  1029. 'eq': f(x).diff(x) - C1*g(x).diff(x),
  1030. 'sol': [Eq(f(x), C2 + C1*g(x))],
  1031. 'func': f(x),
  1032. },
  1033. # https://github.com/sympy/sympy/issues/4838
  1034. 'algeb_23': {
  1035. 'eq': f(x).diff(x) - 3*C1 - 3*x**2,
  1036. 'sol': [Eq(f(x), C2 + 3*C1*x + x**3)],
  1037. },
  1038. }
  1039. }
  1040. @_add_example_keys
  1041. def _get_examples_ode_sol_nth_order_reducible():
  1042. return {
  1043. 'hint': "nth_order_reducible",
  1044. 'func': f(x),
  1045. 'examples':{
  1046. 'reducible_01': {
  1047. 'eq': Eq(x*Derivative(f(x), x)**2 + Derivative(f(x), x, 2), 0),
  1048. 'sol': [Eq(f(x),C1 - sqrt(-1/C2)*log(-C2*sqrt(-1/C2) + x) +
  1049. sqrt(-1/C2)*log(C2*sqrt(-1/C2) + x))],
  1050. 'slow': True,
  1051. },
  1052. 'reducible_02': {
  1053. 'eq': -exp(x) + (x*Derivative(f(x), (x, 2)) + Derivative(f(x), x))/x,
  1054. 'sol': [Eq(f(x), C1 + C2*log(x) + exp(x) - Ei(x))],
  1055. 'slow': True,
  1056. },
  1057. 'reducible_03': {
  1058. 'eq': Eq(sqrt(2) * f(x).diff(x,x,x) + f(x).diff(x), 0),
  1059. 'sol': [Eq(f(x), C1 + C2*sin(2**Rational(3, 4)*x/2) + C3*cos(2**Rational(3, 4)*x/2))],
  1060. 'slow': True,
  1061. },
  1062. 'reducible_04': {
  1063. 'eq': f(x).diff(x, 2) + 2*f(x).diff(x),
  1064. 'sol': [Eq(f(x), C1 + C2*exp(-2*x))],
  1065. },
  1066. 'reducible_05': {
  1067. 'eq': f(x).diff(x, 3) + f(x).diff(x, 2) - 6*f(x).diff(x),
  1068. 'sol': [Eq(f(x), C1 + C2*exp(-3*x) + C3*exp(2*x))],
  1069. 'slow': True,
  1070. },
  1071. 'reducible_06': {
  1072. 'eq': f(x).diff(x, 4) - f(x).diff(x, 3) - 4*f(x).diff(x, 2) + \
  1073. 4*f(x).diff(x),
  1074. 'sol': [Eq(f(x), C1 + C2*exp(-2*x) + C3*exp(x) + C4*exp(2*x))],
  1075. 'slow': True,
  1076. },
  1077. 'reducible_07': {
  1078. 'eq': f(x).diff(x, 4) + 3*f(x).diff(x, 3),
  1079. 'sol': [Eq(f(x), C1 + C2*x + C3*x**2 + C4*exp(-3*x))],
  1080. 'slow': True,
  1081. },
  1082. 'reducible_08': {
  1083. 'eq': f(x).diff(x, 4) - 2*f(x).diff(x, 2),
  1084. 'sol': [Eq(f(x), C1 + C2*x + C3*exp(-sqrt(2)*x) + C4*exp(sqrt(2)*x))],
  1085. 'slow': True,
  1086. },
  1087. 'reducible_09': {
  1088. 'eq': f(x).diff(x, 4) + 4*f(x).diff(x, 2),
  1089. 'sol': [Eq(f(x), C1 + C2*x + C3*sin(2*x) + C4*cos(2*x))],
  1090. 'slow': True,
  1091. },
  1092. 'reducible_10': {
  1093. 'eq': f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x),
  1094. 'sol': [Eq(f(x), C1 + C2*x*sin(x) + C2*cos(x) - C3*x*cos(x) + C3*sin(x) + C4*sin(x) + C5*cos(x))],
  1095. 'slow': True,
  1096. },
  1097. 'reducible_11': {
  1098. 'eq': f(x).diff(x, 2) - f(x).diff(x)**3,
  1099. 'sol': [Eq(f(x), C1 - sqrt(2)*sqrt(-1/(C2 + x))*(C2 + x)),
  1100. Eq(f(x), C1 + sqrt(2)*sqrt(-1/(C2 + x))*(C2 + x))],
  1101. 'slow': True,
  1102. },
  1103. # Needs to be a way to know how to combine derivatives in the expression
  1104. 'reducible_12': {
  1105. 'eq': Derivative(x*f(x), x, x, x) + Derivative(f(x), x, x, x),
  1106. 'sol': [Eq(f(x), C1 + C3/Mul(2, (x**2 + 2*x + 1), evaluate=False) +
  1107. x*(C2 + C3/Mul(2, (x**2 + 2*x + 1), evaluate=False)))], # 2-arg Mul!
  1108. 'slow': True,
  1109. },
  1110. }
  1111. }
  1112. @_add_example_keys
  1113. def _get_examples_ode_sol_nth_linear_undetermined_coefficients():
  1114. # examples 3-27 below are from Ordinary Differential Equations,
  1115. # Tenenbaum and Pollard, pg. 231
  1116. g = exp(-x)
  1117. f2 = f(x).diff(x, 2)
  1118. c = 3*f(x).diff(x, 3) + 5*f2 + f(x).diff(x) - f(x) - x
  1119. t = symbols("t")
  1120. u = symbols("u",cls=Function)
  1121. R, L, C, E_0, alpha = symbols("R L C E_0 alpha",positive=True)
  1122. omega = Symbol('omega')
  1123. return {
  1124. 'hint': "nth_linear_constant_coeff_undetermined_coefficients",
  1125. 'func': f(x),
  1126. 'examples':{
  1127. 'undet_01': {
  1128. 'eq': c - x*g,
  1129. 'sol': [Eq(f(x), C3*exp(x/3) - x + (C1 + x*(C2 - x**2/24 - 3*x/32))*exp(-x) - 1)],
  1130. 'slow': True,
  1131. },
  1132. 'undet_02': {
  1133. 'eq': c - g,
  1134. 'sol': [Eq(f(x), C3*exp(x/3) - x + (C1 + x*(C2 - x/8))*exp(-x) - 1)],
  1135. 'slow': True,
  1136. },
  1137. 'undet_03': {
  1138. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - 4,
  1139. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + 2)],
  1140. 'slow': True,
  1141. },
  1142. 'undet_04': {
  1143. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - 12*exp(x),
  1144. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + 2*exp(x))],
  1145. 'slow': True,
  1146. },
  1147. 'undet_05': {
  1148. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - exp(I*x),
  1149. 'sol': [Eq(f(x), (S(3)/10 + I/10)*(C1*exp(-2*x) + C2*exp(-x) - I*exp(I*x)))],
  1150. 'slow': True,
  1151. },
  1152. 'undet_06': {
  1153. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - sin(x),
  1154. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + sin(x)/10 - 3*cos(x)/10)],
  1155. 'slow': True,
  1156. },
  1157. 'undet_07': {
  1158. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - cos(x),
  1159. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + 3*sin(x)/10 + cos(x)/10)],
  1160. 'slow': True,
  1161. },
  1162. 'undet_08': {
  1163. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - (8 + 6*exp(x) + 2*sin(x)),
  1164. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + exp(x) + sin(x)/5 - 3*cos(x)/5 + 4)],
  1165. 'slow': True,
  1166. },
  1167. 'undet_09': {
  1168. 'eq': f2 + f(x).diff(x) + f(x) - x**2,
  1169. 'sol': [Eq(f(x), -2*x + x**2 + (C1*sin(x*sqrt(3)/2) + C2*cos(x*sqrt(3)/2))*exp(-x/2))],
  1170. 'slow': True,
  1171. },
  1172. 'undet_10': {
  1173. 'eq': f2 - 2*f(x).diff(x) - 8*f(x) - 9*x*exp(x) - 10*exp(-x),
  1174. 'sol': [Eq(f(x), -x*exp(x) - 2*exp(-x) + C1*exp(-2*x) + C2*exp(4*x))],
  1175. 'slow': True,
  1176. },
  1177. 'undet_11': {
  1178. 'eq': f2 - 3*f(x).diff(x) - 2*exp(2*x)*sin(x),
  1179. 'sol': [Eq(f(x), C1 + C2*exp(3*x) - 3*exp(2*x)*sin(x)/5 - exp(2*x)*cos(x)/5)],
  1180. 'slow': True,
  1181. },
  1182. 'undet_12': {
  1183. 'eq': f(x).diff(x, 4) - 2*f2 + f(x) - x + sin(x),
  1184. 'sol': [Eq(f(x), x - sin(x)/4 + (C1 + C2*x)*exp(-x) + (C3 + C4*x)*exp(x))],
  1185. 'slow': True,
  1186. },
  1187. 'undet_13': {
  1188. 'eq': f2 + f(x).diff(x) - x**2 - 2*x,
  1189. 'sol': [Eq(f(x), C1 + x**3/3 + C2*exp(-x))],
  1190. 'slow': True,
  1191. },
  1192. 'undet_14': {
  1193. 'eq': f2 + f(x).diff(x) - x - sin(2*x),
  1194. 'sol': [Eq(f(x), C1 - x - sin(2*x)/5 - cos(2*x)/10 + x**2/2 + C2*exp(-x))],
  1195. 'slow': True,
  1196. },
  1197. 'undet_15': {
  1198. 'eq': f2 + f(x) - 4*x*sin(x),
  1199. 'sol': [Eq(f(x), (C1 - x**2)*cos(x) + (C2 + x)*sin(x))],
  1200. 'slow': True,
  1201. },
  1202. 'undet_16': {
  1203. 'eq': f2 + 4*f(x) - x*sin(2*x),
  1204. 'sol': [Eq(f(x), (C1 - x**2/8)*cos(2*x) + (C2 + x/16)*sin(2*x))],
  1205. 'slow': True,
  1206. },
  1207. 'undet_17': {
  1208. 'eq': f2 + 2*f(x).diff(x) + f(x) - x**2*exp(-x),
  1209. 'sol': [Eq(f(x), (C1 + x*(C2 + x**3/12))*exp(-x))],
  1210. 'slow': True,
  1211. },
  1212. 'undet_18': {
  1213. 'eq': f(x).diff(x, 3) + 3*f2 + 3*f(x).diff(x) + f(x) - 2*exp(-x) + \
  1214. x**2*exp(-x),
  1215. 'sol': [Eq(f(x), (C1 + x*(C2 + x*(C3 - x**3/60 + x/3)))*exp(-x))],
  1216. 'slow': True,
  1217. },
  1218. 'undet_19': {
  1219. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - exp(-2*x) - x**2,
  1220. 'sol': [Eq(f(x), C2*exp(-x) + x**2/2 - x*Rational(3,2) + (C1 - x)*exp(-2*x) + Rational(7,4))],
  1221. 'slow': True,
  1222. },
  1223. 'undet_20': {
  1224. 'eq': f2 - 3*f(x).diff(x) + 2*f(x) - x*exp(-x),
  1225. 'sol': [Eq(f(x), C1*exp(x) + C2*exp(2*x) + (6*x + 5)*exp(-x)/36)],
  1226. 'slow': True,
  1227. },
  1228. 'undet_21': {
  1229. 'eq': f2 + f(x).diff(x) - 6*f(x) - x - exp(2*x),
  1230. 'sol': [Eq(f(x), Rational(-1, 36) - x/6 + C2*exp(-3*x) + (C1 + x/5)*exp(2*x))],
  1231. 'slow': True,
  1232. },
  1233. 'undet_22': {
  1234. 'eq': f2 + f(x) - sin(x) - exp(-x),
  1235. 'sol': [Eq(f(x), C2*sin(x) + (C1 - x/2)*cos(x) + exp(-x)/2)],
  1236. 'slow': True,
  1237. },
  1238. 'undet_23': {
  1239. 'eq': f(x).diff(x, 3) - 3*f2 + 3*f(x).diff(x) - f(x) - exp(x),
  1240. 'sol': [Eq(f(x), (C1 + x*(C2 + x*(C3 + x/6)))*exp(x))],
  1241. 'slow': True,
  1242. },
  1243. 'undet_24': {
  1244. 'eq': f2 + f(x) - S.Half - cos(2*x)/2,
  1245. 'sol': [Eq(f(x), S.Half - cos(2*x)/6 + C1*sin(x) + C2*cos(x))],
  1246. 'slow': True,
  1247. },
  1248. 'undet_25': {
  1249. 'eq': f(x).diff(x, 3) - f(x).diff(x) - exp(2*x)*(S.Half - cos(2*x)/2),
  1250. 'sol': [Eq(f(x), C1 + C2*exp(-x) + C3*exp(x) + (-21*sin(2*x) + 27*cos(2*x) + 130)*exp(2*x)/1560)],
  1251. 'slow': True,
  1252. },
  1253. #Note: 'undet_26' is referred in 'undet_37'
  1254. 'undet_26': {
  1255. 'eq': (f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x) - 2*x -
  1256. sin(x) - cos(x)),
  1257. 'sol': [Eq(f(x), C1 + x**2 + (C2 + x*(C3 - x/8))*sin(x) + (C4 + x*(C5 + x/8))*cos(x))],
  1258. 'slow': True,
  1259. },
  1260. 'undet_27': {
  1261. 'eq': f2 + f(x) - cos(x)/2 + cos(3*x)/2,
  1262. 'sol': [Eq(f(x), cos(3*x)/16 + C2*cos(x) + (C1 + x/4)*sin(x))],
  1263. 'slow': True,
  1264. },
  1265. 'undet_28': {
  1266. 'eq': f(x).diff(x) - 1,
  1267. 'sol': [Eq(f(x), C1 + x)],
  1268. 'slow': True,
  1269. },
  1270. # https://github.com/sympy/sympy/issues/19358
  1271. 'undet_29': {
  1272. 'eq': f2 + f(x).diff(x) + exp(x-C1),
  1273. 'sol': [Eq(f(x), C2 + C3*exp(-x) - exp(-C1 + x)/2)],
  1274. 'slow': True,
  1275. },
  1276. # https://github.com/sympy/sympy/issues/18408
  1277. 'undet_30': {
  1278. 'eq': f(x).diff(x, 3) - f(x).diff(x) - sinh(x),
  1279. 'sol': [Eq(f(x), C1 + C2*exp(-x) + C3*exp(x) + x*sinh(x)/2)],
  1280. },
  1281. 'undet_31': {
  1282. 'eq': f(x).diff(x, 2) - 49*f(x) - sinh(3*x),
  1283. 'sol': [Eq(f(x), C1*exp(-7*x) + C2*exp(7*x) - sinh(3*x)/40)],
  1284. },
  1285. 'undet_32': {
  1286. 'eq': f(x).diff(x, 3) - f(x).diff(x) - sinh(x) - exp(x),
  1287. 'sol': [Eq(f(x), C1 + C3*exp(-x) + x*sinh(x)/2 + (C2 + x/2)*exp(x))],
  1288. },
  1289. # https://github.com/sympy/sympy/issues/5096
  1290. 'undet_33': {
  1291. 'eq': f(x).diff(x, x) + f(x) - x*sin(x - 2),
  1292. 'sol': [Eq(f(x), C1*sin(x) + C2*cos(x) - x**2*cos(x - 2)/4 + x*sin(x - 2)/4)],
  1293. },
  1294. 'undet_34': {
  1295. 'eq': f(x).diff(x, 2) + f(x) - x**4*sin(x-1),
  1296. 'sol': [ Eq(f(x), C1*sin(x) + C2*cos(x) - x**5*cos(x - 1)/10 + x**4*sin(x - 1)/4 + x**3*cos(x - 1)/2 - 3*x**2*sin(x - 1)/4 - 3*x*cos(x - 1)/4)],
  1297. },
  1298. 'undet_35': {
  1299. 'eq': f(x).diff(x, 2) - f(x) - exp(x - 1),
  1300. 'sol': [Eq(f(x), C2*exp(-x) + (C1 + x*exp(-1)/2)*exp(x))],
  1301. },
  1302. 'undet_36': {
  1303. 'eq': f(x).diff(x, 2)+f(x)-(sin(x-2)+1),
  1304. 'sol': [Eq(f(x), C1*sin(x) + C2*cos(x) - x*cos(x - 2)/2 + 1)],
  1305. },
  1306. # Equivalent to example_name 'undet_26'.
  1307. # This previously failed because the algorithm for undetermined coefficients
  1308. # didn't know to multiply exp(I*x) by sufficient x because it is linearly
  1309. # dependent on sin(x) and cos(x).
  1310. 'undet_37': {
  1311. 'eq': f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x) - 2*x - exp(I*x),
  1312. 'sol': [Eq(f(x), C1 + x**2*(I*exp(I*x)/8 + 1) + (C2 + C3*x)*sin(x) + (C4 + C5*x)*cos(x))],
  1313. },
  1314. # https://github.com/sympy/sympy/issues/12623
  1315. 'undet_38': {
  1316. 'eq': Eq( u(t).diff(t,t) + R /L*u(t).diff(t) + 1/(L*C)*u(t), alpha),
  1317. 'sol': [Eq(u(t), C*L*alpha + C2*exp(-t*(R + sqrt(C*R**2 - 4*L)/sqrt(C))/(2*L))
  1318. + C1*exp(t*(-R + sqrt(C*R**2 - 4*L)/sqrt(C))/(2*L)))],
  1319. 'func': u(t)
  1320. },
  1321. 'undet_39': {
  1322. 'eq': Eq( L*C*u(t).diff(t,t) + R*C*u(t).diff(t) + u(t), E_0*exp(I*omega*t) ),
  1323. 'sol': [Eq(u(t), C2*exp(-t*(R + sqrt(C*R**2 - 4*L)/sqrt(C))/(2*L))
  1324. + C1*exp(t*(-R + sqrt(C*R**2 - 4*L)/sqrt(C))/(2*L))
  1325. - E_0*exp(I*omega*t)/(C*L*omega**2 - I*C*R*omega - 1))],
  1326. 'func': u(t),
  1327. },
  1328. # https://github.com/sympy/sympy/issues/6879
  1329. 'undet_40': {
  1330. 'eq': Eq(Derivative(f(x), x, 2) - 2*Derivative(f(x), x) + f(x), sin(x)),
  1331. 'sol': [Eq(f(x), (C1 + C2*x)*exp(x) + cos(x)/2)],
  1332. },
  1333. }
  1334. }
  1335. @_add_example_keys
  1336. def _get_examples_ode_sol_separable():
  1337. # test_separable1-5 are from Ordinary Differential Equations, Tenenbaum and
  1338. # Pollard, pg. 55
  1339. t,a = symbols('a,t')
  1340. m = 96
  1341. g = 9.8
  1342. k = .2
  1343. f1 = g * m
  1344. v = Function('v')
  1345. return {
  1346. 'hint': "separable",
  1347. 'func': f(x),
  1348. 'examples':{
  1349. 'separable_01': {
  1350. 'eq': f(x).diff(x) - f(x),
  1351. 'sol': [Eq(f(x), C1*exp(x))],
  1352. },
  1353. 'separable_02': {
  1354. 'eq': x*f(x).diff(x) - f(x),
  1355. 'sol': [Eq(f(x), C1*x)],
  1356. },
  1357. 'separable_03': {
  1358. 'eq': f(x).diff(x) + sin(x),
  1359. 'sol': [Eq(f(x), C1 + cos(x))],
  1360. },
  1361. 'separable_04': {
  1362. 'eq': f(x)**2 + 1 - (x**2 + 1)*f(x).diff(x),
  1363. 'sol': [Eq(f(x), tan(C1 + atan(x)))],
  1364. },
  1365. 'separable_05': {
  1366. 'eq': f(x).diff(x)/tan(x) - f(x) - 2,
  1367. 'sol': [Eq(f(x), C1/cos(x) - 2)],
  1368. },
  1369. 'separable_06': {
  1370. 'eq': f(x).diff(x) * (1 - sin(f(x))) - 1,
  1371. 'sol': [Eq(-x + f(x) + cos(f(x)), C1)],
  1372. },
  1373. 'separable_07': {
  1374. 'eq': f(x)*x**2*f(x).diff(x) - f(x)**3 - 2*x**2*f(x).diff(x),
  1375. 'sol': [Eq(f(x), (-x - sqrt(x*(4*C1*x + x - 4)))/(C1*x - 1)/2),
  1376. Eq(f(x), (-x + sqrt(x*(4*C1*x + x - 4)))/(C1*x - 1)/2)],
  1377. 'slow': True,
  1378. },
  1379. 'separable_08': {
  1380. 'eq': f(x)**2 - 1 - (2*f(x) + x*f(x))*f(x).diff(x),
  1381. 'sol': [Eq(f(x), -sqrt(C1*x**2 + 4*C1*x + 4*C1 + 1)),
  1382. Eq(f(x), sqrt(C1*x**2 + 4*C1*x + 4*C1 + 1))],
  1383. 'slow': True,
  1384. },
  1385. 'separable_09': {
  1386. 'eq': x*log(x)*f(x).diff(x) + sqrt(1 + f(x)**2),
  1387. 'sol': [Eq(f(x), sinh(C1 - log(log(x))))], #One more solution is f(x)=I
  1388. 'slow': True,
  1389. 'checkodesol_XFAIL': True,
  1390. },
  1391. 'separable_10': {
  1392. 'eq': exp(x + 1)*tan(f(x)) + cos(f(x))*f(x).diff(x),
  1393. 'sol': [Eq(E*exp(x) + log(cos(f(x)) - 1)/2 - log(cos(f(x)) + 1)/2 + cos(f(x)), C1)],
  1394. 'slow': True,
  1395. },
  1396. 'separable_11': {
  1397. 'eq': (x*cos(f(x)) + x**2*sin(f(x))*f(x).diff(x) - a**2*sin(f(x))*f(x).diff(x)),
  1398. 'sol': [
  1399. Eq(f(x), -acos(C1*sqrt(-a**2 + x**2)) + 2*pi),
  1400. Eq(f(x), acos(C1*sqrt(-a**2 + x**2)))
  1401. ],
  1402. 'slow': True,
  1403. },
  1404. 'separable_12': {
  1405. 'eq': f(x).diff(x) - f(x)*tan(x),
  1406. 'sol': [Eq(f(x), C1/cos(x))],
  1407. },
  1408. 'separable_13': {
  1409. 'eq': (x - 1)*cos(f(x))*f(x).diff(x) - 2*x*sin(f(x)),
  1410. 'sol': [
  1411. Eq(f(x), pi - asin(C1*(x**2 - 2*x + 1)*exp(2*x))),
  1412. Eq(f(x), asin(C1*(x**2 - 2*x + 1)*exp(2*x)))
  1413. ],
  1414. },
  1415. 'separable_14': {
  1416. 'eq': f(x).diff(x) - f(x)*log(f(x))/tan(x),
  1417. 'sol': [Eq(f(x), exp(C1*sin(x)))],
  1418. },
  1419. 'separable_15': {
  1420. 'eq': x*f(x).diff(x) + (1 + f(x)**2)*atan(f(x)),
  1421. 'sol': [Eq(f(x), tan(C1/x))], #Two more solutions are f(x)=0 and f(x)=I
  1422. 'slow': True,
  1423. 'checkodesol_XFAIL': True,
  1424. },
  1425. 'separable_16': {
  1426. 'eq': f(x).diff(x) + x*(f(x) + 1),
  1427. 'sol': [Eq(f(x), -1 + C1*exp(-x**2/2))],
  1428. },
  1429. 'separable_17': {
  1430. 'eq': exp(f(x)**2)*(x**2 + 2*x + 1) + (x*f(x) + f(x))*f(x).diff(x),
  1431. 'sol': [
  1432. Eq(f(x), -sqrt(log(1/(C1 + x**2 + 2*x)))),
  1433. Eq(f(x), sqrt(log(1/(C1 + x**2 + 2*x))))
  1434. ],
  1435. },
  1436. 'separable_18': {
  1437. 'eq': f(x).diff(x) + f(x),
  1438. 'sol': [Eq(f(x), C1*exp(-x))],
  1439. },
  1440. 'separable_19': {
  1441. 'eq': sin(x)*cos(2*f(x)) + cos(x)*sin(2*f(x))*f(x).diff(x),
  1442. 'sol': [Eq(f(x), pi - acos(C1/cos(x)**2)/2), Eq(f(x), acos(C1/cos(x)**2)/2)],
  1443. },
  1444. 'separable_20': {
  1445. 'eq': (1 - x)*f(x).diff(x) - x*(f(x) + 1),
  1446. 'sol': [Eq(f(x), (C1*exp(-x) - x + 1)/(x - 1))],
  1447. },
  1448. 'separable_21': {
  1449. 'eq': f(x)*diff(f(x), x) + x - 3*x*f(x)**2,
  1450. 'sol': [Eq(f(x), -sqrt(3)*sqrt(C1*exp(3*x**2) + 1)/3),
  1451. Eq(f(x), sqrt(3)*sqrt(C1*exp(3*x**2) + 1)/3)],
  1452. },
  1453. 'separable_22': {
  1454. 'eq': f(x).diff(x) - exp(x + f(x)),
  1455. 'sol': [Eq(f(x), log(-1/(C1 + exp(x))))],
  1456. 'XFAIL': ['lie_group'] #It shows 'NoneType' object is not subscriptable for lie_group.
  1457. },
  1458. # https://github.com/sympy/sympy/issues/7081
  1459. 'separable_23': {
  1460. 'eq': x*(f(x).diff(x)) + 1 - f(x)**2,
  1461. 'sol': [Eq(f(x), (-C1 - x**2)/(-C1 + x**2))],
  1462. },
  1463. # https://github.com/sympy/sympy/issues/10379
  1464. 'separable_24': {
  1465. 'eq': f(t).diff(t)-(1-51.05*y*f(t)),
  1466. 'sol': [Eq(f(t), (0.019588638589618023*exp(y*(C1 - 51.049999999999997*t)) + 0.019588638589618023)/y)],
  1467. 'func': f(t),
  1468. },
  1469. # https://github.com/sympy/sympy/issues/15999
  1470. 'separable_25': {
  1471. 'eq': f(x).diff(x) - C1*f(x),
  1472. 'sol': [Eq(f(x), C2*exp(C1*x))],
  1473. },
  1474. 'separable_26': {
  1475. 'eq': f1 - k * (v(t) ** 2) - m * Derivative(v(t)),
  1476. 'sol': [Eq(v(t), -68.585712797928991/tanh(C1 - 0.14288690166235204*t))],
  1477. 'func': v(t),
  1478. 'checkodesol_XFAIL': True,
  1479. },
  1480. #https://github.com/sympy/sympy/issues/22155
  1481. 'separable_27': {
  1482. 'eq': f(x).diff(x) - exp(f(x) - x),
  1483. 'sol': [Eq(f(x), log(-exp(x)/(C1*exp(x) - 1)))],
  1484. }
  1485. }
  1486. }
  1487. @_add_example_keys
  1488. def _get_examples_ode_sol_1st_exact():
  1489. # Type: Exact differential equation, p(x,f) + q(x,f)*f' == 0,
  1490. # where dp/df == dq/dx
  1491. '''
  1492. Example 7 is an exact equation that fails under the exact engine. It is caught
  1493. by first order homogeneous albeit with a much contorted solution. The
  1494. exact engine fails because of a poorly simplified integral of q(0,y)dy,
  1495. where q is the function multiplying f'. The solutions should be
  1496. Eq(sqrt(x**2+f(x)**2)**3+y**3, C1). The equation below is
  1497. equivalent, but it is so complex that checkodesol fails, and takes a long
  1498. time to do so.
  1499. '''
  1500. return {
  1501. 'hint': "1st_exact",
  1502. 'func': f(x),
  1503. 'examples':{
  1504. '1st_exact_01': {
  1505. 'eq': sin(x)*cos(f(x)) + cos(x)*sin(f(x))*f(x).diff(x),
  1506. 'sol': [Eq(f(x), -acos(C1/cos(x)) + 2*pi), Eq(f(x), acos(C1/cos(x)))],
  1507. 'slow': True,
  1508. },
  1509. '1st_exact_02': {
  1510. 'eq': (2*x*f(x) + 1)/f(x) + (f(x) - x)/f(x)**2*f(x).diff(x),
  1511. 'sol': [Eq(f(x), exp(C1 - x**2 + LambertW(-x*exp(-C1 + x**2))))],
  1512. 'XFAIL': ['lie_group'], #It shows dsolve raises an exception: List index out of range for lie_group
  1513. 'slow': True,
  1514. 'checkodesol_XFAIL':True
  1515. },
  1516. '1st_exact_03': {
  1517. 'eq': 2*x + f(x)*cos(x) + (2*f(x) + sin(x) - sin(f(x)))*f(x).diff(x),
  1518. 'sol': [Eq(f(x)*sin(x) + cos(f(x)) + x**2 + f(x)**2, C1)],
  1519. 'XFAIL': ['lie_group'], #It goes into infinite loop for lie_group.
  1520. 'slow': True,
  1521. },
  1522. '1st_exact_04': {
  1523. 'eq': cos(f(x)) - (x*sin(f(x)) - f(x)**2)*f(x).diff(x),
  1524. 'sol': [Eq(x*cos(f(x)) + f(x)**3/3, C1)],
  1525. 'slow': True,
  1526. },
  1527. '1st_exact_05': {
  1528. 'eq': 2*x*f(x) + (x**2 + f(x)**2)*f(x).diff(x),
  1529. 'sol': [Eq(x**2*f(x) + f(x)**3/3, C1)],
  1530. 'slow': True,
  1531. 'simplify_flag':False
  1532. },
  1533. # This was from issue: https://github.com/sympy/sympy/issues/11290
  1534. '1st_exact_06': {
  1535. 'eq': cos(f(x)) - (x*sin(f(x)) - f(x)**2)*f(x).diff(x),
  1536. 'sol': [Eq(x*cos(f(x)) + f(x)**3/3, C1)],
  1537. 'simplify_flag':False
  1538. },
  1539. '1st_exact_07': {
  1540. 'eq': x*sqrt(x**2 + f(x)**2) - (x**2*f(x)/(f(x) - sqrt(x**2 + f(x)**2)))*f(x).diff(x),
  1541. 'sol': [Eq(log(x),
  1542. C1 - 9*sqrt(1 + f(x)**2/x**2)*asinh(f(x)/x)/(-27*f(x)/x +
  1543. 27*sqrt(1 + f(x)**2/x**2)) - 9*sqrt(1 + f(x)**2/x**2)*
  1544. log(1 - sqrt(1 + f(x)**2/x**2)*f(x)/x + 2*f(x)**2/x**2)/
  1545. (-27*f(x)/x + 27*sqrt(1 + f(x)**2/x**2)) +
  1546. 9*asinh(f(x)/x)*f(x)/(x*(-27*f(x)/x + 27*sqrt(1 + f(x)**2/x**2))) +
  1547. 9*f(x)*log(1 - sqrt(1 + f(x)**2/x**2)*f(x)/x + 2*f(x)**2/x**2)/
  1548. (x*(-27*f(x)/x + 27*sqrt(1 + f(x)**2/x**2))))],
  1549. 'slow': True,
  1550. 'dsolve_too_slow':True
  1551. },
  1552. # Type: a(x)f'(x)+b(x)*f(x)+c(x)=0
  1553. '1st_exact_08': {
  1554. 'eq': Eq(x**2*f(x).diff(x) + 3*x*f(x) - sin(x)/x, 0),
  1555. 'sol': [Eq(f(x), (C1 - cos(x))/x**3)],
  1556. },
  1557. # these examples are from test_exact_enhancement
  1558. '1st_exact_09': {
  1559. 'eq': f(x)/x**2 + ((f(x)*x - 1)/x)*f(x).diff(x),
  1560. 'sol': [Eq(f(x), (i*sqrt(C1*x**2 + 1) + 1)/x) for i in (-1, 1)],
  1561. },
  1562. '1st_exact_10': {
  1563. 'eq': (x*f(x) - 1) + f(x).diff(x)*(x**2 - x*f(x)),
  1564. 'sol': [Eq(f(x), x - sqrt(C1 + x**2 - 2*log(x))), Eq(f(x), x + sqrt(C1 + x**2 - 2*log(x)))],
  1565. },
  1566. '1st_exact_11': {
  1567. 'eq': (x + 2)*sin(f(x)) + f(x).diff(x)*x*cos(f(x)),
  1568. 'sol': [Eq(f(x), -asin(C1*exp(-x)/x**2) + pi), Eq(f(x), asin(C1*exp(-x)/x**2))],
  1569. },
  1570. }
  1571. }
  1572. @_add_example_keys
  1573. def _get_examples_ode_sol_nth_linear_var_of_parameters():
  1574. g = exp(-x)
  1575. f2 = f(x).diff(x, 2)
  1576. c = 3*f(x).diff(x, 3) + 5*f2 + f(x).diff(x) - f(x) - x
  1577. return {
  1578. 'hint': "nth_linear_constant_coeff_variation_of_parameters",
  1579. 'func': f(x),
  1580. 'examples':{
  1581. 'var_of_parameters_01': {
  1582. 'eq': c - x*g,
  1583. 'sol': [Eq(f(x), C3*exp(x/3) - x + (C1 + x*(C2 - x**2/24 - 3*x/32))*exp(-x) - 1)],
  1584. 'slow': True,
  1585. },
  1586. 'var_of_parameters_02': {
  1587. 'eq': c - g,
  1588. 'sol': [Eq(f(x), C3*exp(x/3) - x + (C1 + x*(C2 - x/8))*exp(-x) - 1)],
  1589. 'slow': True,
  1590. },
  1591. 'var_of_parameters_03': {
  1592. 'eq': f(x).diff(x) - 1,
  1593. 'sol': [Eq(f(x), C1 + x)],
  1594. 'slow': True,
  1595. },
  1596. 'var_of_parameters_04': {
  1597. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - 4,
  1598. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + 2)],
  1599. 'slow': True,
  1600. },
  1601. 'var_of_parameters_05': {
  1602. 'eq': f2 + 3*f(x).diff(x) + 2*f(x) - 12*exp(x),
  1603. 'sol': [Eq(f(x), C1*exp(-2*x) + C2*exp(-x) + 2*exp(x))],
  1604. 'slow': True,
  1605. },
  1606. 'var_of_parameters_06': {
  1607. 'eq': f2 - 2*f(x).diff(x) - 8*f(x) - 9*x*exp(x) - 10*exp(-x),
  1608. 'sol': [Eq(f(x), -x*exp(x) - 2*exp(-x) + C1*exp(-2*x) + C2*exp(4*x))],
  1609. 'slow': True,
  1610. },
  1611. 'var_of_parameters_07': {
  1612. 'eq': f2 + 2*f(x).diff(x) + f(x) - x**2*exp(-x),
  1613. 'sol': [Eq(f(x), (C1 + x*(C2 + x**3/12))*exp(-x))],
  1614. 'slow': True,
  1615. },
  1616. 'var_of_parameters_08': {
  1617. 'eq': f2 - 3*f(x).diff(x) + 2*f(x) - x*exp(-x),
  1618. 'sol': [Eq(f(x), C1*exp(x) + C2*exp(2*x) + (6*x + 5)*exp(-x)/36)],
  1619. 'slow': True,
  1620. },
  1621. 'var_of_parameters_09': {
  1622. 'eq': f(x).diff(x, 3) - 3*f2 + 3*f(x).diff(x) - f(x) - exp(x),
  1623. 'sol': [Eq(f(x), (C1 + x*(C2 + x*(C3 + x/6)))*exp(x))],
  1624. 'slow': True,
  1625. },
  1626. 'var_of_parameters_10': {
  1627. 'eq': f2 + 2*f(x).diff(x) + f(x) - exp(-x)/x,
  1628. 'sol': [Eq(f(x), (C1 + x*(C2 + log(x)))*exp(-x))],
  1629. 'slow': True,
  1630. },
  1631. 'var_of_parameters_11': {
  1632. 'eq': f2 + f(x) - 1/sin(x)*1/cos(x),
  1633. 'sol': [Eq(f(x), (C1 + log(sin(x) - 1)/2 - log(sin(x) + 1)/2
  1634. )*cos(x) + (C2 + log(cos(x) - 1)/2 - log(cos(x) + 1)/2)*sin(x))],
  1635. 'slow': True,
  1636. },
  1637. 'var_of_parameters_12': {
  1638. 'eq': f(x).diff(x, 4) - 1/x,
  1639. 'sol': [Eq(f(x), C1 + C2*x + C3*x**2 + x**3*(C4 + log(x)/6))],
  1640. 'slow': True,
  1641. },
  1642. # These were from issue: https://github.com/sympy/sympy/issues/15996
  1643. 'var_of_parameters_13': {
  1644. 'eq': f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x) - 2*x - exp(I*x),
  1645. 'sol': [Eq(f(x), C1 + x**2 + (C2 + x*(C3 - x/8 + 3*exp(I*x)/2 + 3*exp(-I*x)/2) + 5*exp(2*I*x)/16 + 2*I*exp(I*x) - 2*I*exp(-I*x))*sin(x) + (C4 + x*(C5 + I*x/8 + 3*I*exp(I*x)/2 - 3*I*exp(-I*x)/2)
  1646. + 5*I*exp(2*I*x)/16 - 2*exp(I*x) - 2*exp(-I*x))*cos(x) - I*exp(I*x))],
  1647. },
  1648. 'var_of_parameters_14': {
  1649. 'eq': f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x) - exp(I*x),
  1650. 'sol': [Eq(f(x), C1 + (C2 + x*(C3 - x/8) + 5*exp(2*I*x)/16)*sin(x) + (C4 + x*(C5 + I*x/8) + 5*I*exp(2*I*x)/16)*cos(x) - I*exp(I*x))],
  1651. },
  1652. # https://github.com/sympy/sympy/issues/14395
  1653. 'var_of_parameters_15': {
  1654. 'eq': Derivative(f(x), x, x) + 9*f(x) - sec(x),
  1655. 'sol': [Eq(f(x), (C1 - x/3 + sin(2*x)/3)*sin(3*x) + (C2 + log(cos(x))
  1656. - 2*log(cos(x)**2)/3 + 2*cos(x)**2/3)*cos(3*x))],
  1657. 'slow': True,
  1658. },
  1659. }
  1660. }
  1661. @_add_example_keys
  1662. def _get_examples_ode_sol_2nd_linear_bessel():
  1663. return {
  1664. 'hint': "2nd_linear_bessel",
  1665. 'func': f(x),
  1666. 'examples':{
  1667. '2nd_lin_bessel_01': {
  1668. 'eq': x**2*(f(x).diff(x, 2)) + x*(f(x).diff(x)) + (x**2 - 4)*f(x),
  1669. 'sol': [Eq(f(x), C1*besselj(2, x) + C2*bessely(2, x))],
  1670. },
  1671. '2nd_lin_bessel_02': {
  1672. 'eq': x**2*(f(x).diff(x, 2)) + x*(f(x).diff(x)) + (x**2 +25)*f(x),
  1673. 'sol': [Eq(f(x), C1*besselj(5*I, x) + C2*bessely(5*I, x))],
  1674. },
  1675. '2nd_lin_bessel_03': {
  1676. 'eq': x**2*(f(x).diff(x, 2)) + x*(f(x).diff(x)) + (x**2)*f(x),
  1677. 'sol': [Eq(f(x), C1*besselj(0, x) + C2*bessely(0, x))],
  1678. },
  1679. '2nd_lin_bessel_04': {
  1680. 'eq': x**2*(f(x).diff(x, 2)) + x*(f(x).diff(x)) + (81*x**2 -S(1)/9)*f(x),
  1681. 'sol': [Eq(f(x), C1*besselj(S(1)/3, 9*x) + C2*bessely(S(1)/3, 9*x))],
  1682. },
  1683. '2nd_lin_bessel_05': {
  1684. 'eq': x**2*(f(x).diff(x, 2)) + x*(f(x).diff(x)) + (x**4 - 4)*f(x),
  1685. 'sol': [Eq(f(x), C1*besselj(1, x**2/2) + C2*bessely(1, x**2/2))],
  1686. },
  1687. '2nd_lin_bessel_06': {
  1688. 'eq': x**2*(f(x).diff(x, 2)) + 2*x*(f(x).diff(x)) + (x**4 - 4)*f(x),
  1689. 'sol': [Eq(f(x), (C1*besselj(sqrt(17)/4, x**2/2) + C2*bessely(sqrt(17)/4, x**2/2))/sqrt(x))],
  1690. },
  1691. '2nd_lin_bessel_07': {
  1692. 'eq': x**2*(f(x).diff(x, 2)) + x*(f(x).diff(x)) + (x**2 - S(1)/4)*f(x),
  1693. 'sol': [Eq(f(x), C1*besselj(S(1)/2, x) + C2*bessely(S(1)/2, x))],
  1694. },
  1695. '2nd_lin_bessel_08': {
  1696. 'eq': x**2*(f(x).diff(x, 2)) - 3*x*(f(x).diff(x)) + (4*x + 4)*f(x),
  1697. 'sol': [Eq(f(x), x**2*(C1*besselj(0, 4*sqrt(x)) + C2*bessely(0, 4*sqrt(x))))],
  1698. },
  1699. '2nd_lin_bessel_09': {
  1700. 'eq': x*(f(x).diff(x, 2)) - f(x).diff(x) + 4*x**3*f(x),
  1701. 'sol': [Eq(f(x), x*(C1*besselj(S(1)/2, x**2) + C2*bessely(S(1)/2, x**2)))],
  1702. },
  1703. '2nd_lin_bessel_10': {
  1704. 'eq': (x-2)**2*(f(x).diff(x, 2)) - (x-2)*f(x).diff(x) + 4*(x-2)**2*f(x),
  1705. 'sol': [Eq(f(x), (x - 2)*(C1*besselj(1, 2*x - 4) + C2*bessely(1, 2*x - 4)))],
  1706. },
  1707. # https://github.com/sympy/sympy/issues/4414
  1708. '2nd_lin_bessel_11': {
  1709. 'eq': f(x).diff(x, x) + 2/x*f(x).diff(x) + f(x),
  1710. 'sol': [Eq(f(x), (C1*besselj(S(1)/2, x) + C2*bessely(S(1)/2, x))/sqrt(x))],
  1711. },
  1712. }
  1713. }
  1714. @_add_example_keys
  1715. def _get_examples_ode_sol_2nd_2F1_hypergeometric():
  1716. return {
  1717. 'hint': "2nd_hypergeometric",
  1718. 'func': f(x),
  1719. 'examples':{
  1720. '2nd_2F1_hyper_01': {
  1721. 'eq': x*(x-1)*f(x).diff(x, 2) + (S(3)/2 -2*x)*f(x).diff(x) + 2*f(x),
  1722. 'sol': [Eq(f(x), C1*x**(S(5)/2)*hyper((S(3)/2, S(1)/2), (S(7)/2,), x) + C2*hyper((-1, -2), (-S(3)/2,), x))],
  1723. },
  1724. '2nd_2F1_hyper_02': {
  1725. 'eq': x*(x-1)*f(x).diff(x, 2) + (S(7)/2*x)*f(x).diff(x) + f(x),
  1726. 'sol': [Eq(f(x), (C1*(1 - x)**(S(5)/2)*hyper((S(1)/2, 2), (S(7)/2,), 1 - x) +
  1727. C2*hyper((-S(1)/2, -2), (-S(3)/2,), 1 - x))/(x - 1)**(S(5)/2))],
  1728. },
  1729. '2nd_2F1_hyper_03': {
  1730. 'eq': x*(x-1)*f(x).diff(x, 2) + (S(3)+ S(7)/2*x)*f(x).diff(x) + f(x),
  1731. 'sol': [Eq(f(x), (C1*(1 - x)**(S(11)/2)*hyper((S(1)/2, 2), (S(13)/2,), 1 - x) +
  1732. C2*hyper((-S(7)/2, -5), (-S(9)/2,), 1 - x))/(x - 1)**(S(11)/2))],
  1733. },
  1734. '2nd_2F1_hyper_04': {
  1735. 'eq': -x**(S(5)/7)*(-416*x**(S(9)/7)/9 - 2385*x**(S(5)/7)/49 + S(298)*x/3)*f(x)/(196*(-x**(S(6)/7) +
  1736. x)**2*(x**(S(6)/7) + x)**2) + Derivative(f(x), (x, 2)),
  1737. 'sol': [Eq(f(x), x**(S(45)/98)*(C1*x**(S(4)/49)*hyper((S(1)/3, -S(1)/2), (S(9)/7,), x**(S(2)/7)) +
  1738. C2*hyper((S(1)/21, -S(11)/14), (S(5)/7,), x**(S(2)/7)))/(x**(S(2)/7) - 1)**(S(19)/84))],
  1739. 'checkodesol_XFAIL':True,
  1740. },
  1741. }
  1742. }
  1743. @_add_example_keys
  1744. def _get_examples_ode_sol_2nd_nonlinear_autonomous_conserved():
  1745. return {
  1746. 'hint': "2nd_nonlinear_autonomous_conserved",
  1747. 'func': f(x),
  1748. 'examples': {
  1749. '2nd_nonlinear_autonomous_conserved_01': {
  1750. 'eq': f(x).diff(x, 2) + exp(f(x)) + log(f(x)),
  1751. 'sol': [
  1752. Eq(Integral(1/sqrt(C1 - 2*_u*log(_u) + 2*_u - 2*exp(_u)), (_u, f(x))), C2 + x),
  1753. Eq(Integral(1/sqrt(C1 - 2*_u*log(_u) + 2*_u - 2*exp(_u)), (_u, f(x))), C2 - x)
  1754. ],
  1755. 'simplify_flag': False,
  1756. },
  1757. '2nd_nonlinear_autonomous_conserved_02': {
  1758. 'eq': f(x).diff(x, 2) + cbrt(f(x)) + 1/f(x),
  1759. 'sol': [
  1760. Eq(sqrt(2)*Integral(1/sqrt(2*C1 - 3*_u**Rational(4, 3) - 4*log(_u)), (_u, f(x))), C2 + x),
  1761. Eq(sqrt(2)*Integral(1/sqrt(2*C1 - 3*_u**Rational(4, 3) - 4*log(_u)), (_u, f(x))), C2 - x)
  1762. ],
  1763. 'simplify_flag': False,
  1764. },
  1765. '2nd_nonlinear_autonomous_conserved_03': {
  1766. 'eq': f(x).diff(x, 2) + sin(f(x)),
  1767. 'sol': [
  1768. Eq(Integral(1/sqrt(C1 + 2*cos(_u)), (_u, f(x))), C2 + x),
  1769. Eq(Integral(1/sqrt(C1 + 2*cos(_u)), (_u, f(x))), C2 - x)
  1770. ],
  1771. 'simplify_flag': False,
  1772. },
  1773. '2nd_nonlinear_autonomous_conserved_04': {
  1774. 'eq': f(x).diff(x, 2) + cosh(f(x)),
  1775. 'sol': [
  1776. Eq(Integral(1/sqrt(C1 - 2*sinh(_u)), (_u, f(x))), C2 + x),
  1777. Eq(Integral(1/sqrt(C1 - 2*sinh(_u)), (_u, f(x))), C2 - x)
  1778. ],
  1779. 'simplify_flag': False,
  1780. },
  1781. '2nd_nonlinear_autonomous_conserved_05': {
  1782. 'eq': f(x).diff(x, 2) + asin(f(x)),
  1783. 'sol': [
  1784. Eq(Integral(1/sqrt(C1 - 2*_u*asin(_u) - 2*sqrt(1 - _u**2)), (_u, f(x))), C2 + x),
  1785. Eq(Integral(1/sqrt(C1 - 2*_u*asin(_u) - 2*sqrt(1 - _u**2)), (_u, f(x))), C2 - x)
  1786. ],
  1787. 'simplify_flag': False,
  1788. 'XFAIL': ['2nd_nonlinear_autonomous_conserved_Integral']
  1789. }
  1790. }
  1791. }
  1792. @_add_example_keys
  1793. def _get_examples_ode_sol_separable_reduced():
  1794. df = f(x).diff(x)
  1795. return {
  1796. 'hint': "separable_reduced",
  1797. 'func': f(x),
  1798. 'examples':{
  1799. 'separable_reduced_01': {
  1800. 'eq': x* df + f(x)* (1 / (x**2*f(x) - 1)),
  1801. 'sol': [Eq(log(x**2*f(x))/3 + log(x**2*f(x) - Rational(3, 2))/6, C1 + log(x))],
  1802. 'simplify_flag': False,
  1803. 'XFAIL': ['lie_group'], #It hangs.
  1804. },
  1805. #Note: 'separable_reduced_02' is referred in 'separable_reduced_11'
  1806. 'separable_reduced_02': {
  1807. 'eq': f(x).diff(x) + (f(x) / (x**4*f(x) - x)),
  1808. 'sol': [Eq(log(x**3*f(x))/4 + log(x**3*f(x) - Rational(4,3))/12, C1 + log(x))],
  1809. 'simplify_flag': False,
  1810. 'checkodesol_XFAIL':True, #It hangs for this.
  1811. },
  1812. 'separable_reduced_03': {
  1813. 'eq': x*df + f(x)*(x**2*f(x)),
  1814. 'sol': [Eq(log(x**2*f(x))/2 - log(x**2*f(x) - 2)/2, C1 + log(x))],
  1815. 'simplify_flag': False,
  1816. },
  1817. 'separable_reduced_04': {
  1818. 'eq': Eq(f(x).diff(x) + f(x)/x * (1 + (x**(S(2)/3)*f(x))**2), 0),
  1819. 'sol': [Eq(-3*log(x**(S(2)/3)*f(x)) + 3*log(3*x**(S(4)/3)*f(x)**2 + 1)/2, C1 + log(x))],
  1820. 'simplify_flag': False,
  1821. },
  1822. 'separable_reduced_05': {
  1823. 'eq': Eq(f(x).diff(x) + f(x)/x * (1 + (x*f(x))**2), 0),
  1824. 'sol': [Eq(f(x), -sqrt(2)*sqrt(1/(C1 + log(x)))/(2*x)),\
  1825. Eq(f(x), sqrt(2)*sqrt(1/(C1 + log(x)))/(2*x))],
  1826. },
  1827. 'separable_reduced_06': {
  1828. 'eq': Eq(f(x).diff(x) + (x**4*f(x)**2 + x**2*f(x))*f(x)/(x*(x**6*f(x)**3 + x**4*f(x)**2)), 0),
  1829. 'sol': [Eq(f(x), C1 + 1/(2*x**2))],
  1830. },
  1831. 'separable_reduced_07': {
  1832. 'eq': Eq(f(x).diff(x) + (f(x)**2)*f(x)/(x), 0),
  1833. 'sol': [
  1834. Eq(f(x), -sqrt(2)*sqrt(1/(C1 + log(x)))/2),
  1835. Eq(f(x), sqrt(2)*sqrt(1/(C1 + log(x)))/2)
  1836. ],
  1837. },
  1838. 'separable_reduced_08': {
  1839. 'eq': Eq(f(x).diff(x) + (f(x)+3)*f(x)/(x*(f(x)+2)), 0),
  1840. 'sol': [Eq(-log(f(x) + 3)/3 - 2*log(f(x))/3, C1 + log(x))],
  1841. 'simplify_flag': False,
  1842. 'XFAIL': ['lie_group'], #It hangs.
  1843. },
  1844. 'separable_reduced_09': {
  1845. 'eq': Eq(f(x).diff(x) + (f(x)+3)*f(x)/x, 0),
  1846. 'sol': [Eq(f(x), 3/(C1*x**3 - 1))],
  1847. },
  1848. 'separable_reduced_10': {
  1849. 'eq': Eq(f(x).diff(x) + (f(x)**2+f(x))*f(x)/(x), 0),
  1850. 'sol': [Eq(- log(x) - log(f(x) + 1) + log(f(x)) + 1/f(x), C1)],
  1851. 'XFAIL': ['lie_group'],#No algorithms are implemented to solve equation -C1 + x*(_y + 1)*exp(-1/_y)/_y
  1852. },
  1853. # Equivalent to example_name 'separable_reduced_02'. Only difference is testing with simplify=True
  1854. 'separable_reduced_11': {
  1855. 'eq': f(x).diff(x) + (f(x) / (x**4*f(x) - x)),
  1856. 'sol': [Eq(f(x), -sqrt(2)*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1857. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)/6
  1858. - sqrt(2)*sqrt(-3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1859. + 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 4/x**6
  1860. - 4*sqrt(2)/(x**9*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1861. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)))/6 + 1/(3*x**3)),
  1862. Eq(f(x), -sqrt(2)*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1863. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)/6
  1864. + sqrt(2)*sqrt(-3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1865. + 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 4/x**6
  1866. - 4*sqrt(2)/(x**9*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1867. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)))/6 + 1/(3*x**3)),
  1868. Eq(f(x), sqrt(2)*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1869. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)/6
  1870. - sqrt(2)*sqrt(-3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1871. + 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1872. + 4/x**6 + 4*sqrt(2)/(x**9*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1873. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)))/6 + 1/(3*x**3)),
  1874. Eq(f(x), sqrt(2)*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3)
  1875. - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)/6
  1876. + sqrt(2)*sqrt(-3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1)
  1877. + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 4/x**6 + 4*sqrt(2)/(x**9*sqrt(3*3**Rational(1,3)*(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1))
  1878. - exp(12*C1)/x**6)**Rational(1,3) - 3*3**Rational(2,3)*exp(12*C1)/(sqrt((3*exp(12*C1) + x**(-12))*exp(24*C1)) - exp(12*C1)/x**6)**Rational(1,3) + 2/x**6)))/6 + 1/(3*x**3))],
  1879. 'checkodesol_XFAIL':True, #It hangs for this.
  1880. 'slow': True,
  1881. },
  1882. #These were from issue: https://github.com/sympy/sympy/issues/6247
  1883. 'separable_reduced_12': {
  1884. 'eq': x**2*f(x)**2 + x*Derivative(f(x), x),
  1885. 'sol': [Eq(f(x), 2*C1/(C1*x**2 - 1))],
  1886. },
  1887. }
  1888. }
  1889. @_add_example_keys
  1890. def _get_examples_ode_sol_lie_group():
  1891. a, b, c = symbols("a b c")
  1892. return {
  1893. 'hint': "lie_group",
  1894. 'func': f(x),
  1895. 'examples':{
  1896. #Example 1-4 and 19-20 were from issue: https://github.com/sympy/sympy/issues/17322
  1897. 'lie_group_01': {
  1898. 'eq': x*f(x).diff(x)*(f(x)+4) + (f(x)**2) -2*f(x)-2*x,
  1899. 'sol': [],
  1900. 'dsolve_too_slow': True,
  1901. 'checkodesol_too_slow': True,
  1902. },
  1903. 'lie_group_02': {
  1904. 'eq': x*f(x).diff(x)*(f(x)+4) + (f(x)**2) -2*f(x)-2*x,
  1905. 'sol': [],
  1906. 'dsolve_too_slow': True,
  1907. },
  1908. 'lie_group_03': {
  1909. 'eq': Eq(x**7*Derivative(f(x), x) + 5*x**3*f(x)**2 - (2*x**2 + 2)*f(x)**3, 0),
  1910. 'sol': [],
  1911. 'dsolve_too_slow': True,
  1912. },
  1913. 'lie_group_04': {
  1914. 'eq': f(x).diff(x) - (f(x) - x*log(x))**2/x**2 + log(x),
  1915. 'sol': [],
  1916. 'XFAIL': ['lie_group'],
  1917. },
  1918. 'lie_group_05': {
  1919. 'eq': f(x).diff(x)**2,
  1920. 'sol': [Eq(f(x), C1)],
  1921. 'XFAIL': ['factorable'], #It raises Not Implemented error
  1922. },
  1923. 'lie_group_06': {
  1924. 'eq': Eq(f(x).diff(x), x**2*f(x)),
  1925. 'sol': [Eq(f(x), C1*exp(x**3)**Rational(1, 3))],
  1926. },
  1927. 'lie_group_07': {
  1928. 'eq': f(x).diff(x) + a*f(x) - c*exp(b*x),
  1929. 'sol': [Eq(f(x), Piecewise(((-C1*(a + b) + c*exp(x*(a + b)))*exp(-a*x)/(a + b),\
  1930. Ne(a, -b)), ((-C1 + c*x)*exp(-a*x), True)))],
  1931. },
  1932. 'lie_group_08': {
  1933. 'eq': f(x).diff(x) + 2*x*f(x) - x*exp(-x**2),
  1934. 'sol': [Eq(f(x), (C1 + x**2/2)*exp(-x**2))],
  1935. },
  1936. 'lie_group_09': {
  1937. 'eq': (1 + 2*x)*(f(x).diff(x)) + 2 - 4*exp(-f(x)),
  1938. 'sol': [Eq(f(x), log(C1/(2*x + 1) + 2))],
  1939. },
  1940. 'lie_group_10': {
  1941. 'eq': x**2*(f(x).diff(x)) - f(x) + x**2*exp(x - (1/x)),
  1942. 'sol': [Eq(f(x), (C1 - exp(x))*exp(-1/x))],
  1943. 'XFAIL': ['factorable'], #It raises Recursion Error (maixmum depth exceeded)
  1944. },
  1945. 'lie_group_11': {
  1946. 'eq': x**2*f(x)**2 + x*Derivative(f(x), x),
  1947. 'sol': [Eq(f(x), 2/(C1 + x**2))],
  1948. },
  1949. 'lie_group_12': {
  1950. 'eq': diff(f(x),x) + 2*x*f(x) - x*exp(-x**2),
  1951. 'sol': [Eq(f(x), exp(-x**2)*(C1 + x**2/2))],
  1952. },
  1953. 'lie_group_13': {
  1954. 'eq': diff(f(x),x) + f(x)*cos(x) - exp(2*x),
  1955. 'sol': [Eq(f(x), exp(-sin(x))*(C1 + Integral(exp(2*x)*exp(sin(x)), x)))],
  1956. },
  1957. 'lie_group_14': {
  1958. 'eq': diff(f(x),x) + f(x)*cos(x) - sin(2*x)/2,
  1959. 'sol': [Eq(f(x), C1*exp(-sin(x)) + sin(x) - 1)],
  1960. },
  1961. 'lie_group_15': {
  1962. 'eq': x*diff(f(x),x) + f(x) - x*sin(x),
  1963. 'sol': [Eq(f(x), (C1 - x*cos(x) + sin(x))/x)],
  1964. },
  1965. 'lie_group_16': {
  1966. 'eq': x*diff(f(x),x) - f(x) - x/log(x),
  1967. 'sol': [Eq(f(x), x*(C1 + log(log(x))))],
  1968. },
  1969. 'lie_group_17': {
  1970. 'eq': (f(x).diff(x)-f(x)) * (f(x).diff(x)+f(x)),
  1971. 'sol': [Eq(f(x), C1*exp(x)), Eq(f(x), C1*exp(-x))],
  1972. },
  1973. 'lie_group_18': {
  1974. 'eq': f(x).diff(x) * (f(x).diff(x) - f(x)),
  1975. 'sol': [Eq(f(x), C1*exp(x)), Eq(f(x), C1)],
  1976. },
  1977. 'lie_group_19': {
  1978. 'eq': (f(x).diff(x)-f(x)) * (f(x).diff(x)+f(x)),
  1979. 'sol': [Eq(f(x), C1*exp(-x)), Eq(f(x), C1*exp(x))],
  1980. },
  1981. 'lie_group_20': {
  1982. 'eq': f(x).diff(x)*(f(x).diff(x)+f(x)),
  1983. 'sol': [Eq(f(x), C1), Eq(f(x), C1*exp(-x))],
  1984. },
  1985. }
  1986. }
  1987. @_add_example_keys
  1988. def _get_examples_ode_sol_2nd_linear_airy():
  1989. return {
  1990. 'hint': "2nd_linear_airy",
  1991. 'func': f(x),
  1992. 'examples':{
  1993. '2nd_lin_airy_01': {
  1994. 'eq': f(x).diff(x, 2) - x*f(x),
  1995. 'sol': [Eq(f(x), C1*airyai(x) + C2*airybi(x))],
  1996. },
  1997. '2nd_lin_airy_02': {
  1998. 'eq': f(x).diff(x, 2) + 2*x*f(x),
  1999. 'sol': [Eq(f(x), C1*airyai(-2**(S(1)/3)*x) + C2*airybi(-2**(S(1)/3)*x))],
  2000. },
  2001. }
  2002. }
  2003. @_add_example_keys
  2004. def _get_examples_ode_sol_nth_linear_constant_coeff_homogeneous():
  2005. # From Exercise 20, in Ordinary Differential Equations,
  2006. # Tenenbaum and Pollard, pg. 220
  2007. a = Symbol('a', positive=True)
  2008. k = Symbol('k', real=True)
  2009. r1, r2, r3, r4, r5 = [rootof(x**5 + 11*x - 2, n) for n in range(5)]
  2010. r6, r7, r8, r9, r10 = [rootof(x**5 - 3*x + 1, n) for n in range(5)]
  2011. r11, r12, r13, r14, r15 = [rootof(x**5 - 100*x**3 + 1000*x + 1, n) for n in range(5)]
  2012. r16, r17, r18, r19, r20 = [rootof(x**5 - x**4 + 10, n) for n in range(5)]
  2013. r21, r22, r23, r24, r25 = [rootof(x**5 - x + 1, n) for n in range(5)]
  2014. E = exp(1)
  2015. return {
  2016. 'hint': "nth_linear_constant_coeff_homogeneous",
  2017. 'func': f(x),
  2018. 'examples':{
  2019. 'lin_const_coeff_hom_01': {
  2020. 'eq': f(x).diff(x, 2) + 2*f(x).diff(x),
  2021. 'sol': [Eq(f(x), C1 + C2*exp(-2*x))],
  2022. },
  2023. 'lin_const_coeff_hom_02': {
  2024. 'eq': f(x).diff(x, 2) - 3*f(x).diff(x) + 2*f(x),
  2025. 'sol': [Eq(f(x), (C1 + C2*exp(x))*exp(x))],
  2026. },
  2027. 'lin_const_coeff_hom_03': {
  2028. 'eq': f(x).diff(x, 2) - f(x),
  2029. 'sol': [Eq(f(x), C1*exp(-x) + C2*exp(x))],
  2030. },
  2031. 'lin_const_coeff_hom_04': {
  2032. 'eq': f(x).diff(x, 3) + f(x).diff(x, 2) - 6*f(x).diff(x),
  2033. 'sol': [Eq(f(x), C1 + C2*exp(-3*x) + C3*exp(2*x))],
  2034. 'slow': True,
  2035. },
  2036. 'lin_const_coeff_hom_05': {
  2037. 'eq': 6*f(x).diff(x, 2) - 11*f(x).diff(x) + 4*f(x),
  2038. 'sol': [Eq(f(x), C1*exp(x/2) + C2*exp(x*Rational(4, 3)))],
  2039. 'slow': True,
  2040. },
  2041. 'lin_const_coeff_hom_06': {
  2042. 'eq': Eq(f(x).diff(x, 2) + 2*f(x).diff(x) - f(x), 0),
  2043. 'sol': [Eq(f(x), C1*exp(x*(-1 + sqrt(2))) + C2*exp(-x*(sqrt(2) + 1)))],
  2044. 'slow': True,
  2045. },
  2046. 'lin_const_coeff_hom_07': {
  2047. 'eq': diff(f(x), x, 3) + diff(f(x), x, 2) - 10*diff(f(x), x) - 6*f(x),
  2048. 'sol': [Eq(f(x), C1*exp(3*x) + C3*exp(-x*(2 + sqrt(2))) + C2*exp(x*(-2 + sqrt(2))))],
  2049. 'slow': True,
  2050. },
  2051. 'lin_const_coeff_hom_08': {
  2052. 'eq': f(x).diff(x, 4) - f(x).diff(x, 3) - 4*f(x).diff(x, 2) + \
  2053. 4*f(x).diff(x),
  2054. 'sol': [Eq(f(x), C1 + C2*exp(-2*x) + C3*exp(x) + C4*exp(2*x))],
  2055. 'slow': True,
  2056. },
  2057. 'lin_const_coeff_hom_09': {
  2058. 'eq': f(x).diff(x, 4) + 4*f(x).diff(x, 3) + f(x).diff(x, 2) - \
  2059. 4*f(x).diff(x) - 2*f(x),
  2060. 'sol': [Eq(f(x), C3*exp(-x) + C4*exp(x) + (C1*exp(-sqrt(2)*x) + C2*exp(sqrt(2)*x))*exp(-2*x))],
  2061. 'slow': True,
  2062. },
  2063. 'lin_const_coeff_hom_10': {
  2064. 'eq': f(x).diff(x, 4) - a**2*f(x),
  2065. 'sol': [Eq(f(x), C1*exp(-sqrt(a)*x) + C2*exp(sqrt(a)*x) + C3*sin(sqrt(a)*x) + C4*cos(sqrt(a)*x))],
  2066. 'slow': True,
  2067. },
  2068. 'lin_const_coeff_hom_11': {
  2069. 'eq': f(x).diff(x, 2) - 2*k*f(x).diff(x) - 2*f(x),
  2070. 'sol': [Eq(f(x), C1*exp(x*(k - sqrt(k**2 + 2))) + C2*exp(x*(k + sqrt(k**2 + 2))))],
  2071. 'slow': True,
  2072. },
  2073. 'lin_const_coeff_hom_12': {
  2074. 'eq': f(x).diff(x, 2) + 4*k*f(x).diff(x) - 12*k**2*f(x),
  2075. 'sol': [Eq(f(x), C1*exp(-6*k*x) + C2*exp(2*k*x))],
  2076. 'slow': True,
  2077. },
  2078. 'lin_const_coeff_hom_13': {
  2079. 'eq': f(x).diff(x, 4),
  2080. 'sol': [Eq(f(x), C1 + C2*x + C3*x**2 + C4*x**3)],
  2081. 'slow': True,
  2082. },
  2083. 'lin_const_coeff_hom_14': {
  2084. 'eq': f(x).diff(x, 2) + 4*f(x).diff(x) + 4*f(x),
  2085. 'sol': [Eq(f(x), (C1 + C2*x)*exp(-2*x))],
  2086. 'slow': True,
  2087. },
  2088. 'lin_const_coeff_hom_15': {
  2089. 'eq': 3*f(x).diff(x, 3) + 5*f(x).diff(x, 2) + f(x).diff(x) - f(x),
  2090. 'sol': [Eq(f(x), (C1 + C2*x)*exp(-x) + C3*exp(x/3))],
  2091. 'slow': True,
  2092. },
  2093. 'lin_const_coeff_hom_16': {
  2094. 'eq': f(x).diff(x, 3) - 6*f(x).diff(x, 2) + 12*f(x).diff(x) - 8*f(x),
  2095. 'sol': [Eq(f(x), (C1 + x*(C2 + C3*x))*exp(2*x))],
  2096. 'slow': True,
  2097. },
  2098. 'lin_const_coeff_hom_17': {
  2099. 'eq': f(x).diff(x, 2) - 2*a*f(x).diff(x) + a**2*f(x),
  2100. 'sol': [Eq(f(x), (C1 + C2*x)*exp(a*x))],
  2101. 'slow': True,
  2102. },
  2103. 'lin_const_coeff_hom_18': {
  2104. 'eq': f(x).diff(x, 4) + 3*f(x).diff(x, 3),
  2105. 'sol': [Eq(f(x), C1 + C2*x + C3*x**2 + C4*exp(-3*x))],
  2106. 'slow': True,
  2107. },
  2108. 'lin_const_coeff_hom_19': {
  2109. 'eq': f(x).diff(x, 4) - 2*f(x).diff(x, 2),
  2110. 'sol': [Eq(f(x), C1 + C2*x + C3*exp(-sqrt(2)*x) + C4*exp(sqrt(2)*x))],
  2111. 'slow': True,
  2112. },
  2113. 'lin_const_coeff_hom_20': {
  2114. 'eq': f(x).diff(x, 4) + 2*f(x).diff(x, 3) - 11*f(x).diff(x, 2) - \
  2115. 12*f(x).diff(x) + 36*f(x),
  2116. 'sol': [Eq(f(x), (C1 + C2*x)*exp(-3*x) + (C3 + C4*x)*exp(2*x))],
  2117. 'slow': True,
  2118. },
  2119. 'lin_const_coeff_hom_21': {
  2120. 'eq': 36*f(x).diff(x, 4) - 37*f(x).diff(x, 2) + 4*f(x).diff(x) + 5*f(x),
  2121. 'sol': [Eq(f(x), C1*exp(-x) + C2*exp(-x/3) + C3*exp(x/2) + C4*exp(x*Rational(5, 6)))],
  2122. 'slow': True,
  2123. },
  2124. 'lin_const_coeff_hom_22': {
  2125. 'eq': f(x).diff(x, 4) - 8*f(x).diff(x, 2) + 16*f(x),
  2126. 'sol': [Eq(f(x), (C1 + C2*x)*exp(-2*x) + (C3 + C4*x)*exp(2*x))],
  2127. 'slow': True,
  2128. },
  2129. 'lin_const_coeff_hom_23': {
  2130. 'eq': f(x).diff(x, 2) - 2*f(x).diff(x) + 5*f(x),
  2131. 'sol': [Eq(f(x), (C1*sin(2*x) + C2*cos(2*x))*exp(x))],
  2132. 'slow': True,
  2133. },
  2134. 'lin_const_coeff_hom_24': {
  2135. 'eq': f(x).diff(x, 2) - f(x).diff(x) + f(x),
  2136. 'sol': [Eq(f(x), (C1*sin(x*sqrt(3)/2) + C2*cos(x*sqrt(3)/2))*exp(x/2))],
  2137. 'slow': True,
  2138. },
  2139. 'lin_const_coeff_hom_25': {
  2140. 'eq': f(x).diff(x, 4) + 5*f(x).diff(x, 2) + 6*f(x),
  2141. 'sol': [Eq(f(x),
  2142. C1*sin(sqrt(2)*x) + C2*sin(sqrt(3)*x) + C3*cos(sqrt(2)*x) + C4*cos(sqrt(3)*x))],
  2143. 'slow': True,
  2144. },
  2145. 'lin_const_coeff_hom_26': {
  2146. 'eq': f(x).diff(x, 2) - 4*f(x).diff(x) + 20*f(x),
  2147. 'sol': [Eq(f(x), (C1*sin(4*x) + C2*cos(4*x))*exp(2*x))],
  2148. 'slow': True,
  2149. },
  2150. 'lin_const_coeff_hom_27': {
  2151. 'eq': f(x).diff(x, 4) + 4*f(x).diff(x, 2) + 4*f(x),
  2152. 'sol': [Eq(f(x), (C1 + C2*x)*sin(x*sqrt(2)) + (C3 + C4*x)*cos(x*sqrt(2)))],
  2153. 'slow': True,
  2154. },
  2155. 'lin_const_coeff_hom_28': {
  2156. 'eq': f(x).diff(x, 3) + 8*f(x),
  2157. 'sol': [Eq(f(x), (C1*sin(x*sqrt(3)) + C2*cos(x*sqrt(3)))*exp(x) + C3*exp(-2*x))],
  2158. 'slow': True,
  2159. },
  2160. 'lin_const_coeff_hom_29': {
  2161. 'eq': f(x).diff(x, 4) + 4*f(x).diff(x, 2),
  2162. 'sol': [Eq(f(x), C1 + C2*x + C3*sin(2*x) + C4*cos(2*x))],
  2163. 'slow': True,
  2164. },
  2165. 'lin_const_coeff_hom_30': {
  2166. 'eq': f(x).diff(x, 5) + 2*f(x).diff(x, 3) + f(x).diff(x),
  2167. 'sol': [Eq(f(x), C1 + (C2 + C3*x)*sin(x) + (C4 + C5*x)*cos(x))],
  2168. 'slow': True,
  2169. },
  2170. 'lin_const_coeff_hom_31': {
  2171. 'eq': f(x).diff(x, 4) + f(x).diff(x, 2) + f(x),
  2172. 'sol': [Eq(f(x), (C1*sin(sqrt(3)*x/2) + C2*cos(sqrt(3)*x/2))*exp(-x/2)
  2173. + (C3*sin(sqrt(3)*x/2) + C4*cos(sqrt(3)*x/2))*exp(x/2))],
  2174. 'slow': True,
  2175. },
  2176. 'lin_const_coeff_hom_32': {
  2177. 'eq': f(x).diff(x, 4) + 4*f(x).diff(x, 2) + f(x),
  2178. 'sol': [Eq(f(x), C1*sin(x*sqrt(-sqrt(3) + 2)) + C2*sin(x*sqrt(sqrt(3) + 2))
  2179. + C3*cos(x*sqrt(-sqrt(3) + 2)) + C4*cos(x*sqrt(sqrt(3) + 2)))],
  2180. 'slow': True,
  2181. },
  2182. # One real root, two complex conjugate pairs
  2183. 'lin_const_coeff_hom_33': {
  2184. 'eq': f(x).diff(x, 5) + 11*f(x).diff(x) - 2*f(x),
  2185. 'sol': [Eq(f(x),
  2186. C5*exp(r1*x) + exp(re(r2)*x) * (C1*sin(im(r2)*x) + C2*cos(im(r2)*x))
  2187. + exp(re(r4)*x) * (C3*sin(im(r4)*x) + C4*cos(im(r4)*x)))],
  2188. 'checkodesol_XFAIL':True, #It Hangs
  2189. },
  2190. # Three real roots, one complex conjugate pair
  2191. 'lin_const_coeff_hom_34': {
  2192. 'eq': f(x).diff(x,5) - 3*f(x).diff(x) + f(x),
  2193. 'sol': [Eq(f(x),
  2194. C3*exp(r6*x) + C4*exp(r7*x) + C5*exp(r8*x)
  2195. + exp(re(r9)*x) * (C1*sin(im(r9)*x) + C2*cos(im(r9)*x)))],
  2196. 'checkodesol_XFAIL':True, #It Hangs
  2197. },
  2198. # Five distinct real roots
  2199. 'lin_const_coeff_hom_35': {
  2200. 'eq': f(x).diff(x,5) - 100*f(x).diff(x,3) + 1000*f(x).diff(x) + f(x),
  2201. 'sol': [Eq(f(x), C1*exp(r11*x) + C2*exp(r12*x) + C3*exp(r13*x) + C4*exp(r14*x) + C5*exp(r15*x))],
  2202. 'checkodesol_XFAIL':True, #It Hangs
  2203. },
  2204. # Rational root and unsolvable quintic
  2205. 'lin_const_coeff_hom_36': {
  2206. 'eq': f(x).diff(x, 6) - 6*f(x).diff(x, 5) + 5*f(x).diff(x, 4) + 10*f(x).diff(x) - 50 * f(x),
  2207. 'sol': [Eq(f(x),
  2208. C5*exp(5*x)
  2209. + C6*exp(x*r16)
  2210. + exp(re(r17)*x) * (C1*sin(im(r17)*x) + C2*cos(im(r17)*x))
  2211. + exp(re(r19)*x) * (C3*sin(im(r19)*x) + C4*cos(im(r19)*x)))],
  2212. 'checkodesol_XFAIL':True, #It Hangs
  2213. },
  2214. # Five double roots (this is (x**5 - x + 1)**2)
  2215. 'lin_const_coeff_hom_37': {
  2216. 'eq': f(x).diff(x, 10) - 2*f(x).diff(x, 6) + 2*f(x).diff(x, 5)
  2217. + f(x).diff(x, 2) - 2*f(x).diff(x, 1) + f(x),
  2218. 'sol': [Eq(f(x), (C1 + C2*x)*exp(x*r21) + (-((C3 + C4*x)*sin(x*im(r22)))
  2219. + (C5 + C6*x)*cos(x*im(r22)))*exp(x*re(r22)) + (-((C7 + C8*x)*sin(x*im(r24)))
  2220. + (C10*x + C9)*cos(x*im(r24)))*exp(x*re(r24)))],
  2221. 'checkodesol_XFAIL':True, #It Hangs
  2222. },
  2223. 'lin_const_coeff_hom_38': {
  2224. 'eq': Eq(sqrt(2) * f(x).diff(x,x,x) + f(x).diff(x), 0),
  2225. 'sol': [Eq(f(x), C1 + C2*sin(2**Rational(3, 4)*x/2) + C3*cos(2**Rational(3, 4)*x/2))],
  2226. },
  2227. 'lin_const_coeff_hom_39': {
  2228. 'eq': Eq(E * f(x).diff(x,x,x) + f(x).diff(x), 0),
  2229. 'sol': [Eq(f(x), C1 + C2*sin(x/sqrt(E)) + C3*cos(x/sqrt(E)))],
  2230. },
  2231. 'lin_const_coeff_hom_40': {
  2232. 'eq': Eq(pi * f(x).diff(x,x,x) + f(x).diff(x), 0),
  2233. 'sol': [Eq(f(x), C1 + C2*sin(x/sqrt(pi)) + C3*cos(x/sqrt(pi)))],
  2234. },
  2235. 'lin_const_coeff_hom_41': {
  2236. 'eq': Eq(I * f(x).diff(x,x,x) + f(x).diff(x), 0),
  2237. 'sol': [Eq(f(x), C1 + C2*exp(-sqrt(I)*x) + C3*exp(sqrt(I)*x))],
  2238. },
  2239. 'lin_const_coeff_hom_42': {
  2240. 'eq': f(x).diff(x, x) + y*f(x),
  2241. 'sol': [Eq(f(x), C1*exp(-x*sqrt(-y)) + C2*exp(x*sqrt(-y)))],
  2242. },
  2243. 'lin_const_coeff_hom_43': {
  2244. 'eq': Eq(9*f(x).diff(x, x) + f(x), 0),
  2245. 'sol': [Eq(f(x), C1*sin(x/3) + C2*cos(x/3))],
  2246. },
  2247. 'lin_const_coeff_hom_44': {
  2248. 'eq': Eq(9*f(x).diff(x, x), f(x)),
  2249. 'sol': [Eq(f(x), C1*exp(-x/3) + C2*exp(x/3))],
  2250. },
  2251. 'lin_const_coeff_hom_45': {
  2252. 'eq': Eq(f(x).diff(x, x) - 3*diff(f(x), x) + 2*f(x), 0),
  2253. 'sol': [Eq(f(x), (C1 + C2*exp(x))*exp(x))],
  2254. },
  2255. 'lin_const_coeff_hom_46': {
  2256. 'eq': Eq(f(x).diff(x, x) - 4*diff(f(x), x) + 4*f(x), 0),
  2257. 'sol': [Eq(f(x), (C1 + C2*x)*exp(2*x))],
  2258. },
  2259. # Type: 2nd order, constant coefficients (two real equal roots)
  2260. 'lin_const_coeff_hom_47': {
  2261. 'eq': Eq(f(x).diff(x, x) + 2*diff(f(x), x) + 3*f(x), 0),
  2262. 'sol': [Eq(f(x), (C1*sin(x*sqrt(2)) + C2*cos(x*sqrt(2)))*exp(-x))],
  2263. },
  2264. #These were from issue: https://github.com/sympy/sympy/issues/6247
  2265. 'lin_const_coeff_hom_48': {
  2266. 'eq': f(x).diff(x, x) + 4*f(x),
  2267. 'sol': [Eq(f(x), C1*sin(2*x) + C2*cos(2*x))],
  2268. },
  2269. }
  2270. }
  2271. @_add_example_keys
  2272. def _get_examples_ode_sol_1st_homogeneous_coeff_subs_dep_div_indep():
  2273. return {
  2274. 'hint': "1st_homogeneous_coeff_subs_dep_div_indep",
  2275. 'func': f(x),
  2276. 'examples':{
  2277. 'dep_div_indep_01': {
  2278. 'eq': f(x)/x*cos(f(x)/x) - (x/f(x)*sin(f(x)/x) + cos(f(x)/x))*f(x).diff(x),
  2279. 'sol': [Eq(log(x), C1 - log(f(x)*sin(f(x)/x)/x))],
  2280. 'slow': True
  2281. },
  2282. #indep_div_dep actually has a simpler solution for example 2 but it runs too slow.
  2283. 'dep_div_indep_02': {
  2284. 'eq': x*f(x).diff(x) - f(x) - x*sin(f(x)/x),
  2285. 'sol': [Eq(log(x), log(C1) + log(cos(f(x)/x) - 1)/2 - log(cos(f(x)/x) + 1)/2)],
  2286. 'simplify_flag':False,
  2287. },
  2288. 'dep_div_indep_03': {
  2289. 'eq': x*exp(f(x)/x) - f(x)*sin(f(x)/x) + x*sin(f(x)/x)*f(x).diff(x),
  2290. 'sol': [Eq(log(x), C1 + exp(-f(x)/x)*sin(f(x)/x)/2 + exp(-f(x)/x)*cos(f(x)/x)/2)],
  2291. 'slow': True
  2292. },
  2293. 'dep_div_indep_04': {
  2294. 'eq': f(x).diff(x) - f(x)/x + 1/sin(f(x)/x),
  2295. 'sol': [Eq(f(x), x*(-acos(C1 + log(x)) + 2*pi)), Eq(f(x), x*acos(C1 + log(x)))],
  2296. 'slow': True
  2297. },
  2298. # previous code was testing with these other solution:
  2299. # example5_solb = Eq(f(x), log(log(C1/x)**(-x)))
  2300. 'dep_div_indep_05': {
  2301. 'eq': x*exp(f(x)/x) + f(x) - x*f(x).diff(x),
  2302. 'sol': [Eq(f(x), log((1/(C1 - log(x)))**x))],
  2303. 'checkodesol_XFAIL':True, #(because of **x?)
  2304. },
  2305. }
  2306. }
  2307. @_add_example_keys
  2308. def _get_examples_ode_sol_linear_coefficients():
  2309. return {
  2310. 'hint': "linear_coefficients",
  2311. 'func': f(x),
  2312. 'examples':{
  2313. 'linear_coeff_01': {
  2314. 'eq': f(x).diff(x) + (3 + 2*f(x))/(x + 3),
  2315. 'sol': [Eq(f(x), C1/(x**2 + 6*x + 9) - Rational(3, 2))],
  2316. },
  2317. }
  2318. }
  2319. @_add_example_keys
  2320. def _get_examples_ode_sol_1st_homogeneous_coeff_best():
  2321. return {
  2322. 'hint': "1st_homogeneous_coeff_best",
  2323. 'func': f(x),
  2324. 'examples':{
  2325. # previous code was testing this with other solution:
  2326. # example1_solb = Eq(-f(x)/(1 + log(x/f(x))), C1)
  2327. '1st_homogeneous_coeff_best_01': {
  2328. 'eq': f(x) + (x*log(f(x)/x) - 2*x)*diff(f(x), x),
  2329. 'sol': [Eq(f(x), -exp(C1)*LambertW(-x*exp(-C1 + 1)))],
  2330. 'checkodesol_XFAIL':True, #(because of LambertW?)
  2331. },
  2332. '1st_homogeneous_coeff_best_02': {
  2333. 'eq': 2*f(x)*exp(x/f(x)) + f(x)*f(x).diff(x) - 2*x*exp(x/f(x))*f(x).diff(x),
  2334. 'sol': [Eq(log(f(x)), C1 - 2*exp(x/f(x)))],
  2335. },
  2336. # previous code was testing this with other solution:
  2337. # example3_solb = Eq(log(C1*x*sqrt(1/x)*sqrt(f(x))) + x**2/(2*f(x)**2), 0)
  2338. '1st_homogeneous_coeff_best_03': {
  2339. 'eq': 2*x**2*f(x) + f(x)**3 + (x*f(x)**2 - 2*x**3)*f(x).diff(x),
  2340. 'sol': [Eq(f(x), exp(2*C1 + LambertW(-2*x**4*exp(-4*C1))/2)/x)],
  2341. 'checkodesol_XFAIL':True, #(because of LambertW?)
  2342. },
  2343. '1st_homogeneous_coeff_best_04': {
  2344. 'eq': (x + sqrt(f(x)**2 - x*f(x)))*f(x).diff(x) - f(x),
  2345. 'sol': [Eq(log(f(x)), C1 - 2*sqrt(-x/f(x) + 1))],
  2346. 'slow': True,
  2347. },
  2348. '1st_homogeneous_coeff_best_05': {
  2349. 'eq': x + f(x) - (x - f(x))*f(x).diff(x),
  2350. 'sol': [Eq(log(x), C1 - log(sqrt(1 + f(x)**2/x**2)) + atan(f(x)/x))],
  2351. },
  2352. '1st_homogeneous_coeff_best_06': {
  2353. 'eq': x*f(x).diff(x) - f(x) - x*sin(f(x)/x),
  2354. 'sol': [Eq(f(x), 2*x*atan(C1*x))],
  2355. },
  2356. '1st_homogeneous_coeff_best_07': {
  2357. 'eq': x**2 + f(x)**2 - 2*x*f(x)*f(x).diff(x),
  2358. 'sol': [Eq(f(x), -sqrt(x*(C1 + x))), Eq(f(x), sqrt(x*(C1 + x)))],
  2359. },
  2360. '1st_homogeneous_coeff_best_08': {
  2361. 'eq': f(x)**2 + (x*sqrt(f(x)**2 - x**2) - x*f(x))*f(x).diff(x),
  2362. 'sol': [Eq(log(x), C1 - log(f(x)/x) + acosh(f(x)/x))],
  2363. },
  2364. }
  2365. }
  2366. def _get_all_examples():
  2367. all_examples = _get_examples_ode_sol_euler_homogeneous + \
  2368. _get_examples_ode_sol_euler_undetermined_coeff + \
  2369. _get_examples_ode_sol_euler_var_para + \
  2370. _get_examples_ode_sol_factorable + \
  2371. _get_examples_ode_sol_bernoulli + \
  2372. _get_examples_ode_sol_nth_algebraic + \
  2373. _get_examples_ode_sol_riccati + \
  2374. _get_examples_ode_sol_1st_linear + \
  2375. _get_examples_ode_sol_1st_exact + \
  2376. _get_examples_ode_sol_almost_linear + \
  2377. _get_examples_ode_sol_nth_order_reducible + \
  2378. _get_examples_ode_sol_nth_linear_undetermined_coefficients + \
  2379. _get_examples_ode_sol_liouville + \
  2380. _get_examples_ode_sol_separable + \
  2381. _get_examples_ode_sol_1st_rational_riccati + \
  2382. _get_examples_ode_sol_nth_linear_var_of_parameters + \
  2383. _get_examples_ode_sol_2nd_linear_bessel + \
  2384. _get_examples_ode_sol_2nd_2F1_hypergeometric + \
  2385. _get_examples_ode_sol_2nd_nonlinear_autonomous_conserved + \
  2386. _get_examples_ode_sol_separable_reduced + \
  2387. _get_examples_ode_sol_lie_group + \
  2388. _get_examples_ode_sol_2nd_linear_airy + \
  2389. _get_examples_ode_sol_nth_linear_constant_coeff_homogeneous +\
  2390. _get_examples_ode_sol_1st_homogeneous_coeff_best +\
  2391. _get_examples_ode_sol_1st_homogeneous_coeff_subs_dep_div_indep +\
  2392. _get_examples_ode_sol_linear_coefficients
  2393. return all_examples