You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am quite often in the situation that i have several functions f1,f2,... defined on exactly the same domain X. I then have to interpolate each of them at the same point x \in X. Currently, I have to reconstruct an Interpolation object for each interpolation I want to do. This is not efficient, because the coefficients are going to be the same on each of those objects. In other words, this:
julia>f(x) =3x + x^2
f (generic function with 5 methods)
julia>f2(x) =3x + x^3
f2 (generic function with 1 method)
julia> domain =0:0.1:1
julia> v1 = Float64[f(i) for i in domain]
11-element Array{Float64,1}:0.00.310.640.991.361.752.162.593.043.514.0
julia> v2 = Float64[f2(i) for i in domain];
julia> itp =interpolate(v1, BSpline(Quadratic(Line())), OnCell())
11-element Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line}},Interpolations.OnCell,1}:0.00.310.640.991.361.752.162.593.043.514.0
julia> itp[1.1]
0.03070710674992569
julia> itp2 =interpolate(v2, BSpline(Quadratic(Line())), OnCell())
11-element Interpolations.BSplineInterpolation{Float64,1,Array{Float64,1},Interpolations.BSpline{Interpolations.Quadratic{Interpolations.Line}},Interpolations.OnCell,1}:0.00.3010.6080.9271.2641.6252.0162.4432.9123.4294.0
julia> itp2[1.1]
0.03002499990621737# would instead like to do
itp2 =swapValues(itp,v2)
any way this could be added? I see there is already itp.coefs. Can I construct itp2 with those coefficients? thanks.
The text was updated successfully, but these errors were encountered:
Hi @floswald I'm not 100% sure if this suits your needs, but to do multi-function interpolation on the same domain you can try to used FixedSizeArrays as hinted at in this comment
Bingo, that's exactly what I'm looking for. So the answer is that the package already supports interpolating matrices, not only vectors. Documentation is clearly lagging behind with all that's going on here!
I'm not totally sure I get the FixedSizeArray thing though. So I should cast my interpolation data as this Vec type? anyway, just if you have some experience with that, let me know. thanks!
wait a sec, that's not actually what I need. It would be my use case if the example contained 2 matrices a and aa (for example), both interpolated with the same set of coefficients. But I'm just realizing that what I'm saying makes only sense for linear interpolation, I think. the idea is that the main costly operation when interpolating x in xgrid is to searchsortedlast(xgrid,x) (or similar) to find the bracket in xgrid that contains x. Now the idea was that given I interpolate all functions on the same xgrid at the same point x, I have to do that operation only once. One could just use the weights implied by the position of x within the bracket and multiply with different function values defined at the bracket edges. Possible that this is completely pointless for the approach taken here.
I am quite often in the situation that i have several functions
f1,f2,...
defined on exactly the same domainX
. I then have to interpolate each of them at the same pointx \in X
. Currently, I have to reconstruct anInterpolation
object for each interpolation I want to do. This is not efficient, because the coefficients are going to be the same on each of those objects. In other words, this:any way this could be added? I see there is already
itp.coefs
. Can I constructitp2
with those coefficients? thanks.The text was updated successfully, but these errors were encountered: