# Revision history [back]

### Error in polynomial interpolation

Certainly an error from my type setting but this code

# Polynomial interpolation
# Passing the matrix
A = Matrix([[0,0],[0.5,0.25],[0.6,0.36],[2,4]])
var('a0, a1, a2, a3, a4')
B =[[A[i][1], a3*A[i][0]^3+ a2*A[i][0]^2+ a1*A[i][0]+ a0] for i in range(0,4)]
C=[[(B[i][0]-B[i][1])^2] for i in range(0,4)]
# sum of the square of errors
ssr=sum(C[i][0] for i in range(4))
# First order condition of optimality
ssr_a0=ssr.diff(a0)
ssr_a1=ssr.diff(a1)
ssr_a2=ssr.diff(a2)
ssr_a3=ssr.diff(a3)
ssr_a4=ssr.diff(a4)
# solution
sol=solve([ssr_a0==0,ssr_a1==0,ssr_a2==0,ssr_a3==0,ssr_a4==0], a0, a1, a2, a3, a4, solution_dict=True)
sol


as the following solution [{a0: 0, a1: 0, a2: 1, a3: 0, a4: r3}]. Could some one find my mistake ?

### Error in polynomial interpolation

Certainly I have edited this question to insist on what goes wrong

The following code ends with an error from my type setting but this codeindetermination of a parameter.

# Polynomial interpolation
# Passing the matrix
A = Matrix([[0,0],[0.5,0.25],[0.6,0.36],[2,4]])
var('a0, a1, a2, a3, a4')
B =[[A[i][1], a3*A[i][0]^3+ a2*A[i][0]^2+ a1*A[i][0]+ a0] for i in range(0,4)]
C=[[(B[i][0]-B[i][1])^2] for i in range(0,4)]
# sum of the square of errors
ssr=sum(C[i][0] for i in range(4))
# First order condition of optimality
ssr_a0=ssr.diff(a0)
ssr_a1=ssr.diff(a1)
ssr_a2=ssr.diff(a2)
ssr_a3=ssr.diff(a3)
ssr_a4=ssr.diff(a4)
# solution
sol=solve([ssr_a0==0,ssr_a1==0,ssr_a2==0,ssr_a3==0,ssr_a4==0], a0, a1, a2, a3, a4, solution_dict=True)
sol


as the following solution [{a0: 0, a1: 0, a2: 1, a3: 0, a4: r3}]. Could some

But the ssr_ai $i = 0,\ldots, 3$ are all linear. So sol should gives the same result that the following code

C=matrix([[8, 6.2, 9.22, 16.682], [6.2, 9.22,16.68,32.3842],[9.22,16.682,32.3842,64.21802],[16.68,32.3842,64.21802,128.124562]])
b=vector([9.22,16.68,32.3842,64.21902])
C.solve_right(b)


So why it is not the case ? (There is one find my mistake and only one solution)

This lead to a second question : for the ssr_ai how can I select the parameters to construct the C matrix and the b vector nopt by hand as I have been obliged to do ?

### Error in polynomial interpolation

I have edited this question to insist on what goes wrong

The following code ends with an indetermination of a indetermined parameter.

# Polynomial interpolation
# Passing the matrix
A = Matrix([[0,0],[0.5,0.25],[0.6,0.36],[2,4]])
var('a0, a1, a2, a3, a4')
B =[[A[i][1], a3*A[i][0]^3+ a2*A[i][0]^2+ a1*A[i][0]+ a0] for i in range(0,4)]
C=[[(B[i][0]-B[i][1])^2] for i in range(0,4)]
# sum of the square of errors
ssr=sum(C[i][0] for i in range(4))
# First order condition of optimality
ssr_a0=ssr.diff(a0)
ssr_a1=ssr.diff(a1)
ssr_a2=ssr.diff(a2)
ssr_a3=ssr.diff(a3)
ssr_a4=ssr.diff(a4)
# solution
sol=solve([ssr_a0==0,ssr_a1==0,ssr_a2==0,ssr_a3==0,ssr_a4==0], a0, a1, a2, a3, a4, solution_dict=True)
sol


as the following The proposed solution being [{a0: 0, a1: 0, a2: 1, a3: 0, a4: r3}].

But the ssr_ai $i = 0,\ldots, 3$ are all linear. So sol should gives the same result that the following code

C=matrix([[8, 6.2, 9.22, 16.682], [6.2, 9.22,16.68,32.3842],[9.22,16.682,32.3842,64.21802],[16.68,32.3842,64.21802,128.124562]])
b=vector([9.22,16.68,32.3842,64.21902])
C.solve_right(b)


So why it is not the case ? (There is one and only one solution)

This lead to a second question : for the ssr_ai how can I select the parameters to construct the C matrix and the b vector nopt not by hand as I have been obliged to do ?