LagrangeBasis - Maple Help

LagrangeBasis

Lagrange polynomials on a set of nodes

 Calling Sequence LagrangeBasis(k, nodes, x)

Parameters

 k - algebraic expression; the index nodes - list of algebraic expressions; the nodes where the polynomial is known x - algebraic expression; the argument

Description

 • $\mathrm{LagrangeBasis}\left(k,\mathrm{nodes},x\right)={w}_{k}\prod _{j\ne k}\left(x-{\mathrm{nodes}}_{j}\right)$ defines the $k$th Lagrange polynomial of degree $n$ which is either $1$ or $0$ on the given nodes. By convention, the nodes are indexed from $0$, so $\mathrm{nodes}=\left[{x}_{0},{x}_{1},...,{x}_{n}\right]$ , and the barycentric weights ${w}_{k}$ are defined as ${w}_{k}=\prod _{j\ne k}\left(\frac{1}{{x}_{k}-{x}_{j}}\right)$.
 • At present, this can only be evaluated in Maple by prior use of the object-oriented representation obtained by P:=convert(p,MatrixPolynomialObject,x) and subsequent call to P:-Value() , which uses the numerically stable barycentric form to evaluate the polynomial p.

Examples

 > $\mathrm{nodes}≔\left[-1,-\frac{1}{3},\frac{1}{3},1\right]$
 ${\mathrm{nodes}}{≔}\left[{-1}{,}{-}\frac{{1}}{{3}}{,}\frac{{1}}{{3}}{,}{1}\right]$ (1)
 > $p≔3\mathrm{LagrangeBasis}\left(0,\mathrm{nodes},x\right)+5\mathrm{LagrangeBasis}\left(2,\mathrm{nodes},x\right)+7\mathrm{LagrangeBasis}\left(3,\mathrm{nodes},x\right)$
 ${p}{≔}{3}{}{\mathrm{LagrangeBasis}}{}\left({0}{,}\left[{-1}{,}{-}\frac{{1}}{{3}}{,}\frac{{1}}{{3}}{,}{1}\right]{,}{x}\right){+}{5}{}{\mathrm{LagrangeBasis}}{}\left({2}{,}\left[{-1}{,}{-}\frac{{1}}{{3}}{,}\frac{{1}}{{3}}{,}{1}\right]{,}{x}\right){+}{7}{}{\mathrm{LagrangeBasis}}{}\left({3}{,}\left[{-1}{,}{-}\frac{{1}}{{3}}{,}\frac{{1}}{{3}}{,}{1}\right]{,}{x}\right)$ (2)

That polynomial has the value 3 at $x=-1$, the value 0 at $x=-\frac{1}{3}$, the value 5 at $x=\frac{1}{3}$, and the value 7 at $x=1$.

 > $P≔\mathrm{convert}\left(p,\mathrm{MatrixPolynomialObject},x\right)$
 ${P}{≔}{\mathrm{Record}}{}\left({\mathrm{Value}}{=}{{\mathrm{Default}}}_{{\mathrm{value}}}{,}{\mathrm{Variable}}{=}{x}{,}{\mathrm{Degree}}{=}{3}{,}{\mathrm{Coefficient}}{=}{\mathrm{coe}}{,}{\mathrm{Dimension}}{=}\left[{1}{,}{1}\right]{,}{\mathrm{Basis}}{=}{\mathrm{LagrangeBasis}}{,}{\mathrm{BasisParameters}}{=}\left[\left[{-1}{,}{-}\frac{{1}}{{3}}{,}\frac{{1}}{{3}}{,}{1}\right]\right]{,}{\mathrm{IsMonic}}{=}{\mathrm{mon}}{,}{\mathrm{OutputOptions}}{=}\left[{\mathrm{shape}}{=}\left[\right]{,}{\mathrm{storage}}{=}{\mathrm{rectangular}}{,}{\mathrm{order}}{=}{\mathrm{Fortran_order}}{,}{\mathrm{fill}}{=}{0}{,}{\mathrm{attributes}}{=}\left[\right]\right]\right)$ (3)
 > $P:-\mathrm{Degree}\left(\right)$
 ${3}$ (4)

Note that the result returned by $\mathrm{convert}\left(...,\mathrm{MatrixPolynomialObject}\right)$ represents a matrix polynomial; hence these results are 1 by 1 matrices.

 > $\mathrm{seq}\left(P:-\mathrm{Value}\left(\mathrm{nodes}\left[k\right]\right)\left[1,1\right],k=1..\mathrm{nops}\left(\mathrm{nodes}\right)\right)$
 ${3}{,}{0}{,}{5}{,}{7}$ (5)
 > $P:-\mathrm{Value}\left(0.3\right)$
 $\left[\begin{array}{c}{4.729812500}\end{array}\right]$ (6)
 > $\mathrm{factor}\left(P:-\mathrm{Value}\left(t\right)\left[1,1\right]\right)$
 ${-}\frac{\left({33}{}{{t}}^{{2}}{-}{26}{}{t}{-}{35}\right){}\left({3}{}{t}{+}{1}\right)}{{16}}$ (7)