如何在 Julia 中从不均匀排列的数组中插入数据?
How to interpolate data from unevenly spaced array in Julia?
如何使用最近邻插值在 Julia 中构造 不均匀间隔数据的插值?我查看了 the documentation 并在 REPL 中输入了以下内容:
using Interpolations
input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0]
itp = interpolate(input[:,1], input[:,2], Gridded(Constant()))
这对我来说似乎很简单,但给出了:
ERROR: LoadError: MethodError: no method matching
interpolate(::Array{Float64,1}, ::Array{Float64,1},
::Gridded{Constant})
我需要将 Array
转换为 Vector
吗?如果是这样,如何?请告诉我有一个简单的解决方案...
当你在N维space时,你应该把插值坐标"knots"放在N-向量元组。在一维中,这意味着像 (x,)
这样的 1 元组而不是普通的 x
:
julia> input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0]
6×2 Array{Float64,2}:
1.0 60.0
1.1 0.0
2.0 60.0
2.3 0.0
4.0 430.0
4.05 0.0
julia> x = input[:, 1];
julia> y = input[:, 2];
julia> itp = interpolate((x,), y, Gridded(Constant()))
6-element interpolate((::Array{Float64,1},), ::Array{Float64,1}, Gridded(Constant())) with element type Float64:
60.0
0.0
60.0
0.0
430.0
0.0
julia> itp(1.01)
60.0
如何使用最近邻插值在 Julia 中构造 不均匀间隔数据的插值?我查看了 the documentation 并在 REPL 中输入了以下内容:
using Interpolations
input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0]
itp = interpolate(input[:,1], input[:,2], Gridded(Constant()))
这对我来说似乎很简单,但给出了:
ERROR: LoadError: MethodError: no method matching interpolate(::Array{Float64,1}, ::Array{Float64,1}, ::Gridded{Constant})
我需要将 Array
转换为 Vector
吗?如果是这样,如何?请告诉我有一个简单的解决方案...
当你在N维space时,你应该把插值坐标"knots"放在N-向量元组。在一维中,这意味着像 (x,)
这样的 1 元组而不是普通的 x
:
julia> input = [1.0 60; 1.1 0; 2.0 60; 2.3 0; 4.0 430; 4.05 0]
6×2 Array{Float64,2}:
1.0 60.0
1.1 0.0
2.0 60.0
2.3 0.0
4.0 430.0
4.05 0.0
julia> x = input[:, 1];
julia> y = input[:, 2];
julia> itp = interpolate((x,), y, Gridded(Constant()))
6-element interpolate((::Array{Float64,1},), ::Array{Float64,1}, Gridded(Constant())) with element type Float64:
60.0
0.0
60.0
0.0
430.0
0.0
julia> itp(1.01)
60.0