axiom-math
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-math] rational interpolation for axiom


From: Martin Rubey
Subject: [Axiom-math] rational interpolation for axiom
Date: Sat, 12 Jun 2004 21:46:26 +0000

Hi,

well, here's my first try on distributing a pamphlet file. I hope it's
useful. Comments welcome.

To use it, (having installed axiom) do

document rinterp.spad.pamphlet

which should produce a dvi and a spad file.

Martin

\documentclass{article}
\usepackage{axiom,amsmath,url}
\begin{document}
\title{rinterp.spad}
\author{Martin Rubey}
\maketitle
\begin{abstract}
Rational Interpolation
\end{abstract}
\section{Introduction}
This file contains a crude na\"ive implementation of rational interpolation,
where the coefficients of the rational function are in any given field.

\section{Questions and Outlook}
\begin{itemize}
\item Maybe this file should be joined with pinterp.spad, where polynomial
  Lagrange interpolation is implemented. I have a second version that parallels
  the structure of pinterp.spad closely. 
\item There are probably better ways to implement rational interpolation. Maybe
  \url{http://www.cs.ucsb.edu/~omer/personal/abstracts/rational.html} contains
  something useful, but I don't know.
\item Comments welcome!
\end{itemize}

<<*>>=
<<RINTERP Header>>
<<RINTERP Exports>>
<<RINTERP Implementation>>
@

\section{RationalInterpolation}

<<RINTERP Header>>=
)abbrev package RINTERP RationalInterpolation
++ Description:
++ This package exports rational interpolation algorithms
RationalInterpolation(xx,F): Exports == Implementation  where
    xx: Symbol
    F: Field 
@

<<RINTERP Exports>>=
    Exports == with
        interpolate: (List F, List F, NonNegativeInteger, 
                                NonNegativeInteger) -> Fraction Polynomial F
@

The implementation sets up a system of linear equations and solves it. 
<<RINTERP Implementation>>=
    Implementation == add
        interpolate(xlist, ylist, m, k) ==
@

First we check whether we have the right number of points and values. Clearly
the number of points and the number of values must be identical. Note that we
want to determine the numerator and denominator polynomials only up to a
factor. Thus, we want to determine $m+k+1$ coefficients, where $m$ is the degree
of the polynomial in the numerator and $k$ is the degree of the polynomial in
the denominator.

In fact, we could also leave -- for example -- $k$ unspecified and determine it
as $k=[[#xlist]]-m-1$: I don't know whether this would be better.
<<RINTERP Implementation>>=
            #xlist ^= #ylist =>
                error "Different number of points and values."
            #xlist ^= m+k+1 =>
                error "wrong number of points"
@

The next step is to set up the matrix. Suppose that our numerator polynomial is
$p(x)=a_0+a_1x+\dots+a_mx^m$ and that our denominator polynomial is
$q(x)=b_0+b_1x+\dots+b_mx^m$. Then we have the following equations, writing $n$
for $m+k+1$:

\begin{align*}
 p(x_1)-y_1q(x_1)&=a_0+a_1x_1+\dots +a_mx_1^m-y_1(b_0+b_1x_1+\dots 
+b_kx_1^k)=0\\
 p(x_2)-y_2q(x_2)&=a_0+a_1x_2+\dots +a_mx_2^m-y_2(b_0+b_1x_2+\dots 
+b_kx_2^k)=0\\
                 &\;\;\vdots\\                                                 
 p(x_n)-y_nq(x_n)&=a_0+a_1x_n+\dots +a_mx_n^m-y_n(b_0+b_1x_n+\dots +b_kx_n^k)=0
\end{align*}

This can be written as
$$
\begin{pmatrix}
  1&x_1&\dots&x_1^m&-y_1&-y_1x_1&\dots&-y_1x_1^k\\
  1&x_2&\dots&x_2^m&-y_2&-y_2x_2&\dots&-y_2x_2^k\\
\vdots\\
  1&x_n&\dots&x_n^m&-y_n&-y_nx_n&\dots&-y_nx_2^k
\end{pmatrix}
\begin{pmatrix}
  a_0\\a_1\\\vdots\\a_m\\b_0\\b_1\\\vdots\\b_k
\end{pmatrix}=\mathbf 0
$$
We generate this matrix columnwise:
<<RINTERP Implementation>>= 
            tempvec: List F := [1 for i in 1..(m+k+1)]

            collist: List List F := cons(tempvec, 
                                         [(tempvec := [tempvec.i * xlist.i _
                                                       for i in 1..(m+k+1)]) _
                                          for j in 1..max(m,k)])

            collist := append([collist.j for j in 1..(m+1)], _
                              [[- collist.j.i * ylist.i for i in 1..(m+k+1)] _
                               for j in 1..(k+1)])
@
Now we can solve the system:
<<RINTERP Implementation>>=
            res: List Vector F := nullSpace((transpose matrix collist) _
                                            ::Matrix F)
@

Note that it may happen that the system has several solutions. In this case,
some of the data points may not be interpolated correctly. However, the
solution is often still useful, thus we do not signal an error.

<<RINTERP Implementation>>=
            if #res~=1 then output("Warning: unattainable points!" _
                                   ::OutputForm)$OutputPackage
@

In this situation, all the solutions will be equivalent, thus we can always
simply take the first one:

<<RINTERP Implementation>>=
            reslist: List List Polynomial F := _
                      [[(res.1).(i+1)*(xx::Polynomial F)**i for i in 0..m], _
                      [(res.1).(i+m+2)*(xx::Polynomial F)**i for i in 0..k]] 
@
Finally, we generate the rational function:
<<RINTERP Implementation>>=
            reduce((_+),reslist.1)/reduce((_+),reslist.2)
@
\eject
\begin{thebibliography}{99}
\bibitem{1} nothing
\end{thebibliography}
\end{document}

reply via email to

[Prev in Thread] Current Thread [Next in Thread]