Exercise 16.1.3

Exercise 16.1.3#

Question 1#

Implement the linear least squares solution for three variables to find the constants in the Cepheid variable functional relation:

\[ M = a_0 + a_1 \log P + a_2 (B - V) \]

using the same data file as before: ./data/cepheid_data.csv.

(Answer: a_0 = -2.15 mag, a1 = -3.12 mag, a2 = 1.49)

Question 2#

Package the multivariate least squares solution into a function, taking the file path (and possibly the delimeter used as well as number of lines to skip) and return the \(\boldsymbol{A}\) matrix. Unlike in the case with the Cepheid variable data, you can assume that the first column of the file will contain \(y\) data and the rest \(x_j\) data.

Test your function on the data sets ./exercise-data/data02.csv and ./exercise-data/data03.csv.

Answers:

\[\begin{eqnarray*} \text{data02.csv} & \quad \quad \quad & \text{data03.csv}\\ \boldsymbol{A} = \begin{pmatrix} -0.402\\ 0.201\\ 1.222\\ 0.341\\ 0.134\\ \end{pmatrix} & \quad \quad \quad & \boldsymbol{A} = \begin{pmatrix} 2.81\\ 0.55\\ 1.63\\ 2.71\\ 1.33\\ -1.16\\ 2.39\\ 1.12\\ 0.65\\ 4.05\\ -2.81\\ \end{pmatrix}\\ \end{eqnarray*}\]