Linear Algebra with Sage

<Interpolation>

Made by SKKU Linear Algebra Lab (2011)

For given four points $(0,3)$,$(1,0)$,$(-1,2)$,$(3,6)$ to obtain an interpolating polynomial

$f(x)=a_0 + a_1 x + a_2 x^2 + a_3 x^3$, we have to solve the linear system of equations as follow.

(주어진 점을 통과하는 다항식을 구하자.)

$\begin{bmatrix} 1 & 0 & 0 & 0 \\ 1 & 1 & 1 & 1 \\ 1 & -1 & 1 & -1 \\ 1 & 3 & 9 & 27 \end{bmatrix} \begin{bmatrix}a_0 \\ a_1 \\ a_2 \\ a_3 \end{bmatrix} = \begin{bmatrix}3 \\ 0 \\ 2 \\ 6 \end{bmatrix}$

Define matrices (행렬과 벡터 생성 및 확인)

 A=matrix([[1,0,0,0],[1,1,1,1],[1,-1,1,-1],[1,3,9,27]]); b=vector([3,0,2,6]); print A print b

[ 1  0  0  0]

[ 1  1  1  1]

[ 1 -1  1 -1]

[ 1  3  9 27]

(3, 0, 2, 6)

Find $\textbf{x} = A^{-1} \textbf{b}$ (해 $\textbf{x}$(coefficients) 구하기.)

 X=A\b; X

(3, -2, -2, 1)

Interpolating polynomial (Interpolating 다항식 구하기)

 f(x)=(X*(vector([1,x,x^2,x^3]))); f(x)

x^3 - 2*x^2 - 2*x + 3

Show points and interpolating polynomial (주어진 점들과 함께 구한 interpolating 다항식을 보여주기)

 v=((0,3),(1,0),(-1,2),(3,6)) p1=points(v, pointsize=35, rgbcolor='#d03030') p2=plot(f, (x,-3,4)) show(p1+p2, ymin=-2,ymax=8, aspect_ratio=1)