- #1

https://projecteuler.net/problem=101
The ##j^{\mathrm{th}}## estimate ##\mathrm{OP}(j,n)## which fits ##j## data points is a ##(j-1)^{\mathrm{th}}## degree polynomial ##u^{(j)}(n) = a_{j-1} n^{j-1} + \dots + a_{0}## which agrees with ##u_n## on the set ##n \in \{1, \dots, j \}##, so$$\mathbf{a} := \begin{pmatrix} a_{j-1} \\ \vdots \\ a_0 \end{pmatrix} = \begin{pmatrix} 1 & 1 & \cdots & 1 \\ 2^{j-1} & 2^{j-2} & \cdots & 1 \\ \vdots & \vdots & & \vdots \\ j^{j-1} & j^{j-2} & \cdots & 1\end{pmatrix}^{-1} \begin{pmatrix} u_1 \\ \vdots \\ u_j \end{pmatrix} := \mathbf{M}^{-1} \mathbf{u}$$I need to make the matrix ##\mathbf{M}##, why does it not work?

Code:

```
import numpy as np
for j in range (1,11):
M = np.empty([j, j])
for x in range(1,j+1):
for y in range(1,j+1):
M[y,x] = y**(j-x)
Minv = np.linalg.inv(M)
```

Code:

```
M[y,x] = y**(j-x)
IndexError: index 1 is out of bounds for axis 0 with size 1
```

Last edited by a moderator: