-
Notifications
You must be signed in to change notification settings - Fork 53
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
pFq Not compatible with TaylorSeries package #335
Comments
Quoting this comment from #209:
|
I am not sure why this is happening... Yet, I do notice that you are overloading |
Thanks for your reply, the "isless"problem is solved. |
I think I begin to understand the problem. Somehow you need to obtain the coefficients of the series. To be concrete, let us build a simple example: julia> x, y = set_variables("x y", order=8)
2-element Vector{TaylorN{Float64}}:
1.0 x + 𝒪(‖x‖⁹)
1.0 y + 𝒪(‖x‖⁹)
julia> ee = exp(x-y^3)
1.0 + 1.0 x + 0.5 x² + 0.16666666666666666 x³ - 1.0 y³ + 0.041666666666666664 x⁴ - 1.0 x y³ + 0.008333333333333333 x⁵ - 0.5 x² y³ + 0.001388888888888889 x⁶ - 0.16666666666666666 x³ y³ + 0.5 y⁶ + 0.0001984126984126984 x⁷ - 0.041666666666666664 x⁴ y³ + 0.5 x y⁶ + 2.48015873015873e-5 x⁸ - 0.008333333333333333 x⁵ y³ + 0.25 x² y⁶ + 𝒪(‖x‖⁹) Let me assume that you require the coeff of the monomial x³ y³ and x⁵ y³. Then: julia> getcoeff(ee, (3,3))
-0.16666666666666666
julia> getcoeff(ee, (5,3))
-0.008333333333333333 Another alternative is to get the homogeneous polynomial of specific degree, and then from the way they are ordered, the specific monomial. In order to know the actual order, use julia> show_monomials(6)
1 --> x⁶
2 --> x⁵ y
3 --> x⁴ y²
4 --> x³ y³
5 --> x² y⁴
6 --> x y⁵
7 --> y⁶
julia> ee[6] # returns the homogeneous polynomial of degree 6
0.001388888888888889 x⁶ - 0.16666666666666666 x³ y³ + 0.5 y⁶
julia> ee[6][4] # 4th coef, of homogeneous polynomial of order 6
-0.16666666666666666 The last line is equivalent to Is this what you are after? |
Two comments in your code here:
|
My problem is I tried to use TaylorSeries on hyperfunctin.here is my code |
however getcoeff can not be used on hyperfunction |
I do not know |
The following seems to work... though I still do not know if this is what you are after: julia> using HypergeometricFunctions
julia> using TaylorSeries
julia> t = Taylor1(5);
julia> pFq((0.0,), (0.0,), 0.1)
1.1051709180756477
julia> Base.float(t::Taylor1) = Taylor1(float(t.coeffs))
julia> pFq((0.0,), (0.0,), 0.1+t)
1.1051709180756477 + 1.1051709180756477 t + 0.5525854590378239 t² + 0.18419515301260794 t³ + 0.046048788253151986 t⁴ + 0.009209757650630397 t⁵ + 𝒪(t⁶) |
Thanks,that helps me! |
function bbb(params,t) ERROR: MethodError: no method matching eps(::Type{Taylor1{Float64}}) Closest candidates are: |
I think he is interested in finding series coefficients to a customized function involving Hypergeometric functions.
|
Yes, I tried to get Taylor coefficients series with hypergeometric functions t = Taylor1(5) Closest candidates are: |
I will have a look later... I need to see how is it used in HyperGeometricFunctions. I am not sure if by using a similar trick as I did before is enough or not, or if the result is supposed to be a scalar. |
First, let me indicate where the problem appears, which is not included in your message above; I essentially use the same code you have: julia> using HypergeometricFunctions
julia> using TaylorSeries
julia> Base.float(t::Taylor1) = Taylor1(float(t.coeffs))
julia> t = Taylor1(5)
1.0 t + 𝒪(t⁶)
julia> f1 = pFq((1.0,), (2.0,), t-1) # seemingly ok
0.6321205588285577 + 0.26424111765711533 t + 0.08030139707139416 t² + 0.018988156876153774 t³ + 0.003659846827343676 t⁴ + 0.0005941848175816562 t⁵ + 𝒪(t⁶)
julia> f2 = pFq((3.0,), (2.0,), t-1) # throws error related to eps
ERROR: MethodError: no method matching eps(::Type{Taylor1{Float64}})
Closest candidates are:
eps()
@ Base float.jl:957
eps(::AbstractFloat)
@ Base float.jl:953
eps(::T) where T<:Dates.TimeType
@ Dates /opt/julia/julia-1.9.2/share/julia/stdlib/v1.9/Dates/src/types.jl:435
...
Stacktrace:
[1] pFqweniger(α::Tuple{Float64}, β::Tuple{Float64}, z::Taylor1{Float64}; kmax::Int64)
@ HypergeometricFunctions ~/.julia/packages/HypergeometricFunctions/LZbIV/src/weniger.jl:158
... The reason I copy-pasted part of the error message is because it points out to the line where the error is thrown: in this case, it is this line of HypergeometricFunctions.jl, where So I extended julia> Base.eps(a::Taylor1) = eps(constant_term(a))
julia> Base.eps(::Type{Taylor1{T}}) where {T<:Number} = eps(T)
With these changes, it seems to work: julia> f2 = pFq((3.0,),(2.0,),t-1)
0.1839397205857213 + 0.36787944117141885 t + 0.27590958088092615 t² + 0.12262648021343794 t³ + 0.038320783898288496 t⁴ + 0.009196673989352056 t⁵ + 𝒪(t⁶)
I am not sure if the result is correct/consistent; you should check that with known concrete values, because it could be that a different output of the I hope this helps! |
This works for me!!! Thanks! |
Closing this because the discussion is following in #336; feel free to reopen if you think there is more to discuss here... |
I tried to use HypergeometricFunctions and TaylorSeries at the same time as follows.
using HypergeometricFunctions
using Plots
using TaylorSeries
x = set_variables("x", order=100)[1];
Base.isless(y::Number, x::TaylorN) = isless(y, x.coeffs[1].coeffs[1])
Base.log1p(x::TaylorN) = log(1+x)
Base.eps(::Type{TaylorN{T}}) where T = eps(T)
Base.isless(x::TaylorN, y::Number) = isless(x.coeffs[1].coeffs[1], y)
HypergeometricFunctions.pFq((2.0,),(5.0,),x)
However, I got the error:
ERROR: MethodError: no method matching AbstractFloat(::TaylorN{Float64})
Closest candidates are:
(::Type{T})(::T) where T<:Number
@ Core boot.jl:792
(::Type{T})(::AbstractChar) where T<:Union{AbstractChar, Number}
@ Base char.jl:50
(::Type{T})(::Base.TwicePrecision) where T<:Number
@ Base twiceprecision.jl:266
..
The text was updated successfully, but these errors were encountered: