Vandermonde Matrix for Polynomial Interpolation - Maple

113 Views Asked by At

I have a problem with the following code in Maple. I am trying to solve a problem regarding the Vandermonde Matrix for Polynomial Interpolation. $$\\restart:\\with(LinearAlgebra):\\A := VandermondeMatrix([1, 2, 3, 4, 5], 5, 5)\\x := <seq(alpha[i], i = 1 .. 5)>\\b := <1, 2, 3, 4, 5>\\eqnsb := {seq((A . x)[i] = b[i], i = 1 .. 5)}\\$$ This bloc of code is directly copied from my textbook, and the output is not correct. The ideal output should be: $$eqnsb:= \begin{Bmatrix} \\ a_{1}+a_{2}+a_{3}+a_{4}+a_{5}=1, \\ a_{1}+2a_{2}+4a_{3}+8a_{4}+16a_{5}=2, \\ a_{1}+3a_{2}+9a_{3}+27a_{4}+81a_{5}=3, \\ a_{1}+4a_{2}+16a_{3}+64a_{4}+25a_{5}=4, \\a_{1}+5a_{2}+25a_{3}+125a_{4}+625a_{5}=5, \end{Bmatrix}$$ then one can solve the coefficients after. I have no clue how to go about to correct the textbook error. Could anyone help me out here, please! Many thanks in advance!

1

There are 1 best solutions below

1
On BEST ANSWER

That code works fine if entered in 1D (plaintext) Maple Notation.

But in 2D Math input mode the (A.x)[i] is being mis-parsed as (A.x)*[i], which of course is not what's indended. What's intended is to index the result A.x by i.

The following should work in either input mode:

restart;
with(LinearAlgebra):
A:=VandermondeMatrix([1,2,3,4,5],5,5):
x:=<seq(alpha[i],i=1..5)>:
b:=<1,2,3,4,5>:
Ab:=A.x:
eqnsb:={seq(Ab[i]=b[i],i=1..5)};

That is also more efficient. The original code (even when working ok as 1D input) is unnecessarily inefficient because it recomputes A.x for each value of i in the seq call. The revision computes it just once.

For fun, here are some alternative ways to get the result (in a few forms):

As a list,

Equate(A.x,b)

As an expression sequence (the operands of that list),

Equate(A.x,b)[]

or,

op(Equate(A.x,b))

As a set,

{Equate(A.x,b)[]}