Last active
June 15, 2025 02:50
-
-
Save joinr/d7c91d4da215447a1a1f9c578d3c0685 to your computer and use it in GitHub Desktop.
interpolation demo usinig fastmath v3 (from the noj bundle)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns demo | |
(:require [fastmath.interpolation :as interpolation] | |
[scicloj.tableplot.v1.plotly :as plotly] | |
[tablecloth.api :as tc])) | |
(def px [0 1 3 4 5 8 9]) | |
(def py [0 0 1 7 3 4 6]) | |
(def in (tc/dataset {:x (range 0 8.0 0.01)})) | |
;;subset of available interpolations. | |
(def kinds [:linear | |
:cubic | |
:monotone | |
:akima | |
:neville | |
:divided-difference | |
:polynomial | |
:sprague | |
:step-before | |
:step-after]) | |
kinds | |
(def results | |
(->> (for [k kinds ] | |
(let [f (interpolation/interpolation k px py)] | |
[k (mapv f x)])) | |
(reduce (fn [acc [k v]] | |
(tc/add-column acc k v)) in))) | |
results | |
(defn plot-it [data kind] | |
(-> data | |
(plotly/layer-line | |
{:=x :x | |
:=y kind}))) | |
(plot-it results :linear) | |
(plot-it results :cubic) | |
(plot-it results :monotone) | |
(plot-it results :akima) | |
(plot-it results :neville) | |
(plot-it results :divided-difference) | |
(plot-it results :polynomial) | |
(plot-it results :sprague) | |
(plot-it results :step-before) | |
(plot-it results :step-after) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment