Skip to content

Commit

Permalink
Fix interpolate function
Browse files Browse the repository at this point in the history
  • Loading branch information
paulobruno committed Nov 19, 2022
1 parent 6dfd4b9 commit 3fcc740
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/functions.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ function interpolate(x, yvalues::Tuple{Vararg{Float64}}, xrange::Tuple{Float64,

# y gets the min y value if less than the min x range
# or the max y value if greater than the max x range
y = (x < xrange[1]) * yvalues[1] + (x > xrange[2]) * yvalues[end]
y = (x < xrange[1]) * yvalues[1] + (x xrange[2]) * yvalues[end]

# in case x is inside the range, y gets the interpolated value
for i 1:length(yvalues)-1
y += (x xvalues[i]) * (x xvalues[i+1]) * interpolate(x, xvalues[i], xvalues[i+1], yvalues[i], yvalues[i+1])
y += (x xvalues[i]) * (x < xvalues[i+1]) * interpolate(x, xvalues[i], xvalues[i+1], yvalues[i], yvalues[i+1])
end

return y
Expand Down

0 comments on commit 3fcc740

Please sign in to comment.