Refactor bessel solver - #21706
Conversation
|
✅ Hi, I am the SymPy bot (v161). I'm here to help you write a release notes entry. Please read the guide on how to write release notes.
Click here to see the pull request description that was parsed. |
| self.rn = {'b':self.rn[a4],'m':self.rn[b4]} | ||
| does_match = True | ||
| return does_match | ||
|
|
There was a problem hiding this comment.
@oscarbenjamin According to my understanding about 2nd_linear_airy, I attempted to simplify the match function something like :
def _matches(self):
eq = self.ode_problem.eq_high_order_free
f = self.ode_problem.func
order = self.ode_problem.order
x = self.ode_problem.sym
df = f.diff(x)
a4 = Wild('a4', exclude=[x,f,df])
b4 = Wild('b4', exclude=[x,f,df])
match = self.ode_problem.get_linear_coefficients(eq, f, order)
does_match = False
if order == 2 and match and match[2] != 0:
if match[1].is_zero:
self.rn = match[0].match(a4+b4*x)
if self.rn and self.rn[b4] != 0:
self.rn = {'b':self.rn[a4],'m':self.rn[b4]}
does_match = True
return does_matchIt passes all the tests but wanted to ask you does this diff look ok?
There was a problem hiding this comment.
Does get_linear_coefficients divide by the leading coefficient?
What happens if you have something like x y'' + x y = 0?
There was a problem hiding this comment.
x y'' + x y = 0
It fails for this. I thought self.ode_problem.eq_high_order_free passing in the get_linear_coefficients would work as eq_high_order_free removes leading coefficient but it only remove f(x) not x.
There was a problem hiding this comment.
if we replace self.rn = match[0].match(a4+b4*x) with self.rn = cancel(match[0]/match[2]).match(a4+b4*x) . It will solve the problem 🤔
| def _get_general_solution(self, *, simplify_flag: bool = True): | ||
| f = self.ode_problem.func.func | ||
| x = self.ode_problem.sym | ||
| (C0, C1) = self.ode_problem.get_numbered_constants(num=2) |
|
@oscarbenjamin I have updated the match function. PTAL |
|
I just noticed this bug on master: In [43]: dsolve(x*f(x).diff(x, 2) - x*f(x))
Out[43]: f(x) = √x⋅(C₁⋅besselj(1/2, ⅈ⋅x) + C₂⋅bessely(1/2, ⅈ⋅x))Is that bug also in this PR? |
Isn't it the correct solution as |
It might be correct for some part of the domain but it is definitely not as good as this: In [68]: eq = f(x).diff(x, 2) - f(x)
In [69]: dsolve(eq)
Out[69]:
-x x
f(x) = C₁⋅ℯ + C₂⋅ℯ
In [70]: dsolve(expand(x*eq))
Out[70]: f(x) = √x⋅(C₁⋅besselj(1/2, ⅈ⋅x) + C₂⋅bessely(1/2, ⅈ⋅x))The Bessel solution is not continuous at |
So should we first check if the equation is analytic at 0 or some point? 🤔 |
This should definitely match the constant coefficients solver. I'm not sure what should be done with the Bessel solver. |
It doesn't not match directly with constant coefficients solver because in |
@oscarbenjamin Thanks for pointing out this example! |
|
|
||
|
|
||
| def test_slow_examples_factorable(): | ||
| _ode_solver_test(_get_examples_ode_sol_factorable, run_slow_test=True) |
There was a problem hiding this comment.
Shouldn't this be marked as slow?
| Gives solution of the Bessel differential equation | ||
|
|
||
| .. math :: x^2 \frac{d^2y}{dx^2} + x \frac{dy}{dx} y(x) + (x^2-n^2) y(x) | ||
|
|
||
| if n is integer then the solution is of the form Eq(f(x), C0 besselj(n,x) | ||
| + C1 bessely(n,x)) as both the solutions are linearly independent else if | ||
| n is a fraction then the solution is of the form Eq(f(x), C0 besselj(n,x) | ||
| + C1 besselj(-n,x)) which can also transform into Eq(f(x), C0 besselj(n,x) | ||
| + C1 bessely(n,x)). |
There was a problem hiding this comment.
The equations here should be in LaTeX. If they are supposed to be code rather than equations then they should be in double backticks.
| NthLinearEulerEqNonhomogeneousVariationOfParameters: ('nth_linear_euler_eq_nonhomogeneous_variation_of_parameters',), | ||
| NthLinearEulerEqNonhomogeneousUndeterminedCoefficients: ('nth_linear_euler_eq_nonhomogeneous_undetermined_coefficients',), | ||
| LinearBessel2nd: ('2nd_linear_bessel',), | ||
| LinearAiry2nd: ('2nd_linear_airy',), |
There was a problem hiding this comment.
It would be better to call these e.g. SecondLinearBessel
There was a problem hiding this comment.
Also Hypergeometric2nd should be renamed.
|
Looks good. Thanks |
|
@oscarbenjamin should I raise PR for lie_group first and then speedup the process of calling classify_ode? |
Up to you. You can also just work on both in parallel. |
References to other Issues or PRs
Brief description of what is fixed or changed
SEE #18348
Other comments
Release Notes
NO ENTRY