Climate Mathematics

1 Chapter 1 Dimensional Analysis for Climate Science


This chapter is an introduction and doesn’t use R yet. I’m using this space to see about using Clay for mathematical notation as I do some exercises.

I will not share every exercise here, as many of the answers for chapter 1 are found in the back of the book and I don’t want to spoil the fun for anyone else.

1.1 Exercise 1.1

\[v = \alpha m^a g^b t^c\]

\[[v] = [\alpha] [m]^a [g]^b [t]^c\]

\[LT^{-1} = 1 \times M^a (LT ^{-2})^b T^c\]

\[LT^{-1} = M^a L^b T ^{c-2b+1}\]

\[a = 0, b = 1, c = 2b - 1 = 2 - 1 = 1\]

So the original equation is

\[v = \alpha m^0 g^1 t^1 = \alpha g t\]

1.2 Exercise 1.2

\[h = \beta m^a g^b t^c\]

\[[h] = [\beta] [m]^a [g]^b [t]^c\]

\[L = 1 \times M^a (LT^{-2})^b T^c\]

\[L = M^a L^b T^{-2} T^c\]

\[1 = M^a L^{b-1} T^{c-2}\]

\[a = 0, b - 1 = 0, c - 2 = 0\]

\[h = \beta m^0 g^1 t^2 = \beta g t^2\]

1.3 Exercise 1.8

\[F_g = G\frac{m_1 m_2}{r^2}\]

\[[F_g] = [G] \frac{[m_1][m_2]}{[r]^2}\]

\[MLT^{-2} = [G] \frac{M^2}{L^2}\]

\[[G] = M^{-1} L^{3} T^{-2}\]

1.4 Exercise 1.10

I am using this example to play with making a scatterplot here. I am using sample data.

time position
0.2178 0
0.327 0.15
0.3944 0.3
0.4487 0.45
0.4954 0.6
0.5367 0.75
0.5746 0.9
0.6096 1.05
0.6425 1.2
0.6736 1.35
0.6998 1.5
0.7808 1.65

Trying this for a trendline in Plotly:

(defn linear-regression [x y]
  (let [n             (count x)
        sum-x         (reduce + x)
        sum-y         (reduce + y)
        sum-xy        (reduce + (map * x y))
        sum-x-squared (reduce + (map * x x))
        slope         (/ (- (* n sum-xy) (* sum-x sum-y))
                         (- (* n sum-x-squared) (* sum-x sum-x)))
        intercept     (/ (- (* sum-y sum-x-squared) (* sum-x sum-xy))
                         (- (* n sum-x-squared) (* sum-x sum-x)))]
    {:slope slope :intercept intercept}))
(let [{:keys [slope intercept]} (linear-regression (map :time force-data) (map :position force-data))
      trend-line-x              (map :time force-data)
      trend-line-y              (map #(-> (* slope %) (+ intercept)) trend-line-x)]
   ;; Add the trend line to the scatterplot
   (def scatterplot-with-trendline
     (update plotly-example :data conj {:x    trend-line-x
                                        :y    trend-line-y
                                        :type :scatter
                                        :mode :lines
                                        :line {:color "red"}
                                        :name "Trend Line"})))
#'index/scatterplot-with-trendline

Still need to figure out how to add a trendline in Hanami

source: notebooks/index.clj