Ian Jauslin
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'src/interpolation.jl')
-rw-r--r--src/interpolation.jl36
1 files changed, 28 insertions, 8 deletions
diff --git a/src/interpolation.jl b/src/interpolation.jl
index fa3bcdb..066bc20 100644
--- a/src/interpolation.jl
+++ b/src/interpolation.jl
@@ -1,4 +1,4 @@
-## Copyright 2021 Ian Jauslin
+## Copyright 2021-2023 Ian Jauslin
##
## Licensed under the Apache License, Version 2.0 (the "License");
## you may not use this file except in compliance with the License.
@@ -14,7 +14,11 @@
# linear interpolation: given vectors x,y, compute a linear interpolation for y(x0)
# assume x is ordered
-@everywhere function linear_interpolation(x0,x,y)
+@everywhere function linear_interpolation(
+ x0::Float64,
+ x::Array{Float64,1},
+ y::Array{Float64,1}
+)
# if x0 is beyond all x's, then return the corresponding boundary value.
if x0>x[length(x)]
return y[length(y)]
@@ -28,7 +32,12 @@
# interpolate
return y[i]+(y[i+1]-y[i])*(x0-x[i])/(x[i+1]-x[i])
end
-@everywhere function bracket(x0,x,a,b)
+@everywhere function bracket(
+ x0::Float64,
+ x::Array{Float64,1},
+ a::Int64,
+ b::Int64
+)
i=floor(Int64,(a+b)/2)
if x0<x[i]
return bracket(x0,x,a,i)
@@ -41,15 +50,18 @@ end
# polynomial interpolation of a family of points
-@everywhere function poly_interpolation(x,y)
+@everywhere function poly_interpolation(
+ x::Array{Float64,1},
+ y::Array{Float64,1}
+)
# init for recursion
- rec=Array{Polynomial{Float64}}(undef,length(x))
+ rec=Array{Polynomial{Float64},1}(undef,length(x))
for i in 1:length(x)
rec[i]=Polynomial([1.])
end
# compute \prod (x-x_i)
- poly_interpolation_rec(rec,x,1,length(x))
+ poly_interpolation_rec(rec,x,1.,length(x))
# sum terms together
out=0.
@@ -60,7 +72,12 @@ end
return out
end
# recursive helper function
-@everywhere function poly_interpolation_rec(out,x,a,b)
+@everywhere function poly_interpolation_rec(
+ out::Array{Float64,1},
+ x::Array{Float64,1},
+ a::Float64,
+ b::Float64
+)
if a==b
return
end
@@ -91,7 +108,10 @@ end
return
end
## the following does the same, but has complexity N^2, the function above has N*log(N)
-#@everywhere function poly_interpolation(x,y)
+#@everywhere function poly_interpolation(
+# x::Array{Float64,1},
+# y::Array{Float64,1}
+#)
# out=Polynomial([0.])
# for i in 1:length(x)
# prod=Polynomial([1.])