def test_pde_1st_linear_constant_coeff_homogeneous(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = 2 * u + u.diff(x) + u.diff(y) assert classify_pde(eq) == ('1st_linear_constant_coeff_homogeneous', ) sol = pdsolve(eq) assert sol == Eq(u, F(x - y) * exp(-x - y)) assert checkpdesol(eq, sol)[0] eq = 4 + (3 * u.diff(x) / u) + (2 * u.diff(y) / u) assert classify_pde(eq) == ('1st_linear_constant_coeff_homogeneous', ) sol = pdsolve(eq) assert sol == Eq( u, F(2 * x - 3 * y) * exp(-Integer(12) * x / 13 - Integer(8) * y / 13)) assert checkpdesol(eq, sol)[0] eq = u + (6 * u.diff(x)) + (7 * u.diff(y)) assert classify_pde(eq) == ('1st_linear_constant_coeff_homogeneous', ) sol = pdsolve(eq) assert sol == Eq( u, F(7 * x - 6 * y) * exp(-6 * x / Integer(85) - 7 * y / Integer(85))) assert checkpdesol(eq, sol)[0] eq = a * u + b * u.diff(x) + c * u.diff(y) sol = pdsolve(eq) assert checkpdesol(eq, sol)[0]
def test_pdsolve_variable_coeff(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = x * (u.diff(x)) - y * (u.diff(y)) + y**2 * u - y**2 sol = pdsolve(eq, hint="1st_linear_variable_coeff") assert sol == Eq(u, F(x * y) * exp(y**2 / 2) + 1) assert checkpdesol(eq, sol)[0] eq = x**2 * u + x * u.diff(x) + x * y * u.diff(y) sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, F(y * exp(-x)) * exp(-x**2 / 2)) assert checkpdesol(eq, sol)[0] eq = y * x**2 * u + y * u.diff(x) + u.diff(y) sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, F(-2 * x + y**2) * exp(-x**3 / 3)) assert checkpdesol(eq, sol)[0] eq = exp(x)**2 * (u.diff(x)) + y sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, y * exp(-2 * x) / 2 + F(y)) assert checkpdesol(eq, sol)[0] eq = exp(2 * x) * (u.diff(y)) + y * u - u sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, exp((-y**2 + 2 * y + 2 * F(x)) * exp(-2 * x) / 2))
def test_solvefun(): f, F, G, H = map(Function, ['f', 'F', 'G', 'H']) eq1 = f(x, y) + f(x, y).diff(x) + f(x, y).diff(y) assert pdsolve(eq1) == Eq(f(x, y), F(x - y) * exp(-x / 2 - y / 2)) assert pdsolve(eq1, solvefun=G) == Eq(f(x, y), G(x - y) * exp(-x / 2 - y / 2)) assert pdsolve(eq1, solvefun=H) == Eq(f(x, y), H(x - y) * exp(-x / 2 - y / 2))
def test_checkpdesol(): f, F = map(Function, ['f', 'F']) eq1 = a * f(x, y) + b * f(x, y).diff(x) + c * f(x, y).diff(y) eq2 = 3 * f(x, y) + 2 * f(x, y).diff(x) + f(x, y).diff(y) eq3 = a * f(x, y) + b * f(x, y).diff(x) + 2 * f(x, y).diff(y) for eq in [eq1, eq2, eq3]: assert checkpdesol(eq, pdsolve(eq))[0] eq4 = x * f(x, y) + f(x, y).diff(x) + 3 * f(x, y).diff(y) eq5 = 2 * f(x, y) + 1 * f(x, y).diff(x) + 3 * f(x, y).diff(y) eq6 = f(x, y) + 1 * f(x, y).diff(x) + 3 * f(x, y).diff(y) assert checkpdesol(eq4, [pdsolve(eq5), pdsolve(eq6)]) == [ (False, (x - 2) * F(3 * x - y) * exp(-x / Integer(5) - 3 * y / Integer(5))), (False, (x - 1) * F(3 * x - y) * exp(-x / Integer(10) - 3 * y / Integer(10))) ] for eq in [eq4, eq5, eq6]: assert checkpdesol(eq, pdsolve(eq))[0]
def test_pde_1st_linear_constant_coeff(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = -2 * u.diff(x) + 4 * u.diff(y) + 5 * u - exp(x + 3 * y) sol = pdsolve(eq) assert sol == Eq(f( x, y), (F(4 * x + 2 * y) + exp(x / Integer(2) + 4 * y) / Integer(15)) * exp(x / Integer(2) - y)) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = (u.diff(x) / u) + (u.diff(y) / u) + 1 - (exp(x + y) / u) sol = pdsolve(eq) assert sol == Eq(f(x, y), F(x - y) * exp(-x / 2 - y / 2) + exp(x + y) / Integer(3)) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = 2 * u + -u.diff(x) + 3 * u.diff(y) + sin(x) sol = pdsolve(eq) assert sol == Eq( f(x, y), F(3 * x + y) * exp(x / Integer(5) - 3 * y / Integer(5)) - 2 * sin(x) / Integer(5) - cos(x) / Integer(5)) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = u + u.diff(x) + u.diff(y) + x * y sol = pdsolve(eq) assert sol == Eq( f(x, y), -x * y + x + y + F(x - y) * exp(-x / Integer(2) - y / Integer(2)) - 2) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = u + u.diff(x) + u.diff(y) + log(x) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral')
def test_pdsolve_all(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = u + u.diff(x) + u.diff(y) + x**2*y sol = pdsolve(eq, hint='all') keys = ['1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral', 'default', 'order'] assert sorted(sol) == keys assert sol['order'] == 1 assert sol['default'] == '1st_linear_constant_coeff' assert sol['1st_linear_constant_coeff'] == Eq(f(x, y), -x**2*y + x**2 + 2*x*y - 4*x - 2*y + F(x - y)*exp(-x/Integer(2) - y/Integer(2)) + 6)
def test_checkpdesol(): f, F = map(Function, ['f', 'F']) eq1 = a*f(x, y) + b*f(x, y).diff(x) + c*f(x, y).diff(y) eq2 = 3*f(x, y) + 2*f(x, y).diff(x) + f(x, y).diff(y) eq3 = a*f(x, y) + b*f(x, y).diff(x) + 2*f(x, y).diff(y) for eq in [eq1, eq2, eq3]: assert checkpdesol(eq, pdsolve(eq))[0] eq4 = x*f(x, y) + f(x, y).diff(x) + 3*f(x, y).diff(y) eq5 = 2*f(x, y) + 1*f(x, y).diff(x) + 3*f(x, y).diff(y) eq6 = f(x, y) + 1*f(x, y).diff(x) + 3*f(x, y).diff(y) assert checkpdesol(eq4, [pdsolve(eq5), pdsolve(eq6)]) == [ (False, (x - 2)*F(3*x - y)*exp(-x/Integer(5) - 3*y/Integer(5))), (False, (x - 1)*F(3*x - y)*exp(-x/Integer(10) - 3*y/Integer(10)))] for eq in [eq4, eq5, eq6]: assert checkpdesol(eq, pdsolve(eq))[0] sol = pdsolve(eq4) sol4 = Eq(sol.lhs - sol.rhs, 0) pytest.raises(NotImplementedError, lambda: checkpdesol(eq4, sol4, solve_for_func=False)) assert checkpdesol(f(x, y).diff(x) - x*f(x, y).diff(y) + 1, F(x**2/2 + y) - x)[0]
def test_pdsolve_all(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = u + u.diff(x) + u.diff(y) + x**2*y sol = pdsolve(eq, hint='all') keys = ['1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral', 'default', 'order'] assert sorted(sol) == keys assert sol['order'] == 1 assert sol['default'] == '1st_linear_constant_coeff' assert sol['1st_linear_constant_coeff'] == Eq(f(x, y), -x**2*y + x**2 + 2*x*y - 4*x - 2*y + F(x - y)*exp(-x/2 - y/2) + 6)
def test_checkpdesol(): f, F = map(Function, ['f', 'F']) eq1 = a*f(x, y) + b*f(x, y).diff(x) + c*f(x, y).diff(y) eq2 = 3*f(x, y) + 2*f(x, y).diff(x) + f(x, y).diff(y) eq3 = a*f(x, y) + b*f(x, y).diff(x) + 2*f(x, y).diff(y) for eq in [eq1, eq2, eq3]: assert checkpdesol(eq, pdsolve(eq))[0] eq4 = x*f(x, y) + f(x, y).diff(x) + 3*f(x, y).diff(y) eq5 = 2*f(x, y) + 1*f(x, y).diff(x) + 3*f(x, y).diff(y) eq6 = f(x, y) + 1*f(x, y).diff(x) + 3*f(x, y).diff(y) assert checkpdesol(eq4, [pdsolve(eq5), pdsolve(eq6)]) == [ (False, (x - 2)*F(3*x - y)*exp(-x/5 - 3*y/5)), (False, (x - 1)*F(3*x - y)*exp(-x/10 - 3*y/10))] for eq in [eq4, eq5, eq6]: assert checkpdesol(eq, pdsolve(eq))[0] sol = pdsolve(eq4) sol4 = Eq(sol.lhs - sol.rhs, 0) pytest.raises(NotImplementedError, lambda: checkpdesol(eq4, sol4, solve_for_func=False)) assert checkpdesol(f(x, y).diff(x) - x*f(x, y).diff(y) + 1, F(x**2/2 + y) - x)[0]
def test_pde_1st_linear_constant_coeff(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = -2*u.diff(x) + 4*u.diff(y) + 5*u - exp(x + 3*y) sol = pdsolve(eq) assert sol == Eq(f(x, y), (F(4*x + 2*y) + exp(x/2 + 4*y)/15)*exp(x/2 - y)) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = (u.diff(x)/u) + (u.diff(y)/u) + 1 - (exp(x + y)/u) sol = pdsolve(eq) assert sol == Eq(f(x, y), F(x - y)*exp(-x/2 - y/2) + exp(x + y)/3) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = 2*u + -u.diff(x) + 3*u.diff(y) + sin(x) sol = pdsolve(eq) assert sol == Eq(f(x, y), F(3*x + y)*exp(x/5 - 3*y/5) - 2*sin(x)/5 - cos(x)/5) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = u + u.diff(x) + u.diff(y) + x*y sol = pdsolve(eq) assert sol == Eq(f(x, y), -x*y + x + y + F(x - y)*exp(-x/2 - y/2) - 2) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral') assert checkpdesol(eq, sol)[0] eq = u + u.diff(x) + u.diff(y) + log(x) assert classify_pde(eq) == ('1st_linear_constant_coeff', '1st_linear_constant_coeff_Integral')
def test_pde_1st_linear_constant_coeff_homogeneous(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = 2*u + u.diff(x) + u.diff(y) assert classify_pde(eq) == ('1st_linear_constant_coeff_homogeneous',) sol = pdsolve(eq) assert sol == Eq(u, F(x - y)*exp(-x - y)) assert checkpdesol(eq, sol)[0] eq = 4 + (3*u.diff(x)/u) + (2*u.diff(y)/u) assert classify_pde(eq) == ('1st_linear_constant_coeff_homogeneous',) sol = pdsolve(eq) assert sol == Eq(u, F(2*x - 3*y)*exp(-12*x/13 - 8*y/13)) assert checkpdesol(eq, sol)[0] eq = u + (6*u.diff(x)) + (7*u.diff(y)) assert classify_pde(eq) == ('1st_linear_constant_coeff_homogeneous',) sol = pdsolve(eq) assert sol == Eq(u, F(7*x - 6*y)*exp(-6*x/85 - 7*y/85)) assert checkpdesol(eq, sol)[0] eq = a*u + b*u.diff(x) + c*u.diff(y) sol = pdsolve(eq) assert checkpdesol(eq, sol)[0]
def test_pdsolve_variable_coeff(): f, F = map(Function, ['f', 'F']) u = f(x, y) eq = x*(u.diff(x)) - y*(u.diff(y)) + y**2*u - y**2 sol = pdsolve(eq, hint="1st_linear_variable_coeff") assert sol == Eq(u, F(x*y)*exp(y**2/2) + 1) assert checkpdesol(eq, sol)[0] eq = x**2*u + x*u.diff(x) + x*y*u.diff(y) sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, F(y*exp(-x))*exp(-x**2/2)) assert checkpdesol(eq, sol)[0] eq = y*x**2*u + y*u.diff(x) + u.diff(y) sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, F(-2*x + y**2)*exp(-x**3/3)) assert checkpdesol(eq, sol)[0] eq = exp(x)**2*(u.diff(x)) + y sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, y*exp(-2*x)/2 + F(y)) assert checkpdesol(eq, sol)[0] eq = exp(2*x)*(u.diff(y)) + y*u - u sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, exp((-y**2 + 2*y + 2*F(x))*exp(-2*x)/2)) eq = u.diff(x) + y*u - 3 sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, 3/y + exp(-x*y)*exp(y*F(y))/y) eq = u.diff(x) + x*u.diff(y) - 3 sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert sol == Eq(u, 3*x + F(-x**2/2 + y)) eq = x*u.diff(y) - y sol = pdsolve(eq, hint='1st_linear_variable_coeff') assert pdsolve(eq) == Eq(u, F(x) + y**2/x/2)
def test_solvefun(): f, F, G, H = map(Function, ['f', 'F', 'G', 'H']) eq1 = f(x, y) + f(x, y).diff(x) + f(x, y).diff(y) assert pdsolve(eq1) == Eq(f(x, y), F(x - y)*exp(-x/2 - y/2)) assert pdsolve(eq1, solvefun=G) == Eq(f(x, y), G(x - y)*exp(-x/2 - y/2)) assert pdsolve(eq1, solvefun=H) == Eq(f(x, y), H(x - y)*exp(-x/2 - y/2))