# Documentation

## NURBS and Other Rational Splines

### Introduction to Rational Splines

A rational spline is, by definition, any function that is the ratio of two splines:

$r\left(x\right)=s\left(x\right)/w\left(x\right)$

This requires w to be scalar-valued, but s is often chosen to be vector-valued. Further, it is desirable that w(x) be not zero for any x of interest.

Rational splines are popular because, in contrast to ordinary splines, they can be used to describe certain basic design shapes, like conic sections, exactly.

### rsform: rpform, rBform

The two splines, s and w, in the rational spline r(x)=s(x)/w(x) need not be related to one another. They could even be of different forms. But, in the context of this toolbox, it is convenient to restrict them to be of the same form, and even of the same order and with the same breaks or knots. For, under that assumption, you can represent such a rational spline by the (vector-valued) spline function

$R\left(x\right)=\left[s\left(x\right);w\left(x\right)\right]$

whose values are vectors with one more entry than the values of the rational spline r, and call this the rsform of the rational spline, or, more precisely, the rpform or rBform, depending on whether s and w are in ppform or in B-form. Internally, the only thing that distinguishes these rational forms from their corresponding ordinary spline forms, rpform and B-form, is their form part, i.e., the string obtained via fnbrk(r,'form'). This is enough to alert the fn... commands to act appropriately on a function in one of the rsforms.

For example, as is done in fnval, it is very easy to obtain r(x) from R(x). If v is the value of R at x, then v(1:end-1)/v(end) is the value of r at x. If, in addition, dv is DR(x), then (dv(1:end-1)-dv(end)*v(1:end-1))/v(end) is Dr(x). More generally, by Leibniz's formula,

${D}^{j}s={D}^{j}\left(wr\right)=\sum _{i=0}^{j}\left(\begin{array}{c}j\\ i\end{array}\right){D}^{i}w{D}^{j-i}r$

Therefore,

${D}^{j}r=\left({D}^{j}s-\sum _{i=1}^{j}\left(\begin{array}{c}j\\ i\end{array}\right){D}^{i}w{D}^{j-i}r\right)/w$

This shows that you can compute the derivatives of r inductively, using the derivatives of s and w (i.e., the derivatives of R) along with the derivatives of r of order less than j to compute the jth derivative of r. This inductive scheme is used in fntlr to provide the first so many derivatives of a rational spline. There is a corresponding formula for partial and directional derivatives for multivariate rational splines.