Is there an implemented version of the legendre Polynomials with symbolic variables?
I have checked
But they either don’t implement the Legendre Polynomials or a symbolic equivalent.
What would be the most convenient way to implement them?
1 Like
Their combination does:
julia> using ClassicalOrthogonalPolynomials, Symbolics
julia> @variables x;
julia> p4 = legendrep(4, x)
0.375 + 1.75x*(1.6666666666666667x*(1.5(x^2) - 0.5) - 0.6666666666666666x) - 1.125(x^2)
julia> expand(p4)
0.375 + 4.375(x^4) - 3.75(x^2)
Gotta love composability!
8 Likes
Following up on @stevengj’s enthusiasm for composability, if you needed exact coefficients, you might mix in SpecialPolynomials:
julia> using Symbolics, SpecialPolynomials
julia> @variables x
1-element Vector{Num}:
x
julia> basis(Legendre{Rational{Int}}, 4)(x) |> expand
(3//8) + (35//8)*(x^4) - (15//4)*(x^2)
7 Likes
Excelent! As a rule of thumb, which functions should I expect to work with Symbolics.jl?
1 Like
Really nice! But this option seems to overflow for degrees n > 25
basis(Legendre{Rational{Int}}, 25)(x) |> expand
ERROR: OverflowError: -148257227381443 * 74290 overflowed for type Int64
[...]
Replacing Int for Int128 does not seem to work, because I’ll need to work with polynomials of degree 50 or more
Use BigInt if you need exact rational coefficients for high degrees?
3 Likes