(11C) Quadratic Regression
|
11-20-2022, 10:28 PM
(This post was last modified: 11-24-2022 06:00 PM by Thomas Klemm.)
Post: #1
|
|||
|
|||
(11C) Quadratic Regression
Formula
Given a set of points \(\{(x_1, y_1), (x_2, y_2), \cdots, (x_n, y_n)\}\) where \(n \geqslant 3\) we want to find the best fit for a quadratic polynomial: \( \begin{align} y = a \cdot x^2 + b \cdot x + c \end{align} \) This leads to the following linear system of equations: \( \begin{bmatrix} n & \Sigma x & \Sigma x^2 \\ \Sigma x & \Sigma x^2 & \Sigma x^3 \\ \Sigma x^2 & \Sigma x^3 & \Sigma x^4 \\ \end{bmatrix} \cdot \begin{bmatrix} c \\ b \\ a \\ \end{bmatrix} = \begin{bmatrix} \Sigma y \\ \Sigma xy \\ \Sigma x^2y \\ \end{bmatrix} \) We can perform Gauss elimination on the first row to get: \( \begin{bmatrix} n & \Sigma x & \Sigma x^2 \\ 0 & n \cdot \Sigma x^2 - (\Sigma x)^2 & n \cdot \Sigma x^3 - \Sigma x \cdot \Sigma x^2 \\ 0 & n \cdot \Sigma x^3 - \Sigma x \cdot \Sigma x^2 & n \cdot \Sigma x^4 - (\Sigma x^2)^2 \\ \end{bmatrix} \cdot \begin{bmatrix} c \\ b \\ a \\ \end{bmatrix} = \begin{bmatrix} \Sigma y \\ n \cdot \Sigma xy - \Sigma x \cdot \Sigma y \\ n \cdot \Sigma x^2y - \Sigma x^2 \cdot \Sigma y \\ \end{bmatrix} \) We define the following: \( \begin{align} S_{x^2} &= n \cdot \Sigma x^2 - (\Sigma x)^2 \\ S_{xy} &= n \cdot \Sigma xy - \Sigma x \cdot \Sigma y \\ S_{xx^2} &= n \cdot \Sigma x^3 - \Sigma x \cdot \Sigma x^2 \\ S_{x^2x^2} &= n \cdot \Sigma x^4 - (\Sigma x^2)^2 \\ S_{x^2y} &= n \cdot \Sigma x^2y - \Sigma x^2 \cdot \Sigma y \\ \end{align} \) This allows us to rewrite the linear system for \(b\) and \(a\) as: \( \begin{bmatrix} S_{x^2} & S_{xx^2} \\ S_{xx^2} & S_{x^2x^2} \\ \end{bmatrix} \cdot \begin{bmatrix} b \\ a \\ \end{bmatrix} = \begin{bmatrix} S_{xy} \\ S_{x^2y} \\ \end{bmatrix} \) Since the matrix is symmetric we can use the built-in function L.R. to solve it. In case of linear regression we have the following linear system: \( \begin{bmatrix} n & \Sigma x \\ \Sigma x & \Sigma x^2 \\ \end{bmatrix} \cdot \begin{bmatrix} b \\ a \\ \end{bmatrix} = \begin{bmatrix} \Sigma y \\ \Sigma xy \\ \end{bmatrix} \) Registers We use the following registers: \( \begin{align} R_{0} &: n \\ R_{1} &: \Sigma x \\ R_{2} &: \Sigma x^2 \\ R_{3} &: \Sigma y \\ R_{4} &: \Sigma y^2 \\ R_{5} &: \Sigma xy \\ R_{6} &: \Sigma x^3 \\ R_{7} &: \Sigma x^4 \\ R_{8} &: \Sigma x^2y \\ R_{9} &: c \\ R_{.0} &: b \\ R_{.1} &: a \\ I &: \text{scratch} \\ \end{align} \) Thus the function L.R. allows to solve the following linear system: \( \begin{bmatrix} R_{0} & R_{1} \\ R_{1} & R_{2} \\ \end{bmatrix} \cdot \begin{bmatrix} b \\ a \\ \end{bmatrix} = \begin{bmatrix} R_{3} \\ R_{5} \\ \end{bmatrix} \) This means we have to do the following assignments: \( \begin{align} R_{0} &\leftarrow R_{0} \cdot R_{2} - R_{1}^2 \\ R_{1} &\leftarrow R_{0} \cdot R_{6} - R_{1} \cdot R_{2} \\ R_{2} &\leftarrow R_{0} \cdot R_{7} - R_{2}^2 \\ R_{3} &\leftarrow R_{0} \cdot R_{5} - R_{1} \cdot R_{3} \\ R_{5} &\leftarrow R_{0} \cdot R_{8} - R_{2} \cdot R_{3} \\ \end{align} \) We temporarily store the previous values in the following registers: \( \begin{align} R_{9} &\leftarrow R_{0} \\ R_{.0} &\leftarrow R_{1} \\ R_{.1} &\leftarrow R_{2} \\ I &\leftarrow R_{3} \\ \end{align} \) Forecast The linear estimate function ŷ allows to calculate: \( \begin{align} \hat{y} &= a \cdot x + b \end{align} \) This can be used to calculate: \( \begin{align} \hat{y} \cdot x + c &= (a \cdot x + b) \cdot x + c \\ &= a \cdot x^2 + b \cdot x + c \\ \end{align} \) Program Code: 001 - 42,21,11 LBL A Usage
Example Q H (flow) (head) [m3/h] [m] ---------------- 0 90.0 30 90.2 60 86.4 90 79.0 120 67.7 150 52.4 90.0 ENTER 0 A 1 90.2 ENTER 30 A 2 86.4 ENTER 60 A 3 79.0 ENTER 90 A 4 67.7 ENTER 120 A 5 52.4 ENTER 150 A 6 C -0.002132936508 (a) R↓ 0.06955952381 (b) R↓ 89.99642857 (c) 100 D 75.62301587 (y) Hint A linear regression can be performed before calculating the best fit. This result can then later be compared with the quadratic regression. References |
|||
11-24-2022, 01:24 PM
Post: #2
|
|||
|
|||
RE: (11C) Quadratic Regression
Thanks for the credit at the end!
In the first matrix-coefficient equation row 3-coloumn 3 the sum(x^3) is wrong. Pls update. Cs. |
|||
11-24-2022, 06:01 PM
Post: #3
|
|||
|
|||
RE: (11C) Quadratic Regression
Thank you for pointing out the typo.
|
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 1 Guest(s)