-
Notifications
You must be signed in to change notification settings - Fork 51
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add function-like behavior for Taylor1, HomogeneousPolynomial and TaylorN? #116
Comments
It sounds as it could be interesting. Any comments or ideas, @dpsanders ? |
Seems like a good idea! (Is it common to evaluate Taylor series like this?) |
Thanks for the feedback! Well I guess it wouldn't hurt to be able to do This notation is helpful, for example, when working with Legendre polynomials. Using this trick, one would be able to do things such as: julia> using TaylorSeries
julia> t = Taylor1(16) #the independent variable
1.0 t + 𝒪(t¹⁷)
julia> P_2 = (5t^3-3t)/2 #2nd-degree Legendre polynomial
- 1.5 t + 2.5 t³ + 𝒪(t¹⁷)
julia> (p::Taylor1)(x) = evaluate(p, x) #add function-like behavior for Taylor1s
julia> P_2
- 1.5 t + 2.5 t³ + 𝒪(t¹⁷)
julia> P_2(-1.0) #what is the value of P_2 at -1.0?
-1.0
julia> P_2(cos(t)) #what is the Taylor expansion of P_2(cos(t)), up to 16th order?
1.0 - 3.0 t² + 2.125 t⁴ - 0.6333333333333333 t⁶ + 0.10171130952380952 t⁸ - 0.010170304232804232 t¹⁰ + 0.0006934235710277377 t¹² - 3.429014217704694e-5 t¹⁴ + 1.2858801882549402e-6 t¹⁶ + 𝒪(t¹⁷) Thus, we get a nice, legible interface for evaluating polynomials, thanks to the design of |
I like the idea too! I think it becomes much more clear! It's also natural to extend the definition into using TaylorSeries
julia> xN = TaylorN(2) + TaylorN(1)
1.0 x₁ + 1.0 x₂ + 𝒪(‖x‖⁷)
julia> (p::TaylorN)(x) = evaluate(p,x)
julia> xN([1,2])
3.0 |
#118 is merged, so I am closing this. |
Hi! I was reading the Function-like objects section of the Julia language documentation, and also @dpsanders's recent blog post, and thought that perhaps it would be nice to add function-like behavior for Taylor1, TaylorN and HomogeneousPolynomial variables? My idea is to implement something like:
And similar stuff for HomogeneousPolynomials and TaylorNs... If you think this is a worthwhile feature to add to
TaylorSeries
, I'd be more than happy to submit a PR! 😄The text was updated successfully, but these errors were encountered: