Given the points:
numpy.linalg.solve
, solve it.numpy.linalg.cond
. Explain why this result was to be expected.import numpy as np
import matplotlib.pyplot as plt
As we saw in the interpolation unit, the system to solve to calculate the interpolation polynomial that passes through 5 points would be
And its coefficient matrix is the Vandermonde matrix. For our points, the system is
And solving it with python
A = np.array([[1.,1,1,1,1],
[1,2,4,8,16],
[1,3,9,27,81],
[1,4,16,64,256],
[1,5,25,125,625]])
b = np.array([1,2,4,3,5])
P = np.linalg.solve(A,b)
print('a = ', P)
If we modify some element
now the solution is
A1 = np.array([[1,1,1,1,1],
[1,2,4,8,15],
[1,3,9,27,81],
[1,4,16,64,256],
[1,5,24,125,625]])
b1 = np.array([1,2,4,3,5])
P1 = np.linalg.solve(A1,b1)
print('a = ', P1)
which, as we see, is very different from the previous solution.
print('a = ', P)
We are solving the interpolation problem, that is, we are calculating the polynomial that passes through the points. Graphically, the solutions are
%run T5_Ej4_dibu
How is the conditioning of the coefficient matrix evaluated? With the condition number
The condition number is always greater than one, but the closer to one, the better conditioned the matrix is and vice versa. In this example
print(np.linalg.cond(A))