Regression project in octave/matlab

114 Views Asked by At

I'm trying to establish a polynomial model to adjust the variation of the dollar throughout the year. Suppose hypothetically that I have the following data

Month (t)    1    2    3    4    5    6    7    8    9   10   11   12
Dollar Y(t) 3.21 2.21 2.12 2.92 2.91 2.81 2.91 2.12 3.01 3.02 3.09 2.92

And I want to set this through a polynomial model type $$y=B_0+B_1x+B_2x^2+B_3x^3$$ However I need to find the parameters of the model through the normal system using Cholesky factorization

A= \begin{bmatrix}n&\sum x_i&\sum x_i^2&\sum x_i^3\\\sum x_i&\sum x_i^2&\sum x_i^3&\sum x_i^4\\\sum x_i^2&\sum x_i^3&\sum x_i^4&\sum x_i^5\\\sum x_i^3&\sum x_i^4&\sum x_i^5&\sum x_i^6\end{bmatrix} x= \begin{bmatrix}B_0\\B_1\\B_2\\B_3\end{bmatrix}

b= \begin{bmatrix}\sum y_i\\\sum x_iy_i\\\sum x_i^2y_i\\\sum x_i^3yi\end{bmatrix}

So I need to solve the system $Ax=b$, so I need to find matrix Cholesky $G$ and solve $$G^ty=b$$ $$Gx=y$$

Can anyone give me a hand, because I have not much knowledge about octave

1

There are 1 best solutions below

0
On BEST ANSWER

Matlab/Octave: To solve $Ax=b,$ simply try: x = A\b;

If you need the Cholesky factorization for some reason, the command is "chol". For example, G=chol(A); y=(G')\b; x=G\y;