Spline functions - computations methods. 9781611973891, 1611973899

2,034 20 30MB

English Pages 425 si [426] Year 2015

Report DMCA / Copyright

DOWNLOAD FILE

Polecaj historie

Spline functions - computations methods.
 9781611973891, 1611973899

Citation preview

Spline Functions

Spline Functions COMPUTATIONAL METHODS

Larry L. Schumaker Vanderbilt University Nashville, Tennessee

Society for Industrial and Applied Mathematics Philadelphia

Copyright © 2015 by the Society for Industrial and Applied Mathematics 10 9 8 7 6 5 4 3 2 1 All rights reserved. Printed in the United States of America. No part of this book may be reproduced, stored, or transmitted in any manner without the written permission of the publisher. For information, write to the Society for Industrial and Applied Mathematics, 3600 Market Street, 6th Floor, Philadelphia, PA 19104-2688 USA. Macintosh is a trademark of Apple Computer, Inc., registered in the United States and other countries. Spline Functions: Computational Methods is an independent publication and has not been authorized, sponsored, or otherwise approved by Apple Computer, Inc. MATLAB is a registered trademark of The MathWorks, Inc. For MATLAB product information, please contact The MathWorks, Inc., 3 Apple Hill Drive, Natick, MA 01760-2098 USA, 508-647-7000, Fax: 508-647-7001, [email protected], www.mathworks.com. UNIX is a registered trademark of The Open Group in the United States and other countries. Windows is a registered trademark of Microsoft Corporation in the United States and/or other countries. Publisher David Marshall Acquisitions Editor Elizabeth Greenspan Developmental Editor Gina Rinelli Managing Editor Kelly Thomas Production Editor David Riegelhaupt Copy Editor David Riegelhaupt Production Manager Donna Witzleben Production Coordinator Cally Shrader Compositor Techsetters, Inc. Graphic Designer Lois Sellers Library of Congress Cataloging-in-Publication Data Schumaker, Larry L., 1939Spline functions : computational methods / Larry L. Schumaker, Vanderbilt University, Nashville, Tennessee. pages cm. -- (Other titles in applied mathematics ; 142) Includes bibliographical references and index. ISBN 978-1-611973-89-1 1. Spline theory. 2. Numerical calculations. I. Title. QA224.S34 2015 518’.5--dc23 2015012804

is a registered trademark.

Contents

Preface 1

2

3

ix

Univariate Splines 1.1 Introduction . . . . . . . . . . . . . . . . . . . 1.2 B-splines . . . . . . . . . . . . . . . . . . . . 1.3 Computing with the B-form . . . . . . . . . . . 1.4 Interpolation with univariate splines . . . . . . 1.5 Hermite interpolation . . . . . . . . . . . . . . 1.6 Interpolation with shape control . . . . . . . . 1.7 Quasi-interpolation . . . . . . . . . . . . . . . 1.8 Discrete least-squares approximation . . . . . . 1.9 The effect of noise . . . . . . . . . . . . . . . 1.10 Penalized least-squares approximation . . . . . 1.11 Choosing optimal knots for least-squares splines 1.12 Two-point boundary-value problems . . . . . . 1.13 Error bounds . . . . . . . . . . . . . . . . . . 1.14 Remarks . . . . . . . . . . . . . . . . . . . . . 1.15 Historical notes . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

. . . . . . . . . . . . . . .

1 1 2 4 8 13 16 20 22 25 26 29 32 39 45 49

Tensor-Product Splines 2.1 Introduction . . . . . . . . . . . . . . 2.2 Tensor-product B-splines . . . . . . . 2.3 Computing with the tensor B-form . . 2.4 Lagrange interpolation on a grid . . . 2.5 Hermite interpolation . . . . . . . . . 2.6 Tensor-product quasi-interpolation . . 2.7 Tensor-product discrete least-squares . 2.8 The effect of noise . . . . . . . . . . 2.9 Penalized least-squares approximation 2.10 Error bounds . . . . . . . . . . . . . 2.11 Remarks . . . . . . . . . . . . . . . . 2.12 Historical notes . . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

51 51 52 52 57 60 64 66 68 69 72 73 76

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

Computing with Triangulations 79 3.1 Triangulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 v

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

vi

Contents

3.2 3.3 3.4 3.5 3.6 3.7 3.8 3.9 3.10 3.11 3.12 3.13 3.14 3.15 4

5

Triangulations with hanging vertices . . . . . . Storing and plotting triangulations . . . . . . . Additional data structure for triangulations . . . Stars of vertices and triangles . . . . . . . . . . Barycentric coordinates . . . . . . . . . . . . . Finding the triangle containing a point . . . . . Constructing a triangulation with given vertices Grid generation . . . . . . . . . . . . . . . . . Triangulations of gridded data on a rectangle . Refining a triangulation . . . . . . . . . . . . . Adjusting triangulations by edge swapping . . . Euler relations . . . . . . . . . . . . . . . . . . Remarks . . . . . . . . . . . . . . . . . . . . . Historical notes . . . . . . . . . . . . . . . . .

Computing with Splines 4.1 Bernstein basis polynomials . . . . . . . . 4.2 Domain points on a triangle . . . . . . . . . 4.3 Evaluating polynomials in B-form . . . . . 4.4 Derivatives of polynomials in B-form . . . 4.5 Integrals and inner products of polynomials 4.6 Integrals of general functions over triangles 4.7 Plotting a polynomial patch . . . . . . . . . 4.8 Domain points on a triangulation . . . . . . 4.9 The space S 0d () . . . . . . . . . . . . . . 4.10 Evaluating splines and their derivatives . . . 4.11 Integrals and inner products of splines . . . 4.12 Rendering a spline surface . . . . . . . . . 4.13 Spaces of smooth splines . . . . . . . . . . 4.14 Some useful macro-element spaces . . . . . 4.15 Degree raising . . . . . . . . . . . . . . . . 4.16 Subdivision . . . . . . . . . . . . . . . . . 4.17 Remarks . . . . . . . . . . . . . . . . . . . 4.18 Historical notes . . . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

. . . . . . . . . . . . . .

79 80 81 84 84 85 86 89 89 90 91 92 94 95

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . . .

97 97 98 99 100 101 102 104 105 106 109 110 110 113 120 130 131 132 133

Macro-element Interpolation Methods 5.1 Introduction . . . . . . . . . . . . . . . . . . 5.2 The C 1 Powell–Sabin interpolant . . . . . . . 5.3 The C 1 Powell–Sabin-12 interpolant . . . . . 5.4 The C 1 Clough–Tocher interpolant . . . . . . 5.5 The C 1 quintic Argyris interpolant . . . . . . 5.6 The C 2 Wang interpolant . . . . . . . . . . . 5.7 A comparison of the methods . . . . . . . . . 5.8 Rate of convergence for less smooth functions 5.9 Interpolation on domains with holes . . . . . 5.10 Interpolation at badly spaced points . . . . . 5.11 Scale invariance . . . . . . . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

. . . . . . . . . . .

135 135 137 141 143 146 149 150 151 153 154 155

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Contents

5.12 5.13 5.14 6

7

8

vii

The role of the minimal angle in error bounds . . . . . . . . . . . . . 157 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 158 Historical notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 160

Scattered Data Interpolation 6.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . 6.2 Interpolation with S10 () . . . . . . . . . . . . . . . . 6.3 Minimal energy interpolating splines . . . . . . . . . . 6.4 A local C 0 cubic spline method . . . . . . . . . . . . . 6.5 A local C 1 Clough–Tocher method . . . . . . . . . . . 6.6 Estimating derivatives from scattered data . . . . . . . 6.7 Local two-stage methods based on derivative estimation 6.8 A comparison of the methods . . . . . . . . . . . . . . 6.9 Scale invariance . . . . . . . . . . . . . . . . . . . . . 6.10 Nonrectangular domains and holes . . . . . . . . . . . 6.11 Interpolating at a large number of data points . . . . . 6.12 The error as a function of mesh size . . . . . . . . . . 6.13 Non-Delaunay triangulations . . . . . . . . . . . . . . 6.14 Scattered data interpolation with radial basis functions 6.15 Almost interpolation with tensor-product splines . . . . 6.16 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . 6.17 Historical notes . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . . . . . . . . . . .

161 161 162 166 173 175 178 185 190 192 195 198 202 203 204 208 213 216

Scattered Data Fitting 7.1 Least-squares fitting . . . . . . . . . . . . . . . . . . . . . . . . 7.2 Least-squares fitting with C 0 splines . . . . . . . . . . . . . . . 7.3 Least-squares fitting with C 1 splines . . . . . . . . . . . . . . . 7.4 Least-squares fitting with C 2 splines . . . . . . . . . . . . . . . 7.5 Scale invariance of least-squares fitting . . . . . . . . . . . . . . 7.6 A comparison of the methods . . . . . . . . . . . . . . . . . . . 7.7 The effect of noise . . . . . . . . . . . . . . . . . . . . . . . . 7.8 Penalized least-squares fitting . . . . . . . . . . . . . . . . . . . 7.9 Penalized least-squares fitting with macro-element spline spaces 7.10 Nonscale invariance of penalized least-squares fitting . . . . . . 7.11 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7.12 Historical notes . . . . . . . . . . . . . . . . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

. . . . . . . . . . . .

219 219 223 226 231 233 234 236 236 239 243 244 246

Shape Control 8.1 Nonnegative interpolation 8.2 Nonnegative least-squares 8.3 Monotone interpolation . 8.4 Monotone least-squares . 8.5 Convex interpolation . . 8.6 Convex least-squares . . 8.7 Remarks . . . . . . . . . 8.8 Historical notes . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

247 247 251 254 268 270 283 285 287

. . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . . . . . . . . . . .

. . . . . . . .

. . . . . . . .

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

viii

9

10

11

Contents

Boundary-Value Problems 9.1 Examples of boundary-value problems . . . . . . . . . . . . . . . . 9.2 The Ritz–Galerkin method . . . . . . . . . . . . . . . . . . . . . . 9.3 Solving second order boundary-value problems with Sd0 () . . . . . 9.4 Solving second order boundary-value problems using macro-element spaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.5 Solving second order boundary-value problems using the space S51,2 () . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.6 Solving the biharmonic equation with C 1 quintic splines . . . . . . 9.7 Remarks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9.8 Historical notes . . . . . . . . . . . . . . . . . . . . . . . . . . . .

289 . 289 . 290 . 294

. . . .

308 316 322 324

Spherical Splines 10.1 Spherical triangulations . . . . . . . . . . . 10.2 Spherical polynomials . . . . . . . . . . . 10.3 The space Sd0 () on a spherical triangulation 10.4 Spaces of smooth spherical splines . . . . . 10.5 Spherical macro-element spaces . . . . . . 10.6 Remarks . . . . . . . . . . . . . . . . . . . 10.7 Historical notes . . . . . . . . . . . . . . .

. 307

. . . . . . . . . . . . . . . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

. . . . . . .

325 325 333 340 344 348 353 355

Applications of Spherical Splines 11.1 Interpolation with S10 () . . . . . . . . . . . . . 11.2 Hermite interpolation with macro-element spaces 11.3 Scattered data interpolation on the sphere . . . . 11.4 Least-squares fitting with spherical splines . . . . 11.5 The effect of noise . . . . . . . . . . . . . . . . 11.6 Spherical penalized least-squares . . . . . . . . . 11.7 PDE’s on the sphere . . . . . . . . . . . . . . . . 11.8 Remarks . . . . . . . . . . . . . . . . . . . . . . 11.9 Historical notes . . . . . . . . . . . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

. . . . . . . . .

357 357 361 369 384 391 393 396 399 402

Bibliography

403

Script Index

407

Function Index

409

Subject Index

411

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Preface Spline functions have been studied intensively for over 50 years, and there are now many thousands of papers on the subject. The reason for this great interest is that splines have many desirable features that make them ideal tools for a wide variety of application areas where it is required to approximate an unknown function computationally. Thus, they have found applications in Approximation Theory, Numerical Analysis, Engineering, and a variety of other business, medical, and scientific areas. What makes splines especially attractive is the fact that • they are easy to work with computationally, and in particular, there are stable and efficient algorithms for evaluating them, their derivatives, and their integrals; • there are very convenient representations which provide a strong connection between the shape of a spline and its associated coefficients; • splines are capable of approximating smooth functions well, and the exact relationship between the smoothness of a function and its order of approximation can be quantified. The theoretical aspects of splines have been well documented in the literature; see the list of books at the end of this book and the online reference list. Some of them discuss applications, and a few even describe computational methods. The purpose of this book is to give a detailed treatment of some of the most important computational aspects of splines. It can be considered as a complement to my two earlier books on splines, neither of which dealt with applications or computations. The first, Spline Functions: Basic Theory, was first published in 1978 by Wiley Interscience, and deals only with univariate and tensor-product splines. A third edition with supplementary material and references was published in 2007 by Cambridge University Press. The second book, Spline Functions on Triangulations, was written with M.-J. Lai, and deals with bivariate splines defined on triangulations and quadrangulations, spherical splines defined on the sphere, and trivariate splines defined on tetrahedral partitions in R3 . It was also published in 2007 by Cambridge University Press. Splines can be used to solve several of the most basic problems in numerical analysis. The topics discussed here include • interpolation in one or several variables, • data fitting in one or several variables, • numerical quadrature, i.e., the computation of derivatives and integrals based only on discrete data, ix

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

x

Preface

• the numerical solution of problems involving ordinary or partial differential equations. The goal of this book is to not only describe a variety of methods for attacking these problems using splines, but to also explain why the methods work, and to give actual numerical examples. The aim is to describe each method in enough detail to allow the reader to program it himself. However, to enhance the learning process, and to encourage more experimentation with splines, I have prepared a MATLAB package SplinePak which includes implementations of all of the methods discussed in the book. The package includes an extensive collection of p-files containing MATLAB functions for carrying out the various algorithms in the book, a set of scripts provided as m-files for carrying out specific tasks, and finally a number of data files used in the numerous examples in the book. The package is licensed by Nashboro Press; see www.splinepak.com. It should be emphasized that the code in the package is not production code, and has not been designed to achieve maximal efficiency. Indeed, for large scale computation, the user should consider coding the algorithms in another language. The book is primarily about bivariate polynomial splines on triangulations, but for the sake of completeness, and to provide numerical tools for comparison purposes, I have included chapters on univariate splines, tensor-product splines, and splines on spherical triangulations. The material is organized as follows. Chapter 1 deals with univariate splines. First, we discuss algorithms for evaluating splines and their derivatives, for computing integrals of splines, and for plotting splines. Then we discuss several methods for solving the basic Lagrange and Hermite interpolation problems in one variable. In addition, quasi-interpolation, least-squares, penalized least-squares, and the use of splines for solving two-point boundary-value problems are treated. Chapter 2 is devoted to the use of tensor-product splines to solve interpolation and approximation problems in the bivariate setting. First, it is shown how univariate algorithms can be used to evaluate tensor-product splines, and to compute their derivatives and integrals. Then we study interpolation, quasi-interpolation, least-squares, and penalized least-squares methods based on tensor-product splines. Chapter 3 explains how to deal with triangulations computationally, and is a critical preparation for the later chapters. Here we explain how to construct, store, and manipulate triangulations. Refinement and edge swapping algorithms are also included. Chapter 4 describes in detail how to store, evaluate, and render splines on triangulations. The algorithms described here are essential tools for the remainder of the book. The key underlying concept is the Bernstein–Bézier representation of splines. Here we explain how to compute with the space Sd0 () of C 0 splines, and with arbitrary subspaces of smoother splines. Several special macro-element spaces to be used extensively later are discussed in detail. Chapter 5 is the first chapter where real applications are addressed. Here we show how certain macro-element spaces can be used to solve interpolation problems in the bivariate setting. The focus is on Hermite interpolation at the vertices of a triangulation. I give numerical examples for each of the methods, and include the results of some experiments comparing the various interpolation methods. Chapter 6 treats the problem of scattered data fitting where no derivative information is available. Both local and global methods are discussed, beginning with minimal energy

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Preface

xi

methods which may be the most useful for the typical interpolation problem. This is followed by a discussion of some special local schemes which are quite useful for larger problems. We then treat two-stage local methods based on the Hermite interpolation methods of the previous chapter. The idea of these methods is to estimate the needed derivative information directly from the scattered data. For comparison purposes, interpolation with radial basis functions is also discussed. In addition to numerous numerical examples, the results of some experiments comparing the various methods are included. Chapter 7 is about the fitting of data as opposed to interpolating it. This approach is generally preferable for large amounts of data, or when we have noisy data. Both least-squares and penalized least-squares methods are treated, along with many numerical examples and a comparison of the various methods. Chapter 8 is concerned with methods for interpolating and fitting bivariate data with shape control. Here we are looking for splines which are nonnegative, monotone, or convex. Problems of this type are of considerable importance in applications. Chapter 9 is devoted to the numerical solution of boundary-value problems using bivariate splines with the Ritz–Galerkin (finite-element) method. This is a well-established technique in the Engineering community. The implementations there typically make use of isoparametric mappings with a heavy emphasis on C 0 piecewise polynomial spaces. Here we show how to work with spline spaces with higher order smoothness directly without using such mappings. The key is to use the Bernstein–Bézier representation. The focus is on elliptic problems of orders two and four. Chapter 10 discusses spaces of splines defined on the sphere which are made up of piecewise spherical harmonics defined on spherical triangulations. In particular, it is shown how the methods for storing and manipulating bivariate splines can be easily extended to spherical splines. Chapter 11 shows how the various interpolation and data fitting methods discussed in Chapters 6–7 can be easily adapted to work on the sphere. In particular, we give algorithms for scattered data interpolation with either Lagrange or Hermite data, and for least-squares and penalized-least squares fitting. We also describe a method for solving partial differential equations on the sphere. Each chapter of the book includes a section with remarks, where the aim is to provide interesting and useful tangential information without interrupting the flow of the book. Moreover, each chapter concludes with a section with historical notes designed to give the reader some insight into how the material of the chapter developed. Because of the huge literature, it was impossible to go into much detail. A bibliography listing books on splines is included at the end of this book. Unfortunately, it was not practical to include a list of papers on splines related to the material in this book. It would have taken well over 100 pages. For the full list of references for the book, see www.siam.org/books/ot142. There is also a link there to an even more extensive bibliography of papers related to splines, maintained by Carl de Boor and the author. That site even includes files with the references in TEX form. Since we have different reference lists for books and papers, we need a mechanism for distinguishing between the two in citations. We use double brackets for books, and single brackets for papers. Thus, [[LaiS07]] refers to a book whose details can be found in the Bibliography, but [AlfNS96] refers to a paper which is not listed here, but rather in the online reference set. Each reference is assigned a code based on the first three letters of the

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

xii

Preface

first author’s name, along with the first letter of each coauthor. The code also includes the year of publication. In some cases we have used more than three letters for the first author in order to distinguish authors. For convenience, after the Bibliography we have included an index of the scripts referred to in the examples given in the book. This is followed by an index of the functions used in these scripts. The MATLAB m-code of the scripts and the p-code for the functions called by them (along with some other supporting functions) are all included in the package SplinePak. The book concludes with a detailed subject index. This list includes page numbers for all the words defined in the book as identified by this special font. Various other important concepts are also indexed. We do not attempt to list every page on which a given word appears. To fit this book into space and time constraints, there are many topics that have not been discussed here. In particular, we have opted not to discuss computing with trivariate splines. There are also many specific applications of splines in the literature that have not been touched on here. In many ways, the preparation of this book has stretched over the entire 50 years that the author has been working on splines. At some point, almost all of the algorithms described here were originally coded in Fortran. The material of the book has been used in many of my courses over the years, starting in 1966–1968 when I was a postdoc at the Mathematics Research Center in Madison. It was further developed for spline courses I taught later in Austin, Berlin, Sao Paulo, College Station, Munich, and for the last 25 years in Nashville. Over the years, I have benefited from discussions of this material with many of my colleagues. I make no attempt to list them all here, but I would like to especially thank Peter Alfeld, Carl de Boor, Oleg Davydov, Manfred von Golitschek, Ming-jun Lai, and Tom Lyche. I would also like to thank my graduate students over the years for their interest and feedback. I am particularly grateful to my students Lujun Wang and Wenjia Zhang, who read the entire manuscript and checked all of the numerical examples.

Chapter 1

Univariate Splines

In this chapter we briefly discuss how to use univariate splines to solve various interpolation and approximation problems. Besides being of interest in its own right, this material is essential to our discussion of tensor-product spline methods, and also provides useful background for the entire book.

1.1 Introduction Univariate splines have been heavily studied in the literature, and are discussed in detail in several books; see, e.g., [[Boo78, Schum81]]. Here we give just the basics. Let Pd1 := space of univariate polynomials of degree at most d.

(1.1)

This is a (d + 1)-dimensional linear space. Let  := [a, b] be an interval that has been k+1 with partitioned into subintervals via a set of points  := {x i }i=0 a = x 0 < x 1 < · · · < x k < x k+1 = b.

(1.2)

Definition 1.1. Given integers 0 ≤ r < d and a partition  satisfying (1.2), we define the

space of univariate polynomial splines of smoothness r and degree d with knots  as

Sdr () := {s ∈ C r () : s|(xi ,xi+1 ) ∈ Pd1 , i = 0, . . . , k}.

(1.3)

It is possible to define much more general spaces of polynomial splines where the degree of smoothness between adjoining pieces varies from knot to knot (see Remark 1.1), and virtually all of what is said here holds for these more general spaces. However, for most applications the spaces Sdr () will suffice, and so we focus on them. Note that despite the huge literature on splines, there is no standard notation for univariate spline spaces. We have made the above choice with an eye to using a similar notation for bivariate spline spaces on triangulations. Also note that here we work with the degree d of the splines. In the literature it is more common to refer to their order, which is d + 1. 1

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2

Chapter 1. Univariate Splines

1.2 B-splines Since a spline s ∈ Sdr () consists of k + 1 polynomial pieces of degree d, where these pieces are joined together by enforcing r + 1 smoothness conditions at each interior knot, we expect n := dim Sdr () = (k + 1)(d + 1) − k(r + 1) = k(d − r ) + d + 1.

(1.4)

For a formal proof of this fact, see Theorem 4.4 of [[Schum81]]. For computational purposes, it is important to have a suitable basis for this space. This is provided by the so-called B-splines, which we now discuss. Guided by Definition 4.8 in [[Schum81]], we introduce the following notation. k+1 , the associated extended partition e is Definition 1.2. Given 0 ≤ r < d and  = {x i }i=0 n+d+1 , where n is the dimension of Sdr () given in (1.4), defined to be {yi }i=1

a = y1 = · · · = yd+1 , and

yn+1 = · · · = yn+d+1 = b, d−r

d−r

      yd+2 ≤ · · · ≤ yn = x 1 , . . . , x 1 , . . . , x k , . . . , x k . Given an extended partition e , let  Q 1i (t) := for i = 1, . . ., n + d, and let  Qm i (t)

:=

1 yi+1 −yi ,

yi ≤ t < yi+1 ,

0,

otherwise,

m−1 (t −yi )Q im−1 (t )+(yi+m −t )Q i+1 (t ) , (yi+m −yi )

yi ≤ t < yi+m ,

0,

otherwise,

(1.5)

for 2 ≤ m ≤ d + 1 and i = 1, . . ., n + d − m + 1. Definition 1.3. Let Nim (t) := (yi+m − yi )Q m i (t),

i = 1, . . . , n + d − m + 1.

(1.6)

We call these the normalized B-splines of order m (or degree m − 1) associated with the extended partition e . The B-splines defined above are not defined at the right-hand endpoint of the domain [a, b]. By convention we set their values at b to be their limits as x approaches b from the left. B-splines have a number of important properties. We list just a few of them here. For all 1 ≤ m ≤ d + 1, 1) The B-spline Q m i vanishes outside of the interval [yi , yi+m ] and is positive in the interior.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.2. B-splines

3

2) For all i with yi < yi+m , the right derivative of Q m i is given by D+ Q m i (t) = (m − 1)

(t) − Q m−1 [Q m−1 i i+1 (t)] (yi+m − yi )

.

(1.7)

3) For all i with yi < yi+m , the integral of Q m i over the interval [a, b] is  a

b

Qm i (t) dt = 1/m.

(1.8)

4) The normalized B-splines {Nim }n+d−m+1 form a partition of unity, i.e., i=1 n+d−m+1 

Nim (t) ≡ 1

for all a ≤ t ≤ b.

(1.9)

i=1 m 5) N1m (a) = Nn+d−m+1 (b) = 1.

The most important property of the B-splines is the following result; see Theorem 4.18 in [[Schum81]]. Theorem 1.4. Let B := {Nid+1 }ni=1 be the set of normalized B-splines of order d + 1 corresponding to the extended partition e associated with Sdr (). Then B is a basis for Sdr (). We conclude this section with one example. k+1 Example 1.5. Given a partition  = {x i }i=0 of the interval [a, b], consider the space S10 () of linear splines.

Discussion: This space has dimension n := k + 2. In Figure 1.1 we present graphs of the normalized B-splines of order two corresponding to the partition  = {0, 1, 2, 3, 4} of the interval [0, 4]. Since we have plotted all five B-splines on the same figure, we have shaded the areas under N32 and N42 to better emphasize their local supports. N12

N22

N32

N42

N52

y1 y2

y3

y4

y5

y6 y7

Figure 1.1. Graphs of the linear B-splines of Example 1.5.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4

Chapter 1. Univariate Splines

1.3 Computing with the B-form In view of Theorem 1.4, every spline s ∈ Sdr () has a unique expansion in the form s(t) =

n 

ci Nid+1 (t).

(1.10)

i=1

We call this the B-form of s. Now to store s in a digital computer, we simply need to store its degree d, its knot vector, and the coefficient vector c := (c1 , . . . , cn ). We now discuss some efficient algorithms for evaluating splines and their derivatives. For more details, see Chapter 5 of [[Schum81]].

1.3.1 Finding the interval containing a given point To evaluate a spline s ∈ Sdr () at a point t ∈ [a, b], we first have to find the integer  such n+d+1 that y ≤ x < y+1 , where e = {yi }i=1 is the extended partition associated with Sdr (). We have implemented this algorithm in SplinePak as the following function: l = findinterval(n,y,t) Here n is the dimension of the spline space, y is the extended knot vector, and t is the point of interest. If t = yn+1 = b, this function returns l = n.

1.3.2 Evaluating the B-form Given x, suppose  is the integer produced by the function findinterval. We now discuss how to compute the value of s(t) from the expansion (1.10). One way to do this is to compute all of the B-splines that have value at t and insert them in the expansion; see section 1.3.6. However, a more efficient way to compute s(t) is to use the following recurrence for j = 1, . . . , d and i =  − d + j , . . ., : ⎧ ⎨0, if yi+d− j +1 − yi = 0, [ j +1] [ j] (t) = (t −yi )ci[ j ] (t )+(yi+d− j +1 −t )ci−1 ci (t ) ⎩ otherwise. (yi+d− j +1 −yi ), This recurrence is started with ci[1] (t) = ci for i =  − d, . . ., . It is known that c[d+1] (t) gives the value of s(t); see Theorem 5.7 of [[Schum81]]. Here is a diagram of how the computation progresses: [1] c−d

[1] c−d+1

···

[1] c−1

c[1]

[2] c−d+1

···

[2] c−1 .. .

c[2] .. .

[d] c−1

c[d] c[d+1]

For pseudocode, see Algorithm 5.8 in [[Schum81]]. Note that the first row contains coefficients of s, which are given constants. All other entries depend on t, but for simplicity,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.3. Computing with the B-form

5

we have not indicated this in the array. Each entry in the ( j + 1)st row of this array is computed as a convex combination of two entries in the previous row. We have implemented this algorithm in SplinePak as the following function: val = sval(d,y,c,t,l) It is useful to have an extended version of this function that can be called to give spline values at a vector t of points. For this we have the following function: val = sval2(d,y,c,t) For a given vector t = (t1 , . . . , tm ), this function produces the vector of values val := (s(t1 ), . . . , s(tm )).

1.3.3 Computing the derivatives of a spline r−1 It is clear that if s ∈ Sdr (), then its derivative belongs to the space Sd−1 (). More genern+d+1 ally, if s is a spline of degree d corresponding to an extended knot sequence y := {yi }i=1 , then its derivative is a spline of degree d − 1 corresponding to the extended knot sequence yˆ := {yi }n+d i=2 . In particular, suppose that s has been written in the B-form (1.10). Then it can be shown (cf. Theorem 5.9 of [[Schum81]]) that 

s (t) =

n−1 

cˆi Nˆ id (t),

(1.11)

i=1

where the { Nˆ id }n−1 i=1 are the B-splines of degree d − 1 on the extended knot sequence yˆ , and the coefficients {cˆi }n−1 i=1 are given by  0, if yi+d+1 − yi+1 = 0, (1.12) cˆi = d(ci+1 −ci ) (yi+d+1 −yi+1 ), otherwise, for i = 1, . . ., n − 1. The following function computes the extended knot sequence yd and coefficient vector cd for the derivative of a spline: [yd,cd] = derspl(d,y,c) To evaluate s  at a point t, we simply call findinterval to find the interval in the extended knot sequence yˆ containing t, and then call on sval with d replaced by d − 1 and c replaced by c. ˆ To get a higher derivative, we simply repeat the computation on the previous derivative; see Example 1.6 below and the associated script Usplinedemo given on p. 7.

1.3.4 Computing the integral of a spline r+1 If s is a spline in Sdr (), then its antiderivative S is a spline in Sd+1 (). More generally, n+d+1 if s is a spline of degree d corresponding to an extended knot sequence y := {yi }i=1 , then its antiderivative is a spline of degree d + 1 corresponding to the augmented extended

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6

Chapter 1. Univariate Splines

knot sequence y˜ := { y˜1 , . . . , y˜n+d+3 }, where y˜1 = y1 , y˜i = yi−1 for i = 2, . . . , n + d + 2, and y˜n+d+3 = yn+d+1 . In particular, suppose that s has been written in the B-form (1.10). Then it can be shown (cf. Theorem 5.17 of [[Schum81]]) that the antiderivative of s can be written as  t n+1  S(t) := s(u) du = c˜i N˜ id+2 (t), y1

i=1

where { N˜ id+2 }n+1 i=1 are the B-splines of degree d + 1 associated with the extended knot sequence y˜ , and i  (yd+ j +1 − y j ) , i = 1, . . ., n + 1. c˜i = cj d +1 j =1

Note that by definition S(y1 ) = 0, so the coefficient c˜1 = 0. SplinePak includes the following function for computing the coefficient vector c˜ and extended knot vector y˜ corresponding to S: [cw,yw] = intsplco(d,y,c) β Given a ≤ α < β ≤ b, we can compute α s(u) du = S(β) − S(α) by performing two evaluations of the spline S. The following function carries this out: val = intspl(d,yw,cw,alpha,beta)

1.3.5 Plotting a spline and its derivatives We give one example to illustrate the use of the above functions. Example 1.6. Let s ∈ S32 () be the spline corresponding to the knots 0 < .1 < .3 < .5 < .6 < 1 and coefficients c = (1, 2, 1, −1, 1, 3, −2, 1). Plot s and its first and second derivatives, and compute some definite integrals. Discussion: We make use of the script Usplinedemo; see below. Here d = 3, n = 8, and y = {0, 0, 0, 0, .1, .3, .5, .6, 1, 1, 1,1}. Figure 1.2 shows a plot of s and its first derivative on the interval [0, 1]. The script also computes the integrals on the intervals [0, .5], [.5, 1], and [0, 1]. It returns the values 0.297381, 0.452619, and .75, respectively.

30

2 1.5

5

0.5

-0.5 0

0.5

1

-15 0

0.5

Figure 1.2. Plots of the spline and its derivative for Example 1.6.

1

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.3. Computing with the B-form

7

% Usplinedemo d = 3; k = 4; n = k + d + 1; knots = [.1,.3,.5,.6]; y = [zeros(1,d+1),knots,ones(1,d+1)]; c = [1,2,1,-1,1,3,-2,1]; % Compute the first and 2nd derivatives [yd,cd] = derspl(d,y,c); [yd2,cd2] = derspl(d-1,yd,cd); % Set up evaluation points ng = 100; xg = linspace(y(1),y(n+1),ng); zg = sval2(d,y,c,xg); zg1 = sval2(d-1,yd,cd,xg); zg2 = sval2(d-2,yd2,cd2,xg); figure; plot(tg,zg); figure; plot(tg,zg1); figure; plot(tg,zg2); % Compute the antiderivative [cw,yw] = intsplco(d,y,c); val1 = intspl(d,yw,cw,0,.5) val2 = intspl(d,yw,cw,.5,1) val3 = intspl(d,yw,cw,0,1)

1.3.6 Computing all B-splines with a value at a given point Suppose y is an extended partition corresponding to a spline of degree d with n coefficients. For some applications we need to compute all the B-splines with nonzero values at a given point t in the interval [a, b]. If  is the output of findinterval corresponding to t, we know from the support properties of the B-splines that only the following d + 1 B-splines are nonzero at t: d+1 N−d (t), . . . , Nd+1 (t). (1.13) Using the recurrence formula (1.5) defining B-splines, we can generate the following array of values: Q 1

Q d+1 −d

Q 2−1 .. .

Q 2 .. .

Q d−d+1

···

Q d−1

Q d

Q d+1 −d+1

···

Q d+1 −1

Q d+1 

All of these quantities depend on t, which we do not show in this array. Now normalizing the last row, we get the desired values (1.13). For pseudocode, see Algorithm 5.5 in [[Schum81]]. We have implemented it in SplinePak as the following function: b = bspl(d,l,t,y)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8

Chapter 1. Univariate Splines

The output of this function is the vector b containing the d + 1 values in (1.13). Taking account of (1.7), it is easy to adjust the above algorithm to produce the values of the mth derivatives of the B-splines in (1.13) at the point t. For this purpose we provide bder = bsplder(d,y,l,t,m)

1.4 Interpolation with univariate splines In this section we discuss the following interpolation problem. Problem 1.7. Suppose we are given a = t1 < · · · < tn = b and associated values z 1 , . . . , z n . Find a function s defined on [a, b] such that s(ti ) = z i ,

i = 1, . . . , n.

(1.14)

Our aim is to solve this problem using a univariate spline space of the form Sdr () defined on a partition  of [a, b]. We are free to choose the smoothness r , the degree d, and the number and placement of the knots, but we must make sure that the dimension of the spline space turns out to be equal to the number n of data to be interpolated. This requires some care. In practice it is usually best to work with low values of d, and we usually choose r = d − 1.

1.4.1 Linear spline interpolation The simplest spline interpolation method is based on the space S10 (), where we choose k+1 the knots {x i }i=0 to coincide with the points {ti }ni=1 . Let {Ni2 }ni=1 be the corresponding linear B-splines. Then it is clear from the properties of the B-splines that s=

n 

z i Ni2

i=1

satisfies the interpolation condition (1.14). This spline is just the piecewise linear function that results from connecting successive data points in R2 . Figure 1.3 shows a typical linear spline with five knots. It is produced by the following script: % U01.m % Choose sample points t = [0 .25 .5 .75 1]; % Choose values to be interpolated z = [1 2 0 .75 -1]; % plot the spline figure; plot(t,z);

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.4. Interpolation with univariate splines

9

2

1

0

-1 0

0.5

1

Figure 1.3. A plot of a linear spline interpolating five values.

1.4.2 Interpolation with higher degree splines For many applications, we want to solve Problem 1.7 with a spline that is more than just continuous. To get higher smoothness, we will have to work with splines of degree d > 1. Suppose we want to solve the interpolation problem using the spline space Sdr (). In order to get a unique interpolating spline, we will have to choose r , d, and the knots to ensure that the dimension of Sdr () is equal to the number of interpolation conditions n. Suppose Ni = Nid+1 , i = 1, . . . , n, are the associated B-splines. We now look for an interpolating spline s ∈ Sdr () in the B-form (1.10). Then writing down the interpolation conditions (1.14) leads to the following system of linear equations for the coefficient vector c: ⎡ ⎤ N1 (t1 ) · · · Nn (t1 ) ⎡c1 ⎤ ⎡z 1 ⎤ ⎢ ⎥ ⎢ ⎥ c2 ⎥ ⎢ N1 (t2 ) · · · Nn (t2 )⎥ ⎢ ⎥ ⎢z 2 ⎥ ⎢ . ⎥⎢ = (1.15) ⎢ ⎢ . ⎥. ⎥ . . . ⎢ . .. .. ⎥ ⎣ . ⎦ ⎣ .. ⎦ ⎣ .. ⎦ N1 (tn )

···

Nn (tn )

cn

zn

Let M be the n × n matrix appearing in this system. It turns out that M is nonsingular if and only if certain conditions on the locations of the knots and interpolation points are satisfied. These conditions are given in the following theorem, which is referred to as the Schoenberg–Whitney theorem. For a proof, see Theorem 4.64 in [[Schum81]]. Theorem 1.8. The matrix M in (1.15) is nonsingular if and only if its diagonal entries are positive, i.e., Ni (ti ) > 0 for i = 1, . . . , n. (1.16) In view of the fact that for d ≥ 1, the B-spline Ni has positive values precisely in the interval (yi , yi+d+1 ), the condition (1.16) is equivalent to ti ∈ (yi , yi+d+1 ) for i = 1, . . . , n. Here {y j }n+d+1 is the set of extended knots used to define the B-splines; see section 1.2. j =1

1.4.3 Not-a-knot interpolation In this section we solve the interpolation problem using the spline spaces Sdd−1 () where d is odd. We need to choose knots so that the dimension of Sdd−1 () is equal to the number

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10

Chapter 1. Univariate Splines

of interpolation conditions n. This means that we cannot choose the knots to lie at the data points t1 , . . . , tn , since this would give dim Sdd−1 () = d +n −1. This works for d = 1 as we saw in the previous section, but for d > 1 the dimension of the space exceeds n. However, if the degree d is odd, there is a very elegant way out of this dilemma: in choosing knots we simply leave out some data points. In particular, we choose the interior knots of  to be x i = ti+μ , i = 1, . . ., k, (1.17) where k = n − d − 1 and μ = (d + 1)/2. In this case we get dim Sdd−1 () = n. To compute the coefficients of the not-a-knot interpolant in B-form, we first set up the matrix M in (1.15). This can be done using the function bspl described in section 1.3.6. Note that by the support properties of the B-splines, M will be a d + 1-banded matrix. Now we can find c by solving Mc = z, where z = (z 1 , . . . , z n )T . SplinePak includes the following function for computing the not-a-knot interpolant: [y,c] = notaknot(d,t,z) This code produces both the coefficient vector c and the extended knot vector y. For convenience, we now describe a script for testing the not-a-knot interpolation method. It creates the data by sampling a test function f at n equally spaced points in the interval [0, 1]. This function is defined as an anonymous function in the script. % Unotaknot f = @(x) exp(x).*sin(2*pi*x); d = input(’input d = ’); n = input(’input n = ’); a = -1; b = 1; t = linspace(a,b,n); z = f(t)’; [y,c] = notaknot(d,t,z); % Compute error and plot ng = 201; xg = linspace(y(1),y(n+1),ng); fg = f(xg); zg = sval2(d,y,c,xg); e = fg - zg; fprintf(’maxerr = %g, rms = %g\n’,norm(e,inf),erms(e)); figure; plot(xg,zg); In this script we have used sval2 to evaluate the spline on ng = 201 equally spaced points in the interval [−1, 1]. These values are used to create the plot, and are compared with the values of f to compute two error measures. The first is the maximum error on the set of points xg defined by norm(e,inf) := max |ei |, 1≤i≤ng

(1.18)

where ei := s(xgi ) − f (xgi ), while the second is the root mean square (RMS) error defined by  1/2 ng 1  2 erms(e) := ei . (1.19) ng i=1

We have written the function erms to calculate this value.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.4. Interpolation with univariate splines

11

1.5

0.5

-0.5

-1.5

-2.5 -1

-0.5

0

0.5

1

Figure 1.4. Plot of the cubic not-a-knot interpolant of the test function (1.20) for n = 9 equally spaced points in [0, 1].

Example 1.9. Explore the accuracy of not-a-knot interpolation with d = 3 for the test function f (x) = e x sin(2π x) (1.20) on the interval [−1, 1]. Discussion: We make use of the script Unotaknot with n = 5, 9, 17, 33, 65. This gives a nested sequence of sample points where the mesh size || = max |yi+1 − yi | 1≤i≤n

(1.21)

is halved each time we increase n. Figure 1.4 shows the cubic spline interpolant for n = 9. The following table lists the errors for the various values of n, and also shows the ratios of the errors: n emax rms ratios 5 2.14(0) 9.38(−1) 9 2.71(−1) 7.40(−2) 7.90 12.68 17 2.63(−2) 4.95(−3) 10.30 14.95 33 1.53(−3) 2.06(−4) 17.19 24.03 65 8.49(−5) 8.29(−6) 18.02 24.85 Since this test function belongs to C ∞ [0, 1], Theorem 1.57 below shows that the error should behave like O(||4 ). This means that for each row in the table, the ratio of the error in the previous row to the error in the current row should be approximately 16.

1.4.4 Clamped cubic spline interpolation In this section we briefly discuss another univariate spline interpolation method that has been heavily studied in the literature. This method is based on C 2 cubic splines, i.e., on the space S32 (). Suppose we are given a = t1 < · · · < tm = b and corresponding values z 1 , . . . , z m that we want to interpolate. We choose  = {ti }m i=1 , i.e., we choose the knots to be the sample points. By (1.4), n = dim S32 () = m + 2. Thus, in addition to the m interpolation conditions, we need to interpolate two additional values. We can take these to be the slopes of the spline at a and b.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

12

Chapter 1. Univariate Splines

Given real numbers α and β, we define the clamped cubic spline interpolant to be the spline s ∈ S32 () such that s(ti ) = z i , and

s  (a) = α,

i = 1, . . . , m, s  (b) = β.

(1.22)

Thus, to interpolate a function f defined on [a, b] at the abscissae {ti }m i=1 , we also have to provide α = f  (a) and β = f  (b). This is an example of a so-called Hermite interpolation problem, i.e., one where derivative information is also involved. We discuss Hermite interpolation in more detail in the following section. To construct a clamped cubic interpolating spline s, suppose we write it in B-form as in (1.10), where for notational convenience, we write Ni = Ni4 for i = 1, . . ., n. Then the interpolation conditions lead to the following system of n linear equations for the coefficient vector c := (c1 , . . . , cn ): ⎡ ⎤ N1 (t1 ) ··· Nn (t1 ) ⎡ ⎤ z1 ⎢  ⎥ ⎢ N1 (t1 ) ··· Nn (t1 ) ⎥ ⎡ ⎤ ⎢ α ⎥ ⎢ ⎥ c1 ⎢ N (t ) ⎢ ⎥ ··· Nn (t2 ) ⎥ ⎢ 1 2 ⎥ ⎢ c2 ⎥ ⎢ z 2 ⎥ ⎢ ⎥⎢ . ⎥ ⎢ . ⎥ . . . ⎢ ⎥⎢ . ⎥ = ⎢ . ⎥. .. .. .. (1.23) ⎢ ⎥⎢ . ⎥ ⎢ . ⎥ ⎢ ⎥⎣ ⎢ ⎥ ⎦ ⎢ N1 (tm−1 ) · · · Nn (tm−1 )⎥ cn−1 ⎢z m−1 ⎥ ⎢ ⎥ c ⎣ z ⎦ ⎢ N (t ) · · · ⎥ n m Nn (tm ) ⎦ ⎣ 1 m β N1 (tm ) · · · Nn (tm ) Making use of the extended version of the Schoenberg–Whitney theorem (Theorem 1.12 below or Theorem 4.67 in [[Schum81]]), it is easy to check that this matrix is nonsingular. Thus, there is a unique clamped cubic spline interpolant. To compute the coefficients of s, we simply have to set up this system and solve it. The function bspl described in section 1.3.6 can be used to find values of the B-splines. For the second and last rows, we can use the function bsplder also described there. Clamped cubic spline interpolation is implemented in SplinePak as the function [y,c] = cubclamp(t,z,alpha,beta) This function can be tested with the program Ucubclamp, which is essentially the same as the program Unotaknot, but with the call on notaknot replaced by the call on cubclamp, and with the addition of the anonymous function fd = @(x) exp(x).*(sin(2*pi*x) + 2*pi*cos(2*pi*x)) for computing the derivative of the test function (1.20). Example 1.10. Explore the accuracy of clamped cubic spline interpolation by interpolating the test function (1.20) on a nested sequence of partitions of the interval [0, 1].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.5. Hermite interpolation

13

Discussion: We make use of the script Ucubclamp for m = 5, 9, 17, 33, 65 which gives a nested sequence of equally spaced partitions. This is the same test function as in Example 1.9, and for comparison with the not-a-knot results, we give the analogous error table. m 5 9 17 33 65

emax 9.12(−1) 4.91(−2) 2.76(−3) 1.59(−4) 9.68(−6)

rms 4.78(−1) 1.72(−2) 7.71(−4) 4.36(−5) 2.65(−6)

ratios 18.57 27.79 17.79 22.31 17.36 17.68 16.43 16.45

As the table shows, the errors for this spline are very similar to those obtained with the cubic not-a-knot spline in Example 1.9. By Theorem 1.58 below, we expect the error to be O(||4 ), which means that the ratios should be approximately 16. In practice we are usually given data which involves samples of a function but not its derivatives. If this is the case, we can still use the clamped cubic spline, but we need a method for estimating the derivatives at the endpoints. This can be done with standard numerical differentiation formulae. For example, using the forward difference, we have f  (t1 ) ≈ (z 2 − z 1 )/(t2 − t1 ). Assuming we have equally spaced points, this is accurate only to order O(h) for smooth functions. To get more accurate formulae, we have to use more points. For example, to estimate f  (a), we could use the formula f  (t1 ) ≈ (−3z 1 + 4z 2 − z 3 )/(2h). However, this formula is only order two accurate. To preserve the order four accuracy of the clamped cubic spline, we need a more accurate estimate for the derivatives at a and b. Such a formula is given by 

f (a) ≈

5 

wi f (ti ),

(1.24)

i=1

where the weights {wi }5i=1 are obtained from the system ⎡ ⎤ 1 1 1 1 1 ⎡ ⎤ ⎡ ⎤ 0 ⎢ t1 t2 t3 t4 t5 ⎥ w1 ⎢ ⎥ ⎢w2 ⎥ ⎢ 1 ⎥ ⎢2 2 2 2 ⎥ ⎥ ⎢ 2a ⎥ ⎥ ⎢t1 t2 t3 t4 t5 ⎥ ⎢ w3 ⎥ = ⎢ ⎢ ⎥. ⎢ ⎥⎢ ⎢t 3 t 3 t 3 t 3 t 3 ⎥ ⎣w4 ⎦ ⎣3a 2 ⎦ ⎣ 1 2 3 4 5⎦ w5 4a 3 t14 t24 t34 t44 t54 This gives an order four formula. We can estimate f  (b) in a similar way. We have used these formulae in the script Ucubclampest. Using it to recompute the table in Example 1.10, we get errors that are somewhat larger than before, but the ratios again tend to 16, i.e., we are still getting order four convergence.

1.5 Hermite interpolation In the previous section we solved an interpolation problem which involves matching not only function values but certain derivative values. It was an example of the following more general Hermite interpolation problem.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

14

Chapter 1. Univariate Splines

Problem 1.11. Suppose we are given m points a = t1 < · · · < tm = b and associated posij i for i = 1, . . ., m. Find a tive integers k1 , . . . , km . Suppose we are also given values {z i }kj =0 function s defined on [a, b] such that j

s ( j ) (ti ) = z i

for j = 0, . . . , ki ,

(1.25)

for i = 1, . . . , m. When k1 = · · · = km = 0, Problem 1.11 reduces to the (Lagrange) interpolation  Problem 1.7 considered in section 1.4. The total number of equations in (1.25) is n := m i=1 (k i + 1). Thus, we can try to solve Problem 1.11 using any n-dimensional space of splines of smoothness r ≥ maxi ki defined on [a, b]. Suppose Sdr () is such a space, and let {Ni }ni=1 be the corresponding B-spline basis. We seek s in the B-form s=

n 

ci Ni .

(1.26)

i=1

To find the coefficients of s, we have to solve the system of linear equations Mc = z, where M is the n × n matrix ⎡ ⎤ N1 (t1 ) N2 (t1 ) ··· Nn (t1 ) ⎢ .. .. .. ⎥ ⎢ ⎥ . . . ⎢ ⎥ ⎢ (k1 ) ⎥ ⎢ N1 (t1 ) N2(k1 ) (t1 ) · · · Nn(k1 ) (t1 ) ⎥ ⎢ ⎥ .. .. .. ⎢ ⎥ M := ⎢ (1.27) ⎥ . . . ⎢ ⎥ ⎢ N (t ) ⎥ N2 (tm ) ··· Nn (tm ) ⎥ ⎢ 1 m ⎢ ⎥ .. . . ⎢ ⎥ .. .. . ⎣ ⎦ (km ) (km ) (km ) N1 (tm ) N2 (tm ) · · · Nn (tm ) and

k

0 km T , . . . , zm ] . z := [z 10 , . . . , z 11 , . . . , z m

However, this matrix can be singular unless we are careful to match the basis functions to the sample points. Let k1 +1

km +1

      t˜1 , . . . , t˜n = t1 , . . . , t1 , . . . , tm , . . . , tm , and define

  μi := max j : t˜i = · · · = t˜i− j ,

i = 1, . . . , n,

(1.28)

The following is an extended version of the Schoenberg–Whitney theorem; see Theorem 4.67 in [[Schum81]]. Theorem 1.12. The matrix M in (1.27) is nonsingular if and only if μ t˜i ∈ (yi , yi+d+1 ) ∪ {x : D+i Ni (x) = 0},

i = 1, . . . , n,

n+d+1 where e = {yi }i=1 is the extended knot sequence associated with the B-splines.

(1.29)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.5. Hermite interpolation

15

1.5.1 Hermite interpolation with S 13 () In this section we consider a special form of the Hermite interpolation problem (Problem 1.11), where ki = 1 for i = 1 . . . , m. In particular, we suppose a = t1 < · · · < tm = b are given points and that {z i , z i }m i=1 are given real numbers. Now we seek a spline such that s(ti ) = z i , s  (ti ) = z i ,

i = 1, . . ., m.

(1.30)

To solve this problem we use the space S31 (), where  = {t1 , . . . , tm }. By formula (1.4), this space has the required dimension n := 2(m − 2) + 4 = 2m. Let Ni := Ni4 , i = 1, . . . , n, be the associated B-splines. To compute the coefficient vector c of the interpolating spline s ∈ S31 () in the B-form (1.26), we solve the system Mc = z, where ⎤ ⎡ N1 (t1 ) N2 (t1 ) · · · Nn (t1 ) ⎥ ⎢  ⎢ N1 (t1 ) N2 (t1 ) · · · Nn (t1 ) ⎥ ⎢ . .. ⎥ .. ⎥ (1.31) M := ⎢ ⎢ .. . ⎥ . ⎥ ⎢ (t ) N (t ) · · · N (t ) N ⎣ 1 m 2 m n m ⎦ N1 (tm ) N2 (tm ) · · · Nn (tm ) and

 T ] . z := [z 1 , z 1 , . . . , z m , z m

(1.32)

We can calculate the values of the B-splines and their derivatives using our functions bspl and bsplder, respectively. We have programmed this cubic Hermite interpolation method in the function [y,c] = cubherm(t,z,z1) Here z1 is a vector containing the derivatives to be interpolated. This program can be tested with Ucubherm. Using the test function (1.20), we get the following table of errors which are slightly better than what we got for cubic not-a-knot and clamped cubic spline interpolation in Examples 1.9 and 1.10. m 5 9 17 33 65

emax 4.05(−1) 3.78(−2) 2.25(−3) 1.46(−4) 9.57(−6)

rms 1.59(−1) 1.07(−2) 6.71(−4) 4.21(−5) 2.63(−6)

ratios 10.71 14.86 16.80 15.95 15.41 15.94 15.26 16.01

1.5.2 Hermite interpolation with S21 () The Hermite interpolation problem of the previous section can also be solved using C 1 quadratic splines by inserting knots between the interpolation points. Let  = {t1 < ξ1 < t2 < ξ2 < t3 < · · · < ξm−1 < tm }.

(1.33)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

16

Chapter 1. Univariate Splines

With this partition, we have n := dim S21 () := 2m, which is what we need for constructing a spline s satisfying the Hermite interpolation conditions (1.30). Suppose {Ni }ni=1 are the B-splines forming a basis for this space. Then writing s in the B-form (1.26), we can find the coefficients of s that ensure that s satisfies the interpolation conditions (1.30) by solving the system Mc = z, where M and z are given in (1.31) and (1.32). Using the extended version of the Schoenberg–Whitney theorem (Theorem 1.12), it is not hard to check that M is nonsingular. We have programmed this interpolation method in the function [y,c] = quadherm(t,z,z1) where we have used ξi = (ti + ti+1 )/2 for i = 1, . . . , m − 1. Example 1.13. Explore the accuracy of quadratic C 1 Hermite interpolation for the test function (1.20) using data at m equally spaced points in the interval [−1, 1] for m = 5, 9, 17, 33, 65. Discussion: We use the script Uquadherm with the same test function as in Examples 1.9 and 1.10. For comparison purposes, we again give the max and RMS errors on 201 equally spaced points in [−1, 1]. m 5 9 17 33 65

emax 4.17(−1) 4.28(−2) 4.25(−3) 4.92(−4) 5.98(−5)

rms 1.59(−1) 1.23(−2) 1.11(−3) 1.21(−4) 1.47(−5)

ratios 9.74 12.93 10.07 11.08 8.74 9.17 8.23 8.23

As the table shows, the rate of convergence for this spline is approximately order three, which is what we expect for quadratic splines.

1.6 Interpolation with shape control In many applications we know that the function we are trying to approximate has some shape properties such as positivity, monotonicity, or convexity on certain subintervals of its domain. In such cases it would be desirable to construct a spline that preserves these properties. The following example shows that to achieve this aim, we will need special methods. Example 1.14. Interpolate the seven data values {.2, .2, 0, 0, .5, .8, 1} at the sample points {0, .2, .4, .5, .6, .7, 1} using notaknot, cubclamp, and cubherm. Discussion: We make use of the script Ushape. For the clamped cubic spline we use zero derivatives at the endpoints, and for the cubic Hermite interpolant we choose a zero derivative at each data point. Figure 1.5 shows plots of the resulting splines, along with a plot of the C 0 linear spline that interpolates the same data. The linear spline exhibits the expected shape properties: it is nonnegative on the entire interval [0, 1], and is monotone and concave on [0, .4] and [.5, 1]. The cubic Hermite spline with zero derivatives captures the positivity and monotonicity properties, but not the convexity on [.5, 1]. The other two splines fail to have any of the desired shape properties. In the following subsections we present two methods based on C 1 splines which are designed to interpolate with shape control.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.6. Interpolation with shape control

17 1

1

0.8 0.8 0.6 0.6 0.4 0.4

0.2

0.2 0 0

0

0.2

0.4

0.6

0.8

1

-0.2 0

0.2

0.4

0.6

0.8

1

0.2

0.4

0.6

0.8

1

1

1

0.8

0.8 0.6

0.6

0.4 0.4 0.2 0.2

0 -0.2 0

0.2

0.4

0.6

0.8

1

0 0

Figure 1.5. The linear, cubic not-a-knot, clamped cubic, and cubic Hermite spline interpolants of the data of Example 1.14.

1.6.1 Shape-preserving cubic Hermite splines Suppose we are given points t1 < · · · < tm and corresponding data values {z i }m i=1 , and that we want to construct a spline satisfying the interpolation conditions s(ti ) = z i ,

i = 1, . . . , m.

(1.34)

1 Now given additional values {z i }m i=1 , let s be the C cubic Hermite interpolating spline discussed in section 1.5.1. We can regard the slopes si := z i , i = 1, . . ., m, as free parameters that can be adjusted to make s have desirable shape properties. We begin with a result showing what happens if we take zero slopes.

Theorem 1.15. Suppose s is the cubic Hermite spline interpolating given values {z i }m i=1 and zero derivatives at points a = t1 < · · · < tm = b. Then for every 1 ≤ i < m, s is monotone on [ti , ti+1 ], and it is nonnegative on [ti , ti+1 ] if z i , z i+1 ≥ 0. Proof. The monotonicity follows from the fact that s  (x) reduces to a quadratic polynomial that vanishes at both ti and ti+1 , and so has only one sign on [ti , ti+1 ]. The nonnegativity assertion follows. This is a useful result, but as we have already seen in Example 1.14, the use of zero derivatives results in flat spots at all of the sample points. Thus, it is not a very satisfactory

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

18

Chapter 1. Univariate Splines

approach to creating a shape-preserving cubic Hermite spline. Clearly, we need a way to choose better slope values. We want an automatic procedure that computes the values {si }m i=1 directly from the data. We now describe an approach suggested by [But80]. Let δi :=

z i+1 − z i , ti+1 − ti

i = 1, . . . , m − 1.

Algorithm 1.16. For i = 2, . . . , m − 1, set  0, si = 2δi−1 δi and let

(1.35)

if δi−1 δi ≤ 0, δi−1 +δi , otherwise,

(1.36)

s1 := min{0, 2δ1 − s2 }, sm := min{0, 2δm−1 − sm−1 }.

(1.37)

The following function can be used to interpolate values z at given points t using a cubic spline with slopes computed by this algorithm: [y,c] = cubshape(t,z) The function outputs the extended knot vector y and the coefficient vector c. Example 1.17. Interpolate the data in Example 1.14 using the cubic Hermite spline with slopes generated by (1.36) and (1.37). Discussion: We use the script Ucubshape which calls on cubshape. Figure 1.6 shows a plot of the resulting cubic Hermite spline. It clearly has the desired shape properties. Despite the good behavior in this example, the use of the Butland formulae (1.36) and (1.37) is not sufficient to guarantee that a cubic Hermite spline interpolant of monotone increasing data will be monotone. However, it is possible to derive necessary and sufficient conditions on the si which do ensure monotonicity, and using them, one can adjust the slopes given by (1.36) and (1.37) to get a monotone spline; see [FriC80]. We do not give the details here, since in the next section we discuss an alternative method based on C 1 quadratic splines which has even stronger shape preserving properties. 1 0.8 0.6 0.4 0.2 0 0

0.2

0.4

0.6

0.8

1

Figure 1.6. The cubic Hermite spline interpolant of the data in Example 1.14 with derivatives computed by (1.36) and (1.37).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.6. Interpolation with shape control

19

1.6.2 Shape-preserving C 1 quadratic splines In this section we explore the use of quadratic Hermite splines to interpolate given values {z i }m i=1 at sample points t1 < · · · < tm while preserving the shape of the data as much as possible. Let  be the partition in (1.33). Then as shown in section 1.5.2, for any slopes 1 {z i }m i=1 , there is a unique spline s ∈ S2 () satisfying (1.30). As in the previous section, we can compute reasonable values for the slopes si := z i , i = 1, . . . , m, directly from the data by the formulae (1.36) and (1.37). Unfortunately, just as in the previous section, this is not enough to guarantee that s preserves the shape. We could try to adjust these slopes further, but instead of doing that, we show that by choosing the locations of the inserted knots ξ1 , . . . , ξm−1 in (1.33) judiciously, we can get very strong shape properties. For each i = 1, . . . , m − 1, let δi be as in (1.35). Definition 1.18. We say that the data {z i , z i+1 , si , si+1 } for the interval Ii = [ti , ti+1 ] are monotone-consistent or M-consistent, provided that one of the following holds:

1) si = si+1 = δi = 0, 2) δi < 0 and si , si+1 ≤ 0, 3) δi > 0 and si , si+1 ≥ 0. It is easy to see that if for some interval Ii the data are not M-consistent, then the spline s cannot be monotone on that interval. We want to construct a spline s which is monotone on all intervals Ii where M-consistency holds. Concerning convexity and concavity, we make the following definition. Definition 1.19. We say that the data {z i , z i+1 , si , si+1 } for the interval Ii = [ti , ti+1 ] are convexity-consistent or C-consistent, provided that one of the following holds:

1) si = si+1 = δi , 2) (si+1 − δi )(si − δi ) < 0. If si+1 − δi and si − δi have the same sign and at least one of them is nonzero, i.e., if the data are not C-consistent for the interval Ii , then clearly the interpolating C 1 quadratic spline s must have an inflection point in [ti , ti+1 ], and thus cannot be convex or concave on that interval. In addition to the above monotonicity properties, we want to construct a spline which is convex or concave on intervals where the data are C-consistent. We now describe how to choose the extra knots {ξi }m−1 i=1 to ensure both co-monotonicity and co-convexity. For each i = 1, . . . , m − 1, set Ji = (ti , ti+1 ) and tˆi := ti + (ti+1 − ti )(2δi − si+1 )/(si − si+1 ), t¯i := ti + 2(ti+1 − ti )(si+1 − δi )/(si+1 − si ), t˜i := ti+1 + 2(ti+1 − ti )(si − δi )/(si+1 − si ). Let IiM

⎧ (ti , tˆi ] ∩ Ji , ⎪ ⎪ ⎪ ⎪ ⎨[tˆi , ti+1 ) ∩ Ji , = ⎪[tˆi , ti+1 ) ∩ Ji , ⎪ ⎪ ⎪ ⎩ (ti , tˆi ] ∩ Ji ,

if δi , si , si+1 ≥ 0 and si > si+1 , if δi , si , si+1 ≥ 0 and si < si+1 , if δi , si , si+1 ≤ 0 and si > si+1 , if δi , si , si+1 ≤ 0 and si < si+1 ,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

20

Chapter 1. Univariate Splines

and let

⎧ ⎪ (t , t¯ ] ∩ Ji , if (si+1 − δi )(si − δi ) < 0 and |si+1 − δi | < |si − δi |, ⎪ ⎨ i i C Ii = [t˜i , ti+1 ) ∩ Ji , if (si+1 − δi )(si − δi ) < 0 and |si+1 − δi | > |si − δi |, ⎪ ⎪ ⎩I M , otherwise. i

(1.38)

We can now give conditions on the location of the new knots that guarantee our desired shape properties; see [Schum83, DevY86, SchumS94]. Theorem 1.20. Suppose that for i = 1, . . . , m − 1 we select ξi ∈ IiC , and suppose {si }m i=1 are computed from formulae (1.36) and (1.37). Then the spline s ∈ S21 () interpolating the data as in (1.30) is co-monotone and co-convex in the following sense: 1) if the data are M-consistent on Ii , then s is monotone on Ii ; 2) if δ j < δ j +1 < · · · < δk and the data are C-consistent on I j , . . . , Ik−1 , then s is convex on [t j , tk ]; 3) if δ j > δ j +1 > · · · > δk and the data are C-consistent on I j , . . . , Ik−1 , then s is concave on [t j , tk ]. The above considerations lead to the following algorithm for constructing a shapepreserving C 1 quadratic spline satisfying (1.34). Algorithm 1.21. Fix t1 < · · · < tm and {z i }m i=1 : 1) For each i = 1, . . ., m, choose {si }m i=1 from the formulae (1.36) and (1.37). 2) For each i = 1, . . . , m − 1, choose ξi to be the midpoint of the interval IiC defined in (1.38). 3) Let s be the corresponding spline in S21 () satisfying (1.30). We have implemented this algorithm in [y,c] = quadshape(t,z) Example 1.22. Interpolate the data in Example 1.14 using the C 1 quadratic shape-preserving spline. Discussion: We make use of the script Uquadshape which calls quadshape. Figure 1.7 shows a plot of the interpolating spline. It clearly has the desired shape properties. For this example, the algorithm produced 0, 0, 0, 0, 3.75, 1.0909,0 for the slopes, and the extra knots ξi were taken to be the midpoints of the intervals (ti , ti+1 ) for i = 1, . . ., 6.

1.7 Quasi-interpolation In this section we discuss a method for constructing splines directly from samples of a function without solving any systems of equations for their coefficients. Suppose Sdr () is a space of splines defined on some partition  of an interval [a, b], and suppose {Ni }ni=1 are the B-splines forming a basis of Sdr (). For each i = 1, . . ., n, let λi be a linear functional defined on C[a, b] that can be computed from samples of f at some set of points σ (λi ) in [a, b].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.7. Quasi-interpolation

21 1 0.8 0.6 0.4 0.2 0 0

0.2

0.4

0.6

0.8

1

Figure 1.7. The C 1 quadratic shape-preserving spline interpolant of the data in Example 1.14; see Example 1.22.

Definition 1.23. A formula of the form n  (λi f )Ni (x) Q f (x) :=

(1.39)

i=1

is called a quasi-interpolation formula. By construction, a quasi-interpolation formula as in (1.39) defines a linear operator mapping C[a, b] into Sdr (). Quasi-interpolants have been heavily studied in the literature, both for practical data fitting purposes and as theoretical tools. If we want a quasiinterpolant to produce good approximations, we need to make sure it reproduces polynomials, i.e., Qp = p for all p ∈ Pd1 . As a means to finding λi satisfying this requirement, we recall an important property of B-splines called Marsden’s identity; see, e.g., Theorem 4.21 n+d+1 in [[Schum81]]. Let {yi }i=1 be the extended partition associated with a space of splines d of degree d, and let {Ni }ni=1 be the corresponding B-splines. Let φi (y) := l=1 (y − yi+l ) for i = 1, . . ., n. Lemma 1.24. Fix 1 ≤ j ≤ d + 1. Then x j −1 =

n 

j

ci Ni (x),

(1.40)

i=1

where ci := (−1) j −1 j

( j − 1)! d+1− j D φi (0), d!

i = 1, . . . , n.

(1.41)

This result is an extension of the partition of unity property of B-splines described in (1.9). Indeed, if we take j = 1, the formula (1.41) gives ci1 = 1 for all i = 1, . . . , n. Using this lemma, it is possible to construct a variety of quasi-interpolants with good approximation properties; see [LycS75]. Here we give one example based on cubic splines. Suppose a = t1 < · · · < tm = b are equally spaced points in the interval [a, b]. Let 2  = {ti }m i=1 . Then the cubic spline space S3 () has dimension n := m + 2. We now construct a quasi-interpolant that requires only samples of f at the points t1 , . . . , tm .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

22

Chapter 1. Univariate Splines

Theorem 1.25. Given a function f defined on [a, b], let ⎧ f (t1 ), ⎪ ⎪ ⎪ ⎪ ⎪ ⎪ [7 f (t1 ) + 18 f (t2 ) − 9 f (t3 ) + 2 f (t4 )]/18, ⎪ ⎨ λi f := [− f (ti−2 ) + 8 f (ti−1 ) − f (ti )]/6, ⎪ ⎪ ⎪ ⎪ [7 f (tm ) + 18 f (tm−1 ) − 9 f (tm−2 ) + 2 f (tm−3 )]/18, ⎪ ⎪ ⎪ ⎩ f (tm ),

i = 1, i = 2, 3 ≤ i ≤ n − 2, i = n − 1, i = n.

Then (1.39) defines a linear operator mapping C[a, b] into S32 () with Qp = p for all cubic polynomials p. Proof. Fix j = 1, . . ., 4. Then for all i = 1, . . ., n, simple algebra shows that λi x j −1 = ci , j where ci are the coefficients in (1.40). It follows that Qp = p for every p ∈ P31 . j

We have implemented this cubic spline quasi-interpolant in the function [y,c] = cubquasi(a,b,z) Here the input is a vector z of data values z 1 , . . . , z m at m equally spaced sample points in [a, b]. The output of this function is the extended knot vector y and the vector c of B-coefficients of the cubic spline. Example 1.26. Approximate the function (1.20) using cubic quasi-interpolation with m = 5, 9, 17, 33, 65 points. Discussion: We make use of the script Ucubquasi, which is essentially the same as the script Unotaknot of section 1.4.3, but with the call on notaknot replaced by a call on cubquasi. The test function here is the same as in Examples 1.9, 1.10, and 1.13. For comparison, we give the analogous error table. m 5 9 17 33 65

emax 2.14(0) 2.38(−1) 3.57(−2) 2.28(−3) 1.11(−4)

rms 9.36(−1) 1.02(−1) 1.06(−2) 7.20(−4) 4.53(−5)

ratios 9.00 9.18 6.67 9.62 15.66 14.72 20.54 15.89

As the table shows, the errors for the cubic quasi-interpolating spline are not quite as good as those for the not-a-knot interpolating spline, but the rate of convergence is still O(||4 ); see Theorem 1.59 below.

1.8 Discrete least-squares approximation There are two data fitting situations where interpolation is usually not advisable: 1) when there are a large number of data points, 2) when the measurements are subject to noise. In this section we discuss an alternative to interpolation which is generally more suitable in such situations. Suppose we are given z 1 , . . . , z nd , which we may consider to be samples

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.8. Discrete least-squares approximation

23

of a function f at points t1 < · · · < tnd in an interval [a, b]. Our aim is to approximate f k+1 by a spline in the space Sdr (), where  = {x i }i=0 is some partition of [a, b]. Let n be the r dimension of Sd (). We suppose n d ≥ n. In practice n d is often much larger than n. We now formulate the discrete least-squares problem. Problem 1.27. Find s ∈ Sdr () that minimizes

2 (s) :=

nd  [s(tl ) − z l ]2 .

(1.42)

l=1

To find a solution of this problem, suppose we write s in B-form as s=

n 

ci Ni ,

(1.43)

i=1

where {Ni }ni=1 are the B-splines of degree d forming a basis for the spline space Sdr (). Theorem 1.28. Suppose there exist integers 1 ≤ ν1 < ν2 < · · · < νn ≤ n d such that Ni (tνi ) > 0

for i = 1, . . . , n.

(1.44)

Sdr ()

Then there is a unique spline s ∈ solving Problem 1.27, and its coefficients are the solution of the nonsingular linear system Gc = g, where G i j :=

nd 

i , j = 1 . . . , n,

Ni (tl )N j (tl ),

(1.45)

l=1

and gi :=

nd 

i = 1, . . ., n.

z l Ni (tl ),

l=1

Proof. Let



N1 (t1 ) ⎢ .. A=⎣ .

··· .. .

N1 (tnd ) · · ·

⎤ Nn (t1 ) .. ⎥ . . ⎦ Nn (tnd )

The matrix A is called the observation matrix, and G is called the Gram matrix. It is easy to check that G = A T A, and so G is symmetric. Moreover, for any vector c, we have c T Gc = ( Ac)T Ac =

nd 

s(tl )2 ≥ 0,

(1.46)

l=1

where s is the spline s in (1.43) with coefficient vector c. This shows that G is a nonnegative definite matrix. We now show that it is in fact positive definite. Suppose c is such that c T Gc = c T A T Ac = ( Ac)T Ac = 0. ˜ = 0, where A˜ is the n × n submatrix of A consisting This implies Ac = 0. But then Ac of the rows with indices ν1 , . . . , νn . Now taking account of the condition (1.44), by the Schoenberg–Whitney theorem (Theorem 1.8), we know that A˜ is nonsingular, which im-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

24

Chapter 1. Univariate Splines

plies c = 0. We have shown that G is positive definite. This also shows that Gc = 0 can happen only if c = 0, and we conclude that G is nonsingular. We now know that the system Gc = g has a unique solution c. It remains to show that the corresponding spline minimizes 2 (s). Substituting (1.43) in 2 (s), we get a quadratic function of the n variables c1 , . . . , cn which can be written in the form φ(c) := c T Gc − 2c T g + z T z. Now let δ be a vector with n components. Then φ(c + δ) = (c + δ)T G(c + δ) − 2(c + δ)T g + z T z = φ(c) + 2δ T Gc + δ T Gδ − 2δ T g = φ(c) + δ T Gδ. But by (1.46), δ T Gδ ≥ 0, and so φ(c + δ) ≥ φ(c). By the positive definiteness of the Gram matrix G, δ T Gδ > 0 unless δ = 0, which shows the uniqueness. To implement the least-squares method, we simply have to compute the matrix G and the vector g, and then solve Gc = g. Setting up G and g can be done with the help of the function bspl described in section 1.3.6, which for a given ti gives the values of all of the B-splines with nonzero values at ti . SplinePak includes the following function for constructing a least-squares fit using an n-dimensional spline space associated with a general extended knot sequence y: c = lsqspl(d,n,y,t,z) Note that we do not require that the interior knots in y be distinct, so this function can work with spline spaces of degree d with very general smoothness properties. If the interior knots are distinct, we have the space Sdd−1 (). Here is the script for testing lsqspl for arbitrary d and k. It is based on equally spaced knots in the interval [t1 , tnd ], and makes use of the test function f given in (1.20). The script computes the maximum and RMS errors on a set of 201 equally spaced points in [−1, 1], and also produces a plot of the least-squares spline. % Ulsq a = -1; b = 1; f = @(x) exp(x).*sin(2*pi*x); d = input(’input d ’); k = input(’input k ’); n = k+d+1; y(1:d) = a*ones(1,d); y(n+2:n+d+1) = b*ones(1,d); y(d+1:n+1) = linspace(a,b,k+2); nd = input(’input nd ’); t = linspace(0,1,nd); z = f(t); % Compute coefficients of lsq spline c = lsqspl(d,n,y,nd,t,z) % Compute error and plot ng = 201; xg = linspace(y(1),y(n+1),ng); fg = f(xg); zg = sval2(d,y,c,xg); e = fg - zg; fprintf(’maxerr = %g, rms = %g\n’,norm(e,inf),erms(e)); figure; plot(xg,zg); hold; plot(xg,fg,’r’);

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.9. The effect of noise

25

Example 1.29. Fit the test function (1.20) with cubic least-squares splines on the interval [−1, 1]. Use nd = 201 equally spaced sample points in [−1, 1] and k = 3, 7, 15, 31, 63 equally spaced interior knots. Discussion: We make use of the script Ulsq. Here are the resulting errors and error ratios: k 3 7 15 31 63

emax 6.24(−1) 2.51(−2) 1.47(−3) 8.25(−5) 4.58(−6)

rms 2.25(−1) 9.83(−3) 4.40(−4) 2.40(−5) 1.45(−6)

ratios 24.87 22.90 17.08 22.34 17.82 18.33 18.01 16.55

Since we are using cubic splines, it is reasonable to expect fourth order convergence, which is approximately what we see here. However, in general, to get full approximation power with least-squares fitting we need to impose some conditions on the density of the sample points; see Theorem 1.60 below. It is worthwhile noting that under appropriate conditions, the least-squares spline fit reduces to a spline s that interpolates the data. We have the following result. Theorem 1.30. Let s be the solution of Problem 1.27 using a spline space whose dimension d are such that condition (1.44) holds. n is equal to the number of data n d . Suppose {ti }ni=1 Then s interpolates the data, i.e., s(ti ) = z i for i = 1, . . . , nd. Proof. Under these conditions, the observation matrix A in the proof of Theorem 1.28 is nonsingular. Thus, the two linear systems Ac = z and A T Ac = A T z are equivalent, and so the least-squares solution is the same as the interpolant. For this spline

2 (s) = 0.

1.9 The effect of noise In practical data fitting situations, the measurements are almost always contaminated by noise. This can have a drastic effect on the performance of any spline interpolation method. Noise also has an effect on least-squares spline fits, although if the number of data points is sufficiently large compared to the dimension of the spline space, some of the effects of noise can be removed. The best way to see how noise affects our methods is to look at an example. Example 1.31. Consider fitting the test function f (x) = (x − .5)2 based on noisy measurements at nd = 51 equally spaced points in the interval [0, 1], where the noise is uniformly distributed in the interval [−ε, ε] with ε = .1. Compare cubic not-a-knot interpolation with the cubic least-squares spline with k = 15 equally spaced interior knots. Discussion: We use script Unotaknotnoise which is the same as script Unotaknot except that we now use the function f given here and modify the sample values to include a noise term. In order to get the same noise values each time we run this program, we use the function readnoise to read the noise values from the file noise.dat which contains one million numbers chosen randomly to be uniformly distributed in the interval [−1, 1].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

26

Chapter 1. Univariate Splines 0.35 0.3

0.15

0.1

−0.1 0

0.5

−0.05 0

1

0.5

1

Figure 1.8. Fits to the test function (x − .5)2 based on noisy measurements with random errors at 51 equally spaced points in [0, 1]. The cubic not-a-knot interpolant is shown on the left, while the cubic least-squares spline with 15 interior knots is shown on the right.

The program multiplies these by ε before adding them to the samples of the function. In Figure 1.8 (left) we show the not-a-knot interpolant, while in Figure 1.8 (right) we show the least-squares fit. Both fits show the serious effects of the noise.

1.10 Penalized least-squares approximation In the previous section we saw that noise can affect the quality of least-squares fits by splines. In this section we discuss a useful method for dealing with this problem. As in section 1.9, suppose we are given data z 1 , . . . , z nd , which we may consider to be samples of a function f at points t1 < · · · < tnd in an interval [a, b]. As before, our aim is to approximate f by a spline in an n-dimensional spline space Sdr () with n ≤ n d and r ≥ 2, k+1 where  = {x i }i=0 is some partition of [a, b]. Given s ∈ Sdr (), we define its energy to be the quantity  b [s  (t)]2 dt. (1.47) E(s) := a

We now pose the following problem. Problem 1.32. Fix λ ≥ 0. Find s ∈ Sdr () that minimizes

λ (s) :=

nd 1  [s(tl ) − z l ]2 + λ E(s). nd

(1.48)

l=1

We call the solution of this problem a penalized least-squares spline. This problem differs from the discrete least-squares problem of section 1.8 inasmuch as we have added a penalty term λE(s) to the quadratic form that is being minimized, and have normalized the leastsquares term by dividing by the number of data points. If λ = 0, this problem reduces to the discrete least-squares problem. Generally, we can achieve the desired noise reduction by choosing λ to be quite small; see the experiments below. To find a solution of this problem, suppose we write s in B-form as in (1.43), where {Ni }ni=1 are the B-splines of degree d forming a basis for the spline space Sdr (). Theorem 1.33. Suppose n d ≥ 3 and d > r ≥ 2. Then for any λ > 0, there is a unique spline s ∈ Sdr () solving Problem 1.32. Moreover, its coefficients are the solution of the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.10. Penalized least-squares approximation

27

nonsingular linear system (G + n d λE)c = g, where G and g are as in Theorem 1.28, and  b E i j := Ni (t) N j (t) dt, i , j = 1 . . . , n. (1.49) a

Proof. Clearly, the matrix H := G + n d λE is symmetric. Combining (1.46) and the fact that c T Ec = E(s) ≥ 0, we see that H is nonnegative definite. We claim that H is in fact positive definite. Suppose that c is a vector such that c T H c = c T Gc + n d λc T Ec = 0. But then E(s) = 0, where s is the spline with coefficient vector c, and so s  must vanish at all points in [a, b], i.e., s must be a linear polynomial. On the other hand, by (1.46), c T Gc = 0 implies s(ti ) = 0 for i = 1, . . . , n d . Combining these facts shows that s ≡ 0, and so c = 0. We have shown that H is positive definite and thus also nonsingular. We now know that H c = g has a unique solution c. It remains to show that the corresponding spline s minimizes λ . Inserting (1.43), we see that λ (s) reduces to a quadratic function of the n variables c1 , . . . , cn , which can be written in the form

λ (c) := c T H c − 2c T g + z T z. Now for any δ ∈ Rn ,

λ (c + δ) = (c + δ)T H (c + δ) − 2(c + δ)T g + z T z = λ (c) + 2δ T H c + δ T H δ − 2δ T g = λ (c) + δ T H δ. But δ T H δ ≥ 0, and so λ (c + δ) ≥ φλ (c). By the positive definiteness of H , δ T H δ > 0 unless δ = 0, and the uniqueness assertion follows.

SplinePak includes the following function for constructing a penalized least-squares fit using an n-dimensional space Sdd−1 () associated with an extended knot sequence y: c = penlsq(d,n,y,t,z,lam) Example 1.34. Fit the test function f (x) = (x −.5)2 based on noisy measurements at nd = 51 equally spaced points in the interval [0, 1], where the noise is uniformly distributed in the interval [−ε, ε] with ε = .1. Using a penalized least-squares cubic spline with k = 9 equally spaced interior knots, explore the behavior as λ is varied. Discussion: We make use of the script Upenlsq. Here are the max and RMS errors computed on 51 equally spaced points for some selected values of λ: λ 0 .00001 .0001 .0005 .0008 .001 .01

emax 1.13(−1) 6.36(−2) 3.24(−2) 1.64(−2) 1.58(−2) 1.55(−2) 7.46(−1)

rms 1.89(−2) 1.50(−2) 1.06(−2) 8.71(−3) 8.51(−3) 8.62(−3) 3.47(−2)

The table shows that the errors do not vary too much for λ in the range [0, .001], but as λ becomes larger, the error becomes much worse. It also shows that adding a small penalty

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

28

Chapter 1. Univariate Splines

0.3

0.3

0.15

0.15

-0.05 0

0.5

1

0.25

-0.05 0

0.5

1

0.5

1

0.105

0.2

0 0

0.5

1

0.075 0

Figure 1.9. Penalized least-squares fits to the test function f in Example 1.34 with a cubic spline with nine knots for λ = 0, .00001, .0008, and 1.

improves the error as compared to the least-squares fit, which corresponds to λ = 0. Figure 1.9 shows the relationship between the values of λ and the shape of the spline. The plot in the upper left-hand corner shows the least-squares fit corresponding to λ = 0. It shows significant shape distortions due to the noise. The second plot corresponds to λ = .00001 and still exhibits some shape distortion. The third plot is for λ = .0008 and provides a very good fit as well as a small error. The last plot shows that for larger values of λ, the fit can be very bad. Indeed, the penalty term tries to force the penalized least-squares fit sλ to be a linear polynomial. In this example, sλ approaches the zero function as λ → ∞. To further explore the effect of λ on the error of the fit, we computed the penalized least-squares fit for a set of equally spaced values 0 = λ1 < · · · < λ31 = .002. For each λi , we computed the corresponding RMS error ei . We then interpolated the values {(λi , ei )}101 i=1 using a cubic not-a-knot spline; see the script Upenlsqg. It produced the plot shown in Figure 1.10. This curve has a minimum very near .0008. In this example we used a known test function. If we do not know f , we cannot create an error plot like the one in Figure 1.10, and there is no a priori way to decide what is a good value of λ. In general, it will depend on a number of things, including the shape of the function, the amount of data, and the size of the noise. One way to choose λ when errors cannot be computed is by trial and error, using the plot of the spline as a guide. If goodness of fit is an issue, there are more sophisticated ways of estimating an optimal smoothing parameter λ. One of these is generalized cross validation; see Remark 1.18.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.11. Choosing optimal knots for least-squares splines

29

0.02

0.014

0.008 0

0.5

1

1.5

2 ×10 -3

Figure 1.10. Plot of the RMS error in Example 1.34 as a function of λ.

1.11 Choosing optimal knots for least-squares splines In some applications we have a lot of measurements on a relatively simple function f . In this case we should be able to fit f with a least-squares spline with a relatively small number of knots. In this section we examine the question of how to choose the knot locations to give the best results. We present two approaches — one based on solving an appropriate optimization problem, and the other based on knot removal.

1.11.1 An optimization problem Suppose we are given data z 1 , . . . , z nd at points t1 < · · · < tnd in an interval [a, b], and we want to construct a least-squares fit using a space of splines of degree d with k interior knots x 1 , . . . , x k . Let x = (x 1, . . . , x k ). Problem 1.35. Find x ∗ to minimize (x) :=

nd 

[sx (ti ) − z i ]2 ,

i=1

where sx is the least-squares spline of degree d with interior knot vector x. This is a nonlinear optimization problem which can be solved using standard numerical software such as fmincon in MATLAB. To use fmincon, one needs to define a separate function that solves the least-squares problem with interior knots x, and outputs the value of the least-squares error (x). In addition, we have to provide an initial guess for the optimal x ∗ and constraints on x of the form Ax ≤ b. Here the natural constraints are −x 1 ≤ −a, x 1 − x 2 ≤ −ε, .. . x k−1 − x k ≤ −ε, x k ≤ b, where ε controls the separation between the knots. If we choose a positive ε, we will

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

30

Chapter 1. Univariate Splines 1

1

0.5

0.5

0 0

0.25

0.5

0.75

0 0

1

0.25

0.5

0.75

1

Figure 1.11. Plots of the cubic least-squares spline fits for Example 1.36 with five equally spaced points, and with the five knots computed by lsqopt with ε = .000001.

get distinct knots, and our spline will be in Sdd−1 (). Choosing ε = 0 allows multiple knots, which of course may produce a spline with reduced smoothness. We have coded this algorithm as the function x = lsqopt(d,k,t,z,xo,eps) Here xo is the initial guess for the optimal vector x ∗ . Example 1.36. Find the optimal knot locations for the least-squares cubic spline with five interior knots fitting the test function  1 − 2x, 0 ≤ x ≤ .5, f := (1.50) x − .5, .5 < x ≤ 1, at 51 equally spaced points in [0, 1]. Discussion: We make use of the script Ulsqopt, which takes xo to be the set of equally spaced points in the interval [a, b]. For comparison purposes, we first compute a leastsquares fit using the equally spaced knots .166, .333, .5, .666,.833. In this case the maximum and RMS errors are 3.08(−2) and 7.72(−3), respectively. The fit is shown in Figure 1.11 (left). Next, we ran Ulsqopt with ε = .000001. It found the optimal five interior knots to be 0.19397548, 0.49999906, 0.50000006,0.500001063,0.80602453, rounded to eight digits. The errors in this case are 2.60(−7) and 4.74(−8), respectively.

1.11.2 Knot removal In this section we present an alternative algorithm for selecting good knots for performing least-squares fitting with splines. The idea of the algorithm is perform a fit with a large number k0 of interior knots, and then remove them one by one, where at each step we remove the knot which gives the least increase in error. We stop when we have the desired number k of interior knots. Given any vector x of interior knots, let

(x) :=

nd  [sx (ti ) − z i ]2 , i=1

where sx is the least-squares spline of degree d with interior knot vector x.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.11. Choosing optimal knots for least-squares splines

31

Algorithm 1.37. 1) Pick an initial knot vector x (0) ∈ Rk0 . 2) For i = 1, . . . , k0 − k a) For j = 1, . . . , k0 − i + 1, compute the value of e j := (x˜ ( j )), where x˜ ( j ) is the (i−1) knot vector x (i−1) with x j removed. −i+1 . b) Pick ji such that e ji = min{e j }kj 0=1

c) Set x (i) = x˜ ( ji ) . This algorithm is an example of a knot removal algorithm. It requires solving (k0 − k + 1)(k0 − k)/2 least-squares problems, where at each step the number of coefficients being computed is reduced by one. This method has two disadvantages as compared with the optimization method of the previous section. First, by construction the final knot vector is a subset of the initial knot vector. This is a restriction which means we will get only an approximation to the optimal knot sequence. In particular, it is impossible to get multiple knots unless they were already present in the initial vector. Second, if k0 is large compared to k, the algorithm can be somewhat slow. We have implemented this algorithm in SplinePak as the following function: [c,y] = knotrem(d,k,k0,y0,t,z) Note that our implementation works with the extended knot sequences rather than just the interior knots, but of course knots at the ends of the interval are never removed. Before calling this function, we need to construct an initial extended knot vector y (0) . In our script Uknotrem we choose k0 equally spaced interior knots in [a, b], and let y (0) be the corresponding extended knot vector. Example 1.38. Fit a least-squares cubic spline with five interior knots to the test function (1.50) based on measurements at 201 equally spaced points in [0, 1]. Find good knots with knot removal. Discussion: We make use of Uknotrem. To see what effect the choice of k0 has on the performance of the algorithm, we run the experiment for several values of k0 . The following table gives the maximum and RMS errors between the resulting five-knot spline fits and the true function, measured at 201 equally spaced points in [0, 1]. For comparison, we also give run times in seconds. k0 31 41 51 61

emax 6.21(−2) 6.32(−3) 5.03(−3) 3.20(−2)

rms 3.06(−3) 5.94(−4) 4.57(−4) 1.53(−2)

time 7.5 13.1 20.6 29.4

The best results were obtained for k0 = 51, where the final set of knots is .461538, .480769, .500000, .519231, .538462. We do not present a plot of this spline fit as the plot is visually identical to Figure 1.11.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

32

Chapter 1. Univariate Splines

The table shows that the errors are sensitive to the number k0 of initial knots. It is not good to use too few starting knots, as this limits the positions of the final five knots. On the other hand, too many starting knots can also lead to poor results, as well as large computing times. In fact, if k0 is too large compared to n d , then the conditions of Theorem 1.28 will no longer be satisfied, and we cannot even compute the initial fit.

1.12 Two-point boundary-value problems In this section we discuss how splines can be used in conjunction with the Ritz–Galerkin method to solve two-point boundary-value problems. We first develop an algorithm for the case of homogeneous boundary-conditions. Later we shall see how it can be adapted to solve the problem with arbitrary boundary values. Problem 1.39. Let p, q, and f be given functions defined on [a, b]. Find u satisfying the differential equation Lu(t) := −D[ p(t)Du(t)] + q(t)u(t) = f (t),

all t ∈ (a, b),

(1.51)

along with the boundary conditions u(a) = 0,

u(b) = 0.

(1.52)

We refer to the classical ODE literature for conditions under which this problem has a unique solution. Here we are thinking of p as being in C 1 [a, b], and assume that it never vanishes on [a, b]. To find an approximate solution to this boundary-value problem, we pick a partition  = {a = x 0 < x 1 < · · · < x k+1 = b} of the interval [a, b] and integers 0 ≤ r < d. Let Sdr () be the associated space of splines defined on [a, b], and let {N j }nj=1 be the corresponding basis of B-splines. We look for an approximate solution of Problem 1.39 in the form n  s= cj Nj . (1.53) j =1

Due to the properties of the B-splines, s will satisfy the homogeneous boundary conditions if and only if c1 = cn = 0. We note that the splines N2 , . . . , Nn−1 form a basis for the n 0 := (n − 2)-dimensional linear space U0 := {s ∈ Sdr () : s(a) = s(b) = 0}. We now need an algorithm for computing the coefficients c2 , . . . , cn−1 to make s be a good approximation of the solution u of Problem 1.39. We would like s to satisfy (1.51), but of course this will not generally be possible. The key idea is to make (1.51) be satisfied in a weaker form. Definition 1.40. A spline s ∈ U0 is called the Ritz–Galerkin approximation to the solution u of Problem 1.39, provided that  b [Ls(t) − f (t)] Ni+1 (t) dt = 0, i = 1, . . ., n 0 . (1.54) a

We now show that the coefficients of the Ritz–Galerkin spline can be computed by solving a linear system of equations. For any two functions φ and ψ that are differentiable

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.12. Two-point boundary-value problems

33

on every subinterval Iν := (x ν , x ν+1 ) of the partition of [a, b], let φ, ψ :=

k  φ, ψ Iν ,

(1.55)

ν=0



where φ, ψ Iν :=

[ p(t)φ  (t)ψ  (t) + q(t)φ(t)ψ(t)] dt.

(1.56)



Theorem 1.41. The spline (1.53) is the Ritz–Galerkin approximation to the solution u of Problem 1.39 if and only if the coefficient vector c is given by c = (0, c, ˜ 0), where c˜ is the solution of the linear system M c˜ = r , (1.57) with Mi j = Ni+1 , N j +1 , and



i , j = 1, . . ., n 0 ,

b

ri =  f , Ni+1 2 :=

f (t) Ni+1 (t) dt,

i = 1, . . . , n 0 .

(1.58) (1.59)

a

Proof. Substituting (1.53) in (1.54) and using integration by parts, we see that (1.54) is equivalent to the system M c˜ = r . The matrix M in (1.57) is usually called the stiffness matrix. We need to verify that it is nonsingular. For this we need some conditions on the p and q. First, we need to assume some smoothness for p and q. To this end, we introduce some standard function spaces used in approximation theory. Let L 2 [a, b] be the space of all integrable functions f such that   b

 f 2 :=

1/2

| f (t)| dt 2

< ∞.

(1.60)

a

We also need the subspace L 12 [a, b] of all functions f ∈ L 2 [a, b] whose first derivatives lie in L 2 [a, b]. Theorem 1.42. Suppose p ∈ L 12 [a, b] and q ∈ L 2 [a, b]. Suppose in addition that for some γ > 0,  b  b  2 γ [u (t)] dt ≤ u, u = [ p(t)(u (t))2 + q(t)(u(t))2] dt (1.61) a

a

for all u ∈ U0 . Then the matrix M in (1.57) is symmetric and positive definite. Proof. Equation (1.58) shows that M is symmetric. Now given c˜ = 0 in Rn0 , let s be the associated spline defined in (1.53) with c = (0, c, ˜ 0). Then by (1.61),  b c˜T M c˜ = [ p(x)(s (x))2 + q(x)(s(x))2] d x ≥ γ s  22 ≥ π 2 γ s22 > 0, a

where for the next-to-last inequality, we have used the classical Ritz inequality. We conclude that M is positive definite and thus also nonsingular.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

34

Chapter 1. Univariate Splines

1.12.1 Gaussian quadrature To compute the Ritz–Galerkin spline approximating the solution u of Problem 1.39, we have to set up the matrix M in (1.58) and right-hand side vector r in (1.59) and then solve the system M c˜ = r . However, the entries in M and r involve integrals whose integrands include not only the B-splines and their derivatives but also the functions p and q. In general, we cannot find these integrals in closed form, and so we have to resort to numerical quadrature formulae. These integrals can be written as sums of integrals over the subintervals Iν := [x ν , x ν+1 ] defined by the partition  of [a, b]. The following theorem provides a tool for approximating the integral of a given function g over an interval I := [α, β]. Theorem 1.43. Fix m. Then there exist points α < t1 < · · · < tm < β and positive weights {wν }m ν=1 such that the quadrature formula (β − α)  wν g(tν ) 2 m

Ig :=

(1.62)

ν=1

for approximating the integral of g over [α, β] is exact for all polynomials of degree 2m −1, i.e.,  Ip=

β

α

p(t) dt,

1 all p ∈ P2m−1 .

(1.63)

Proof. This is a standard theorem in numerical analysis, and can be found in most text books on the subject; see, e.g., [[KinC02]]. Usually the result is stated for the interval [−1, 1], but it is easily adapted to work on an arbitrary interval [α, β] by a linear change of variables. The factor (β − α)/2 in the formula (1.62) comes from the change of variables. Note that in order to integrate constants correctly, the weights must sum to two. Tables of the sample points and weights for various values of m can be found in the literature. The most convenient way to give the locations of the sample points is to write them as averages of the endpoints α and β of the interval. The following script illustrates the use of a six-point formula. It integrates polynomials up to degree 11 exactly. % Ugauss n = input(’input n ’); g = @(x,n) x.∧ n; a = input(’input a ’); b = input(’input b ’); h = (b-a)/2; r = [0.966234757, 0.830604693, 0.619309593,... 0.380690407, 0.169395307, 0.033765243]; w = [0.171324492, 0.360761573, 0.467913935,... 0.467913935, 0.360761573, 0.171324492]; x = a*r + b*(1-r); quadval = h*sum(w.*g(x,n));

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.12. Two-point boundary-value problems

35

The fact that a quadrature formula is exact for polynomials up to a certain degree suggests that it should do a good job of approximating the integral of an arbitrary continuous function g over the interval I := [α, β], provided that its length h := β − α is small. We write g I for the maximum norm of g over the interval I . Theorem 1.44. Suppose g ∈ C  [α, β] for some 0 ≤  ≤ 2m. Then  β    2h +1 ()  ≤ g  I . g(t) dt − Ig   ! α Proof. Let p be the Taylor expansion of degree  − 1 of g with respect to the point α. Then by the classical remainder formula, |g(t) − p(t)| ≤

h  () g  I !

for all t ∈ I , which implies   β  h +1 ()  ≤  g  I . [g(t) − p(t)] dt   ! α Now using (1.63), we have 

β α

 g(t) dt − Ig =

β α

[g(t) − p(t)] dt + I( p − g).

Since the weights are positive and sum to two, we have |I(g − p)| ≤ hg − p I ≤

h +1 () g  I , !

and the result follows.

1.12.2 The Ritz–Galerkin method with homogeneous boundary conditions By Theorem 1.41, to compute an approximate solution of Problem 1.39 using the spline space Sdd−1 (), we need to assemble the stiffness matrix M in (1.58) and vector r in (1.59), and then solve the system M c˜ = r for the vector c˜ = (c2 , . . . , cn−1 ). Both M and r involve computing integrals over [a, b] which can be computed as sums of integrals over the subintervals [x ν , x ν+1 ] of the partition . Each of these can be computed using Gauss quadrature as explained in the previous section. The needed values of the B-splines and their derivatives at the quadrature points can be computed using our functions bspl and bsplder. Here is our code: [c,y] = bvph(d,k,a,b,p,q,f) The input parameter k controls the number of interior knots in the interval [a,b]. We take them to be equally spaced. The inputs p, q, and f are the functions appearing in

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

36

Chapter 1. Univariate Splines

(1.51). The output is the extended knot vector y and associated vector c of B-coefficients in the expansion (1.53) with c1 = cn = 0. We have written the following script for testing this function. It makes use of the six-point Gauss quadrature formula given in the previous section. % p f u a

Ubvph = @(x) = @(x) = @(x) = 0; b

exp(x); q = @(x) exp(x); (1-x)*exp(x+1) -(3+x)*exp(2*x); x*(exp(x)-exp(1)); = 1;

d = input(’input d ’); k = input(’input k ’); n = k+d+1; [c,y] = bvph(d,k,a,b,p,q,f); % Compute error and plot ng = 101; xg = linspace(a,b,ng); ug = u(xg); zg = sval2(d,y,c,xg); e = ug-zg; fprintf(’maxerr = %g, rms = %g\n’,norm(e,inf),erms(e)); figure; plot(xg,zg);

Example 1.45. Solve the two-point boundary-value problem associated with the differential equation Lu := D[e x Du] + e x u = (1 − x)e x+1 − (3 + x)e2x on [0, 1] with zero boundary conditions at 0 and 1. Discussion: We make use of the script Ubvph with d = 3. It is easy to check that the exact solution of this problem is u(x) := x(e x − e). We use cubic splines with k knots in the interior of [0, 1]. Figure 1.12 shows the numerical solution corresponding to k = 7. The following table shows the maximum and RMS errors for a sequence of partitions where the 0

-0.3

-0.6 0

0.5

1

Figure 1.12. Plot of the cubic spline solution to the two-point boundary-value problem in Example 1.45 with k = 7 interior knots in [0, 1].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.12. Two-point boundary-value problems

37

mesh size is halved at each step: k 3 7 15 31 63

emax rms 4.75(−5) 2.47(−5) 3.80(−6) 1.70(−6) 2.67(−7) 1.11(−7) 1.58(−8) 7.02(−9) 1.03(−9) 4.40(−10)

ratios 12.50 14.53 14.23 15.31 16.90 15.81 15.34 15.95

The rate of convergence is O(||4 ), as is to be expected with cubic splines from the theoretical error bounds given in section 1.13.8. The Ritz–Galerkin method does not require that we use splines with continuous derivatives. In fact, in the engineering literature, finite element methods are usually implemented using only C 0 elements. Example 1.46. Repeat Example 1.45 using C 0 linear splines. Discussion: We again use the script Ubvph but now with d = 1. The following table gives the maximum and RMS errors for a nested sequence of partitions whose mesh size is halved at each step: k 3 7 15 31 63 127 255 511

emax 5.07(−2) 1.42(−2) 3.75(−3) 8.78(−4) 2.23(−4) 5.81(−5) 1.48(−5) 3.66(−6)

rms 2.27(−2) 5.66(−3) 1.41(−3) 3.53(−4) 8.84(−5) 2.21(−5) 5.52(−6) 1.38(−6)

ratios 3.57 4.00 3.79 4.01 4.27 3.99 3.94 3.99 3.84 4.00 3.93 4.00 4.04 4.00

Here the rate of convergence is clearly O(||2), as expected with linear splines. This example shows the advantages of using higher degree splines. We got essentially the same accuracy with cubic splines with only seven knots as we did here with linear splines with 511 knots. In addition, the cubic spline is a C 2 function, whereas the linear spline is only continuous.

1.12.3 The Ritz–Galerkin method with nonhomogeneous boundary conditions In this section we consider the following two-point boundary-value problem with nonhomogeneous boundary conditions. Problem 1.47. Let p, q, and f be given functions defined on [a, b], and suppose α, β are given real numbers. Find u satisfying the differential equation Lu(t) := −D[ p(t)Du(t)] + q(t)u(t) = f (t),

all t ∈ (a, b),

(1.64)

along with the boundary conditions u(a) = α,

u(b) = β.

(1.65)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

38

Chapter 1. Univariate Splines

We now show how to reduce this problem to an equivalent one with homogeneous boundary conditions. Theorem 1.48. Suppose u b is a C 2 function such that u b (a) = α and u b (b) = β. Let u 0 be such that all t ∈ (a, b), Lu 0 (t) = f (t) − Lu b (t), and u 0 (a) = u 0 (b) = 0. Then u = u 0 + u b solves Problem 1.47. Proof. It is clear that u(a) = α and u(b) = β. Moreover, Lu = Lu 0 + Lu b = f − Lu b + Lu b = f . In this theorem u b is an arbitrary (smooth) function satisfying the boundary conditions. Assuming we want to find a numerical solution in a space of splines with B-spline basis {Ni }ni=1 , it is natural to take u b to be a spline in this space. In view of the properties of B-splines, we can take u b = α N1 + β Nn . It is a simple matter to modify the function bvph to solve problems with nonhomogeneous boundary conditions. Note, however, that to compute Lu b , we need to have an explicit definition for the function p . Here is our function based on splines in the space Sdd−1 (). [c,y] = bvp(d,k,a,b,p,pder,q,f,alpha,beta) Here pder is the name of the function which describes the derivative of the function p. The function bvp uses k equally spaced knots in the interior of the interval [a, b]. We have written a special version of this code for the case d = 1 called bvp1. Example 1.49. Use cubic splines to solve the two-point boundary-value problem −D[e x Du(x)] + sin(x 2 )u(x) = (1 + x) sin(x 2 ) − e x − 3πe x (2 + x) cos(3π x) + sin(3π x)[e x (9π 2 x − 1) + x sin(x 2 )] on [0, 1] with boundary conditions u(0) = 1 and u(1) = 2. Discussion: We use the script Ubvp with d = 3. It is easy to check that the exact solution of this problem is u(x) := 1 + x + x sin(3π x). Figure 1.13 shows the numerical solution corresponding to d = 3 and k = 7. The following table shows the maximum and RMS errors for the same sequence of partitions as in Example 1.45. It also gives the condition numbers of the stiffness matrices. k 3 7 15 31 63

emax 8.96(−2) 3.50(−3) 1.91(−4) 9.07(−6) 5.77(−7)

rms 4.67(−2) 1.49(−3) 6.61(−5) 3.68(−6) 2.24(−7)

cond 7.05(0) 2.43(1) 9.37(1) 3.75(2) 1.50(3)

ratios 25.60 31.34 18.32 22.54 21.06 17.96 15.72 16.43

As in Example 1.45, the rate of convergence is O(||4 ), as expected from the theoretical error bounds in section 1.13.8. We note that the condition numbers grow somewhat with increasing k.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.13. Error bounds

39 2.8

1.8

0.8 0

0.5

1

Figure 1.13. Plot of the cubic spline solution to the two-point boundary-value problem in Example 1.49 with k = 7 interior knots in [0, 1].

Example 1.50. Repeat Example 1.49 using C 0 linear splines. Discussion: We now use the script Ubvp with d = 1. In this case we get the following table of maximum and RMS errors for the same sequence of partitions used in Example 1.46. For comparison we also give the condition numbers of the associated stiffness matrices. k 3 7 15 31 63 127 255 511

emax 5.04(−1) 1.15(−1) 3.41(−2) 8.91(−3) 2.21(−3) 5.68(−4) 1.39(−4) 3.36(−5)

rms 2.11(−1) 5.38(−2) 1.37(−2) 3.46(−3) 8.65(−4) 2.16(−4) 5.41(−5) 1.35(−5)

cond 7.77(0) 4.06(1) 1.85(2) 7.88(2) 3.25(3) 1.32(4) 5.33(4) 2.14(5)

ratios 4.38 3.92 3.37 3.93 3.83 3.96 4.03 4.00 3.89 3.99 4.08 3.99 4.14 4.01

The rate of convergence is clearly O(||2 ), as expected for linear splines. As in the homogeneous case, it is clear that there is an advantage in using higher order splines. We got better accuracy using C 2 cubic splines with 31 knots than with C 0 linear splines with 511 knots. As before, we see that the condition numbers grow somewhat with increasing k.

1.13 Error bounds There is an extensive theory giving error bounds for various univariate spline approximation and interpolation methods. In this section we offer a glimpse of this theory by presenting error bounds for the specific methods discussed above. We begin by presenting a basic result which shows how well smooth functions can be approximated by splines. Unless explicitly stated, all norms in this chapter are the maximum norm on the interval [a, b] defined by  f  := max | f (t)|. t ∈[a,b]

For any subinterval I of [a, b], we write  f  I for the maximum norm of f on I .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

40

Chapter 1. Univariate Splines

1.13.1 The approximation power of univariate splines In this section we discuss how well smooth functions (and their derivatives) can be approximated by univariate splines. Suppose Sdr () is a space of splines of degree d and k+1 of the interval [a, b]. smoothness 0 ≤ r < d defined on a partition  = {x i }i=0 Theorem 1.51. Suppose f ∈ C m+1 [a, b] with 0 ≤ m ≤ d. Then there exists a spline s ∈ Sdr () such that D j ( f − s) ≤ K ||m+1− j D m+1 f  (1.66) for all 0 ≤ j ≤ min(m,r ), where the constant K depends only on d. Here || is the mesh size of the partition as defined in (1.21). For a proof of this theorem, see [Schum81], where much more on the approximation power of splines can be found, including results in other norms. We make several remarks about this theorem. 1) The bounds do not depend on the smoothness r of the spline space. In other words, all spline spaces of degree d defined on  have the same approximation power. 2) The same bounds hold for f ∈ L m+1 ∞ [a, b], provided that we replace the maximum norm by the essential supremum norm. In this case we can allow 0 ≤ j ≤ m. 3) The theorem shows that not only is f well-approximated by s, but the derivatives of f are simultaneously approximated by the derivatives of s, albeit with reduced orders. 4) If we assume that f ∈ C d+1 [a, b], then the order of approximation of f is O(||d+1 ). This is called the optimal order of approximation, since it is known that this type of bound cannot hold for any order greater than d + 1. 5) We emphasize that the constant K in (1.66) does not depend on the spacing of the knots in .

1.13.2 Locally bounded spline methods Many spline interpolation and approximation methods define linear operators Q mapping C[a, b] into a spline space Sdr (). In this section we show that with appropriate assumptions on Q, we can get optimal order error bounds as in (1.66). Since the right-hand side of (1.66) with m = d vanishes for p ∈ Pd , in order for D j ( f − Q f ) to satisfy that inequality, we must have Qp = p. When a linear operator has this property, we say that it reproduces polynomials of degree d . Definition 1.52. Suppose Q is a linear operator mapping C[a, b] to Sdr (), and suppose there exist constants K 1 , K 2 independent of f such that for every subinterval Ii of the partition , there exists an interval Ji containing Ii with 1) |Ji | ≤ K 1 |Ii | and 2) Q f  Ii ≤ K 2  f  Ji for all f ∈ C[a, b]. Then we say that Q is locally bounded.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.13. Error bounds

41

Theorem 1.53. Suppose Q : C[a, b] → Sdr () is a locally bounded linear operator mapping C[a, b] into Sdr () such that Q reproduces polynomials of degree d. Then for every f ∈ C m+1 [a, b] with 0 ≤ m ≤ d, D j ( f − Q f ) ≤ K ||m+1− j D m+1 f 

(1.67)

for all 0 ≤ j ≤ min(m,r ). For j = 0, the constant K depends only on d and the constants K 1 and K 2 in Definition 1.52. But for j > 0, it also depends on the global mesh ratio max (x i+1 − x i )

σ :=

0≤i≤k

min (x i+1 − x i )

.

(1.68)

0≤i≤k

Proof. Consider one subinterval Ii := [x i , x i+1 ] of the partition defined by , and let h i := (x i+1 − x i ) > 0 be its length. Let Ji be the interval associated with Ii in Definition 1.52, and let K 1 , K 2 be the constants appearing there. Fix f ∈ C m+1 [a, b] with 0 ≤ m ≤ d, and let p be the mth degree Taylor expansion of f about x i . Then for all 0 ≤ j ≤ m, D j ( f − p) Ji ≤ K 3 |Ji |m+1− j D m+1 f  Ji m+1− j

≤ K1

m+1− j

K3hi

D m+1 f  Ji ,

(1.69)

where K 3 = 1/(m + 1)!. Now since Qp = p, we have D j ( f − Q f ) Ii ≤ D j ( f − p) Ii + D j Q( f − p) Ii .

(1.70)

Since Ii ⊆ Ji , the first term is bounded by the quantity in (1.69). Now Q f restricted to Ii is a polynomial of degree d, and using the Markov inequality (cf. Theorem 3.3 of [[Schum81]]) and the local boundedness of Q, we get −j

−j

D j Q( f − p) Ii ≤ K 4 h i Q( f − p) Ii ≤ K 2 K 4 h i  f − p Ji for any 0 ≤ j ≤ min(m,r ), where K 4 depends only on d. Then by (1.69) with j = 0, we get −j

D j Q( f − p) Ii ≤ K 5 h i ||m+1 D m+1 f  Ji ≤ K 5 σ j ||m+1− j D m+1 f  Ji , where K 5 depends on K 1 , . . . , K 4 . Since this bound holds for every subinterval Ii , we get (1.67). As a simple corollary of this result we can establish error bounds for bounded linear projectors. Definition 1.54. Suppose Q is a linear mapping from C[a, b] into a spline space Sdr (). Then we say that Q is a linear projector onto Sdr (), provided that for every s ∈ Sdr (), Qs = s. We say that Q is bounded, provided that Q ≤ K  f  for every f ∈ C[a, b]. If Q is a bounded linear projector, we define its norm to be Q =

sup

f ∈C[a,b]

Q f  . f

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

42

Chapter 1. Univariate Splines

Theorem 1.55. Suppose Q is a bounded linear projector mapping C[a, b] onto a spline space Sdr (), and suppose f ∈ C m+1 [a, b] with 0 ≤ m ≤ d. Then D j ( f − Q f ) ≤ K ||m+1− j D m+1 f 

(1.71)

for all 0 ≤ j ≤ min(m,r ). For j = 0 the constant K depends only on d and Q, while for j > 1 it also depends on the global mesh ratio (1.68).

1.13.3 Error bounds for linear spline interpolation Given a function f ∈ C[a, b] and any partition  of [a, b], let I1 f to be the linear spline in S10 () that interpolates f at the knots x 0 , . . . , x k+1 ; see section 1.4.1. It is easy to see that I1 is a linear projector and that I1  ≤ 1. Then we can apply Theorem 1.55 to get an error bound for  f − I1 f . However, since I1 f is just a linear polynomial on each subinterval Ii := [x i , x i+1 ] which interpolates f at its endpoints, we can get more specific local results. Recall that the modulus of continuity of a continuous function f is defined by ω( f ; h) = max | f (t2 ) − f (t1 )|. |t2 −t1 |≤h

Theorem 1.56. We have

⎧ ⎪ ω( f , ||), all f ∈ C[a, b], ⎪ ⎨   f − I1 f  ≤ || all f ∈ C 1 [a, b], 2  f , ⎪ ⎪ ⎩ ||  f  , all f ∈ C 2 [a, b]. 8

Proof. See, e.g., Theorem 6.15 in [[Schum79]], where the result is established with L 1∞ and L 2∞ replacing C 1 and C 2 . It can also be established locally, i.e., for each subinterval of the partition . Following the ideas of the proof of Theorem 1.53, and using Markov’s inequality, we also can get a local error bound for the first derivative in case f ∈ C 2 [a, b]. In particular, for each interval I of the partition, D( f − I1 f ) I ≤ 4 || f   I .

1.13.4 Error bounds for not-a-knot interpolation Suppose we interpolate a given function f at points a = t1 < · · · < tn = b using the nota-knot spline interpolant of odd degree d discussed in section 1.4.2. This defines a linear operator Id mapping C[a, b] into the spline space Sdd−1 (), where  is the partition associated with the interior knots (1.17). Since the coefficients of Id f are determined from a nonsingular linear system of equations, the interpolating spline is unique, and it follows that Id s = s for every s ∈ Sdd−1 (), i.e., Id is a linear projector. In contrast to the case of linear spline interpolation, the projector Id is not bounded for arbitrary sets of sample points τ := {ti }ni=1 . However, it is known (see p. 182 of [[Boo01]]) that the norm of Id is bounded by a constant that depends on the global mesh ratio (1.68). Applying Theorem 1.55, we get the following error bound for not-a-knot interpolation.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.13. Error bounds

43

Theorem 1.57. For any f ∈ C m+1 [a, b] with 0 ≤ m ≤ d, D j ( f − Id f ) ≤ K ||m+1− j D m+1 f  for 0 ≤ j ≤ min(m, d − 1). Here the constant depends on d and the global mesh ratio.

1.13.5 Error bounds for the clamped cubic spline Theorem 1.57 shows that not-a-knot spline interpolation gives optimal order error bounds, but with a constant that depends on the global mesh ratio of the partition . The following theorem shows that clamped cubic spline interpolation also provides optimal order error bounds, but with an absolute constant. Given any f ∈ C 1 [a, b], we write Icc f for the clamped cubic spline interpolant associated with the partition . Although Icc is clearly a linear operator, it is not defined on all of C[a, b], and so the general results on projectors and quasi-interpolants of sections 1.13.1– 1.13.3 cannot be directly applied. The following result is established in [Hall68] and [HallM76]. Theorem 1.58. Let f ∈ C 4 [a, b]. Then D j ( f − Icc f ) ≤ K j ||4− j D 4 f  for 0 ≤ j ≤ 2, where K 0 =

5 384 ,

K1 =

1 24 ,

(1.72)

and K 2 = 38 .

It has been shown in [HallM76] that the bound (1.72) also holds for j = 3, but with a constant K 3 depending on the global mesh ratio.

1.13.6 Error bounds for the quasi-interpolant of section 1.7 For each f ∈ C[a, b], let Q 3 f be the quasi-interpolant constructed in section 1.7 based on samples of f at equally spaced points a = t1 < · · · < tm = b using cubic B-splines defined on the corresponding extended knot sequence y1 , . . . , yn+4 with n = m + 2. Theorem 1.59. For any f ∈ C m+1 [a, b] with 0 ≤ m ≤ 3, D j ( f − Q 3 f ) ≤ K ||m+1− j D m+1 f  for 0 ≤ j ≤ min(m, 2). Here K is an absolute constant. Proof. Q 3 defines a linear operator mapping C[a, b] into S32 (). In Theorem 1.25 we showed that Q 3 p = p for all cubic polynomials p. We now show it is locally bounded. Let Il := [yl , yl+1 ] be one of the subintervals of the partition with 4 ≤ l ≤ n. Then by the support properties of the B-splines, for any f ∈ C[a, b] and any x ∈ Il ,  l  l     (λi f )Ni (x) ≤ max |λi f | |Ni (x)|. |Q 3 f (x)| =  i=l−3

l−3≤i≤l

i=l−3

By the partition of unity property of the B-splines, the sum is bounded by 1. Now examining the formulae for the λi f in Theorem 1.25, we see that for every i = 1, . . . , n,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

44

Chapter 1. Univariate Splines

the value of λi f depends on f in at most seven subintervals centered around Ii . Defining Ji to be the union of these intervals, and examining the formulae for the λi in the theorem, we see that condition 2 of Definition 1.52 holds with K 1 := 7 and K 2 := 2. It follows that Q 3 is a locally bounded quasi-interpolant, and the result follows from Theorem 1.53.

1.13.7 Error bounds for discrete least-squares Suppose we have samples z i := f (ti ) of a function f at points t1 < · · · < tnd in an interval [a, b]. Let Sdr () be a space of splines defined on a partition  of [a, b]. Suppose the choice of sample points and knots is compatible in the sense that the condition (1.44) is satisfied. Then by Theorem 1.28 there is a unique spline in Sdr () solving the discrete least-squares problem (Problem 1.27). We denote it by Ld f . Clearly, Ld defines a linear operator mapping C[a, b] into Sdr (). In fact, by the uniqueness of the least-squares fit, if s is any spline in Sdr (), then Ld s = s, i.e., Ld is actually a linear projector onto Sdr (). To get an error bound we would like to apply Theorem 1.55. Thus, we now show that under additional conditions on the location of the data relative to the subintervals of the partition, Ld is bounded subordinate to the maximum norm. For a proof of the following theorem, see [GolS02]. Theorem 1.60. Fix Sdr (), and suppose that for each subinterval I of [a, b] defined by the partition , ⎞1/2 ⎛  (1.73) K 1 s I ≤ ⎝ [s(ti )]2 ⎠ ti ∈I

for all s ∈ Sdr (). Then

Ld  ≤ K 2 ,

where K 2 depends on d, K 1 , the global mesh ratio (1.68), and the maximum number of points in any subinterval of . It follows that under the hypotheses of this theorem, the discrete least-squares spline Ld f satisfies the optimal order error bounds given in Theorem 1.55.

1.13.8 Error bounds for the Ritz–Galerkin method Given p, q, f , let s ∈ Sdr () be the corresponding Ritz–Galerkin solution of the two-point boundary-value problem (Problem 1.47). Assuming u is the true solution, in this section we present error bounds for u − s, measured in the maximum norm on [a, b]. We give two different results depending on properties of the functions p, q, and f . Theorem 1.61. Suppose that the hypotheses of Theorem 1.42 hold. Then there exists a constant K such that u − s ≤ K ||d  f , where K depends on the constant γ in (1.61).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.14. Remarks

45

For details, see [[Pre75]] or [[Schul73]]. The proof requires working first through the L 2 norms of derivatives and using several tricks. A stronger version of this result can be proved under additional properties on the differential operator L. We say that L is strongly coercive, provided that there exists a constant γ2 > 0 such that the solution u satisfies γ2 D 2 u2 ≤  f 2 .

(1.74)

The following result is also established in both [[Pre75]] and [[Schul73]]. Theorem 1.62. Suppose that the differential operator L in Problem 1.47 is strongly coercive. Then there exists a constant K such that u − s ≤ K ||d+1 f , where K depends on the constant γ2 in (1.74).

1.14 Remarks Remark 1.1. Throughout this chapter we have opted to work with univariate spline spaces of the form Sdr (), rather than more general spline spaces with variable smoothness at the knots in the interior of [a, b]. However, virtually everything in the chapter remains valid n+d+1 for spline spaces associated with general extended knot sequences {yi }i=1 where at most d + 1 knots fall at any one point. Remark 1.2. In section 1.2 we have defined B-splines by a recurrence relation. Originally, they were defined in terms of divided differences of certain Green’s functions, or equivalently as linear combinations of certain one-sided piecewise polynomials; see, e.g., section 4.3 of [[Schum81]]. These alternate definitions are used in much of the early spline literature. Algorithms for converting between the various representations of splines are discussed in [Boo78]. Remark 1.3. Some of the formulae and computational algorithms simplify in case we work with equally spaced interior knots; see, e.g., [[Schum81]]. However, generally the savings in computation time is not worth the extra programming time. Remark 1.4. In working with univariate splines, we strongly recommend using the B-form based on the B-splines described in section 1.2. Of course, this is not the only way to store and work with splines. For example, it is also possible to work with the coefficients of each polynomial piece directly. For some algorithms for converting between the two representations, see [Boo78]. Remark 1.5. The clamped cubic spline interpolant discussed in section 1.4.4 is also referred to as the cubic complete spline in the literature. Remark 1.6. The clamped cubic spline interpolant is based on choosing the knots to coincide with the interpolation points a = t1 < · · · < tn = b. To uniquely define a corresponding cubic spline, we had to add conditions on s  (a) and s  (b). If we use the conditions s  (a) = 0 and s  (b) = 0 instead, we get what is called the natural cubic spline. It has also been studied intensively in the literature, and is often included as the main spline example in elementary numerical analysis books. However, because of the natural end conditions, natural cubic splines do not give optimal order approximation throughout the entire interval [a, b]; see [Nor67].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

46

Chapter 1. Univariate Splines

Remark 1.7. In section 1.5 we have discussed Hermite interpolation with splines. This involves setting values and a consecutive sequence of derivatives at each interpolation point. More generally, one could consider interpolation problems where we set a total of ki derivatives at the point ti , without requiring that these derivatives be consecutive. For example, we might set the value and the second derivative. We call this problem the Hermite–Birkhoff interpolation problem. This problem has been studied extensively. For some early work, see [Scho68, KarK72, MunS73, Fer74]. The book [[LorJR83]] gives further references. Remark 1.8. In Hermite–Birkhoff interpolation the list of derivatives to be interpolated can vary from data point to data point. The special case where the same list of derivatives is used at every data point is called lacunary interpolation. Thus, for example, we might want to interpolate values and second derivatives at a set of points x 1 < · · · < x m . For some papers on the use of splines for solving such problems, see, e.g., [MeirS73, SwaV73, Kuo75, Demk76, Varm78, MisM80, FawS86, FawH87, Che81, Che81c, Hua83]. Remark 1.9. The C 1 cubic Hermite interpolant constructed in section 1.5.1 is based on having a value and the first derivative at each interpolation point. This procedure is easily generalized to the case where we are given a value and derivatives up to order  at each  point. In this case, we can replace S31 () by S2+1 () to define a unique interpolant with many of the same properties as we have in the cubic case. Remark 1.10. In section 1.7 we have restricted our discussion to quasi-interpolants that are based on samples of the function being approximated. It is also possible to define quasiinterpolants that sample derivatives; see, e.g., [Boo73, BooF73, LycS75, Boo92]. It is also possible to define quasi-interpolants based on local integrals. They are then applicable to functions which are in L 1 [a, b] and are not necessarily continuous. For details, see [LycS75]. Remark 1.11. Perhaps the simplest example of a quasi-interpolating spline defined on C[a, b] is one due to Schoenberg which has the form Q f :=

n 

f (ξi )Nid+1 ,

(1.75)

i=1

where ξi := (yi+1 + · · · + yi+d−1 )/(d − 1) for i = 1, . . . , n. These sample points are called the Greville points and are just the values of the coefficients ci2 appearing in Marsden’s identity (1.40). This quasi-interpolant reproduces linear polynomials, and approximates C 2 functions to order O(||2 ). For early work on this quasi-interpolant; see [MarS66, Scho67, KarK68, Mar70]. Remark 1.12. The quasi-interpolant discussed in section 1.7 is not a projector. To get a quasi-interpolant which is a projector, for each 1 ≤ i ≤ n, we have to choose all of the sample points used to construct λi in one subinterval of the partition; see [BooF73, LycS75]. To get full approximation power using splines of degree d, this would require putting d + 1 sample points in each subinterval. Remark 1.13. The system of equations Gc = g appearing in Theorem 1.28 are usually called the normal equations. It is generally recommended to avoid working with the normal equations due to the fact that they are usually badly conditioned. However, due to the local

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.14. Remarks

47

support properties of the B-splines, we have not had any problem with solving this system, even in the case where the number of data points n d is relatively small compared to the dimension n of the space, and even when these points are taken to be random numbers. Indeed, we found that the matrix G may be singular when the points are not sufficiently spread out to satisfy the condition (1.44). However, in all cases where the matrix was nonsingular, the condition number turned out to be quite small. Remark 1.14. In section 1.11 we have discussed the question of how to choose knots when performing least-squares fitting. This question arises whenever we have the freedom to choose the knot locations. For example, assuming we want to interpolate smooth functions at given sample points a = t1 < · · · < tn = b using splines with a fixed number of interior knots, how should we choose the knot locations? This problem can be addressed theoretically by trying to minimize the worst error bound for arbitrary functions in the class of functions whose mth derivatives are bounded in an appropriate norm. This is often referred to as optimal recovery or optimal interpolation. For a discussion along with a program to find optimal interpolants, see [[Boo78]]. Remark 1.15. We know that the penalized least-squares spline approaches the leastsquares spline as the smoothing parameter tends to zero. It is possible to describe the rate of convergence. In particular, it is shown in Theorem 7.1 of [GolS02] that if s0 is the least-squares cubic fit to data, then the penalized least-squares fit sλ with smoothing parameter λ satisfies √ −1/2 √ s0 − sλ  ≤ C1 δh 0 λ min{C0 δh −2 λ} s0 2 . 0 Here h 0 is the minimum spacing between knots, and δ is a constant such that nd 1  s(ti )2 s2 ≤ δ nd i=1

for all cubic splines. Remark 1.16. If we perform penalized least-squares approximation as in section 1.10 using the space S32 () with knots at the sample points and with the natural end conditions s  (a) = 0 and s  (b) = 0, we get what is called a smoothing spline in the literature. Smoothing splines seem to have been introduced in [Scho64d] and were intensely studied in the 1960’s and 1970’s; see, e.g., [Rei67, Ansl68, Rein71, LycS73b]. For programs, see [LycS73, LycSS83] and the book [[Boo78]]. Remark 1.17. Smoothing splines found considerable interest in statistics as a means for doing nonparametric regression. For a statistician’s account, see [[Wah90]]. Papers on smoothing splines and their applications are still appearing in the statistics literature today. Remark 1.18. For applications of smoothing splines, an important question is how to set the smoothing parameter. One computational approach is to use cross validation. For some early papers, see [WahWo75, WahWo75b], but for a more complete account see the book [[Wah90]]. Remark 1.19. It is straightforward to generalize the idea of penalized least-squares fitting discussed in section 1.10 in various ways. For example, we can replace the term measuring

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

48

Chapter 1. Univariate Splines

the goodness of fit in terms of a sum of squared errors  by some other measure of goodness of fit. For example, an 1 expression of the form n1d |s(ti )−z i | could be used. In addition, the penalty term measuring the smoothness of the fit could be replaced by some other quadratic functional, such as the integral of the square of a higher order derivative. Remark 1.20. In programming lsqopt we found that fmincon performed better when we used optimset to reduce the parameter TolFun from its default value to 10−12 . Remark 1.21. The knot removal algorithm described in section 1.11 is based on an iteration in which just one knot is removed at each step. It is also possible to design algorithms in which groups of knots are removed at each step. For a discussion of this in the context of design of curves, see [LycM87, LycM88, ArgDLM90, Lyc92, SchumSt96]. Remark 1.22. For more on the use of splines with the Ritz–Galerkin method for two-point boundary-value problems, see the books [[Pre75, Schultz73]] and references therein. Remark 1.23. All of the error bounds presented in section 1.13 are given in terms of maximum norms. Many of them can be extended to general L p norms with 1 ≤ p ≤ ∞. For example, for the L p version of Theorem 1.51, see [[Schum81]]. Remark 1.24. Some of the error bounds in section 1.13 depend on the global mesh ratio σ defined in (1.68). This dependence disappears for equally spaced knots, since in this case σ = 1. Remark 1.25. In this chapter we have discussed splines as a tool for approximating univariate functions defined on an interval [a, b]. If the function is periodic, as it often is in practice, we should require the spline to also be periodic, i.e., we should work with the space of periodic splines

Sˆdr () := {s ∈ Sd () : D j s(a) = D j s(b), j = 0, . . . , d}. For a detailed treatment of periodic splines, see section 8.1 of [[Schum81]]. As explained there, we can compute with periodic splines using the same programs described here for the nonperiodic case — all that is necessary is to define the extended knot sequence in an appropriate periodic way as explained in detail in [[Schum81]]. Remark 1.26. In section 1.12 we have shown how splines can be used to find approximate solutions to two-point boundary-value problems for ordinary differential equations. The approach uses the Ritz–Galerkin method. An alternative method studied heavily in the literature is to use collocation instead; see the list of references in the following section. In particular, to solve Problem 1.39, the idea is to determine the coefficients of a spline s so that s satisfies the boundary conditions and for some appropriate set of points {ξ j } jN=1 in the interval [a, b], we have Ls(ξ j ) = f (ξ j ) for j = 1, . . . , N. Remark 1.27. There are still other numerical methods for approximating solutions of the two-point boundary-value problem, such as the shooting method; see, e.g., [KinC02]. Remark 1.28. In section 1.13.4 we stated that the not-a-knot spline operator Id is bounded by a constant depending on the global mesh ratio σ defined in (1.68). Some error bounds for splines involve only local mesh ratios.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

1.15. Historical notes

49

Remark 1.29. Univariate splines provide a useful tool for constructing certain wavelets. For an introduction to the theory, see [[Chu92]] and references therein. In the meantime, there are many other books on wavelets. Remark 1.30. Univariate splines are also useful in computer-aided geometric design (CAGD) as a tool for working with curves in R2 or R3 . The idea is to work with parametric curves whose components are splines. Here the B-spline basis functions are particularly useful, since when the coefficients are connected with straight lines, we get a control polygon which closely resembles the curve, and which can be used to adjust its shape. The heavily used NURBS are based on B-splines. It is beyond the scope of this book to discuss applications in CAGD, but see any of the standard books such as [[Far88, HosL93, CohRE01, PraBP02]].

1.15 Historical notes Although there were a few isolated papers about splines prior to 1960, the explosive development of univariate splines as a computational tool really began in the late 1950’s and early 1960’s with a number of papers dealing with interpolation by certain cubic splines or various extensions; see, e.g., [Holl57, TheiS61, Ask62, FowW63, Boo63, BirB64, Grev64, Scho64, AhlNW64, AhlN65, AhlNW65bc, BirB65, Sec65, SharmM66, Schur68]. Many of the early papers on univariate splines focused on error bounds, and in particular on how they depend on properties of the mesh. Most of the earliest papers (and many later ones) required some assumption on the mesh spacing, either a kind of global quasiuniformity or at least a local one. Some results required working on a subset of the interval containing the interpolation points. It was soon recognized that for many spline interpolation methods, these restrictions were necessary; see Remark 1.6. Here are some early papers: [WalAN62, AhlN62, Boo63, BirB64, AhlNW65b, Sec65, WalAN65, Hand66b, SharM66, Boo68b, Hall68, MeirS68b, SchurC68, SharM68, Swa68, MeirS69, Sonn69, Varg69]. Here we have presented only a few of the best available methods, with an emphasis on methods with good error behavior. Thus, for example, we do not discuss natural cubic spline interpolation, although it is a favorite topic in many modern numerical analysis books. It was also recognized in the early 1960’s that splines could be used to solve problems involving ordinary differential equations and integral equations. For ordinary differential equations, both initial-value problems and two-point boundary-value problems were treated, usually with either collocation (see Remark 1.26) or the Ritz–Galerkin method of section 1.12. Some of the earliest papers include [BirBSW66, LosT67, LosT67b, Bic68, AlbH69, Joh69, Los69, Fyf69]. Computations with univariate polynomial splines can be carried out in different ways: 1) with an explicit representation of each polynomial piece, 2) by using one-sided basis functions (see [[Boo78, Schu81]]], or 3) using the B-splines discussed in section 1.2. Although the B-splines (without calling them by that name) appear in various forms in a number of papers going back to the 1900’s (see the detailed historical account in [ButER86]),

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

50

Chapter 1. Univariate Splines

they were not used for actual computation in early spline papers. Eventually it was realized that due to the nice properties (such as local support, nonnegativity, and the fact that they form a partition of unity), B-splines ought to be used instead of the one-sided basis. However, computing with them was still hampered by the fact that B-splines were initially defined in terms of divided differences of certain Green’s functions (see section 4.3 of [[Schum81]]), with all the associated stability and roundoff problems. Computation with B-splines became much more attractive with the discovery of the recurrence formula (1.5). It was introduced to the spline community simultaneously by Carl deBoor [Boo72], Maurice Cox [Cox72], and Lois Mansfield, but it was discovered later that it in fact can be found already in early work of Popoviciu and Tschaloff in the 1930’s; see [BooP03]. In our discussion here of interpolation with univariate polynomial splines, we have focused on only a few of the most useful possible schemes. Many others have been discussed in the literature. Starting in the 1970’s, a large number of papers have appeared on the problem of interpolating data while preserving shape. Here we mention only a few of the earliest papers: [NewPR72, Pas74, Gav75, PasR75, BooS77, Dev77, McAPR77, Pas77, PasRo77, McAR78, Den79, Fu79, Hor79, Pen79, Wan79]. For a useful survey with many references, see [Gre91]. Approximating data using the method of least-squares is an old topic in approximation theory. For some early papers on least-squares with splines, see [TheS61, BooR68, BoorR68b]. Penalized least-squares methods seem to have come later, see [Eub86, EubG86, GolS90, Wey92, GolS02b, ZhoH09, LaiW13] and the book [[GreeS94]].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 2

Tensor-Product Splines

In this chapter we discuss how to use tensor-product splines to solve various interpolation and approximation problems defined on rectangular domains in R2 . The methods extend easily to tensor domains in any number of variables.

2.1 Introduction In this chapter we deal with functions defined on a rectangular domain ¯ := {(x, y) : a ≤ x ≤ b and a¯ ≤ y ≤ b}. ¯  := [a, b] ⊗ [a, ¯ b]

(2.1)

 := {a = x 0 < x 1 < · · · < x k+1 = b}, ¯ := {a¯ = y0 < y1 < · · · < yk+1 ¯  = b}, ¯

(2.2)

Given points

let i j := [x i , x i+1 ) ⊗ [y j , y j +1 ),

i = 0, . . ., k, ¯ j = 0, . . ., k,

¯ This where we replace the half-open intervals by closed intervals when i = k or j = k. partitions the rectangle  into (k + 1) × (k¯ + 1) subrectangles. To build bivariate splines defined on this partition, we introduce the space of tensorproduct polynomials in two variables

! 2 Pd, d¯

:= Pd1 ⊗ Pd1¯

:= p(x, y) :=

d  d¯ 

" ai j x y . i

j

(2.3)

i=0 j =0

2 is a linear space of dimension (d + 1)(d¯ + 1). Given integers 0 ≤ r ≤ d It is clear that Pd, d¯ ¯ let C r,¯r () be the set of all functions defined on  such that the derivatives and 0 ≤ r¯ ≤ d, μ Dxν D y f are continuous for all ν = 0, . . . ,r and μ = 0, . . . , r¯ .

51

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

52

Chapter 2. Tensor-Product Splines

¯ let Definition 2.1. Given integers 0 ≤ r ≤ d and 0 ≤ r¯ ≤ d,  ¯ := s(x, y) ∈ C r,¯r () : s|i j ∈ P 2 ¯ , Sdr () ⊗ Sdr¯¯ () d,d  i = 0, . . . , k and j = 0, . . . , k¯ .

(2.4)

¯ and smoothness (r , r). We call this the space of tensor-product splines of degree (d, d) ¯ We ¯ the knots of the spline. call the points in  and  It is easy to prove (see, e.g., [[Schum81]]) that the dimension of this space is n × n, ¯ where n := k(d − r ) + d + 1 is the dimension of Sdr (), and n¯ := k¯ (d¯ − r¯ ) + d¯ + 1 is the ¯ dimension of Sdr¯¯ ().

2.2 Tensor-product B-splines ¯ we take tensor products of univariate B-splines. Let To create a basis for Sdr () ⊗ Sdr¯¯ (), ¯ ¯ d+1 Nid+1, (x, y) := Nid+1 (x) N¯ d+1 (y), j j

i = 1, . . ., n, j = 1, . . . , n, ¯

(2.5)

¯ where {Nid+1 }ni=1 is the normalized B-spline basis for Sdr (), and { N¯ dj +1 }nj¯=1 is the nor¯ malized B-spline basis for Sdr¯¯ (). We now list some useful properties of the tensor-product B-splines. Suppose xˆ and yˆ are ¯ respectively. the extended knot sequences associated with Sdr () and Sdr¯¯ (), ¯

d+1 1) For each i , j , the B-spline Nid+1, vanishes outside of the rectangle j [xˆi , xˆi+d+1 ] ⊗ [ yˆ j , yˆ j +d+1 ¯ ], and is positive in the interior.

2) The B-splines form a partition of unity, i.e., n  n¯ 

¯

d+1 Nid+1, (x, y) ≡ 1, j

all (x, y) ∈ .

(2.6)

i=1 j =1

3) For each i , j , 

¯



d+1 Nid+1, (x, y) d x d y = j

− yˆ j ) (xˆi+d+1 − xˆ i )( yˆ j +d+1 ¯ . (d + 1)(d¯ + 1)

(2.7)

¯ d+1 n¯ r r¯ ¯ }n, 4) The set {Nid+1, j i=1, j =1 is a basis for Sd () ⊗ Sd¯ ().

2.3 Computing with the tensor B-form ¯ it follows that every s Since the tensor-product B-splines form a basis for Sdr () ⊗ Sdr¯¯ (), in this space can be written uniquely in the tensor-product B-form s(x, y) =

n  n¯  i=1 j =1

¯

d+1 ci j Nid+1, (x, y) = j

n  n¯  i=1 j =1

¯

ci j Nid+1 (x) N¯ d+1 (y). j

(2.8)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.3. Computing with the tensor B-form

53

The corresponding set of coefficients can be assembled in the n × n¯ matrix ⎡

c11 ⎢ .. C := ⎣ . cn1

··· ···

⎤ c1n¯ .. ⎥ . . ⎦

(2.9)

cnn¯

Now we can write s in matrix form as ⎤ ¯ N¯ 1d +1 (y) ⎥ ⎢ .. ⎥. s(x, y) = [N1 (x), . . ., Nn (x)] C ⎢ . ⎦ ⎣ ¯ N¯ n¯d +1 (y) ⎡

(2.10)

It follows that to store a tensor-product spline in a computer, we need only store the degrees ¯ the extended knot vectors xˆ and yˆ , and the coefficient matrix C. d, d,

2.3.1 Evaluating a tensor-product spline Now suppose we want to evaluate the spline s at a point (x, y) in . Using the function findinterval described in section 1.3.1, we can find the integers l and l¯ such that xˆl ≤ x < xˆl+1 and yˆl¯ ≤ y < yˆl+1 ¯ . By the local support property of the univariate B-splines, the only B-splines with nonzero values at (x, y) are Nl−d (x), . . ., Nl (x) and ¯ ¯ d¯+1 (y). Their values can be found using the function bspl described in N¯ ¯d +1 ¯ (y), . . ., N ¯ l−d

l

section 1.3.6. Then (2.10) reduces to ⎡

⎤ ¯ N¯ l¯d−+1 ¯ (y) d ⎥ l − d, . . .,l ⎢ .. ⎢ ⎥, s(x, y) = [Nl−d (x), . . ., Nl (x)] C ¯ ¯ . ⎣ ⎦ l − d, . . . , l¯ ¯ d +1 ¯ Nl¯ (y) 

where  C

l − d, . . .,l ¯ . . . , l¯ l¯ − d,



⎡ cl−d,l− ¯ d¯ ⎢ .. := ⎣ . cl,l− ¯ d¯



··· ···

⎤ cl−d,l¯ .. ⎥ . . ⎦

(2.11)

(2.12)

cl,l¯

We include the following implementation in SplinePak: val = valtp(d,db,xe,ye,c,l,lb,x,y) Here d and db are the degrees of the spline, while xe and ye are the extended knot vectors. The inputs x and y define the point where the evaluation is to be done. We could have included the search for l and lb in this function, but instead we make them inputs. This may save some searching time in situations where we perform several evaluations at points lying in the same rectangle. This happens, for example, when plotting a tensor-product spline; see section 2.3.3 below.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

54

Chapter 2. Tensor-Product Splines

2.3.2 Computing derivatives ¯ and let ν and μ be integers with 0 ≤ ν ≤ r Suppose s is a spline in the space Sdr () ⊗Sdr¯¯ (), and 0 ≤ μ ≤ r¯ . Then it is clear that r−ν ¯ Dxν D μ (). y s ∈ Sd−ν () ⊗ Sd−μ ¯ r−μ ¯

μ

Using the formulae in section 1.3.3, we can find the corresponding B-coefficients of Dxν D y s. μ Then to compute Dxν D y s(x, y) at a given point (x, y) in , we can evaluate this lower degree spline with the function valtp given in the previous section. It is somewhat simpler to use the following approach. Suppose l and l¯ are such that ν μ xˆl ≤ x < xˆl+1 and yˆl¯ ≤ y < yˆl+1 ¯ . Then taking the partial derivative D x D y of the B-splines in (2.11), we immediately get the formula Dxν D μ y s(x, y)



⎤ μ d¯ +1 D y N¯ l− ¯ d¯ (y) ⎥ l − d, . . .,l ⎢ .. ⎢ ⎥. = [Dxν Nl−d (x), . . ., Dxν Nl (x)] C ¯ ¯ . ⎦ l − d, . . . , l¯ ⎣ ¯ μ D y N¯ l¯d +1 (y) 



The values of the derivatives of B-splines appearing in this formula can be computed using our function bsplder described in section 1.3.6. SplinePak contains the following function for evaluating derivatives: derval = valtpder(d,db,xe,ye,c,nu,mu,l,lb,x,y) This function has the same inputs as valtp, but also includes the integers nu and mu defining the derivative to be evaluated.

2.3.3 Plotting a tensor-product spline We can plot a tensor-product spline defined on a rectangular domain  by evaluating it on a rectangular grid # $n g ,n¯ g G := (ti , t¯j ) i=1, (2.13) j =1 defined by sets of points a = t1 < · · · < tn g = b, ¯ a¯ = t¯1 < · · · < t¯n¯ g = b. μ

The following function can be used to compute grid values of Dxν D y s for any 0 ≤ ν ≤ r and 0 ≤ μ ≤ r¯ : [xg,yg,g] = valtpgrid(d,db,xe,ye,c,nu,mu,ng,nbg,a,b,aw,bw) Here d and db are the degrees of the splines, xe and ye are the extended knot sequences, and c is the matrix of coefficients. The output includes the vectors xg and yg defining the grid points, and a matrix g of size n g × n¯ g with the grid values. Here is our script for testing this function:

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.3. Computing with the tensor B-form

55

0.4 10 0.2

-10

0 1

1 1

1 0.5

0.5

0.5 0

0.5 0

0

0

Figure 2.1. Plots of a bicubic tensor-product B-spline s and its derivative Dx D y s; see Example 2.2.

% TPdemo d = 3; db = 3; n = 11; nb = 11; xe = [0,0,0,linspace(0,1,n-2),1,1,1]; ye = [0,0,0,linspace(0,1,nb-2),1,1,1]; c = zeros(n,nb); c(5,5) = 1; ng = 51; nbg = 51; nu = input(’input nu ’); mu = input(’input mu ’); a = 0; b = 1; aw = 0; bw = 1; [xg,yg,g] = valtpgrid(d,db,xe,ye,c,nu,mu,ng,nbg,a,b,aw,bw); figure; surfl(xg,yg,g’); colormap(copper); This script illustrates the use of the MATLAB command surfl for creating a plot of a surface from a grid of values. Note that because of the way surfl handles the matrix containing the grid values, to get the proper orientation of the surface plot we have called it with the transpose g’ of g. Example 2.2. Choose seven equally spaced interior knots in each direction on the unit square. Plot the corresponding tensor-product bicubic spline N54 (x) N¯ 54 (y) and its Dx D y derivative. Discussion: We make use of the script TPdemo. The resulting spline and its various derivatives all have support on the square [xˆ5 , xˆ9 ] ⊗ [ yˆ5 , yˆ9 ] = [.125, .625]2. Figure 2.1 shows the plots. Note that the spline is positive in the interior of its support, but the derivative changes sign.

2.3.4 Computing the integral of a tensor-product spline Given a spline s defined on a rectangle , suppose we want to compute the integral of s ¯ of . Following the approach used in the univariate case over a subrectangle [α, β] ⊗ [α, ¯ β] in section 1.3.4, we solve this problem by introducing the antiderivative 

x



y

S(x, y) := a



s(u, v) du dv.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

56

Chapter 2. Tensor-Product Splines

Now suppose s is written in the B-form (2.8). Then since S is a spline in the space r+1 r+1 ¯ ¯ Sd+1 () ⊗ Sd+1 ¯ (), we can write S(x, y) =

n+1  n+1 ¯ 

¯

c˜i j Nid+2 (x) N¯ jd+2 (y).

(2.14)

i=1 j =1

Here {Nid+2 }n+1 i=1 are the B-splines of degree d + 1 associated with the extended partition ¯ ¯ obtained from xˆ by adding an extra knot at both a and b. Similarly, { N¯ jd+2 }n+1 j =1 are the B-splines of degree d¯ + 1 associated with the extended partition obtained from yˆ by adding ¯ an extra knot at both a¯ and b. Lemma 2.3. The coefficients of S in (2.14) are given by j i   1 c˜i j = cνμ (xˆd+ν+1 − xˆ ν )( yˆd+μ+1 − yˆμ ) ¯ (d + 1)(d¯ + 1) ν=1 μ=1

(2.15)

for i = 1, . . . , n + 1 and j = 1, . . ., n¯ + 1. Proof. By the formula in section 1.3.4, for each i = 1, . . . , n, we have 

n¯ y

Si (y) := a¯

¯ ci j N¯ jd +1 (v) dv =

j =1

% j n+1 ¯  j =1

Now

 S(x, y) =

n x a i=1

μ=1

& ( yˆd+μ+1 − yˆμ ) d¯+2 ¯ ciμ N¯ j (y). d¯ + 1

Si (y)Nid+1 (u) du,

and we can apply the formula in section 1.3.4 again to get (2.15). We have implemented this algorithm as [xi,yi,ci] = intcotp(d,db,xe,ye,c) This function returns the new extended partitions and the new coefficient matrix. To get a ¯ we note that definite integral over a fixed rectangle [α, β] ⊗ [α, ¯ β],  β  β¯ ¯ + S(α, α) ¯ − S(β, α), s(u, v) du dv = S(β, β) ¯ − S(α, β) ¯ (2.16) α

α¯

which can be computed by evaluating (2.14) at the four corners of the rectangle of interest. We have implemented this in the function val = intspltp(d,db,xi,yi,ci,alpha,beta,alphab,betab) Note that (2.16) is a formula for a subrectangle of . Generally, it is not possible to find formulae of this kind for nonrectangular subsets of . A quadrature formula will be required in such cases.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.4. Lagrange interpolation on a grid

57

Example 2.4. Compute the integral of the tensor-product spline over the unit square. Discussion: We use the script TPdemo which includes the following lines of code: % Test integration on a rectangle [xi,yi,ci] = intcotp(d,db,xe,ye,c); alpha = input(’input alpha ’); beta = input(’input beta ’); alphab = input(’input alphab ’); betab = input(’input betab ’); int = intspltp(d,db,xi,yi,ci,alpha,beta,alphab,betab) It computes the value of the integral over the unit square as .015625. As a check, we divided the unit square into four equally sized subsquares. The integrals over these squares were .0143500434, .0006239149, .0006239149, and .0000271267, rounded to 10 digits. The sum of these four partial integrals is .0156249999.

2.4 Lagrange interpolation on a grid As a first application of tensor-product splines, consider the following Lagrange interpolation problem. ¯ and suppose we are given Problem 2.5. Let a = t1 < · · · < tn = b and a¯ = t¯1 < · · · < t¯n¯ = b, n,n¯ ¯ such associated real numbers {z i j }i=1, j =1 . Find a function s defined on  := [a, b] ⊗ [a, ¯ b] that s(ti , t¯j ) = z i j for i = 1, . . . , n and j = 1, . . . , n. ¯ (2.17) Our aim is to solve this problem using a tensor-product spline space of the form Sdr ()⊗ We are free to choose ¯ the smoothness r , r¯ and the degrees d, d, as well as the number and placement of the knots. Suppose we have chosen these parameters so that the dimension of the spline space is n × n, ¯ and suppose we write our interpolating spline s in the B-form (2.8). Let C be the associated matrix of B-coefficients. Then making use of (2.10), we can write the n × n¯ interpolation conditions as the following system of linear equations for the coefficient matrix C: M C M¯ T = Z , (2.18)

¯ into subrectangles. ¯ defined on a partition of  := [a, b] ⊗[a, ¯ b] Sdr¯¯ ()

where



N1 (t1 )

···

⎢ ⎢ N1 (t2 ) · · · M := ⎢ .. ⎢ .. . ⎣ . N1 (tn ) · · · and

Nn (t1 )





⎥ Nn (t2 )⎥ .. ⎥ ⎥, . ⎦ Nn (tn ) ⎡

z 11 ⎢z 21 ⎢ Z := ⎢ . ⎣ .. z n1

¯ N¯ 1d +1 (t¯1 )

⎢ ¯ ⎢ N¯ d +1 (t¯ ) 2 ⎢ M¯ := ⎢ 1 . ⎢ .. ⎣ ¯ N¯ 1d +1 (t¯n¯ ) ··· ··· .. . ···



z 1n¯ z 2n¯ ⎥ ⎥ .. ⎥ . . ⎦ z nn¯

··· ··· .. . ···

¯ N¯ n¯d +1 (t¯1 )



⎥ ¯ N¯ n¯d +1 (t¯2 )⎥ ⎥ ⎥, .. ⎥ . ⎦ d¯ +1 ¯ ¯ Nn¯ (tn¯ )

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

58

Chapter 2. Tensor-Product Splines

To solve this system of equations, we need to make sure that both M and M¯ are nonsingular. We can check this using the Schoenberg–Whitney theorem (Theorem 1.8). The system ¯ = Z T , and then find C as (2.18) can be solved in two steps. First we find U such that MU the solution of MC = U T . Clearly, we have a great deal of leeway in choosing a spline space to solve Problem 2.5. In the following two sections we present two simple examples of tensor-product spline interpolants with good approximation properties.

2.4.1 Bilinear spline interpolation ¯ = {t¯j }n¯ . Then the spline space S 0 () ⊗ S 0 () ¯ has dimension Let  = {ti }ni=1 and  j =1 1 1 ¯ n × n. ¯ In this case the matrices M and M in (2.18) are both identity matrices, and so C = Z . Thus, the coefficients of the spline fit are immediately determined without solving any linear systems of equations. Here is our function to carry out bilinear spline interpolation. [xe,ye,c] = bilintp(t,tb,z) In addition to the coefficient matrix c, it returns the extended knot vectors xe and ye. This code can be tested with the following script, which calls on our test function franke2 described in Example 2.6 below: % TP01 a = 0; b = 1; aw = 0; bw = 1; n = input(’input n ’); nw = input(’input nw ’); t = linspace(a,aw,n); tw = linspace(aw,bw,nw); z = zeros(n,nw); for i=1:n z(i,:) = franke2(t(i),tw); end [xe,ye,c] = bilin(t,tw,z); figure; surfl(t,tw,z’); colormap(copper); ng = 51; ngw = 51; d = 1; db = 1; nu = 0; mu = 0; [xg,yg,g] = valtpgrid(d,db,xe,ye,c,nu,mu,ng,ngw,a,b,aw,bw); e = errg(xg,yg,g,@franke2); fprintf(’emax =%5.2e, RMS = %5.2e\n’,norm(e,inf),erms(e)); This script calls on our function e = errg(xg,yg,g,f) which, for any bivariate function f, computes a vector e containing the differences between the values in g and the values of f at the grid points defined by xg and yg. This allows us to compute the max error on the grid as norm(e,inf), and the RMS error by erms(e),

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.4. Lagrange interpolation on a grid

59

where the RMS error is defined as % & ng ( ng   *2 1/2 ) 1 rmserr := . g(i , j ) − f (xgi , yg j ) ng × ' ng

(2.19)

i=1 j =1

In TP01 we have called surfl with z’ instead of z to get the proper orientation of the surface plot. Example 2.6. Interpolate the test function F(x, y) = 0.75 exp(−(9x − 7)2/4 − (9y − 7)2)/4) + 0.75 exp(−(9x − 10)2/49 + (9y − 10)/10)

(2.20)

+ 0.5 exp(−(9x − 2)2/4 − (9y − 6)2)/4) − 0.2 exp(−(9x − 5)2 − (9y − 2)2)

at equally spaced grid points in the unit square using a bilinear spline. Discussion: We make use of the script TP01. The values to be interpolated are sampled from our test function franke2. This function is a rotated version of what is called Franke’s function in the literature; see Remark 2.1. We compute the spline using n equally spaced grid lines in both the x and the y variables. Using n = 5, 9, 17, 33, 65, and 129, we get a nested sequence of grids, where the grid spacing is halved at each step. Figure 2.2 shows plots of the resulting surfaces for n = 9 and n = 33. The following table gives the maximum and RMS errors on a 51 × 51 grid as a function of n. n 5 9 17 33 65 129

emax 2.11(−1) 1.00(−1) 2.92(−2) 6.90(−3) 1.73(−3) 4.30(−4)

rms 5.17(−2) 1.95(−2) 5.17(−3) 1.29(−3) 3.26(−4) 8.18(−5)

ratios 2.11 2.65 3.42 3.77 4.23 4.01 3.99 3.96 4.02 3.99

Since the ratio of errors is approaching 4, we are getting a quadratic convergence rate as is expected for bilinear splines, see section 2.10.

1 1 0.5

0.5 0 1

0 1 1 0.5

0.5 0 0

1 0.5

0.5 0 0

Figure 2.2. Plots of the bilinear splines interpolating Franke’s function on n × n equally spaced grids with n = 9 and n = 33; see Example 2.6.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

60

Chapter 2. Tensor-Product Splines

2.4.2 Tensor-product not-a-knot interpolation The bilinear spline interpolants in the previous section are only continuous. In this section we show how to get smoother interpolants using the not-a-knot approach discussed in ¯ we look for a solution section 1.4.3 for the univariate case. Given odd integers d and d, ¯ d−1 d−1 ¯ for some appropriate partitions of Problem 2.5 in the spline space Sd () ⊗ Sd¯ () ¯ ¯  and  of the intervals [a, b] and [a, ¯ b]. To get these partitions, let μ = (d + 1)/2 and μ¯ = (d¯ + 1)/2. Then with k := n − d − 1 and k¯ := n¯ − d¯ − 1, we define  := {a = x 0 < x 1 < · · · < x k+1 = b}, ¯ ¯ := {a¯ = y0 < y1 < · · · < yk+1  = b}, ¯ ¯ With these choices of knots, where x i = ti+μ for i = 1, . . . , k and y j = t¯j +μ¯ for j = 1, . . . , k. ¯ d−1 d−1 ¯ is n × n. ¯ it is easy to check that the dimension of Sd () ⊗ Sd¯ () ¯ d−1 d−1 ¯ in the tensor-product B-form (2.8). Now suppose we write s ∈ Sd () ⊗ Sd¯ () Then s will interpolate if and only if its matrix C of coefficients satisfies the system (2.18). Our choice of knots coupled with the Schoenberg–Whitney theorem (Theorem 1.8) ensures that both of the matrices M and M¯ appearing in the system are nonsingular. The following function produces the extended knot sequences as well as the coefficient matrix: [xe,ye,c] = notaknottp(d,db,t,tb,z) Here d and db are the degrees of the spline, and t and tb give the knots. The matrix z contains the values to be interpolated. The output includes the extended knot sequences xe and ye along with the coefficient matrix c. Example 2.7. Repeat Example 2.6 using bicubic not-a-knot splines. Discussion: We make use of our script TPnotaknot, which is a slight modification of the script TP01 given above. The following table gives the maximum and RMS errors on a 51 × 51 grid for the values n = 5, 9, 17, 33, 65. n 5 9 17 33 65

emax 2.78(−1) 3.78(−2) 1.95(−3) 7.29(−5) 3.87(−6)

rms 6.98(−2) 5.22(−3) 2.20(−4) 7.79(−6) 3.45(−7)

ratios 7.35 13.37 19.38 23.72 26.75 28.24 18.84 22.58

Since we are using bicubic splines, here we expect the order of approximation to be O(||4 ), where || is the maximal side length of the subrectangles of the partition; see section 2.10. Here we seem to be doing a little better. Figure 2.3 shows plots of the interpolating splines corresponding to n = n¯ = 5 and n = n¯ = 9. The first spline doesn’t have enough knots to fully capture the shape of this test function, but the second one is already an excellent fit.

2.5 Hermite interpolation In this section we discuss an interpolation problem which involves matching not only function values but certain derivative values as well. This is called Hermite interpolation. Here

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.5. Hermite interpolation

61

1.4

1.4

1

1

0.5

0.5

0 1

0 1 1

1 0.5

0.5

0.5

0.5 0 0

0 0

Figure 2.3. Plots of the cubic tensor-product not-a-knot splines with n = 5 and n = 9; see Example 2.7.

is the general problem. Suppose we are given m points a = t1 < · · · < tm = b and associated nonnegative integers k1 , . . . , km . Suppose we are also given m¯ points a¯ = t¯1 < · · · < t¯m¯ = b¯ ¯ let and associated nonnegative integers k¯1 , . . . , k¯m¯ . For each i = 1, . . . , m and j = 1, . . ., m, ν,μ k ,k¯

i j {z i j }ν=0,μ=0 be given real numbers.

¯ such that Problem 2.8. Find a function s defined on [a, b] ⊗ [a, ¯ b] ν = 0, . . . , ki , μ = 0, . . . , k¯ j ,

ν,μ ¯ Dxν D μ y s(ti , t j ) = z i j ,

(2.21)

for i = 1, . . . , m and j = 1, . . . , m. ¯ If ki = k¯ j = 0 for all i , j , the Hermite interpolation problem reduces to the Lagrange interpolation problem considered in the previous  section. There are a total of n × n¯ equa m¯ ¯ tions in (2.21), where n = m (k + 1) and n ¯ = i=1 i j =1 (k j + 1). Thus, we should look for a solution in an (n × n)-dimensional ¯ linear space. Let Sdr () be an n-dimensional space of splines defined on [a, b], and suppose {Nid+1 }ni=1 is the corresponding B-spline basis. Let ¯ and suppose { N¯ d¯+1 }n¯ is ¯ be an n-dimensional Sdr¯¯ () ¯ space of splines defined on [a, ¯ b], j =1 j the corresponding B-spline basis. We look for a solution of Problem 2.8 as a tensor-product ¯ Writing s in the tensor-product B-form (2.8), we get spline in the space Sdr () ⊗ Sdr¯¯ (). the following system of equations for the B-coefficients of s: M C M¯ T = Z ,

(2.22)

where M is the matrix in (1.27), M¯ is the corresponding matrix associated with the Bsplines in the y-variable, and Z is the following block matrix: ⎡

Z 11 ⎢ .. Z =⎣ . Z m1

··· ···

⎤ Z 1m¯ .. ⎥ , . ⎦ Z m m¯

(2.23)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

62

Chapter 2. Tensor-Product Splines

where for i = 1, . . . , m and j = 1, . . ., m, ¯ ⎡ z 0,0 ⎢ ij ⎢ 1,0 ⎢ zi j Z i j := ⎢ ⎢ .. ⎢ . ⎣ z ikji ,0

z i0,1 j

0,k¯ j

···

zi j

z i1,1 j

···

1,k¯ zi j j

z ikji ,1

···

z i ji



⎥ ⎥ ⎥ ⎥ .. ⎥ . . ⎥ ⎦

k ,k¯ j

To compute the Hermite interpolating spline, we need the matrices M and M¯ to be nonsingular. This can be checked using the extended Schoenberg–Whitney theorem (Theorem 1.12). The entries in M and M¯ can be computed using our function bsplder; see section 1.3.6.

2.5.1 Hermite bicubic spline interpolation In this section we consider a special case of Problem 2.8 where ki = 1, k¯ j = 1,

i = 1 . . . , m, j = 1 . . . , m. ¯

01 10 11 Here we have four pieces of data at each grid point, namely z i0,0 j , z i j , z i j , and z i j . To find ¯ where  = {t1 , . . . , tm } and a spline satisfying (2.21), we look in the space S31 () ⊗ S31 (), ¯ ¯ where n := 2(m − 2) + 4 =  = {t¯1 , . . . , t¯m¯ }. This space has the required dimension n × n, 2m and n¯ := 2(m¯ −2) +4 = 2m. ¯ We can compute the coefficients of the interpolating spline by solving the system (2.22), where now M is the matrix in (1.31), and M¯ is the analogous one constructed from the B-splines in the y-variable. The following function computes the bicubic Hermite interpolant.

[xe,ye,c] = cubhermtp(t,tb,z) Here z is the matrix of data values described in (2.23). This code returns the extended knot sequences xe and ye, along with the coefficient matrix c. Example 2.9. Explore the behavior of tensor-product cubic Hermite interpolation based on sample values of Franke’s function (2.20) and its first derivatives on a nested sequence of uniform m × m grids on the unit square. Discussion: We make use of our script TPcubherm, where the required function values and derivatives are computed from our test function franke2d. This function gives derivatives up to order 2, but we only make use of those up to order 1. The following table gives the maximum and RMS errors obtained for m = 5, 9, 17, 33, 65. m 5 9 17 33 65

emax 3.41(−2) 1.23(−2) 9.80(−4) 5.73(−5) 3.78(−6)

rms 8.11(−3) 1.20(−3) 7.45(−5) 4.80(−6) 3.00(−7)

ratios 2.77 6.76 12.55 16.11 17.10 15.52 15.16 16.00

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.5. Hermite interpolation

63

The order of convergence is O(||4 ), which is what we expect with tensor-product cubic splines; see section 2.10. Plots of these splines are very similar to those in Figure 2.3.

2.5.2 The clamped bicubic spline As another example of a Hermite interpolation problem, we consider the so-called clamped bicubic spline, which is a tensor-product analog of the univariate clamped cubic m¯ spline discussed in section 1.4.4. Suppose we are given values {z i j }m, i=1, j =1 on a grid defined ¯ by a = t1 < · · · < tm = b and a¯ = t¯1 < · · · < t¯m¯ = b. Here we want to use the tensor-product ¯ where  = {t1 , . . . , tm } and  ¯ = {t¯1 , . . . , t¯m¯ }. The dimension spline space S32 () ⊗ S32 (), of this space is n × n, ¯ where n = m + 2 and n¯ = m¯ + 2. But we only have m × m¯ pieces of data. So we have to add 2(m + m) ¯ + 4 conditions. A reasonable choice would be to interpolate the derivatives D y at the grid points along the top and bottom edges of the rectangle, and the derivatives Dx at the grid points along the left and right edges of the rectangle. For the last four data, we choose the twists Dx y at the four corners. Thus, we are looking for a ¯ such that spline s ∈ S32 () ⊗ S32() s(ti , t¯j ) = z i j and

for i = 1, . . ., m and j = 1, . . . , m, ¯

Dx s(ti , t¯j ) = z i10j

for i = 1, m and j = 1, . . ., m, ¯

D y s(ti , t¯j ) = z i01j

for i = 1, . . ., m and j = 1, m, ¯

Dx y s(ti , t¯j ) = z i11j

for i = 1, m and j = 1, m. ¯

This interpolation problem is a special case of the general Hermite interpolation problem of the previous section, where now k1 = k¯1 = km = k¯m¯ = 1 and k2 = · · · = km−1 = k¯2 = · · · = k¯m−1 = 0. The coefficient matrix of the interpolating spline can be found by solving ¯ the system (2.22). SplinePak contains the following function: [xe,ye,c] = cubclamptp(t,tb,z) Here z is the matrix of data values described in (2.23). This code returns the extended knot sequences xe and ye, along with the coefficient matrix c. Example 2.10. Explore the behavior of tensor-product clamped bicubic spline interpolation based on sample values of Franke’s function (2.20) on a sequence of uniform m × m grids on the unit square. Discussion: We make use of our script TPcubclamp. We get the needed derivative values from our test function franke2d. The following table gives the maximum and RMS errors obtained for m = 5, 9, 17, 33, 65. m 5 9 17 33 65

emax 7.70(−2) 4.03(−2) 1.98(−3) 7.29(−5) 3.87(−6)

rms 2.28(−2) 4.51(−3) 1.50(−4) 5.77(−6) 3.14(−7)

ratios 1.91 5.06 20.35 30.07 27.16 26.00 18.84 18.38

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

64

Chapter 2. Tensor-Product Splines

The ratios are about 16, which is what we expect for this bicubic spline method; see section 2.10.

2.6 Tensor-product quasi-interpolation In this section we show how to turn univariate quasi-interpolation methods into tensorproduct versions. Let Sdr () be an n-dimensional space of splines defined on an interval [a, b], and suppose {Nid+1 }ni=1 is the corresponding B-spline basis associated with an extended knot sequence x. ˆ Suppose {λi }ni=1 are bounded linear functionals based on pointevaluations at points in [a, b] such that the associated quasi-interpolation operator Q f (x) :=

n  (λi f )Nid+1 (x)

(2.24)

i=1

maps polynomials of degree d into themselves. To create a tensor-product quasi-interpolant, ¯ and let { N¯ d¯+1 }n¯ be ¯ is another spline space defined on the interval [a, suppose Sdr¯¯ () ¯ b], j =1 j the corresponding B-spline basis associated with an extended knot sequence yˆ . Suppose ¯ such {λ¯ j }nj¯=1 are bounded linear functionals based on point-evaluations at points in [a, ¯ b] that the associated quasi-interpolation operator Q¯ defined as in (2.24) maps polynomials of ¯ degree d¯ into themselves. Let  be the rectangle [a, b] ⊗ [a, ¯ b]. Theorem 2.11. For every f ∈ C(), let ¯ f (x, y) := (Q ⊗ Q)

n  n¯ 

¯

(λi λ¯ j f ) Nid+1 (x) N¯ d+1 (y). j

(2.25)

i=1 j =1

Then Q ⊗ Q¯ is a linear operator mapping C() into the tensor-product spline space ¯ p = p for all polynomials p in P 1 ⊗ P 1¯ . ¯ Moreover, (Q ⊗ Q) Sdr () ⊗ Sdr¯¯ (). d d Proof. The linearity is clear. Now suppose t is one of the points used in the construction of the linear function λi . Then for any p ∈ Pd1 ⊗ Pd1¯ , p(t, y) =

n¯ 

¯ (y), λ¯ j p(t, ·) N¯ d+1 j

j =1

where the dot means that we are applying the linear function λ¯ j to the second variable of p. We now form λi p by taking a combination of values at different points t. Then multiplying ¯ p = p. by Nid+1 and summing over i = 1, . . . , n, we see that (Q ⊗ Q) This approach allows for the construction of a wide variety of quasi-interpolants. However, if we want to get good approximation results, we need to make sure that both Q and Q¯ are locally bounded as described in Definition 1.52. Here we give just one example of a locally bounded bivariate quasi-interpolant. It uses bicubic splines, and requires only samples of a function f on a grid defined by equally spaced points a = t1 < · · · < tm = b and ¯ In particular, we use the tensor-product space S 2 () ⊗ S 2 (), ¯ where a¯ = t¯1 < · · · < t¯m¯ = b. 3 3

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.6. Tensor-product quasi-interpolation

65

¯ := {t¯1 , . . . , t¯m¯ }. This space has dimension n × n,  := {t1 , . . . , tm } and  ¯ where n = m + 2 and n¯ = m¯ + 2. Theorem 2.12. Let {λi }ni=1 be as in Theorem 1.25, and let {λ¯ j }nj¯=1 be the analogous linear ¯ Then functionals defined on C[a, ¯ b]. ¯ f (x, y) := (Q ⊗ Q)

n  n¯ 

(λi λ¯ j f ) Ni4 (x) N¯ j4 (y)

(2.26)

i=1 j =1

¯ p = p for ¯ and (Q ⊗ Q) maps C() into the tensor-product spline space S32 () ⊗ S32 (), 1 1 ¯ all polynomials p in P3 ⊗ P3 . Moreover, Q ⊗ Q is locally bounded. Proof. The first assertion follows easily from the proof of Theorem 1.25. To show the local boundedness, let Il := [xˆl , xˆl+1 ] and I¯l¯ := [ yˆl¯, yˆl+1 ¯ ] be subintervals in the partitions  and ¯ Then for any (t, t¯) ∈ Il × I¯l¯, .    l¯   l  4 4  ¯ ¯ ¯ |(Q × Q) f (t, t¯)| ≤  (λi λ j ) f Ni (t) N j (t¯) ¯ i=l−3 j =l−3

l l¯  

≤ max |λi λ¯ j f | l−3≤i≤l ¯ l−3≤ j ≤l¯

|Ni4 (t) N¯ j4 (t¯)|

¯ i=l−3 j =l−3

≤ max |λi λ¯ j f |, l−3≤i≤l ¯ l−3≤ j ≤l¯

where we have used the partition of unity property of the B-splines. It remains to estimate the size of the quantities |λi λ¯ j f |. The linear functionals λi and λ¯ j involve samples of f at only a small number of the grid points. For example, for i = 3, . . ., n − 2 and j = 3, . . ., n¯ − 2, it is clear that λi λ¯ j f is a combination of the values of f at the nine grid points {ti−2 , ti−1 , ti } ⊗ {t¯j −2 , t¯j −1 , t¯j }, and is formed by summing the values of f at these points multiplied by the weights 1 36 8 − 36 1 36

8 − 36 64 36 8 − 36

1 36 8 − 36 1 36

Note that these weights sum to one, which is needed for λi λ¯ j f = 1 for the function f ≡ 1. Now examining the various cases, we get max |λi λ¯ j f | ≤ 4 f  Jl × J¯l¯ ,

l−3≤i≤l ¯ l−3≤ j ≤l¯

with Jl := [yl−3 , yl+4 ] and J¯l¯ := [ y¯l−3 ¯ , y¯l+4 ¯ ], and we have established the local bounded¯ ness of Q ⊗ Q.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

66

Chapter 2. Tensor-Product Splines

Here is our function for this quasi-interpolation method: [xe,ye,c] = cubquasitp(t,tb,z) The matrix z contains the samples of f at the grid points. This code returns the extended knot sequences xe and ye, along with the coefficient matrix c. Example 2.13. Explore the behavior of tensor-product bicubic quasi-interpolating splines for the function (2.20) on a sequence of m × m uniform grids on the unit square. Discussion: We make use of our script TPcubquasi. The following table gives the maximum and RMS errors obtained for m = 5, 9, 17, 33, 65: m 5 9 17 33 65

emax 2.10(−1) 6.18(−2) 9.21(−3) 7.31(−4) 5.10(−5)

rms 6.31(−2) 1.01(−2) 1.06(−3) 7.97(−5) 5.27(−6)

ratios 3.40 6.25 6.71 9.53 12.59 13.30 14.33 15.12

The ratios are around 16, which is what we expect for this bicubic spline method; see section 2.10. We do not give plots here as they are similar to those in Figure 2.3.

2.7 Tensor-product discrete least-squares As in the univariate case, there are two data fitting situations where interpolation is usually not advisable: 1) when there are a large number of data points, 2) when the measurements are subject to noise. In this section we discuss an alternative to interpolation which is generally more suitable in such situations. d ,n¯ d Suppose we are given samples {z i j }ni=1, j =1 of a bivariate function f on an n d × n¯ d ¯ Our aim grid defined by grid lines at a = t1 < · · · < tnd = b, and a¯ = t¯1 < · · · < t¯n¯ d = b. ¯ where is to approximate f by a tensor-product spline. We look for s ∈ Sdr () ⊗ Sdr¯¯ (), ¯ 0 ≤ r < d and 0 ≤ r¯ < d are given integers, and where  = {a = x 0 < x 1 < · · · < x k+1 = b} ¯ are partitions of [a, b] and [a, ¯ respectively. Let ¯ = {a¯ = y0 < y1 < · · · < yk+1 and  = b} ¯ b], ¯ r r ¯ ¯ n × n¯ be the dimension of Sd () ⊗ Sd¯ (). We suppose n d ≥ n and n¯ d ≥ n. ¯ In practice, the number of data points n d × n¯ d is usually much larger than the dimension n × n¯ of the spline space. We now formulate the following discrete least-squares problem. ¯ that minimizes Problem 2.14. Find s ∈ Sdr () ⊗ Sdr¯¯ ()

2 (s) :=

n¯ d nd   ν=1 μ=1

[s(tν , t¯μ ) − z νμ ]2 .

(2.27)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.7. Tensor-product discrete least-squares

67

To find a solution of this problem, suppose we write s in the tensor-product B-form (2.8), where {Nid }ni=1 are the B-splines of degree d forming a basis for the spline space ¯ Sdr (), and { N¯ jd }nj¯=1 are the B-splines of degree d¯ forming a basis for the spline space ¯ Sdr¯¯ (). n

d Theorem 2.15. Suppose that the points {ti }i=1 satisfy condition (1.44) for the B-splines n¯ d d+1 n and the B{Ni (x)}i=1 . Suppose the analogous condition holds for the points {t¯j } j =1 ¯ d+1 n¯ r r ¯ ¯ ¯ solving Probsplines { N j (y)} j =1. Then there is a unique spline s ∈ Sd () ⊗ Sd¯ () lem 2.14, and its coefficient matrix C is the solution of the nonsingular linear system

G C G¯ T = H ,

(2.28)

where G is the Gram matrix in (1.45), G¯ is the analogous matrix formed from the B-splines in the y-variable, and Hi j :=

n¯ d nd  

z νμ Nid+1 (tν ) N¯ dj +1 (t¯μ ) ¯

for i = 1, . . . , n and j = 1, . . ., n. ¯

(2.29)

ν=1 μ=1

Proof. We know from Theorem 1.28 that under these hypotheses, both G and G¯ are nonsingular, and in fact are symmetric and positive definite. It follows that there is a unique solution of (2.28) for any H . Suppose C satisfies (2.28), and let s be the corresponding spline. To see that s is the least-squares fit to the data, we cast the problem as an approximation problem in the linear space C() with the discrete inner product  f , g :=

n¯ d nd  

f (tν , t¯μ ) g(tν , t¯μ ).

ν=1 μ=1

It is well known from results on approximation in inner-product spaces that a function ¯ is a best approximation of f from S r () ⊗ S r¯¯ () ¯ with respect to the s ∈ Sdr () ⊗ Sdr¯¯ () d d norm associated with this inner product if and only if , + ¯ for all i = 1, . . ., n and j = 1, . . . , n. ¯ s − f , Nid+1 N¯ dj +1 = 0 See Lemma 16 in [Boo79]. This system of equations is equivalent to (2.28). ¯ and To program tensor-product least squares, we need to set up the matrices G, G, H appearing in (2.28). This is just a matter of evaluating B-splines at the grid points, which can be done with the function bspl described in section 1.3.6, and computing the necessary sums. We have the following implementation: c = lsqtp(d,db,xe,ye,t,tb,z) Here z is the matrix of samples of f and xe and ye are the extended knot sequences defining the tensor-product spline space. The function returns the coefficient matrix c.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

68

Chapter 2. Tensor-Product Splines

Example 2.16. Explore the behavior of bicubic discrete least-squares splines based on samples of Franke’s function (2.20) on a 201 × 201 uniform grid on the unit square. Discussion: We make use of our script TPlsq, where the values to be fit are computed from our test function franke2. The following table gives the maximum and RMS errors obtained using bicubic splines with m equally spaced knot lines in each variable. We choose m = 5, 9, 17, 33, 65, 129 to get a sequence of nested partitions where the mesh size is reduced by one-half at each step. m 5 9 17 33 65 129

emax 8.76(−2) 2.79(−2) 1.19(−3) 4.39(−5) 1.94(−6) 7.69(−8)

rms 1.50(−2) 3.66(−3) 1.02(−4) 3.34(−6) 1.70(−7) 8.73(−9)

ratios 3.14 4.10 23.45 35.88 27.11 30.54 22.63 19.65 25.23 19.47

These ratios are around 16, which suggests that we have cubic convergence as is to be expected for a bicubic spline method when using a sufficient number of well-spaced data; see section 2.10.

2.8 The effect of noise In practical data fitting situations, the measurements are almost always contaminated by noise. This can have a drastic effect on the performance of any spline interpolation method. Noise also has an effect on least-squares spline fits, although if the number of data points is sufficiently large compared to the dimension of the spline space, often much of the effects of noise can be removed. The best way to understand the role of noise is to look at some examples where the samples are given by z i j = f (ti , t¯j ) + i j ,

1 ≤ i ≤ n,

1 ≤ j ≤ n, ¯

(2.30)

where f is the function we are trying to fit. First we look at an example involving interpolation. Example 2.17. Find the bicubic not-a-knot spline that interpolates the test function √ # 2 2 $−1/2 f (x, y) = 1 + 2e20.1−27 x +y (2.31) at the points of a 201 × 201 uniform grid, but with added noise for each sample. Discussion: We make use of our script TPnotaknotnoise. It samples our test function sigmoid, which is an implementation of (2.31). These samples are then corrupted to get the data values (2.30) by adding noise values i j = ε ri j , where ri j are uniformly distributed random numbers lying in the interval [−1, 1]. Rather than generating random numbers ri j in the script, we read them from our file noise.dat. This ensures the reproducibility of the experiment. Here we take ε = .1, and so the maximum noise is approximately 1/10 of the maximum height of f on the unit square. The resulting spline is shown in Figure 2.4 (left). It exhibits very bad oscillations. The maximum and RMS errors on a 51 × 51 grid are 1.00(−1) and 5.98(−2). This should be compared with the excellent fit obtained without noise, which has errors on the order 10−16 on a 301 × 301 grid.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.9. Penalized least-squares approximation

1

69

1

0.5 0 0 1

1 1 0.5 0

1 0.5

0.5

0.5 0

0

0

Figure 2.4. Fits to the test function (2.31) based on noisy measurements on a 201 × 201 grid. Left: The bicubic not-a-knot spline. Right: The bicubic least-squares fit with 17 equally spaced knot lines in each variable.

This example shows that interpolating noisy data is a bad idea. Here we illustrated this with the bicubic not-a-knot interpolant, but we will get similar results with any of the other interpolating methods discussed above. We now explore what happens if we find a least-squares fit instead. Example 2.18. Find a bicubic spline approximation to the test function (2.31) based on noisy samples on a 201 × 201 uniform grid on the unit square  := [0, 1]2. Use 17 equally spaced knots in each variable. Discussion: We make use of our script TPlsqnoise which again calls on the function sigmoid to generate the data. Noise is added as in Example 2.17 with ε = .1. The resulting least-squares spline is shown in Figure 2.4 (right). The maximum and RMS errors for this spline approximant are 3.57(−2) and 4.46(−3), respectively. With ε = 0, i.e., without noise, the least-squares fit gives errors of 2.47(−3) and 4.90(−4). So the addition of noise has resulted in a clear loss of accuracy, and the surface shows significant unwanted oscillations. This example shows that while the least-squares method has the effect of smoothing out some of the noise, we still have unwanted oscillations. In the next section we discuss a method which can help remove even more of the noise.

2.9 Penalized least-squares approximation In the previous section we saw that noisy data can affect the quality of least-squares fits by tensor-product splines. In this section we discuss a useful method for dealing with this problem. Suppose we are given the same data and spline space as in section 2.8. Given ¯ we define its energy to be the quantity s ∈ Sdr () ⊗ Sdr¯¯ (),  E(s) :=

b  b¯

a

We now pose the following problem.



[Dx2 D 2y s(x, y)]2 d x d y.

(2.32)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

70

Chapter 2. Tensor-Product Splines

¯ that minimizes Problem 2.19. Fix λ ≥ 0. Find s ∈ Sdr () ⊗ Sdr¯¯ () n¯ d nd  1  λ (s) := [s(tν , t¯μ ) − z νμ ]2 + λ E(s). n d n¯ d

(2.33)

ν=1 μ=1

The first term in (2.33) is the same measure of discrepancy that we used in the leastsquares problem (Problem 2.14), except that now we have normalized it by dividing by the number of data points n d n¯ d . The second term in (2.33) is a penalty term that forces the spline to have small energy. The parameter λ controls the balance between energy and goodness of fit. If λ = 0, we get the discrete least-squares spline. As we increase λ, we will get smoother and smoother splines, but with a possible loss of accuracy. Choosing the parameter λ is a nontrivial problem, but with a proper choice, we can get a spline which is both smooth and accurate. In practice, good values of λ will be quite small, as shown in the experiments below. A solution s of Problem 2.19 is called a penalized least-squares spline. To find s, we ¯ write it in B-form as in (2.8), where {Nid+1 }ni=1 and { N¯ dj +1 }nj¯=1 are the B-splines forming ¯ respectively. bases for the spline spaces Sdr () and Sdr¯¯ (), Theorem 2.20. Suppose n d , n¯ d ≥ 3, d > r ≥ 2, and d¯ > r¯ ≥ 2. Then for any λ > 0, there is ¯ solving Problem 2.19. Moreover, its coefficient matrix a unique spline s ∈ Sdr () ⊗ Sdr¯¯ () C is the solution of the nonsingular linear system ¯ T = H, (G + n d λE) C (G¯ + n¯ d λ E) ¯ and H are as in Theorem 2.15, and where G, G,  b E i j := Dx2 Nid (x) Dx2 N jd (x) d x, 

i , j = 1, . . . , n,

a



E¯ i j := a¯

(2.34)

(2.35) ¯ ¯ D 2y N¯ id (y) D 2y N¯ jd (y) d y,

i , j = 1, . . . , n. ¯

Proof. Note that G and E are the same matrices as in Theorem 1.33 in the univariate case. The matrices G¯ and E¯ are just the analogs with respect to the y-variable. It follows from Theorem 1.33 that under the hypotheses of this theorem, G + n d λE is symmetric ¯ The fact and positive definite, and hence is nonsingular. The same holds for G¯ + n¯ d λ E. that the spline corresponding to the coefficients obtained from (2.34) is the solution of Problem 2.19 follows by the same inner-product space arguments used in the proof of Theorem 2.15. We have implemented penalized least-squares in the function C = penlsqtp(d,db,xe,ye,lam,t,tb,z) Here z is the matrix of samples of f . This code returns the coefficient matrix C. Example 2.21. Given noisy samples of the test function (2.31) on a 201 × 201 grid, use penalized-least squares to find a bicubic spline fit based on 17 equally spaced knots in each variable.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.9. Penalized least-squares approximation

71

1.2 1 0.4

0 1

-0.6 1 1 0.5 0

1 0.5

0.5

0.5 0

0

0

Figure 2.5. Fits to the test function (2.31) based on noisy measurements on a 201 × 201 grid using a bicubic penalized least-squares spline with 17 equally spaced knots in each variable, and with λ = .00001 and λ = .1; see Example 2.21.

Discussion: We make use of the script TPpenlsq, using the same noisy data on a 201 × 201 grid as in Example 2.18 with ε = .1. The following table gives the maximum and RMS errors for selected values of λ. λ 0 1.0(−7) 1.0(−6) 1.0(−5) 1.0(−4) 1.0(−3) 1.0(−2) 1.0(−1)

emax 3.57(−2) 1.988(−2) 1.621(−2) 2.449(−2) 7.751(−2) 1.710(−1) 2.383(−1) 5.656(−1)

rms 4.456(−3) 4.027(−3) 3.397(−3) 5.840(−3) 2.390(−2) 6.661(−2) 1.160(−1) 1.646(−1)

For λ = 0, we get the least-squares fit shown in Figure 2.4 (right). It has undesirable oscillations. Even a very small value of λ improves the shape of the fit, and as the table shows, it also improves the errors. Some experimentation shows that the minimum RMS error occurs for λ around 1.5(−6). However, the corresponding surface still shows some effect of the noise. It can be removed with a slightly larger value of λ with almost no loss in accuracy. The surface shown in Figure 2.5 (left) corresponds to λ = 1.0(−5). Making λ still larger makes the surface even smoother, but with some loss of accuracy. The energy term E(s) appearing in (2.33) becomes zero when s is a bilinear polynomial. Thus, for large values of λ, we expect s to tend to a bilinear function. Figure 2.5 (right) shows the surface for λ = .1. The problem of selecting an optimal value of λ for penalized least-squares fitting is nontrivial. When we know the true function, we can experiment with values of λ and observe the tradeoff between accuracy and smoothness. Indeed, by computing fits for a set of λ values, we can find a good estimate of the value of λ that delivers the least RMS error. This process is aided by the fact that if we plot the RMS error versus λ, we get a convex shaped curve with a clear minimum. Figure 2.6 shows this curve for Example 2.21. It was produced with the script TPpenlsqg. When the true function is not known, we have to

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

72

Chapter 2. Tensor-Product Splines × 10-3 4.4

4

3.6

3.2 0

1

2

3

4

5 10-6

Figure 2.6. Plot of the RMS error in Example 2.21 for a range of λ values in the interval [0, .000005].

resort to more complicated methods for getting a good value of λ. These usually involve some form of cross validation; see Remark 2.22.

2.10 Error bounds In this section we discuss error bounds for approximation and interpolation with tensorproduct splines defined on a rectangle . We focus only on the maximum norm defined by  f  := max | f (x, y)|. (2.36) (x,y)∈

There are analogous results in the standard L p norms. Suppose  is partitioned into sub¯ := {a¯ = rectangles using the univariate partitions  := {a = x 0 < · · · < x k+1 = b} and  ¯ Our bounds will involve the mesh sizes of  and  ¯ defined by = b}. y0 < · · · < yk+1 ¯ || = max (x i+1 − x i ), 1≤i≤k

¯ = max (y j +1 − y j ). ||

(2.37)

1≤ j ≤k¯

2.10.1 The approximation power of tensor-product splines ¯ are univariate spline spaces defined on the intervals [a, b] and Suppose Sdr () and Sdr¯¯ () ¯ [a, ¯ b], respectively. We have the following result concerning the approximation power of the corresponding tensor-product spline space. See Theorem 12.7 in [[Schum81]] for a proof. ¯ ¯ Then Theorem 2.22. Suppose f ∈ C k+1,0 () ∩ C 0,k+1 () with 0 ≤ k ≤ d and 0 ≤ k¯ ≤ d. ¯ such that there exists a spline s ∈ Sdr () ⊗ Sdr¯¯ () ¯ ¯ ¯ k+1 D k+1 f ),  f − s ≤ K (||k+1 Dxk+1 f  + || y

where the constant K depends only on d.

(2.38)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.11. Remarks

73

It is worth noting that the error bound in (2.38) consists of separate terms involving the mesh sizes in the x and y directions, and smoothness of f in those variables. It should also be pointed out that the highest exponents that work in this bound are d + 1 and d¯ + 1, respectively, regardless of how smooth the function might be. It is also possible to get bounds showing that splines simultaneously approximate the partial derivatives of f . Here is a typical such theorem which uses the semi-norm j

| f |k+1,k+1 := max Dxi D y f  ¯ 0≤i≤k+1 ¯ 0≤ j ≤k+1

(2.39)

to measure the smoothness of a bivariate function defined on a rectangular domain . ¯

¯ Then there exists Theorem 2.23. Suppose f ∈ C k+1,k+1 () with 0 ≤ k ≤ d and 0 ≤ k¯ ≤ d. ¯ such that a spline s ∈ Sdr () ⊗ Sdr¯¯ () ¯ k+1−ν ¯ k+1−μ Dxν D μ + || ) | f |k+1,k+1 ¯ y ( f − s) ≤ K (||

(2.40)

¯ The constant K depends only on d. for all 0 ≤ ν ≤ min(r , k) and 0 ≤ μ ≤ min(¯r, k). We emphasize that these error bounds only state the existence of splines with the stated approximation properties. Interpolation and approximation methods have to be carefully designed to achieve this level of approximation power.

2.10.2 Error bounds for interpolation and approximation In Chapter 1 we gave error bounds for linear, not-a-knot, cubic Hermite, and clamped cubic interpolation, as well as for cubic quasi-interpolation. All of these error bounds can be extended to the tensor-product case. For a recent treatment of how to do this, see [SchumW13]. Except for the not-a-knot interpolant, the constants in the bounds depend only on the degrees of the splines used. For not-a-knot interpolation, the constant depends on the global mesh ratio σd, defined in (1.68) and its analog in the y-variable σd,¯ ¯ . The error bound in section 1.13.8 for discrete least-squares approximation with splines can also be carried over to the tensor-product case, but now we need the condition (1.73) on the density of the data to hold in both the x and the y variables.

2.11 Remarks Remark 2.1. The test function defined in (2.20) is a rotated version of a function first introduced by Richard Franke in [Fra79] for use as a test of scattered data fitting methods, and is by now a standard test function in the literature. The unrotated version is included in MATLAB as the built-in function franke. As originally defined, it has peaks near zero which tend to obscure the rest of the surface when viewed from the standard initial MATLAB viewing angle. Thus, we have defined a new function franke2 which corresponds to the change of variables (x, y) → (1 − x, 1 − y). Remark 2.2. Our package also includes the function franke2d which differs from franke2 in that it also produces values of (mixed) partial derivatives up to order two.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

74

Chapter 2. Tensor-Product Splines

In particular, a call on franke2d gives a vector with six components, namely the values of f , f x , f y , f x x , f x y , f yy at the evaluation point. This test function was used above in examples where derivative values are required. If called with an n-vector of values, it produces an n matrix of values. Remark 2.3. It is relatively easy to extend the methods here to functions of m variables defined on a tensor-product domain  := ⊗m i=1 [ai , bi ]. In three dimensions,  is a box. We have restricted our discussion to two variables for simplicity. Indeed, the main difficulty in working with more variables is just the notation. Remark 2.4. In this chapter we have restricted our attention to tensor products of univariate spline spaces of the form Sdr (), rather than more general spline spaces with variable smoothness at the interior knots. However, virtually everything in this chapter carries over easily for spline spaces associated with general extended knot sequences as in Remark 1.1. Remark 2.5. As in the univariate case, some of the formulae and computational algorithms for tensor-product splines simplify in the case where the knots are equally spaced; see, e.g., [[Boo78, Schum81]]. However, generally the savings in computational time is not worth the extra programming effort. Remark 2.6. In working with tensor-product splines, we strongly recommend using the B-form described in section 2.3. An alternative is to work with the individual polynomial pieces. For a discussion of conversion between the two representations, see [[Boo78]]. Remark 2.7. There is an alternative approach to evaluating a tensor-product spline that may be slightly more efficient than the method described in section 2.3.1. Consider the univariate splines n¯  ¯ si (y) := ci j N¯ dj +1 (y), i = 1, . . ., n, (2.41) j =1

¯ We can evaluate them at the point y with n calls on the defined on the interval [a, ¯ b]. function sval described in section 1.3.2. Now since s(x, y) =

n 

si (y)Nid+1 (x),

i=1

we can get the value of s(x, y) with one additional call to sval with (s1 (y), . . ., sn (y)) as the coefficient vector. Remark 2.8. The clamped bicubic spline discussed in section 2.5.2 is often called the complete bicubic spline in the literature. It has been extensively studied along with the natural bicubic spline, which is the tensor-product analog of the univariate natural cubic spline; see Remark 1.6. We have not discussed the tensor-product natural spline here, since as in the univariate case, the error bounds require conditions on the uniformity of the mesh. Remark 2.9. In our discussion in section 2.5 of Hermite interpolation with tensor-product splines, we have required that at each grid point we have a consecutive set of derivatives, i.e., with no gaps. As in the univariate case (see Remark 1.7), it is possible to allow gaps. This is referred to as Hermite–Birkhoff interpolation.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.11. Remarks

75

Remark 2.10. The tensor-product quasi-interpolation method of section 2.6 is based on samples of a function on a grid. As in the univariate case (see Remark 1.10), it is also possible to define quasi-interpolants based on samples of derivatives and/or local integrals; see, e.g., [BooF73, LycS75] and the books [[Boo78, Schum81]]. Remark 2.11. Perhaps the simplest example of a tensor-product quasi-interpolating spline defined on C[a, b] is Q f (x, y) :=

n  n¯ 

¯ f (ξi , ξ¯j )Nid+1 (x) N¯ d+1 (y), j

(2.42)

i=1 j =1

where the sample points are the Greville points computed from the extended knot sequences xˆ and yˆ by ξi := (xˆi+1 + · · · + xˆi+d−1 )/(d − 1) and ξ¯j := ( yˆ j +1 + · · · + yˆ j +d−1 ¯ )/(d¯ − 1); see Remark 1.11 for the univariate case. This quasi-interpolant reproduces bilinear polynomials, and has approximation order two. Remark 2.12. The tensor-product quasi-interpolant discussed in section 2.6 is not a projector. As discussed for the univariate case in Remark 1.12, to get a quasi-interpolant which is a projector, for each 1 ≤ i ≤ n, we have to choose all of the sample points used to construct λi in one subinterval of the partition, and the analogous condition must hold for the ¯ this would require λ¯ j . To get full approximation power using splines of degrees d and d, putting (d + 1) × (d¯ + 1) sample points in one subrectangle contained in the support of each tensor-product B-spline. Remark 2.13. The first term in the definition of λ (s) in (2.33) is equal to nd1n¯ d times the sum of squares 2 (s) introduced in (2.27) for the least-squares problem. We have introduced the factor here so that we get a combination of average squared error to balance against energy. Remark 2.14. In all of the examples in this chapter we have worked on the unit square with equally spaced knots. However, our programs all work on arbitrary rectangles, and there is no need for the knots to be equally spaced. Indeed, in some applications it may be advantageous to use nonuniform knots, possibly with a different number in each variable. ¯ but again the codes work for general values. We might want Our examples also use d = d, to use different degrees if the function being fitted is less complex in one of the variables. Remark 2.15. In section 1.11 we discussed some strategies for choosing good knots for univariate least-squares spline fitting. These methods can be carried over to the tensorproduct case. Remark 2.16. If we perform penalized least-squares approximation as in section 2.9 using ¯ with knots at the sample points and with natural end conditions, the space S32 () ⊗ S32 () we get what is called a tensor-product smoothing spline in the literature. Remark 2.17. It is straightforward to generalize the idea of penalized least-squares fitting discussed in section 2.9 in various ways. For example, we can replace the term measuring the goodness of fit in terms of a sum of squared errors by some other measure of goodness  d n¯ d ¯ of fit such as an 1 expression of the form nd1n¯ d ni=1 j =1 |s(ti , t j ) − z i j |. In addition, we could replace the penalty term measuring the smoothness of the fit by some other quadratic functional involving the integral of some other combination of derivatives.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

76

Chapter 2. Tensor-Product Splines

Remark 2.18. In Remark 1.14 we mentioned the idea of optimal recovery with univariate splines. This idea can also be carried over to the tensor-product setting. Remark 2.19. Tensor-product splines can be used to solve boundary-value problems on rectangular domains based on either collocation or the Ritz–Galerkin method; see [[Boo78, Schul73, Pre75]]. Remark 2.20. Tensor-product splines are also used heavily in computer-aided geometric design (CAGD) to represent surfaces. For an early paper, see [Rie73]. This generally involves working with surfaces in parametric form (x(t, t¯), y(t, t¯), z(t, t¯)), where x, y, z are all tensor-product splines defined on some reference rectangle. Closed surfaces can be obtained by using periodic splines. For details on these applications, see any of the standard CAGD books such as [[Far88, HosL93, CohRE01, PraBP02]]. Remark 2.21. In many CAGD applications, the tensor-product splines are used to form associated piecewise rational functions called tensor-product NURBS. For details, see standard CAGD books such as those listed in the previous remark. Remark 2.22. There is an automated procedure for estimating a good value for the parameter λ used in the penalized least-squares method discussed in section 2.9. It is known as generalized cross validation, and requires solving the problem several times while removing one or more data points. For details, see [[Wah90]]. Remark 2.23. For some work on tensor-product spline fitting with shape constraints, see [CarlF85, CarlF89, CostF90, CarlF91, Jut97, Bel00]. Fitting of contours using tensorproduct splines was studied in [HessLPP72, DieSV88], while data on a family of lines was treated in [AndCM93]. Tensor-product splines have even been used for fitting data on the sphere [Die84, Die87, SchumT91, LycS00]. Remark 2.24. Tensor-product splines also play a role in statistics, for example for density fitting, histogram fitting, hazard estimation, and nonparametric estimation. The literature is too vast to quote here, but for two early papers on histograms, see [Scho73, Boo73b]. For more on the role of splines in statistics, see the book [[Wah90]] and references therein. Remark 2.25. It is possible to construct wavelets associated with tensor-product splines. For an introduction to the theory, see [[Chu92]] and references therein. Since then, many other books have been written. Such wavelets have been be used for both image compression and image registration. For a recent book with MATLAB programs, see [[AveNZ14]]. Remark 2.26. Tensor-product splines can also be used in the numerical solution of PDE’s. They were used with the finite-element method for elliptic boundary-value problems in [BirSV68, Schul69, Schul70, Schul71, BiaC94]; see also the books [[Schul73, Pre75]]. Recently, they have also been modified for use in the finite-element method on nonrectangular domains; see [HolRW01, HolRW01b, HolRW02] and the book [[Hol03]].

2.12 Historical notes Tensor products have been used for many years for converting univariate approximation and interpolation methods to bivariate methods; see, e.g., the book [[LightC85]] and references therein. Many of the early papers on splines also discussed the tensor-product case, often

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

2.12. Historical notes

77

in terms of bicubic splines; for example, see [TheS61, Boo62, BirB64, AhlNW65, BirB65, BirSV68, Hall68, Bir69, Schul69c, Schul69f, Varg69, Zav69]. They are treated in detail in the books [[Schul73, Pre75, Boo78, Schum81]], as well as in several other early books on splines. Quasi-interpolation with tensor splines was studied in [BooF73, LycS75]. Computation with tensor-product splines became even more attractive once it was realized that they could be dealt with efficiently using only univariate methods; see [Boo79]. For some books with examples of computation with tensor-product splines, see [[Boo78, Die93, Spa95b]].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 3

Computing with Triangulations

In this chapter we discuss various techniques for dealing with triangulations computationally, including how to store, construct, and refine them.

3.1 Triangulations While it is intuitively clear what a triangulation is, there is not general agreement in the literature about a formal definition. In this book we adopt the definition used in [[LaiS07]]. Definition 3.1. A-collection  := {T1 , . . . , Tnt } of triangles in the plane is called a triannt i=1 Ti , provided that if a pair of triangles in  intersect, then their intersection is either a common vertex or a common edge.

gulation of  =

Figure 3.1 shows a triangulation with eight vertices. Definition 3.1 allows quite general triangulations. For example,  may consist of two triangles which are completely separated, or it may consist of two triangles which touch only at a vertex. Moreover, the definition also allows triangulations of domains  with one or more holes as shown in Figure 3.2.

3.2 Triangulations with hanging vertices According to Definition 3.1, the configuration of triangles in Figure 3.3 is not a triangulation. However, it could be considered as a triangulation with a hanging vertex. Trian-

Figure 3.1. A triangulation with eight vertices.

79

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

80

Chapter 3. Computing with Triangulations

Figure 3.2. A triangulation with a hole.

Figure 3.3. An example of a set of triangles which form a triangulation with a hanging vertex. Reprinted with permission from Cambridge University Press [[LaiS07]].

gulations with hanging vertices are useful in some applications, particularly in the finiteelement method; see Remark 3.2. We shall not discuss such triangulations further in this book, although most of the results and algorithms presented here can be adjusted to work with triangulations with hanging vertices.

3.3 Storing and plotting triangulations According to our definition, a triangulation is uniquely determined by 1) the numbers n v and n t of vertices and triangles, 2) vectors x and y such that (x i , yi ) are the Cartesian coordinates of the i th vertex, 3) an n t × 3 matrix TRI such that the three entries in the i th row are the indices of the vertices of the i th triangle. To store a triangulation in a computer, we simply store this information. With it, we can plot a triangulation by drawing the edges connecting the vertices of each triangle. MATLAB contains the built-in function triplot for plotting triangulations. The following script inputs and plots a triangulation: % Btriplot [nv,x,y,nt,TRI] = readtri; triplot(TRI,x,y); The function readtri is used to read a triangulation from a data file. It inputs the number nv of vertices along with their coordinate vectors x and y. It also inputs the number nt of triangles, and a nt x 3 matrix giving the indices of the triangles.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.4. Additional data structure for triangulations

81

As a test, we can run Btriplot with our data file trihole36.dat to get the plot shown in Figure 3.2, but without the shading. For this example the hole is visible without the shading, but if a triangulation has a triangular-shaped hole, we would not be able to see it without shading.

3.4 Additional data structure for triangulations In implementing algorithms for dealing with splines on a triangulation , we usually need information about the structure of  beyond the basic information contained in the matrix TRI of the previous section. We will make use of the following: nb = number of boundary vertices, nv = number of vertices, ne = number of edges, nt = number of triangles, bdy = a list marking the boundary vertices, v1,v2,v3 = lists of the indices of the vertices of each triangle, e1,e2,e3 = lists of the indices of the edges of each triangle, area = a list giving the area of each triangle, ie1,ie2 = lists of the endpoints of each edge, tril= a list of the indices of the triangles to the left of each edge, trir = a list of the indices of the triangles to the right of each edge, vadj = a linked list of the vertices adjacent to each vertex, eadj = a linked list of the edges adjacent to each vertex, adjstart = a list of pointers to the starts of the groups in vadj, eadj, tadj = a linked list of the triangles adjacent to each vertex, tstart = a list of pointers to the starts of the groups in tadj. All of this information can be computed directly from the basic data structure of the previous section. We have written the following function to accomplish this. It produces all the essential information needed to work effectively with splines on triangulations. [nb,ne,nt,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy,vadj,... eadj,adjstart,tadj,tstart,area,TRI] = ... trilists(x,y,TRI) This function uses the following conventions: • For each i , bdy(i) = 1 denotes a boundary vertex, and bdy(i) = 0 denotes an interior vertex. • The vectors v1,v2,v3 are extracted from the columns of TRI to ensure that the vertices v1(i),v2(i),v3(i) appear in counterclockwise order. This orients the triangles so that they have a positive area.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

82

Chapter 3. Computing with Triangulations

• The edge indices e1(i),e2(i),e3(i) also appear in counterclockwise order, where the first edge e1(i) has endpoints v1(i),v2(i). • Each edge is oriented in the sense that ie1(i) < ie2(i). This defines left and right for the lists tril and trir. • For each i , adjstart(i) points into the arrays vadj and eadj to the first entry associated with vertex i . We set adjstart(nv+1) = # vadj + 1. • The integers in the i th group in vadj are the indices of the vertices connected to the i th vertex, listed in counterclockwise order. • The integers in the i th group in eadj are the indices of the edges connected to the i th vertex, listed in counterclockwise order. • tstart(i) points into tadj to the first entry associated with vertex i . We set tstart(nv+1) = # tadj + 1. • The integers in the i th group in tadj are the indices of the triangles attached to the i th vertex, listed in counterclockwise order. Note that the number of triangles attached to a boundary vertex is one less than the number of attached edges, while the number of triangles attached to an interior vertex is equal to the number of attached edges, which is also the number of attached vertices. Example 3.2. Test the function trilists with the data file tri8.dat. Discussion: We can use our script Btridemo which prompts for the name of a data file, and then reads the triangulation from it. Then it calls on trilists. For the file tri8.dat, we get nb = 6, ne = 15, nt = 8, and bdy = (1, 1, 1, 1, 0, 0, 1, 1). We list the other output (except for the adjacency lists) in Table 3.1. According to this table, the Table 3.1. Output of trilists for the data file tri8.dat.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15

v1 1 1 2 2 4 5 6 3

v2 4 5 5 6 7 7 7 6

v3 5 2 6 3 5 6 8 8

e1 1 2 4 5 9 11 13 7

e2 10 4 12 7 11 13 15 14

e3 2 3 5 6 10 12 14 8

area .1000 .1000 .1300 .1325 .1000 .1250 .1900 .1225

i e1 1 1 1 2 2 2 3 3 4 4 5 5 6 6 7

i e2 4 5 2 5 6 3 6 8 7 5 7 6 7 8 8

tril 1 2 0 3 4 0 8 0 5 1 6 3 7 8 7

trir 0 1 2 2 3 4 4 8 0 5 5 6 6 7 0

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.4. Additional data structure for triangulations

4

10

T2

2

1

4

T1

5

T3 12

5

T5 9

2

3

1

83

11

T6 13

6

T4 6

T7

3 7

T8

8

14

8 15

7 Figure 3.4. The triangulation for Example 3.2.

first triangle has vertices numbered 1, 4, 5, and edges numbered 1, 10, 2. The first edge has endpoints numbered 1, 4, and the triangle to the left of this edge is T1 . Figure 3.4 shows this triangulation with the vertices, edges, and triangles labelled. The adjacency information is as follows: adjstart = (1, 4, 8, 11, 14, 19, 24, 28, 31) vadj = (4, 5, 2, 1, 5, 6, 3, 2, 6, 8, 7, 5, 1, 7, 6, 2, 1, 4, 7, 8, 3, 2, 5, 8, 6, 5, 4, 3, 6, 7) eadj = (1, 2, 3, 3, 4, 5, 6, 6, 7, 8, 9, 10, 1, 11, 12, 4, 2, 10, 13, 14, 7, 5, 12, ... 15, 13, 11, 9, 8, 14, 15) tstart = (1, 3, 6, 8, 10, 15, 20, 23, 25) tadj = (1, 2, 2, 3, 4, 4, 8, 5, 1, 6, 3, 2, 1, 5, 7, 8, 4, 3, 6, 7, 6, 5, 8, 7) Each of the lists vadj and eadj consists of eight groups of indices, where each group corresponds to one of the eight vertices of . Here we have written these lists with gaps to help identify the groups. The first group of three integers in vadj indicates that the vertices number 4, 5, 2 are connected to vertex number 1 (in counterclockwise order); see Figure 3.4. The first group of three integers in eadj indicates that the edges numbered 1, 2, and 3 are attached to the vertex numbered 1 (in counterclockwise order). The list tadj also consists of eight groups of indices. The first group contains 1, 2, which indicates that triangles T1 and T2 are attached to vertex number one, in counterclockwise order. The array adjstart shows that the fifth groups in vadj and eadj start in position 14 and end in position 18. These groups of indices show that the vertices attached to vertex 5 are 7, 6, 2, 1, 4, while the attached edges are numbered 11, 12, 4, 2, 10. The array tstart shows that the fifth group in tadj starts in position 10 and ends in position 14. The triangles attached to vertex 5 are T6 , T3 , T2 , T1 , and T5 . The function trilists runs in under a second for 10000 vertices. However, the time to execute seems to grow like O(n 2v ), where n v is the number of vertices in the triangulation, and so for very large triangulations it should be replaced by other functions that produce only the lists needed for a particular application.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

84

Chapter 3. Computing with Triangulations

3.5 Stars of vertices and triangles Definition 3.3. Suppose v is a vertex in a triangulation . The collection of triangles surrounding v is called the star of v . We denote it by star(v). The list tadj produced by trilists gives the stars of each of the vertices of a given triangulation. Thus, for example, for the triangulation in Figure 3.4, the star of the first vertex consists of the two triangles T1 and T2 . For some applications, it is useful to work with higher order stars. Definition 3.4. Given v, let star1 (v) := star(v). Define stari (v) inductively for i > 1 to be the set of all triangles in  which have a nonempty intersection with some triangle in stari−1 (v). Here is a function for finding star(v), where v is the kth vertex of a triangulation whose vertices are listed in v1, v2, and v3. The output is the number nvstar of triangles in the star, along with a list of their indices. [nvstar,list] = starv(k,v1,v2,v3) Higher order stars can be computed by recursively using starv. In particular, to get star2 (v), we combine star(v) with the stars of each of the vertices of the triangles in star(v). Definition 3.5. Let star0 (T ) := T . We define star j (T ) := {star(v) : v ∈ star j −1 (T )} for all j ≥ 1. We call star j (T ) the star of T of order j . Stars of a given triangle can easily be found using the list tadj. The following function finds the first order star associated with the kth triangle in a triangulation. The output is the number ntstar of triangles in the star, along with a list of their indices. [ntstar,list] = startri(k,v1,v2,v3,tstart,tadj) Example 3.6. Find the stars of the first and fifth vertices and the first triangle for the triangulation in Figure 3.4. Discussion: This triangulation can be read in from the data file tri8.dat using the script Btridemo. This script also calls on trilists to produce the various lists describing . Then a call on starv shows that the star of the first vertex consists of the triangles T1 , T2 , while the star of the fifth vertex consists of the triangles T1 , T2 , T3 , T5 , T6 . A call on startri shows that the star of triangle T1 consists of the same five triangles.

3.6 Barycentric coordinates Barycentric coordinates play a central role in calculating with splines. Suppose T is a triangle whose vertices are located at the points {(x i , yi )}3i=1 , and let (tx , t y ) be a point in R2 . Then the barycentric coordinates (b1 , b2 , b3 ) of the point (tx , t y ) relative to T are defined by ⎤⎡ ⎤ ⎡ ⎤ ⎡ 1 1 1 1 b1 ⎣x 1 x 2 x 3 ⎦⎣b2 ⎦ = ⎣tx ⎦ . (3.1) y1 y2 y3 b 3 ty

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.7. Finding the triangle containing a point

85

By Cramer’s rule, b1 =

(x 2 y3 − y2 x 3 ) − tx (y3 − y2) + t y (x 3 − x 2) , det(M)

where det(M) = (x 2 − x 1 )(y3 − y2) − (x 3 − x 2)(y2 − y1)

(3.2)

is the determinant of the matrix in (3.1). Similar formulae hold for b2 and b3 . We have written the following function for computing the barycentric coordinates of a point (tx,ty) relative to a triangle with vertices (x1,y1), (x2,y2), and (x3,y3): [b1,b2,b3] = bcoord(x1,y1,x2,y2,x3,y3,tx,ty) The signs of the barycentric coordinates give some information on where the point (tx , t y ) is located relative to T . In particular, the point (tx , t y ) lies in the triangle T if and only if all three of its barycentric coordinates are nonnegative. Barycentric coordinates can also be interpreted as areas of certain triangles. For details, see section 2.1 of [[LaiS07]]. Finally, we note that if the vertices of T are given in counterclockwise order, it is easy to see that the area of T is given by AT =

1 det(M), 2

(3.3)

where M is the matrix in (3.1).

3.7 Finding the triangle containing a point To evaluate a piecewise polynomial defined on a triangulation  at a point (tx , t y ), we have to first find the triangle containing the point. For rendering and other purposes, we have to do many such searches, and so we need an efficient way to solve this search problem. In view of the results of the previous section, a simple test to check whether a point (tx , t y ) lies in a given triangle T is to compute its barycentric coordinates and check that they are all nonnegative. However, if we have a large number of triangles, this process can take some time, and if we have to do it for a large number of points, a brute force approach becomes too inefficient, although some speedup could be attained with the use of kd-trees. Fortunately, MATLAB contains a built-in function that solves this search problem very efficiently. It works on a whole set of points at once, and returns not only a list of which triangle contains each point, but also gives the barycentric coordinates of the point relative to the triangle that contains it. Suppose TRI is the triangulation of interest, and suppose that the coordinates of its vertices are stored in the vectors x and y. Suppose tx and ty are vectors containing the Cartesian coordinates of a collection of n p points. Then the built-in MATLAB function [tnum,b] = tsearchn([x,y],TRI,[tx,ty]) produces a list tnum such that for the i th point (tx(i),ty(i)), the index of the triangle that contains the point is returned in tnum(i). Here b is a matrix of size n p × 3 whose

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

86

Chapter 3. Computing with Triangulations

i th row contains the barycentric coordinates of the i th point relative to the triangle that contains it, where n p is the number of points being processed. If the i th point is not in any triangle, tnum(i) and the three components of b(i,:) are all assigned the value NaN. Note that a given point may lie in more than one triangle, but only one index is returned. Here is a script for testing tsearchn. It creates a Delaunay triangulation (see section 3.8 below) associated with n vertices chosen randomly in the unit square, and then we choose np random points in the square to perform the search on. % Bfindtri n = input(’input n ’); x = rand(n,1); y = rand(n,1); % Create the Delaunay triangulation TRI = delaunay(x,y); np = input(’input np ’); tx = rand(np,1); ty = rand(np,1); [tnum,b] = tsearchn([x,y],TRI,[tx,ty]); The numbers of triangles in the Delaunay triangulations created in this way are approximately twice the number n of vertices. We conducted tests with n = 1000, 5000, 10000 and np = 1000, 5000, 10000, 20000. Here is a table giving the run times in seconds. The search time seems to be essentially linear in the number np of test points, and grows even more slowly with the number of vertices. np 1000 5000 10000 1000 .03 .035 .04 5000 .17 .17 .20 10000 .34 .34 .38 20000 .66 .66 .75 Note that tsearchn does not work properly for some triangulations with holes; see Remark 5.14. In such cases, the following function can be used instead, although it is much slower. It finds one triangle at a time. [k,r,s,t] = findtri(x,y,v1,v2,v3,tx,ty,ko) The input to this function includes the vectors x, . . . , v3 describing the triangulation, the Cartesian coordinates tx and ty of the point of interest, and a guess ko for which triangle might contain the point. This speeds up the search when evaluating spline on a grid where several nearby points may be in the same triangle. The output is an integer k giving the triangle containing the prescribed point, and the barycentric coordinates of the point relative to that triangle.

3.8 Constructing a triangulation with given vertices In many applications, and in particular in using splines for fitting scattered data, we are given a fixed set of points {(x i , yi )}ni=1 and need to create a triangulation of the convex

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.8. Constructing a triangulation with given vertices

87

Figure 3.5. Two different Delaunay triangulations of the same four points.

hull of these points using the given points as vertices. It is easy to see that for n > 3, this problem does not have a unique solution — there can be many triangulations with the same set of vertices. To construct an algorithm, we will need a way to choose among these. It is generally accepted that a good choice for most applications is the max-min angle triangulation, i.e., the one that maximizes the minimum angle among all of the triangles of . One of the reasons this makes sense is that many error bounds for spline interpolation and approximation methods depend explicitly on the smallest angle in the triangulation; see [[LaiS07]]. It is known (see, e.g., section 4.11 of [[LaiS07]]) that a max-min angle triangulation of a convex domain is the same as the classical Delaunay triangulation. Definition 3.7. Suppose  is a convex polygonal domain. Then a triangulation  of  is called a Delaunay triangulation, provided that for every triangle T in , the circumcircle around T does not contain any vertices in its interior. Delaunay triangulations are unique up to interior edges which are shared by two triangles whose vertices lie on a circle; see Figure 3.5, where we show two different Delaunay triangulations of the same four points. Efficiently constructing a Delaunay triangulation from an arbitrary set of scattered data points turns out to be a challenging problem in computational geometry; see the first paragraph of section 3.15. MATLAB contains the built-in command delaunay for constructing the Delaunay triangulation. Here is a script for using it. % Bdelaunay [n,x,y] = readxy; TRI = delaunay(x,y); triplot(TRI,x,y); This script uses our function readxy. It prompts for the name of a data file containing n and the pairs {(x i , yi )}ni=1 . Example 3.8. Read a set of vertices from a file, and construct and plot the corresponding Delaunay triangulation. Discussion: If we run Bdelaunay with the input file pts8.dat, it produces the triangulation shown in Figure 3.4. If we run it with the file pts9.dat (which contains nine points on a 3 × 3 grid in the unit square), we get the triangulation shown in Figure 3.6. Several other Delaunay triangulations of this same data can be obtained by swapping the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

88

Chapter 3. Computing with Triangulations

Figure 3.6. A Delaunay triangulation of nine points.

edges in the four subsquares. If we make all edges point in the northeast direction, we get the so-called type-1 triangulation discussed in section 3.10. To test the efficiency of the function delaunay, we performed some timing tests using random vertices. Example 3.9. Explore the efficiency of the MATLAB function delaunay. Discussion: We make use of the script Bdelaunayrand. It chooses n random points in the unit square using the MATLAB command rand in the same way as was done in Bfindtri above. Then it calls on delaunay to construct the Delaunay triangulation. The following table gives the times in seconds for a sequence of values of n: n 103 104 105 106

time .003 .04 .44 6.10

It is known that the most efficient algorithms require O(n log(n)) operations to construct a triangulation with n vertices. These times appear to be consistent with this order of complexity. There is an important point to remember about Delaunay triangulations. Although they are max-min angle triangulations, for a given set of scattered points, the corresponding Delaunay triangulation may contain some very thin triangles, particularly near the boundary. Figure 3.7 shows the Delaunay triangulation corresponding to 25 randomly chosen points in the unit square.

Figure 3.7. A Delaunay triangulation of 36 points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.10 Triangulations of gridded data on a rectangle

89

Figure 3.8. A graded triangulation of an L-shaped region.

3.9 Grid generation In many applications, we are given a fixed domain  which may be nonconvex and may even contain holes. Typically, we want to construct a triangulation of  with some specified number of triangles whose angles are not too small. Here we are not given the location or number of vertices. The construction of triangulations under these conditions is usually referred to as grid generation, and is a major topic in computational geometry and in finite-element analysis. It is of key importance in using the finite-element method to solve boundary-value problems. There are a number of libraries of programs for solving the grid generation problem. A good package should allow the user to work on complicated domains . It should include a way to construct a graded triangulation consisting of different sized triangles in different parts of the domain, and should also allow the user to require that certain vertices and edges be present in the final triangulation. MATLAB has grid generation software as part of its PDE toolbox. For a link to a very efficient package written in C, see Remark 3.4. Figure 3.8 shows a graded triangulation of an L-shaped domain with smaller triangles near the reentrant corner.

3.10 Triangulations of gridded data on a rectangle ¯ be a rectangle, and suppose Let  := [a, b] ⊗ [a, ¯ b] a = t0 < t1 < · · · < tk < tk+1 = b, ¯ a¯ = t¯0 < t¯1 < · · · < t¯k¯ < t¯k+1 = b. ¯ These grid lines provide a partition of the rectangle  into subrectangles. We can now construct triangulations of  by splitting each of these rectangles into subtriangles. Definition 3.10. Let  be the triangulation obtained from a tensor-product partition by drawing in the northeast diagonals in all subrectangles of . Then we call  a type-1 triangulation of . If we draw in both diagonals in every subrectangle, we call the resulting triangulation a type-2 triangulation. ¯ k+1 When the grid lines {ti }i=0 and {t¯j }k+1 j =0 are uniformly spaced, we call these triangulations uniform type-1 and uniform type-2 triangulations, respectively. In this case, the resulting meshes are often called the three-direction mesh and four-direction mesh, respectively. Figure 3.9 shows examples of nonuniform type-1 and type-2 triangulations.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

90

Chapter 3. Computing with Triangulations

Figure 3.9. Nonuniform type-1 and type-2 triangulations of a rectangle. Reprinted with permission from Cambridge University Press [[LaiS07]].

For use in later experiments, we have written the following two functions for creating ˜ They can be tested uniform type-1 and type-2 triangulations of a rectangle [a, b] × [a, ˜ b]. with our scripts Btype1 and Btype2. [x,y,TRI] = type1(nx,ny,a,b,aw,bw) [x,y,TRI] = type2(nx,ny,a,b,aw,bw)

3.11 Refining a triangulation Given a pair of triangulations  and  R of the same domain , we say that  R is a refinement of , provided that 1) every vertex of  is a vertex of  R , 2) every triangle t ∈  R is a subtriangle of some triangle T in . When  R is a refinement of , we call  the coarser triangulation and  R the finer triangulation. In this case we also say that the two triangulations are nested. There are many ways to refine a given triangulation. Here is perhaps the simplest. Definition 3.11. Suppose we split each triangle T in a triangulation  into four subtriangles by connecting the midpoints of the edges of T . We call the resulting refinement the uniform refinement of .

SplinePak includes the following function for performing uniform refinement on a given triangulation TRIo with vertices x, y: [x,y,TRI] = refine(x,y,TRIo) This code extends the vectors x and y containing the coordinates of the vertices of TRIo by adding the new vertices created in the refinement process. Example 3.12. Refine the triangulation shown in Figure 3.10 (left). Discussion: We make use of the script Brefine and read the triangulation from the file trihole36.dat. The resulting uniform refinement  R is shown in Figure 3.10 (right). It is clear that for each T ∈ , the four new triangles which cover T are all similar to T , and thus  R has the same smallest angle as .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.12. Adjusting triangulations by edge swapping

91

Figure 3.10. A triangulation and its uniform refinement.

It should be emphasized that in many applications, it is more useful to locally refine a triangulation, i.e., to split only some of the triangles. This is often the case, for example, in using splines in the finite-element method. Figure 3.8 shows an example of a locally refined triangulation. It is beyond the scope of this book to discuss general refinement methods.

3.12 Adjusting triangulations by edge swapping For some applications, the Delaunay triangulation may not be the most suitable choice. For example, in certain data fitting situations we may get better results using a triangulation that has been adjusted to take account of the shape of the underlying function being approximated; see section 6.13. In this section we briefly describe a useful way to adjust a triangulation. Let  be a polygonal domain, and let V be a set of points in  that includes all vertices of the polygon forming the boundary of . Suppose Tri(, V) is the set of all possible triangulations of  with vertices V. Here we are allowing  to be nonconvex and to have holes in it. Now suppose we have some measure a() of the quality of a given triangulation  ∈ Tri(, V) which we wish to maximize over all triangulations in Tri(, V). Definition 3.13. A triangulation ∗ ∈ Tri(, V) is called an optimal triangulation with respect to the criterion a, provided that a() ≤ a(∗ ) for all triangulations  ∈ Tri(, V). The following questions immediately arise: 1) Does there exist an optimal triangulation? 2) Is there a unique optimal triangulation? 3) How can we characterize an optimal triangulation? 4) How can we construct an optimal triangulation? Since Tri(, V) contains a finite number of triangulations, it is clear that there always exists at least one optimal triangulation. It is easy to give examples to show that optimal triangulations need not be unique. In general, characterizing optimal triangulations is difficult, and it is often hard to recognize whether a particular triangulation is optimal.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

92

Chapter 3. Computing with Triangulations

This makes the design of algorithms to find optimal triangulations difficult. However, it is easy to create a simple algorithm that can be used to improve the quality of any given triangulation with respect to a given quality measure. Suppose T and T˜ are two triangles in a triangulation that share a common edge. Then Q := T ∪ T˜ forms a quadrilateral. We say that Q is a strictly convex quadrilateral if the interior angles at its four corners are all less than 180 degrees. Algorithm 3.14 (Swap Algorithm). Let  be an arbitrary triangulation of a set  with vertices V. 1) Set m = 0 and (0) = . 2) Do until no longer possible: Let Q be the set of all strictly convex quadrilaterals Q in (m) such that swapping the diagonal of Q would increase the value of a a) If Q is empty, stop. b) Otherwise, choose Q ∗ ∈ Q such that the resulting swap gives the largest increase in a. Swap the diagonal of Q ∗ , increase m by one, and let (m) be the new triangulation. Since Tri(, V) is finite, this algorithm always stops in a finite number of steps. However, in general there is no guarantee that it produces an optimal triangulation, and in fact, for many quality measures, the best we can hope for is to get a locally optimal triangulation. One way to try to avoid local minima is to use simulated annealing; see Remark 3.9. We conclude this section with an interesting result concerning edge swapping in triangulations. For a proof, see [DynGR93]. ˜ are two triangulations with the same set of vertices. Theorem 3.15. Suppose  and  ˜ Then  can always be obtained from  by a sequence of edge swaps.

3.13 Euler relations Given any triangulation , let n iv := number of interior vertices, n bv := number of boundary vertices, n v := total number of vertices, n ie := number of interior edges, n be := number of boundary edges, n e := total number of edges, n t := number of triangles, n h := number of holes.

(3.4)

It should not be surprising that with certain restrictions on , these quantities are connected to each other. To state a theorem, we need two definitions taken from [[LaiS07]].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.13. Euler relations

93

Figure 3.11. A triangulation where the Euler relations do not hold. Reprinted with permission from Cambridge University Press [[LaiS07]].

Definition 3.16. We say that a triangulation  is shellable, provided that it consists of ˜ by adding a a single triangle, or if it can be obtained from a shellable triangulation  ˜ precisely along either one or two edges. triangle T that intersects  Not all triangulations are shellable. For example, a triangulation consisting of two triangles touching only at a vertex is clearly not shellable. The triangulation in Figure 3.11 is also not shellable, since no matter how we try to build it by adding one triangle at a time, eventually we will get two triangles which touch only at a vertex. Definition 3.17. We say that a triangulation  is regular, provided that 1)  is shellable, or ˜ by removing one or more shellable 2) it can be obtained from a shellable triangulation  ˜ subtriangulations, all of whose vertices are interior vertices of . It is known that if  is a regular triangulation, then for every vertex v of , star(v) is a shellable subtriangulation of ; see Lemma 4.8 of [[LaiS07]]. As observed above, the triangulation in Figure 3.11 is not shellable, and is also not regular. It can indeed be constructed from a shellable triangulation by removing one shellable subtriangulation, but ˜ The following result is established in Theorem 4.11 one with a vertex on the boundary of . of [[LaiS07]]. Theorem 3.18. Suppose  is a regular triangulation. Then n be = n bv , n ie = 3n iv + n bv + 3n h − 3,

(3.5)

n t = 2n iv + n bv + 2n h − 2. We emphasize that these formulae do not hold for arbitrary triangulations as defined in Definition 3.1. Example 3.19. The formulae (3.5) fail for the triangulation shown in Figure 3.11. Discussion: This triangulation is not regular. Here n bv = 12, n iv = 3, n v = 15, and n h = 1. In addition, n be = 13, n ie = 19, n e = 32, and n t = 17. It is easy to check that all three

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

94

Chapter 3. Computing with Triangulations

equations in (3.5) fail. However, the well-known Euler formula nt − ne + nv = 1 − nh

(3.6)

is valid. It holds for general triangulations without hanging vertices.

3.14 Remarks Remark 3.1. The concept of a triangulation is defined in several different ways in the literature. Here we have given a fairly general definition, although in practice we will usually be working with regular triangulations as in our Definition 3.17. Remark 3.2. Although they had been used earlier in the finite-element literature, the study of spline spaces defined on triangulations with hanging vertices is quite recent; see [SchumW12] for references. Remark 3.3. In this book we assume that the vertices of a triangle are listed in counterclockwise order. This guarantees that the triangle has positive area. The triangles produced by the built-in MATLAB function delaunay do not always satisfy this condition. Our function trilists reorders the vertex lists to ensure that all triangles have positive area. Remark 3.4. There is a substantial amount of software in various programming languages for constructing triangulations. For very efficient C-code for constructing triangulations due to Shewchuk, see http://www.cs.cmu.edu/~quake/triangle.html. Remark 3.5. The standard definition of a Delaunay triangulation works only with convex . However, the concept can be extended to nonconvex domains by relaxing the circle criterion of Definition 3.7 for certain triangles near the boundary; see section 4.11 of [[LaiS07]]. Remark 3.6. In section 3.12 we have allowed quite arbitrary quality measures. Perhaps the best known measure is to take a() to be the smallest angle in the triangulation. Then the optimal triangulation is the one that maximizes the minimal angle among all triangles. This turns out to be the Delaunay triangulation; see, e.g., [[LaiS07]]. Indeed, the edge swapping algorithm given here is one way to construct Delaunay triangulations (and was used in several early software packages). It is not the preferred approach, however, since its complexity is O(n 2 ) as compared to the best algorithms which have complexity O(n log(n)). Remark 3.7. It is also possible to build spaces of piecewise polynomials on triangulated quadrangulations which are obtained from a quadrangulation by drawing in both diagonals. For a discussion of quadrangulations and their connection to triangulations, see [[LaiS07]], where some spline spaces defined on quadrangulations are also discussed. Remark 3.8. The term regular triangulation has been used extensively in mathematics, computer science, and engineering, but unfortunately, with many different meanings. In some papers, it refers to a uniform type-1 triangulation. In computer graphics it is used for triangulations which may involve triangles of different sizes, but which all have the same shape. In [Far82] it refers to a triangulation whose interior vertices have degree 6 and whose boundary vertices have degree 4. In much of the spline literature it is used for very

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

3.15. Historical notes

95

general triangulations as described in Definition 3.1; see [AlfS87, AlfPS87a–AlfPS87c] for some early examples. In the computational geometry literature, it is a generalization of the Delaunay triangulation which is obtained as the dual of a Voronoi diagram where each point is assigned a weight; see, e.g., [VigNC02] and references therein. Here we have followed the terminology of [[LaiS07]]. Remark 3.9. One problem with swapping algorithms for optimizing meshes is that, depending on the definition of the optimality criterion, they can easily get stuck at local minima. One way to proceed in such cases is to use so-called simulated annealing; see [Bas91, Schum93, HahK97].

3.15 Historical notes The construction of a planar triangulation with given vertices is an old problem in computational geometry. Once it was realized that Delaunay triangulations have desirable properties for many applications, a number of researchers set about creating algorithms for constructing them. It is easy to create a naive algorithm that works in O(n 2 ) operations, where n is the number of vertices; see, e.g., Algorithm 4.12 in [[LaiS07]]. The best one can do is O(n log(n)), and in the early 1980’s at least a dozen algorithms were proposed claiming this order of complexity; see [Schum87, Schum93b], where the validity of these claims is examined. For algorithms that actually deliver O(n log(n)) complexity, see [LeeS80] and the books [[Ede87, Ede01]]. Here we have avoided writing our own Delaunay triangulation algorithm since the MATLAB function delaunay seems to work well even when n is quite large. The first papers that I can find mentioning type-1 and type-2 triangulations are [ChuiSW83] and [ChuiSW83b]. By now this is established terminology, although some authors prefer to use the equivalent names three-direction mesh and four-direction mesh in the equally spaced case. The idea of swapping edges in a triangulation to improve some quality measure can be found already in [Law72], although it is probably much older. The use of edge swapping to improve spline fits was studied in [DynLR90, DynLR90b, DynR93, QuaS89, QuaS90, QuaS91, Rip92, DynGR93, ChuH97, FloI97, DynHKL01, DynFI02, DyeH03]. For a detailed account and more references, see the book [[FloI97]]. A natural application for splines on triangulations that have been optimized with edge swapping is to image fitting; see, e.g., [DemI03, DemDFI05, DemI11, CohDHM12]. They have also been used in image registration [GonA10].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 4

Computing with Splines

In this chapter we discuss various techniques for dealing with splines computationally, including how to store and evaluate them and their derivatives. We also discuss integrals, inner products, degree-raising, and subdivision. Throughout this chapter we suppose that t  = {Ti }ni=1 is a triangulation of a domain . We allow  to be nonconvex, and to have one or more holes.

4.1 Bernstein basis polynomials We write Pd :=

⎧ ⎨ ⎩



p(x, y) =

ci j x i y j

0≤i+ j ≤d

⎫ ⎬ ⎭

(4.1)

for the space of polynomials of degree d. The key to efficiently dealing with piecewise polynomials defined on triangulations is to replace the Taylor expansion (4.1) by a different representation more appropriate to triangulations. This alternate representation is called the Bernstein–Bézier representation, and is based on barycentric coordinates. Fix a triangle T := v1 , v2 , v3  in , and let b1 (x, y), b2 (x, y), b3 (x, y) be the linear functions giving the barycentric coordinates of the point (x, y) relative to T ; see section 3.6. Definition 4.1. Given an integer d > 0, the associated Bernstein basis polynomials of degree d relative to T are defined as Bidj k :=

d! j bi b bk , i ! j ! k! 1 2 3

i + j + k = d,

(4.2)

where i , j , k are nonnegative integers. The Bernstein basis polynomials have many important properties. For example, on T the Bidj k are nonnegative and form a partition of unity, i.e., 0 ≤ Bidj k (x, y) ≤ 1

for all (x, y) in T , 97

(4.3)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

98

and

Chapter 4. Computing with Splines



Bidj k (x, y) ≡ 1

for all (x, y) in T .

(4.4)

i+ j +k=d

For other properties, see Chapters 2 and 5 of [[LaiS07]], where the following result is established. Lemma 4.2. The polynomials {Bidj k }i+ j +k=d are linearly independent and form a basis ) * for the d+2 2 -dimensional linear space Pd of polynomials of degree d. This result shows that for every p ∈ Pd , there is a unique set of coefficients {ci j k }i+ j +k=d such that  p= ci j k Bidj k . (4.5) i+ j +k=d

This is called the Bernstein–Bézier representation of p, but we will usually refer to it simply as the B-form of p. We refer to {ci j k }i+ j +k=d as the B-coefficients of p. It is clear that to store a polynomial p in B-form in a computer, it suffices to store the vertices of the triangle T and a vector c containing the B-coefficients of p relative to T . It is standard practice to store B-coefficients in lexicographical order. This means that cνμκ comes before ci j k , provided that ν > i , or if ν = i , then μ > j , or if ν = i and μ = j , then κ > k. Thus, for example, for d = 3 the order is c300, c210 , c201, c120 , c111, c102 , c030, c021 , c012 , c003 .          It is not hard to show that the B-form is stable in the sense that c∞ ≤  pT ≤ c∞ , K

(4.6)

where  pT is the maximum norm on T , and K is a constant that depends only on d; see Theorem 2.6 of [[LaiS07]].

4.2 Domain points on a triangle In working with polynomials in B-form, it is convenient to introduce an alternative indexing set for the Bernstein basis polynomials and the B-coefficients. Given an integer d > 0 and a triangle T := v1 , v2 , v3 , we define

 i v1 + j v2 + kv3  Dd,T := ξiTj k := . i+ j +k=d d

(4.7)

This set is called the set of domain points associated with d and T . These points are equally spaced across the face of T . Using domain points, we can now write a polynomial in B-form as  p= cξ Bξd . (4.8) ξ ∈Dd,T

Each B-coefficient of p is uniquely associated with a domain point. The geometric location of these points turns out to be useful in understanding smoothness conditions between polynomials defined on adjoining triangles; see section 4.13.2 below.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.3. Evaluating polynomials in B-form

99

For later use we introduce some additional terminology which is standard in the spline T literature. Domain points of the form ξd−i, j ,k with j + k = i are said to lie on the ring R i (v1 ) of radius i around v1 , with a similar definition for the other vertices of T . The disk Dm (v1 ) of radius m around v1 is defined to be the union of the rings {Ri (v1 )}m i=0 , i.e., the set of domain T points {ξi j k }i≥d−m , with a similar definition for the other vertices of T .

4.3 Evaluating polynomials in B-form There is a very stable and efficient algorithm, called the de Casteljau algorithm, for evaluating polynomials in B-form. Let p be a polynomial written in the B-form (4.5) with coefficients (0) ci j k := ci j k , i + j + k = d. (4.9) The following algorithm can be used to compute the value of p(v), where v has barycentric coordinates (b1 , b2 , b3 ). Algorithm 4.3 (de Casteljau). For  = 1, . . ., d For i + j + k = d −  ()

(−1)

(−1)

(−1)

ci j k := b1 ci+1, j ,k + b2 ci, j +1,k + b3 ci, j ,k+1 It is known (see section 2.5 of [[LaiS07]]) that after completing this algorithm, the (d) value of c000 is equal to p(v). Note the coefficients at step  are obtained from coefficients at the previous step by taking combinations of three neighboring coefficients at a time, using the weights (b1 , b2 , b3 ). For points v ∈ T , the barycentric coordinates b1 , b2 , b3 are all nonnegative, and so the computation is numerically very stable. Indeed, at each step of the algorithm we are taking a convex combination of previously computed quantities. Figure 4.1 illustrates the algorithm for a polynomial of degree d = 2. We have implemented the de Casteljau algorithm as val = decast (d,b1,b2,b3,c) c200

(1)

c100

c110

c020

c101

c011

(2)

c000

c002

(1)

c010

(1)

c001

Figure 4.1. The intermediate coefficients produced by the de Casteljau algorithm. Reprinted with permission from Cambridge University Press [[LaiS07]].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

100

Chapter 4. Computing with Splines

4.4 Derivatives of polynomials in B-form In this section we show how to find the coefficients of a directional derivative of a polynomial written in B-form relative to a triangle T . Suppose v is a point in R2 , and u is a vector in R2 . Given a differentiable function f , its directional derivative at v with respect to u is defined to be * d ) f v + tu  . Du f (v) := (4.10) t =0 dt We refer to u as a direction vector. Note that the value of Du f depends not only on the direction of u, but also on its length. Each point v := (vx , v y ) in R2 is uniquely defined by a set of barycentric coordinates (b1 , b2 , b3 ) which sum to one. We now show that each direction vector u is also uniquely described by a triple (a1 , a2 , a3 ), but one which sums to zero. Definition 4.4. Given any vector u ∈ R2 , let ai := αi − βi ,

i = 1, 2, 3,

where (α1 , α2 , α3 ) and (β1 , β2 , β3 ) are the barycentric coordinates relative to T of two points w and w˜ such that u = w − w. ˜ Then a1 , a2 , a3 are called the directional coordinates of u relative to T . It is clear from this definition that the directional coordinates a1 , a2 , a3 describing a direction vector u sum to zero. Let u and u¯ be two different direction vectors, and suppose we want to compute the mixed directional derivative Dum Dum¯¯ p(v) of a polynomial p ∈ Pd at a point v for some 0 ≤ m + m¯ ≤ d. Suppose a1 , a2 , a3 are the directional coordinates for u, and a¯ 1 , a¯ 2 , a¯ 3 are the directional coordinates for u. ¯ Let b1 , b2 , b3 be the barycentric coordinates of the point v. Algorithm 4.5 (de Casteljau for derivatives). 1) For  = 1, . . ., m For all i + j + k = d −  ()

(−1)

(−1)

(−1)

ci j k := a1 ci+1, j ,k + a2 ci, j +1,k + a3 ci, j ,k+1 2) For  = m + 1, . . ., m + m¯ For all i + j + k = d −  (−1) ci() ¯ 2 ci,(−1) ¯ 3 ci,(−1) j k := a¯ 1 ci+1, j ,k + a j +1,k + a j ,k+1

3) For  = m + m¯ + 1, . . ., d For all i + j + k = d −  ()

(−1)

(−1)

(−1)

ci j k := b1 ci+1, j ,k + b2 ci, j +1,k + b3 ci, j ,k+1 (d)

4) Set Dum Dum¯¯ p(v) = d(d − 1) · · · (d − m − m¯ + 1) c000.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.5. Integrals and inner products of polynomials

101

It can be shown (cf. Theorem 2.12 of [[LaiS07]]) that the coefficients with superscripts  in Step 1 are the coefficients of Du p, modulo a factor d(d − 1) · · · (d −  + 1). Similarly, the coefficients with superscripts  in Step 2 are the coefficients of Dum Du−m p, modulo a ¯ factor d(d − 1) · · · (d −  + 1). Step 3 just carries out the standard de Casteljau algorithm on the coefficients of Dum Dum¯¯ p. Note that if we execute this algorithm with m = m¯ = 0, it is just the usual de Casteljau algorithm to evaluate p(v). We have implemented this algorithm for finding mixed directional derivatives in the following function: val = decastdermix (d,m,mw,b1,b2,b3,a1,a2,a3,aw1,aw2,aw3,c) We have also written a simplified version of this function which can be used when we want derivatives in one direction with directional coordinates a1,a2,a3. val = decastder(d,m,b1,b2,b3,a1,a2,a3,c) For some applications (see, e.g., Algorithm 9.10 for assembling the stiffness matrix associated with the Ritz–Galerkin method for solving a boundary-value problem), it is useful to compute a given mixed derivative for all of the B-basis functions of degree d, i.e., Dum Dum˜˜ Bidj k (v) for all i + j + k = d. For this purpose we have written the following special function: b = mix(d,m,mw,b1,b2,b3,a1,a2,a3,aw1,aw2,aw3) ) * containing the desired mixed derivaThe output of this function is a vector of length d+2 2 tives of the Bernstein basis polynomials at the point v with the barycentric coordinates (b1 , b2 , b3 ). This function could be used to evaluate a mixed directional derivative of a polynomial by simply multiplying the entries of b by the coefficients of p and summing. However, this is less efficient than using decastdermix or decastder.

4.5 Integrals and inner products of polynomials Suppose T is a triangle whose area is A T . Let {Bidj k }i+ j +k=d be the associated Bernstein basis polynomials of degree d. It is shown in Theorem 2.33 of [[LaiS07]] that if {ci j k }i+ j +k=d are the B-coefficients of a polynomial p relative to a triangle T , then   AT p(x, y) d x d y = )d+2* ci j k . (4.11) T

2

i+ j +k=d

This result gives an explicit formula for the integral of p over any triangle T . It is trivial to implement. The formula (4.11) immediately implies that  AT for all i + j + k = d. (4.12) Bidj k (x, y) d x d y = )d+2* T

2

It turns out to be equally as easy to compute inner products of polynomials in B-form. By Theorem 2.34 of [[LaiS07]], )i+ν *) j +μ*)k+κ *  i j k AT d d . (4.13) Bi j k (x, y) Bνμκ (x, y) d x d y = )2d *)2d+2* T

d

2

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

102

Chapter 4. Computing with Splines

Then for any two polynomials  p := ci j k Bidj k and q := i+ j +k=d

 ν+μ+κ=d

d c˜νμκ Bνμκ ,

the inner product of p and q is given explicitly by       i +ν j +μ k +κ AT . p(x, y) q(x, y) d x d y = )2d *)2d+2* ci j k c˜νμκ i j k T i+ j +k=d d

2

ν+μ+κ=d

This inner product can be written in the form  AT p(x, y) q(x, y) d x d y = )2d * )2d+2* c T G c, ˜ T

d

(4.14)

2

where c and c˜ are)the *vectors of coefficients of p and q, respectively (in lexicographical order), and G is a d+2 square matrix. For d = 1, 2 ⎡

⎤ 1 1 2 1⎦ , 1 2

2 G = ⎣1 1 while for d = 2, it is

⎡ 6 ⎢3 ⎢ ⎢3 G=⎢ ⎢1 ⎣1 1

3 4 2 3 2 1

3 2 4 1 2 3

1 3 1 6 3 1

1 2 2 3 4 3

⎤ 1 1⎥ ⎥ 3⎥ ⎥. 1⎥ 3⎦ 6

4.6 Integrals of general functions over triangles In the previous section we saw that it is possible to give explicit formulae for the integral of a polynomial over a triangle T if we know its B-coefficients relative to T . However, in practice, we frequently have to compute the integrals of polynomials multiplied by other nonpolynomial functions. To compute integrals in this case, we will generally have to use a numerical quadrature rule. In this section we describe the classical Gauss quadrature rules for triangles, but see Remark 4.11 for references to some recently developed more efficient alternatives. Suppose T is a given triangle. We are interested in quadrature rules of the form  f ≈ AT T n

nq 

wi f (ηi ),

(4.15)

i=1 n

q q are given points in T , and {wi }i=1 are given weights. In particular, we are where {ηi }i=1 interested in such a formula with a small value of n q , but which is exact for polynomials

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.6. Integrals of general functions over triangles

103

Figure 4.2. The sample points for the quadrature rule (4.15) with nq = 25 and nq = 79.

of as high a degree as possible. Such quadrature rules are called Gaussian quadrature rules, and have been studied in detail in the literature. In fact, there are extensive tables giving various values of n q , the associated weights, and the point locations, usually written in terms of barycentric coordinates so they can be used on arbitrary triangles. The following functions provide the needed values for nq = 25 and nq = 79: [w,rq,sq,tq] = quadset(nq) Here nq is the number of sample points used in the formula. The output vector w contains the weights, and the vectors rq,sq,tq contain the barycentric coordinates of the sample nq in (4.15). For nq = 25 the corresponding quadrature rule exactly integrates points {ηi }i=1 polynomials up to degree d = 10. For nq = 79 it exactly integrates polynomials up to degree d = 23. The locations of the sample points for a typical triangle are shown in Figure 4.2. Here is a script for testing these quadrature rules. % Bgaussquad x1 = 0; y1 = 0; x2 = 1; y2 = .5; x3 = .3; y3 = 1; area = (x2 - x1)*(y3 - y2) - (y2 - y1)*(x3 - x2) d = input(’input d ’); c = zeros(1,(d+2)*(d+1)/2); k = input(’input k ’); c(k) = 1; nq = 25; [w,rq,sq,tq] = quadset(nq); int = 0; for i = 1:nq fi = decast(d,rq(i),sq(i),tq(i),c); int = int + w(i)*fi; end int = area*int; exact = area/choose(d+2,2); fprintf(’the exact integral is %g\ n’,exact); fprintf(’the approximate integral is %g\n’,int); Example 4.6. Explore the exactness of the quadrature formulas defined by quadset. Discussion: We use the script Bgaussquad which uses the formula (4.12) to compute the exact integral of any prescribed Bernstein basis polynomial over a given triangle. With

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

104

Chapter 4. Computing with Splines

nq = 25 we find that the formula gives exact results for all polynomials up to degree d = 10, but for d = 11 this is no longer the case. With nq = 79, we get exact results for all polynomials up to degree 23. For arbitrary functions f , we can compare the results for nq = 25 and nq = 79.

4.7 Plotting a polynomial patch In Chapter 2 we rendered the surface corresponding to a tensor-product spline s by computing a matrix of values of s on a rectangular grid and then using the MATLAB command surfl. For polynomial patches defined over a triangle T , it is more natural to work with a piecewise linear surface defined over a refinement of T . We can then plot this surface using the MATLAB command trisurf. Given a triangle T := v1 , v2 , v3  and a positive integer m, let Vm := Dm,T be the set of domain points of degree m associated with T as defined in (4.7). Let T ,m be the triangulation of T obtained by connecting neighboring points ti j k of Vm , where two points ti j k and tνμκ are considered to be neighbors, provided that |i − ν| + | j − μ| + |k − κ| = 2. * )m * ) The triangulation T ,m consists of m 2 = m+1 2 + 2 congruent triangles Ti j k := ti+1, j ,k , ti, j +1,k , ti, j ,k+1 , T˜i j k := ti, j +1,k+1 , ti+1, j ,k+1 , ti+1, j +1,k ,

i + j + k = m − 1, i + j + k = m − 2.

(4.16)

Figure 4.3 illustrates the case m = 3. We can now describe an algorithm for plotting polynomial patches: ) * 1) Compute vectors gx, gy of length ng := m+2 containing the values of the Cartesian 2 coordinates of the points ti j k in lexicographical order. 2) Compute the corresponding vector gz of values of s at the points (gx i , gyi ), i = 1, . . ., ng. 3) Compute a list of triples gT R I describing the triangulation T ,m . 4) Display the resulting surface using the MATLAB command trisurf.

T200

T110

T020

T˜010

T˜100

T011

T101 T˜001

T002

Figure 4.3. The triangulation T ,3 of a triangle T .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.8. Domain points on a triangulation

105

0.45

0 1 1 0.5

0.5 0

0

3 Figure 4.4. A rendering of the Bernstein basis polynomial B201 produced by Brendpol with d = 3 and m = 20.

We have implemented the first three steps in [gx,gy,gz,gTRI] = rendpol(d,m,x1,y1,x2,y2,x3,y3,c) Here d is the degree of the polynomial and c is the vector of its B-coefficients. The vertices of T are contained in (x1,y1), (x2,y2), and (x3,y3), and m controls the resolution (the number of triangular facets to be displayed). Here is a sample script. % Brendpol x1 = 0; y1 = 0; x2 = 1; y2 = 0; x3 = 0; y3 = 1; d = 3; nd = (d+2)*(d+1)/2; c = zeros(nd); c(3) = 1; m = input(’input m ’); [gx,gy,gz,gTRI] = rendpol(d,m,x1,y1,x2,y2,x3,y3,c); h = trisurf(gTRI,gx,gy,gz); set(h,’FaceColor’,[0 1 1]); Example 4.7. Use Brendpol to display a Bernstein basis polynomial. Discussion: This script is set up for d = 3, but it works for arbitrary d. It sets all coefficients to zero except for the third one. This gives the plot of a single Bernstein basis polynomial. Figure 4.4 shows the surface corresponding to m = 20.

4.8 Domain points on a triangulation t Suppose  = {Ti }ni=1 is a triangulation of a domain , and let d be a positive integer. Then we define the associated set of domain points to be 1 Dd,T , (4.17) Dd, :=

T ∈

where Dd,T is the set of domain points (4.7) associated with T . Domain points of Dd,T on edges shared by two triangles are included just once in Dd, . Figures 4.5 and 4.6 show the sets Dd, corresponding to the triangulation shown in Figure 3.4 for d = 1, 2, 3.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

106

Chapter 4. Computing with Splines

Figure 4.5. The sets D1, and D2, for the triangulation in Figure 3.4.

Figure 4.6. The set D3, for the triangulation in Figure 3.4. Reprinted with permission from Cambridge University Press [[LaiS07]].

4.9 The space Sd0 () t Suppose  = {Ti }ni=1 is a triangulation of a domain , and let d be a positive integer. Then we define the space of C 0 splines of degree d to be the linear space

Sd0 () := {s ∈ C 0 () : s|Ti ∈ Pd ,

i = 1, . . . , n t }.

(4.18)

Here Pd is the space of polynomials of degree d defined in (4.1). Theorem 4.8. dim Sd0 () = #Dd, = n v + (d − 1)n e +

  d −1 nt , 2

(4.19)

where n v , n e , and n t are the numbers of vertices, edges, and triangles in . Proof. Given s ∈ Sd0 (), for each triangle T ∈ , we know that there exists a unique set of coefficients {cξ }ξ ∈Dd,T such that  s|T = cξ Bξd,T , (4.20) ξ ∈Dd,T

where BξT ,d are the Bernstein basis polynomials of degree d associated with the triangle T . Since s is continuous, if ξ lies on an edge between two adjacent triangles T and T˜ , then the coefficients cξ for s|T and s|T˜ are the same. This shows that for each spline s ∈ Sd0 (), there is a unique associated set of coefficients {cξ }ξ ∈Dd, . We call these the B-coefficients of s. The converse also holds, i.e., given any {cξ }ξ ∈Dd, there is a unique spline s ∈ Sd0 () defined by (4.20). It follows that every spline s ∈ Sd0 () is uniquely defined by its set of

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.9. The space Sd0 ()

107

B-coefficients {cξ }ξ ∈Dd, , i.e., Sd0 () is in one-to-one correspondence with the set Dd, . It follows that the dimension of Sd0 () is equal to the cardinality of Dd, , which is clearly given by the formula in (4.19).

4.9.1 Storing splines in Sd0 () In view of the proof of Theorem 4.8, we can store a spline s ∈ Sd0 () in the computer by storing its set of B-coefficients {cξ }ξ ∈Dd, . It is convenient to arrange these coefficients in a single vector c in some specified order. We use the following Storage Convention: 1) The first n v components of c contain the coefficients associated with the domain points at the vertices of . 2) The next set of d − 1 components of c contain the coefficients associated with the edge e1 . These are followed by those for e2 , . . . , ene . ) * 3) The next d−1 components of c contain the coefficients associated with the domain 2 points that lie in the interior of T1 . These are followed by those in the triangles T2 , . . . , Tnt . ) * The total number of coefficients stored is n v + (d − 1)n e + d−1 2 n t , which is the dimension 0 of Sd (). Note that since each edge has an orientation, i.e., we know which end comes first, the order of the coefficients in the edge groups is uniquely defined. Similarly, since each triangle is also oriented, i.e., we know its first vertex and the others follow in counterclockwise order, the order of the coefficients in the triangle groups is also uniquely defined. Using this storage convention, it is easy to recover the coefficients associated with a given triangular patch. We describe a function to do this in section 4.10 below.

4.9.2 A basis for Sd0 () In many applications we can work directly with the B-coefficients of a spline in Sd0 (). However, there are some applications where it is useful to have a basis for the space. Bases can be constructed in various ways. We shall use the following approach. For each ξ ∈ Dd, , let φξ be the unique spline in Sd0 () such that  1, if η = ξ , for all η ∈ Dd, . (4.21) cη = δξ η := 0, otherwise, Theorem 4.9. The splines {φξ }ξ ∈Dd, are linearly independent and form a basis for Sd0 (). Proof. For each η ∈ Dd, , let λη be the linear functional defined on Sd0 () such that for any  s ∈ Sd0 (), λη s = cη . Now suppose ξ ∈Dd, cξ φξ ≡ 0. Then for any η ∈ Dd, , applying λη , we conclude that cη = 0, i.e., all of the coefficients of s must be zero. These basis functions have some very nice properties reminiscent of the B-splines that play such an important role in the univariate and tensor-product cases.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

108

Chapter 4. Computing with Splines

Lemma 4.10. The basis functions in Theorem 4.9 have local support. In particular, for each ξ ∈ Dd, , 1) if ξ is a vertex of , then φξ has support on star(ξ ); 2) if ξ lies in the interior of an edge e of , then φξ has support on the triangle or pair of triangles containing e; 3) if ξ lies in the interior of a triangle T of , then φξ has support on T . Moreover, φξ is nonnegative at all points in , and the {φξ }ξ ∈Dd, form a partition of unity, i.e.,  φξ (x, y) ≡ 1, all (x, y) ∈ . ξ ∈Dd,

Proof. All of these properties follow from (4.20) and the fact that the Bernstein basis polynomials are nonnegative and form a partition of unity. Example 4.11. Plot some of the basis functions in the space S30 () on the type-1 triangulation  shown in Figure 4.7 (left). Discussion: We use the script Brendspgrid, and read in the triangulation from the file type1.25. This script uses the function valspgrid discussed in section 4.12.1 below to generate a grid and evaluate the spline on it. The plot is produced with surfl. For this triangulation, n v = 25, n e = 56, and n t = 32, and thus there are n c = 169 coefficients. We number the basis functions in the same order as used in the vector of domain points {ξi }169 i=1 1

0.5

0 1 1 0.5

0.5 0 0

0.45

0.25

0 1

0 1 1 0.5

0.5 0 0

1 0.5

0.5 0 0

Figure 4.7. A type-1 triangulation with 25 vertices, and plots of the C 0 cubic basis functions φ23 , φ90 , and φ150 on it; see Example 4.11.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.10. Evaluating splines and their derivatives

109

and B-coefficients. To plot φk , we set ck = 1 and all other coefficients to zero. Figure 4.7 shows the triangulation and plots of three basis functions. The plot in the upper right shows φ23 . The domain point ξ23 falls at the 23rd vertex of , so the support of this basis function is star(ξ23 ). The plot in the lower left shows φ90 . The domain point ξ90 falls on edge 33 of the triangulation, so in this case the support is a pair of triangles containing that edge. Finally, the plot in the lower right shows φ150 . The domain point ξ150 falls in the interior of the thirteenth triangle, so the support in this case is just that triangle.

4.10 Evaluating splines and their derivatives We now have the tools needed to evaluate a spline s ∈ Sd0 () with coefficient vector c. Suppose (tx , t y ) is the point where we wish to evaluate s. Then we 1) find a triangle T which contains (tx , t y ), 2) extract the B-coefficients of the polynomial s|T , 3) evaluate this polynomial using the de Casteljau algorithm. If we want to evaluate a derivative of s, we simply evaluate the corresponding derivative of the polynomial s|T . We have discussed Step 1 and Step 3 in section 3.7 and section 4.3, respectively. The second step is straightforward, provided that we have stored c according to the convention described in section 4.9.1. In particular, suppose (x, y) lies in the triangle Tk . Using the lists in section 3.4, we can find the indices of the vertices of Tk , as well as the indices of its oriented edges. Then extracting the coefficients of s|T from the vector c is just a matter of counting. We have written the following function for carrying this out: co = getco(d,k,nv,v1,v2,v3,e1,e2,e3,ie1,c) Here d,k,nv are the degree of the spline, the number of the triangle of interest, and the number of vertices in the triangulation, respectively. The vector c should contain the list of B-coefficients of the spline. The remaining inputs describe the triangulation, where ie1 lists the first endpoints of each edge — see section 3.4. It is needed in this code to establish ) * the orientation of each edge. The output of getco is the vector co containing the d+2 2 B-coefficients of the polynomial s|Tk in lexicographical order. The following script can be used to test getco: % Bgetco [nv,x,y,nt,TRI] = readtri; [nb,ne,nt,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy,vadj,... eadj,adjstart,tadj,tstart,area,TRI] = trilists(x,y,TRI); d = input(’input d ’); nc = nv + (d-1)*ne + (d-1)*(d-2)*nt/2; c = [1:nc]; k = input(’input triangle number ’); co = getco(d,k,nv,v1,v2,v3,e1,e2,e3,ie1,c);

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

110

Chapter 4. Computing with Splines

Example 4.12. Test the function getco for extracting the B-coefficients of a spline corresponding to one patch. Discussion: We use the script Bgetco with the data file tri8.dat. This produces the triangulation  shown in Figure 3.4. The numbers of vertices, edges, and triangles are given by nv = 8, ne = 15, and nt = 8. With d = 3, Theorem 4.8 shows that the dimension of S30 () is nc = n + 2 ne + nt = 46. For test purposes, we set ci = i for i = 1. . . ., n c and extract the coefficients corresponding to s|T3 . In this case, getco returns co = (2, 15, 17, 16, 41, 18, 5,31,32,6). To check this, we refer to Table 3.1. The triangle T3 has vertices 2, 5, 6 and edges 4, 12, 5. Thus, the first component of co should be 2. To get the second component, we observe that the edge e1(k) = 4 connects vertex 2 to vertex 5. Thus, the second component of co should be 8 + 2 × 3 + 1 = 15. The remaining entries in co can be checked in the same way. With d = 4 and k = 3, we get nc = 77, and getco returns co = (2, 18, 21, 19, 60, 22, 20, 61, 62, 23, 5,42,43,44,6). For some applications, we would like to extract the indices of the coefficients associated with a given triangle rather than the coefficients themselves. Thus, we have included the following variant of getco in SplinePak: list = getindex(d,k,nv,v1,v2,v3,e1,e2,e3,ie1) The output of this code is the list of s|Tk , in lexicographical order.

)d+2* 2

indices of the B-coefficients of the polynomial

4.11 Integrals and inner products of splines Suppose  is a triangulation of a domain  and that s is a spline of degree d with Bcoefficient vector c. Then in view of the discussion in section 4.5, it is straightforward to calculate the integral of s over  := ∪T ∈ T for any collection  of triangles in . Indeed, we have    s= s. 

T ∈

T

Each term in this sum can be computed from the formula (4.11), once we have extracted the coefficients of the corresponding polynomial piece. This can be done with the function getco. The situation is similar for inner products over  . However, if we want to compute an integral involving a nonpolynomial integrand, we will have to use a quadrature rule as described in section 4.6.

4.12 Rendering a spline surface Suppose s is a spline defined on a triangulation  of a domain , and let c be the vector containing its B-coefficients. In this section we discuss two approaches to rendering the surface corresponding to s.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.12. Rendering a spline surface

111

4.12.1 Rendering a spline using a rectangular grid MATLAB contains several useful functions for rendering surfaces. One of these is the function surfl, which makes use of values on a rectangular grid. To use it to plot a spline ¯ be a rectangle s, we need a function to evaluate s on such a grid. Let R := [a, b] × [a, ¯ b] that contains all or part of the domain . Given a positive integer n g , let g

g

1

2

g

a = x 1 < x 2 < · · · < x n g = b, g g g ¯ a¯ = y < y < · · · < yn g = b.

(4.22)

This defines a grid of points on R. Suppose g is an ng × ng matrix containing the values of s at the grid points, where if a grid point is outside of , we assign it the value NaN. Then the command surfl(xg,yg,g’) will produce the desired plot, where points outside of  are ignored. To compute the matrix g, we have written the following function: [xg,yg,g] = valspgrid(d,x,y,v1,v2,v3,e1,e2,e3,ie1,c,... ng,a,b,aw,bw) Here d is the degree of the spline, and ng is the number of grid lines to be used for the rendering. The vectors x and y should contain the Cartesian coordinates of the vertices of , while v1,v2,v3 and e1,e2,e3,ie1 are the vectors describing the triangulation as computed using the function trilists discussed in section 3.4. The parameters ¯ of interest. If we want a plot on all a,b,aw,bw define the rectangle R := [a, b] × [a, ¯ b] of , we choose these numbers so that R is the smallest rectangle that contains . The output of valspgrid consists of vectors xg and yg of length n g containing the points in (4.22), along with the n g × n g matrix g. As observed earlier, assuming the rows of g correspond to x-values, we should call surfl with the transpose of g in order to get the correct orientation of the surface. We will use valspgrid extensively throughout this book to plot splines. Most of the plots in this book use ng = 51 since it produces a reasonable number of grid lines. Using larger values of ng leads to plots with too many grid lines. For convenience, we have also included the following variant of valspgrid in our package: [xg,yg,g] = valspgridxy(d,x,y,v1,v2,v3,e1,e2,e3,ie1,c,... ngx,ngy,xmin,xmax,ymin,ymax) This function differs from valspgrid only in that we now input two values ngx and ngy to control the number of grid lines in the x- and y-directions. This gives vectors xg and yg of lengths ngx and ngy, respectively. In this case g is a matrix of size ngx × ngy. The method of this section can also be used to render splines defined on nonrectangular domains. Here is an example. Example 4.13. Let  be the triangulation shown in Figure 3.1, and let s be a spline in S30 () with all coefficients set to one except for the coefficient c6 which we set to two. Plot s on the smallest rectangle containing this triangulation.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

112

Chapter 4. Computing with Splines 1

0 1

1.5 1

0.5

0.5 0

0

Figure 4.8. Plot of a cubic spline on the triangulation in Figure 3.4 using the method of section 4.12.1.

Discussion: We use the script Brendspgrid, and read the triangulation from the file tri8.dat. Figure 4.8 shows the plot corresponding to grid values produced by the function valspgrid. As Figure 4.8 shows, if the edges of  are not aligned with the x- or y-axes, then the plot obtained with valspgrid will have jagged looking edges. In the following section we present an alternative which eliminates this problem.

4.12.2 Rendering a spline using a triangular grid MATLAB also contains a function called trisurfl which is designed to plot a surface consisting of a collection of triangular facets. To use this for rendering a spline, we can loop through the triangles of , and use the function rendpol discussed in section 4.7 to create triangular patches which can be displayed using trisurf. Suppose m is a positive integer. Then for each triangle in T ∈ , we create a subtriangulation T ,m with vertices at the domain points Dm,T ; see Figure 4.3. As shown in section 4.7, the number of subtriangles for each triangle of  is m 2 , and the total number of triangles obtained in this way is Nt := m 2 n t , where n t is the number of triangles in . Here is a function for setting up the subtriangles and evaluating s at their vertices. [gx,gy,gz,gTRI] = valspDP(d,m,x,y,v1,v2,v3,e1,e2,e3,ie1,c) The input to this function is the same as that for valspgrid, except that now we input m instead of ng. The value of m controls the number of triangles displayed, and thus the resolution of the plot. The output includes vectors gx,gy,gz of length Nt giving the Cartesian coordinates in R3 of the triangular patches to be rendered. It also includes a Nt × 3 matrix giving the indices of the Nt triangles to be displayed. Example 4.14. Repeat Example 4.13 using valspDP instead of valspgrid. Discussion: We make use of the script Brendsp, a minor variant of Brendspgrid. As before, we read the triangulation from the file tri8.dat. The spline is defined as in Example 4.13. Figure 4.9 shows the corresponding plot. While the method of this section may seem better suited to rendering splines on nonrectangular domains, it does have some drawbacks. It uses the same number of subtriangles

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.13. Spaces of smooth splines

113

2

1 1

1.5 1

0.5

0.5 0

0

Figure 4.9. Plot of a cubic spline on the triangulation in Figure 3.4 using the method of section 4.12.2.

for each triangle in T . But the sizes of the triangles in  can vary greatly, so that in very small triangles we have too much detail, while in larger ones not enough. This drawback also affects the computation of errors, since if we compare two functions at the vertices of the refined triangles of , the sample points will be very close together in small triangles, and further apart in larger ones. For this reason, for most of the examples in this book we use valspgrid both for rendering splines and for computing errors.

4.12.3 Rendering a directional derivative of a spline Suppose s is a spline of degree d defined on a triangulation . Let u := (u x , u y ) be a given direction vector. In this section we introduce a useful function for plotting the corresponding directional derivative Du s. We proceed as in section 4.12.1, and first evaluate Du s on a rectangular grid as defined in (4.22). Then we can display the surface with a call on surfl as before. The grid evaluation can be accomplished with the function [xg,yg,g] = valspdergrid(d,x,y,v1,v2,v3,e1,e2,e3,ie1,c,... ng,u,xmin,xmax,ymin,ymax) Here d is the degree of the spline, and the inputs x,y, . . . , ie1 describe the corresponding triangulation. The vector c contains the set of B-coefficients of the spline, and ng controls the number of points in the grid, which is defined on the rectangle [x min, x max ] × [ymin, ymax ], where x min and x max are the minimum and maximum of the x-coordinates of the vertices of the triangulation, and ymin and ymax are defined similarly. The output of this function includes the vectors xg and yg defining the grid, and the n g × n g matrix g of values of the spline on the grid.

4.13 Spaces of smooth splines In practice we often want to use spline spaces which are not only continuous, but which also have one or more continuous derivatives. Definition 4.15. Given integers r and d with 0 ≤ r < d, let Sdr () := C r () ∩ Sd0 (). We call Sdr () the space of splines of degree d and smoothness r .

(4.23)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

114

Chapter 4. Computing with Splines

For practical applications, it turns out (see Remark 4.6) that it is often more convenient to work with certain subspaces of Sdr () which have enhanced smoothness at some or all of the vertices of . Given a spline s ∈ Sd0 () and a vertex v of , we say that s ∈ C ρ (v), provided that all of the polynomial pieces of s associated with triangles surrounding the vertex v have common derivatives (in all directions) up to order ρ. Definition 4.16. Suppose r , ρ, d are integers such that 0 ≤ r ≤ ρ < d, and let Sd () := {s ∈ Sdr () : s ∈ C ρ (v) all v ∈ V}, r,ρ

(4.24)

r,ρ

where V is the set of all vertices of . We call Sd () a superspline space. It is possible to define much more general spaces of splines by requiring varying degrees of smoothness across each of the edges of  and/or varying degrees of smoothness at the vertices of . For more on these types of spaces, see [[LaiS07]]. In the remainder of the section we present various tools for working with spaces of smooth splines.

4.13.1 Storing and evaluating smooth splines Suppose S ⊆ Sd0 () is a space of smooth splines of degree d defined on a triangulation . Then any s ∈ S can be regarded as a spline in Sd0 () whose B-coefficients happen to satisfy certain smoothness conditions. Thus, we can store and evaluate s just like any other spline in Sd0 (), and all of the methods discussed earlier in this chapter apply.

4.13.2 Smoothness conditions across an edge One of the big advantages of using the Bernstein–Bézier representation for splines is that it is relatively simple to give conditions for polynomials on two adjoining triangles to join together with C r smoothness. In this section we briefly review how this works. Let T := v1 , v2 , v3  and T˜ := v4 , v3 , v2  be two triangles sharing the edge e := v2 , v3 . Let  p(v) := ci j k Bidj k (v) (4.25) i+ j +k=d



and p(v) ˜ :=

c˜i j k B˜ idj k (v),

(4.26)

i+ j +k=d

where {Bidj k } and { B˜ idj k } are the Bernstein basis polynomials associated with T and T˜ , respectively. The following result is well known; see, e.g., Theorem 2.28 of [[LaiS07]]. Theorem 4.17. Suppose u is any direction not parallel to e. Then Dun p(v) = Dun p(v), ˜

all v ∈ e and n = 0, . . .,r ,

(4.27)

if and only if c˜n j k =

 ν+μ+κ=n

n cν,k+μ, j +κ Bνμκ (v4 ),

j + k = d − n, n = 0, . . .,r .

(4.28)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.13. Spaces of smooth splines

115 c200

v1 v3

T

c002 c110 c011

T˜ v2

c101

v4

c020

c˜101

c˜110

c˜200

Figure 4.10. C 1 smoothness conditions between two quadratic patches.

Example 4.18. Suppose p and p˜ are two quadratic polynomials defined on the pair of triangles shown in Figure 4.10 (left), and suppose the B-coefficients are numbered as shown in Figure 4.10 (right). Let (b1 , b2 , b3 ) be the barycentric coordinates of v4 in terms of T = v1 , v2 , v3 . Then p and p˜ join with C 1 smoothness across the common edge if and only if c˜101 = b1 c110 + b2 c020 + b3c011 , c˜110 = b1 c101 + b2 c011 + b3c002 .

(4.29)

Discussion: Each of these two conditions involves four coefficients. To help visualize the conditions, in Figure 4.10 (right) we have shaded the quadrilaterals involving the four coefficients in each condition. In computing with smooth splines, it is useful to be able to check whether a given spline is actually C 1 , i.e., whether its coefficient vector c satisfies all of the C 1 smoothness conditions. Here is a function that can be used for that purpose: c1ck(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c) The input is the usual information describing the spline, including its coefficient vector c. There is no formal output, but the function prints out the RMS value of the vector of the differences between the left- and right-hand sides of the conditions (4.28). This value should be zero (to machine accuracy) if the spline is C 1 continuous. This function is used in several of the scripts in later chapters. It is also useful to be able to check whether a spline satisfies all of the C 2 smoothness conditions of Theorem 4.17. Here is a function that checks both C 1 and C 2 conditions. cksmooth(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c) This function prints two values: the RMS value of the discrepancies in the C 1 smoothness conditions, and the analogous value for the C 2 smoothness conditions. These values should be zero (to machine accuracy) if the spline is C 2 . This function is also used in several of the scripts in later chapters.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

116

Chapter 4. Computing with Splines

4.13.3 Minimal determining sets Suppose S is a subspace of Sd0 (), and let Dd, be the corresponding set of domain points. We recall the following definition from the spline literature; see, e.g., section 5.6 of [[LaiS07]]. Definition 4.19. Suppose M is a subset of Dd, . Then M is called a determining set for S , provided that if s is a spline in S whose B-coefficients cη are zero for all η ∈ M, then s ≡ 0. A determining set M is called a minimal determining set for S , provided that there is no smaller determining set. Minimal determining sets play a key theoretical role in establishing properties of spaces of splines; see [[LaiS07]]. For example, it is known that if M is a minimal determining set for a spline space S, then the dimension of S is given by #M. Minimal determining sets can also be used to construct a basis for a spline space; see section 4.13.4. Although finding a minimal determining set for a specific spline space is not always easy, they have been given explicitly for a wide variety of useful spline spaces; see section 4.14 below and Chapters 6–8 in [[LaiS07]]. Minimal determining sets are also key tools for computing with spaces of smooth splines. They tell us which coefficients are free parameters, i.e., the degrees of freedom of the spline. Thus, to find a spline s ∈ S solving some interpolation or approximation problem, it suffices to compute the vector c˜ of coefficients {cξ }ξ ∈M . The remaining Bcoefficients of s can then be computed from smoothness conditions. Let N and n c be the dimension and number of B-coefficients for the space S, respectively. Lemma 4.20. Suppose M is a minimal determining set for a space of splines S ⊆ Sd0 (). Then there exists an n c × N matrix A such that for every vector c˜ := {c˜ξ }ξ ∈M , c = A c˜

(4.30)

is the vector of B-coefficients of a spline s ∈ S with cξ = c˜ξ for all ξ ∈ M. Moreover, ˜ ∞, c∞ ≤ K c where K := max

1≤i≤n c

N 

|ai j |.

(4.31)

(4.32)

j =1

Proof. Since M is a minimal determining set for S, we know that every B-coefficient of s can be written as a linear combination of the coefficients cξ with ξ ∈ M. The entries of A can be found from the smoothness conditions across the edges of . We call the matrix A the transformation matrix. Code for computing transformation matrices associated with some of the most useful macro-element spline spaces is given in section 4.14 below. As we shall see in Chapter 6, the transformation matrix will play a key role in programming several global interpolation and approximation methods, including the minimal energy, least-squares, and penalized least-squares methods. It will also be used in Chapter 9 in solving PDE’s by the finite-element method using splines. The size of the constant K in (4.32) is an indicator of the stability of the computation of B-coefficients. We can use it to help in choosing the best minimal determining set for a

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.13. Spaces of smooth splines

117

given spline space S. To help understand the concept of minimal determining set, we now give one very simple example. For other examples, see section 4.14 and [[LaiS07]]. Example 4.21. Consider the spline space S21 () defined on the triangulation consisting of two triangles shown in Figure 4.10. Discussion: Let M be the six domain points in the top triangle, along with ξ˜200 . We can set the coefficients corresponding to the seven domain points in M to arbitrary values. Then the remaining two coefficients of s corresponding to ξ˜110 and ξ˜101 are uniquely determined from the two smoothness conditions given in Example 4.18. We conclude that the dimension of this space is N = 7. Now the first seven rows of the 9 × 7 transformation matrix A correspond to a 7 × 7 identity matrix, and the last two rows correspond to the 2 × 7 matrix appearing in the following smoothness conditions: ⎤ ⎡ c200 ⎢c110⎥ ⎥ % & % &⎢ ⎢c ⎥ c˜101 0 b1 0 b2 b3 0 0 ⎢ 101⎥ = ⎢c ⎥ , 0 0 b1 0 b2 b3 0 ⎢ 020⎥ c˜110 ⎢c011⎥ ⎣c ⎦ 002 c˜200 where (b1 , b2 , b3 ) are the barycentric coordinates of the vertex v4 in terms of the triangle T = v1 , v2 , v3 .

4.13.4 The M-basis Many spline interpolation and approximation methods based on splines do not require knowing a basis for the space. This includes all of the local methods in the following chapter. On the other hand, there are some interpolation and approximation methods (including the finite-element method for solving PDE’s) which do make use of bases. In section 4.9.2. we discussed a basis for the spline space Sd0 (). Here we show that for arbitrary spline spaces S, it is easy to construct a nice basis whenever we have a minimal determining set M for S. For an alternate approach to constructing bases, see section 4.13.6. Suppose M is a minimal determining set for a space of splines S ⊆ Sd0 () defined over a triangulation . For each η ∈ M, let γη be the linear functional such that for every s ∈ S, γη s is the B-coefficient of s corresponding to the domain point η. Theorem 4.22. Suppose M is a minimal determining set for a spline space S ⊆ Sd0 (). Then for each ξ ∈ M, there is a unique spline ψξ ∈ S such that γη ψξ = δη,ξ ,

all η ∈ M.

(4.33)

Moreover,  := {ψξ }ξ ∈M is a basis for S. Proof. The first statement follows from the assumption  that M is a minimal determining set for S. To prove the second statement, suppose s := ξ ∈M cξ ψξ ≡ 0. Then for every η ∈ M we have cη = γη s = 0, which shows that the splines in  are linearly independent. Since # = #M = dim S, it follows that  is a basis.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

118

Chapter 4. Computing with Splines

The basis in this theorem is called the M-basis of S. Note that unlike the basis functions for Sd0 () constructed in section 4.9.2, the basis functions in Theorem 4.22 are not necessarily nonnegative; see Example 4.31 below. We have the following important property of the M basis, proved in Lemma 1 of [Sch08]. Given a triangle T in , let Dd,T be the set of domain points lying in T , and let {BηT }η∈Dd,T be the Bernstein basis polynomials associated with T . Lemma 4.23. For every ξ ∈ M and every triangle T ,  ψξ |T = aηξ BηT ,

(4.34)

η∈Dd,T

where aηξ is the entry in the transformation matrix A corresponding to the row associated with η and the column associated with ξ . Proof. Fix ξ ∈ M. Then by the definition of ψξ , the B-coefficient corresponding to ξ is one, while the B-coefficients corresponding to all other domain points in M are zero. Thus, the vector c˜ in (4.30) has all zero components except for the one corresponding to ξ , which is one. Multiplying by the transformation matrix A associated with M, we get the B-coefficients of ψξ . The choice of the minimal determining set M will affect the nature of the M-basis functions. To be useful in practice, we need basis functions that are local and stable. To define these concepts, recall that if T is a triangle, then star (T ) denotes the star of order  associated with T ; see section 3.5. The following definition comes from section 5.8 of [[LaiS07]]. N Definition 4.24. Suppose := {φi }i=1 is a basis for a spline space S defined on a triangulation . Then we say that is -local, provided that for each i = 1, . . . , N, there exists a triangle Ti such that

supp φi := {(x, y) : φi (x, y) = 0} ⊆ star (Ti ).

(4.35)

We say that is -stable, provided that there exists a constant K depending only on  and the smallest angle in  such that φi  ≤ K ,

i = 1, . . ., N.

(4.36)

In section 4.14 below we give minimal determining sets for some important macroelement spaces which lead to stable local bases. For many more examples, see Chapters 6–8 of [[LaiS07]].

4.13.5 Nodal minimal determining sets Given a point v in a domain , and a set of real numbers {αi j }i+ j =m with m ≥ 0, let  λ := εv ανμ Dxν D μ (4.37) y, ν+μ=m

where εv denotes point evaluation at the point v. By definition, λ is a linear functional defined on C m (). We refer to the point v as the carrier of λ. Now suppose S is a subspace

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.13. Spaces of smooth splines

119

of Sd0 () for some triangulation  of a domain . We recall the following concept from the spline literature; see, e.g., [[LaiS07]]. N is a set of linear functionals of the form (4.37). We Definition 4.25. Suppose N = {λi }i=1 call N a nodal determining set for S , provided that if s ∈ S satisfies λi s = 0 for all 1 ≤ i ≤ N, then s ≡ 0. We say that a nodal determining set N is a nodal minimal determining set for S if there is no nodal determining set with fewer elements.

It is easy to see (cf. section 5.9 of [[LaiS07]]) that if N is a nodal minimal determining set for S, then the dimension of S is equal to #N . Nodal minimal determining sets can also be used in computing with spaces of smooth splines. For examples of nodal minimal determining sets, see section 4.14 and Chapters 6–8 of [[LaiS07]]. Given a spline s ∈ S, let z := (λ1 s, . . . , λ N s)T , and let c = (c1 , . . . , cnc )T be the vector of the B-coefficients of s, indexed in standard form as described in section 4.9.1. We have the following analog of Lemma 4.20. Lemma 4.26. Suppose N is a nodal minimal determining set for a space of splines S ⊆ Sd0 (). Then there exists an n c × N matrix A such that given a vector z := (λ1 s, . . . , λ N s)T of nodal data for a spline s ∈ S, the vector c of all B-coefficients of s is given by c = A z.

(4.38)

c∞ ≤ K z∞ ,

(4.39)

Moreover, where K := max

1≤i≤n c

N 

|ai j |.

(4.40)

j =1

Proof. The existence of A follows from the fact that N is a nodal minimal determining set for S. The entries of A can be found from formulae connecting B-coefficients to nodal data (see section 2.7 of [[LaiS07]]), coupled with smoothness conditions across the edges of .

4.13.6 The N -basis N Suppose N = {λi }i=1 is a nodal minimal determining set for a spline space S ⊆ Sd0 () of dimension N. The following result shows how to construct a corresponding basis; see section 5.9 of [[LaiS07]].

Theorem 4.27. For each 1 ≤ i ≤ N, there is a unique spline φi ∈ S such that λ j φi = δ i j ,

all 1 ≤ i , j ≤ N.

(4.41)

N Moreover, := {φi }i=1 is a basis for S. It is called the N -basis of S.

Proof. The first statement follows the assumption that N is a nodal minimal determining N set for S. To prove the second statement, suppose s := i=1 ci φi ≡ 0. Then for every N 1 ≤ j ≤ N, we have c j = λ j s = 0, which shows that the {φi }i=1 are linearly independent. Since # = #N = dim S, it follows that is a basis.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

120

Chapter 4. Computing with Splines

The basis functions in Theorem 4.27 are not necessarily nonnegative in general. In section 4.14.1 we give an example of an N -basis for an important macro-element space that we will use in various computational examples later. A given spline space will generally have many different nodal minimal determining sets. The choice of N will affect the nature of the basis functions. To be useful in practice, we need basis functions that are local and stable in the sense of Definition 4.24. The N -basis constructed in section 4.14.1 for S21 ( P S ) is 1-local and stable. For further examples of macro-element spaces with stable local N -bases, see Chapters 6–8 of [[LaiS07]]. The following analog of Lemma 4.23 shows how to find all B-coefficients of each basis function in an N -basis. Lemma 4.28. For every 1 ≤ i ≤ N and every triangle T , φi | T =

 η∈DT

aν(η),i BηT ,

(4.42)

where aν(η),i is the entry in A corresponding to the row ν(η) associated with the B-coefficient cη and the column i . Proof. Fix 1 ≤ i ≤ N. Then by the definition of φi , λi φi = 1 while λ j φ = 0 for all other j . Thus, the vector z in (4.38) has all zero components except for the i th, which is one. Multiplying by the transformation matrix A associated with N , we get the B-coefficients of φi .

4.14 Some useful macro-element spaces 4.14.1 The space S21 ( P S ) Given a triangulation , we recall that its Powell–Sabin refinement  P S is defined as follows: 1) find the incenter u T of each triangle T in ; 2) for each T , connect u T to each of its three vertices; 3) for each pair of neighboring triangles T and T˜ ; connect their incenters; 4) for each triangle T with a boundary edge e, connect the incenter u T to the midpoint of e. Note that in forming the Powell–Sabin refinement of , each triangle is divided into six subtriangles. We refer to the original triangles in  as macro triangles. Figure 4.11 shows a triangulation and its Powell–Sabin refinement. For more on Powell–Sabin refinements, see section 4.8.2 of [[LaiS07]]. We now explicitly describe a minimal determining set for S21 ( P S ). Let V be the set of vertices of . For each v ∈ V, let Tv be some triangle with vertex at v. Let Mv be the set of three domain points contained in Dd,T ∩ D2 (v), where D2 (v) is the disk of radius two around v. The following result is well known; see, e.g., Theorem 6.9 of [[LaiS07]].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.14. Some useful macro-element spaces

121

Figure 4.11. A triangulation and its Powell–Sabin refinement.

Theorem 4.29. The dimension of the space S21 ( P S ) is N := 3n, where n is the number of vertices of . Moreover, the set 1 M := Mv (4.43) v∈V

is a minimal determining set for

S21 ( P S ).

Note that there is some freedom in the above construction of M, since for each vertex v, there are generally several different triangles with a vertex at v. For later use, it is important to assign an order to the points in the minimal determining set. Here we use the convention that the first n points are taken to be the vertices of the original triangulation . Given a triangulation, the following function constructs its Powell–Sabin refinement and chooses a minimal determining set. It also sets up the transformation matrix. [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,dof,A] = ... mdsps(xo,yo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro,adjstarto,eadjo,bdyo) The input is the usual information about the initial triangulation  obtained with a call on trilists. Note that the names of the input variables all include the letter o to indicate that they belong to the initial triangulation. The output consists of the corresponding information for the refined triangulation  P S , along with a list of the chosen degrees of freedom, i.e., the indices of the B-coefficients associated with the chosen minimal determining set. The length of the vector dof is equal to the dimension of the spline space S21 ( P S ). The function mdsps also outputs the transformation matrix A defined in Lemma 4.20. It is returned as a sparse matrix of size n c × N, where N is the dimension of S21 ( P S ) and n c = #Dd, P S is the number of B-coefficients for splines in S21 ( P S ). Using A, we can compute the vector c of all B-coefficients of s from the vector c˜ containing the coefficients corresponding to the domain points in M as in (4.30). Here is an example. Example 4.30. Find a minimal determining set for the space S21 ( P S ) defined on the Powell–Sabin refinement  P S of the triangulation shown in Figure 4.11 (left). Discussion: We use the script Bmdsps and read the initial triangulation  from the file tri8.dat. This triangulation has n = 8 vertices, ne = 15 edges, and nt = 8 triangles; see Figure 4.11 (left). For the refined triangulation  P S we have n = 31, ne = 78, and nt = 48; see Figure 4.11 (right). For this triangulation, the dimension of

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

122

Chapter 4. Computing with Splines

Figure 4.12. A minimal determining set for S21 ( P S ).

S21 ( P S ) is 24, and the output of the function mdsps is the vector dof whose entries are 1, 2, 3, 4, 5, 6, 7, 8, 34, 36,40,42,44,46,50,33,51,52,41,55,52,53,59,61. In Figure 4.12 we have marked these domain points with black dots. For this space we have 109 Bcoefficients. Once we have set the 24 coefficients corresponding to M, the remaining coefficients can be computed by multiplication by the sparse matrix A as in (4.30). With the minimal determining set M produced by mdsps, the corresponding M-basis functions are 1-local in the sense of Definition 4.24, i.e., their supports are at most the star of a vertex. The fact that the basis is also stable follows immediately from the nature of the smoothness conditions; see the explicit formulae in section 5.2 below. We now plot a few of these basis functions. Example 4.31. Plot some of the M-basis functions associated with the minimal determining set produced by mdsps for the space S21 ( P S ) on the type-1 triangulation shown in Figure 4.7. Discussion: We use the script Bmdsps with the triangulation file type1.25. It calls on mdsps to create the Powell–Sabin refinement, choose the degrees of freedom, and compute the corresponding transformation matrix A. For this triangulation the dimension of S21 ( P S ) is 75. Thus, to plot a single basis function, we choose an integer m with 1 ≤ m ≤ 75 and set all of the degrees of freedom to be zero except for the mth one, which we set to one. Storing these values in a vector c˜ of length 75, we can compute the full set of B-coefficients of the corresponding spline by (4.30), i.e., we set c = Ac. ˜ This script also calls on the function c1ck introduced at the end of section 4.13.2 to check that we indeed have a C 1 spline. In Figure 4.13 (left) we show the basis function corresponding to the domain point with index m = 13. This point is located at vertex number 13 in the original triangulation , and so the associated M-basis function has support on the star of this vertex. In Figure 4.13 (right) we show the 60th basis function, which corresponds to the domain point dof(60) = 208. It lies in the one-disk around vertex 18, which is located at (.75, .5). Thus, the support of this basis function is the set of triangles in the initial triangulation that surround that vertex. Neither basis function is nonnegative. Concerning the stability of this M-basis, note that for this triangulation and this minimal determining set, the constant K in (4.36) is equal to A∞ = 3.83. In the remainder of this section we discuss a nodal minimal determining set for S21 ( P S ) and the corresponding N -basis. As in section 4.13.5, we write εv for the point evaluation

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.14. Some useful macro-element spaces 1.6

123 1

1 0 0.4 -0.2 1

-1 1 1 0.5 0

1 0.5

0.5

0.5 0

0

0

Figure 4.13. Two M-basis functions in the space S21 ( P S ); see Example 4.31.

functional at the point v ∈ R2 . Let V be the set of all vertices of . The following result is well known; see, e.g., Theorem 6.11 of [[LaiS07]]. Theorem 4.32. The set N :=

1

{εv , εv Dx , εv D y }

(4.44)

v∈V

is a stable nodal minimal determining set for S21 ( P S ). In (4.44) we have not specified an order for the linear functionals making up the nodal minimal determining set. The order determines the entries in the transformation matrix A. For applications, it is important to number the functionals so that evaluation at the vertices of the original triangulation  comes first. Our ordering is to take point evaluation at the n vertices first, followed by the x-derivatives at the n vertices, and then the y-derivatives at the same vertices. [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,A] = ... nmdsps(xo,yo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro) The input is the usual information about the initial triangulation . As with mdsps, we mark all the input variables with the letter o to clearly indicate that they pertain to the initial triangulation. The output includes the corresponding information for the refined triangulation  P S , along with the transformation matrix A defined in Lemma 4.26. It is returned as a matrix of size n c × N, where N is the dimension of S21 ( P S ), and n c is the number of B-coefficients of a spline in S21 ( P S ). Using A, we can compute the vector c of all B-coefficients of s from the vector z := (λ1 s, . . . , λ N s) containing the nodal data; see (4.38). To test the function, we can use the script Bnmdsps. The N -basis functions corresponding to the nodal minimal determining set of Theorem 4.32 all have local support. In particular, for each vertex v of , all three of the basis functions associated with nodal data at v have support on star(v). It turns out that those associated with point evaluation at the vertices are nonnegative, although as shown in the following example, the others are not. Example 4.33. Plot some of the N -basis functions associated with the nodal minimal determining set described in Theorem 4.32 for the space S21 ( P S ) on the type-1 triangulation shown in Figure 4.7 (left).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

124

Chapter 4. Computing with Splines 1.6

0.06

0.8

-0.2 1

-0.06 1 1 0.5

1 0.5

0.5 0

0.5 0

0

0

Figure 4.14. Two nodal basis functions in the space S21 ( P S ); see Example 4.33.

Discussion: We make use of the script Bnmdsps and read the triangulation from the file type1.25. For this triangulation, the dimension of S21 ( P S ) is N = 75. In Figure 4.14 (left) we show the basis function corresponding to the nodal functional corresponding to point evaluation at the 13th vertex of . This basis function is nonnegative. Figure 4.14 (right) shows the nodal basis function corresponding to the 38th degree of freedom, which is point evaluation of the x-derivative at the 13th vertex of . This basis function vanishes at this vertex along with its y-derivative, but its x-derivative is equal to one at this point. It exhibits a sign change. Concerning the stability of this nodal basis, we note that psnmds computes A∞ = 1.125, which is the value of the constant K in (4.39). It is smaller than the corresponding constant K appearing in Example 4.31.

4.14.2 The Argyris space S51,2 () In this section we discuss computing with the space S51,2 (). It is a superspline space (cf. (4.24)), and is often called the Argyris space. To give a formula for the dimension of this space along with a minimal determining set for it, we need some additional notation. Let V and E be the sets of vertices and edges of . For each v ∈ V, let Tv be some triangle with vertex at v, and let Mv be the set of domain points in Tv that lie in a disk of radius two around v. For each edge e := v2 , v3  of , let Te := v1 , v2 , v3  be some triangle Te }. Let n and n e be the numbers of vertices and edges in containing e, and let Me := {ξ122 , respectively. The following result is well known; see, e.g., Theorem 6.1 of [[LaiS07]]. Theorem 4.34. The space S51,2 () has dimension 6n + n e . Moreover, the set M :=

1 v∈V

Mv ∪

1

Me

e∈E

is a minimal determining set for S51,2 (). Note that there is some freedom in the above construction of M. In particular, for each vertex v, the triangle Tv can be any of the triangles with a vertex at v. To get the most stable basis, we recommend choosing Tv to be the triangle with largest angle at v. For interior edges, we also have two choices for the triangle Te used to get Me . We can select these triangles to reduce the constant of stability. We have implemented this algorithm in the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.14. Some useful macro-element spaces

125

.................................................. ......................... ............ .. .. ......................... ............ ... ... ............ ...... ... .... .......... ... ... ... ... ... .... . ...... ... . ... ... . .. .... ... . . ... ... . . ... ..... . ... ... .. ... ... . . ... . . . . ... ... ... .. ... ... ... . . . . . . . . . ... ... ... . .. .. ... ... ... ... ... ... ... ... ... .. ... ... .... . . . . . . ... ... ... .. ... ... ... . ... . . . . . . ... . .... ... .. ... . . . ... ... . . . . ... ... ... ... .. ... . . . . . . . . ... . ... ... ... . ... . ... . . . . . . . . . ... .... ... ... .. . ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .............. . .. ... .. .............. ................... . ............ . ... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .............. . ... .............. ........ .......................................... ... ............ ... . . . . . . . . . . . . . . . . . . . ...................... ... .. ........... ... .... . . . . . ... . . ................. .. . ..... .... ... ..... .... ..... .... ... ..... ... ..... .... ..... .. ... ..... ... ..... ... ..... ... ... ..... ..... ... ... ... .... ..... . . . . . . . . . ... ..... ... .. ..... .... ... ..... ... ..... ... ..... ... ... ..... .... ..... ... ..... ... .... ..... ..... ... ... ..... .... ..... ... ... ..... .. . ..... . . . . . . ... . ... ..... .. ..... ..... ... ... ..... .... ........ ... ...... ..... .. ..... . .. ..... ... .... ........................................................................................................

Figure 4.15. A minimal determining set for S51,2 ().

following function, which can be tested with the script Bmds15: [A,dof] = mds15(x,y,v1,v2,v3,e1,e2,e3,... ie1,ie2,tril,trir,adjstart,eadj,tstart,tadj,bdy) The input is information about the triangulation . The output includes a vector dof containing a list of the indices of the domain points forming the minimal determining set, where we assume the domain points are numbered according to the storage convention of section 4.9.1. The function also computes the transformation matrix, which is a sparse matrix A of size n c × N, where n c = #Dd, is the number of B-coefficients of splines in S51,2 (), and N = #M is the dimension of S51,2 (). The matrix A can be used to compute the vector c of B-coefficients from the vector c˜ containing the coefficients corresponding to the domain points in M; see (4.30). Example 4.35. Find a minimal determining set and the corresponding transformation matrix for the space S51,2 () defined on the triangulation shown in Figure 4.15. Discussion: We use the script Bmds15 and read the triangulation from the file tri9.dat. This triangulation  has n = 9 vertices, ne = 17 edges, and nt = 9 triangles. In this case the dimension of S51,2 () is 71. We have marked the domain points in the MDS M produced by mds15 with black dots for points in the sets Mv , and black triangles for points in the sets Me . For this space we have n c = 131 B-coefficients, so the matrix A is a 131 × 71 sparse matrix. Once we have set the coefficient vector c˜ corresponding to M, the vector c of B-coefficients can be computed by sparse matrix multiplication as in (4.30). The script Bmds15 can also be used to plot the M-basis functions corresponding to the minimal determining set M of Theorem 4.34. Example 4.36. Plot some M-basis functions in the space S51,2 () for the minimal determining set shown in Figure 4.15. Discussion: We make use of the script Bmds15, and read the triangulation from the file type1.25. For this triangulation, the dimension of S51,2 () is N = 206. In Figure 4.16 (left) we show the basis function corresponding to the 13th degree of freedom, which is the coefficient corresponding to the domain point at the 13th vertex of . This basis function is

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

126

Chapter 4. Computing with Splines 2.5 1 0

1.25

-1

0 1 1 0.5

-2 1

0

1 0.5

0.5 0

0.5 0

0

Figure 4.16. Two M-basis functions in the space S51,2 () on the triangulation in Figure 4.15; see Example 4.35.

nonnegative. Figure 4.16 (right) shows the basis function corresponding to the 61st degree of freedom, which corresponds to the domain point numbered 110. Concerning the stability of this basis, we note that mds15 computes A∞ = 19, which is the value of the constant K in (4.36). It is also straightforward to work with a nodal minimal determining set for the space S51,2 (); see section 6.1 of [[LaiS07]].

4.14.3 The macro-element space S92,4 () In this section we describe one of several C 2 macro-element spaces; see Chapter 7 of [[LaiS07]]. Given a triangulation , we consider the superspline space S92,4 () := {s ∈ S92 () : s ∈ C 4 (v) all v ∈ V},

(4.45)

where V is the set of all vertices of . Here s ∈ C 4 (v) means that all of the polynomial pieces of s associated with triangles surrounding the vertex v have common derivatives in all directions up to order four. This space is useful for data fitting problems when we want C 2 splines, and for solving fourth order PDE’s. To give a formula for the dimension of this space, and to identify a corresponding minimal determining set, we need some more notation. Let V and E be the sets of vertices and edges of . For each v ∈ V, let Tv be a triangle with vertex at v, and let Mv := D4 (v) ∩ Tv , where D4 (v) is the set of domain points in the disk of radius four around v. For each edge e := v2 , v3  of , let Te := v1 , v2 , v3  be a triangle containing e, Te Te Te T }. Let n, n , and and let Me := {ξ144 , ξ234 , ξ243 }. For each triangle T of , let MT := {ξ333 e n t be the numbers of vertices, edges, and triangles in , respectively. The following result is well known; see, e.g., Theorem 7.1 of [[LaiS07]]. Theorem 4.37. The space S92,4 () has dimension N = 15n + 3n e + n t . Moreover, the set 1 1 1 M := Mv ∪ Me ∪ MT v∈V

is a stable local minimal determining set.

e∈E

T ∈

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.14. Some useful macro-element spaces

127

As in the previous sections, there is some freedom in the construction of M. In particular, for each vertex v, the triangle Tv can be any of the triangles with a vertex at v. To get the most stable basis, we recommend choosing Tv to be the triangle with largest angle at v. In defining Me for interior edges, we have two choices for Te , and should select the one that gives the smallest constant of stability. We have implemented this algorithm in the following function: [A,dof] = mds29(x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,bdy,tstart,tadj) The input is the usual information about the triangulation . The function returns the transformation matrix A, which is a sparse matrix of size n c × N, where n c = #Dd, is the number of B-coefficients of splines in S92,4 (), and N = #M is its dimension. The matrix A can be used to compute the vector c of B-coefficients from the vector c˜ containing the coefficients corresponding to the domain points in M via multiplication as in (4.30). The output also includes a vector dof containing a list of the indices of the B-coefficients forming the minimal determining set, where we assume the domain points and associated B-coefficients are numbered according to the storage convention of section 4.9.1. Example 4.38. Find a minimal determining set for the space S92,4 () defined on the triangulation shown in Figure 4.17. Discussion: We use the script Bmds29 and read the triangulation from the file tri9.dat. This triangulation  has n = 9 vertices, n e = 17 edges, and n t = 9 triangles. In this case the dimension of S92,4 () is 195 and there are a total of n c = 397 B-coefficients. Thus, the transformation matrix A is of size 397 × 195. In Figure 4.17 we mark domain points corresponding to a minimal determining set for this space. Dots are used for points in the sets Mv , triangles for those in the sets Me , and squares for those in the sets MT . Since it is not really possible to visually confirm from a plot whether a given spline is really C 2 continuous, the script calls on the function cksmooth described in section 4.13.2 to check all of the C 1 and C 2 smoothness conditions of Theorem 4.17. The script Bmds29 can also be used to plot individual basis functions in the space S92,4 (). We simply set one ............ .................................... ......................................... ............................. . ................ .............. .. ... ...... . ... ..... .. .... . . . . ........ ... . .. .... . ... ....... . . ... . ... . .... .. . . . . ... ... .. .... . .. . . . . . .... ... ... .. .... ... ... ... ... . . ... . . .... . . . ... ... . . . .... . . . . . . . . .... ... ... ... . . .. . . .... ... .. ... . . .... . . .... ... .. ... . .... . . . . . .... ... .. .... .. . . . . . . . . . . . . . . . ... ... ....... .. ............................ . . . . . ........ . . .. . . . . . . . . . . . . . . . . . . . . .................... ... .. ............. ............ . ....... .. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .......................................... ..... .. .. . . . . ........................... . . . .. ..... .... .. .... .. ..... .... ..... .... ..... ... .... ... .... ..... .... .. .... . . . . . . . ..... . . . ... .. ..... .... ..... ... .. ..... .... ..... ... ..... .. .... .... ..... .. .... .. . .... . . . . . ..... . . ... . .. ... ..... ... ....... ..... .... ....... .. .... ..... .. .... . .. ........... ..............................................................................................

Figure 4.17. A minimal determining set for S92,4 (). Reprinted with permission from Cambridge University Press [[LaiS07]].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

128

Chapter 4. Computing with Splines v1

•..... .......... ...... ..... .. .. ..... ... .... .......... . . .. . .. ... ... .. .... ..... ... .. ... ... ... .... ... .. ... .... ... ... . . ... ... .. .. . . . ... ... . .. T . . . ... .... . . .. . ... ... . . . . 1 . . ......... ...• ... ... .. . . . . . . . ... ... ... ... ....... . ... . ... . . ..... .. . ... ... . ... . . . . . . ..... .... ... .. ...... ... . . . . ..... .... ... . .. ...... . . . . ... . . ..... .. . .. ...... ... . . . . T . . . . ....... . . .. ...... . . . . . . . . . 3...................•....... ...... . .. ..... . . . . ..... .. . ........ . .. ...... T . . . . . . . . . . . . . . . . ..... ..... . ......................... ........... . 2 . . . ..... .... ...................... .. ... ......• ..... ... ..................... ............ . .......... . . .... ... . . . . . . . . . . . . . . . . . . . . . . . ..................... ... ....... ..................... ............. ........................... .... . •........................................................................................................................................................................................................•...

w

w

w

v2

v3

.... .............. ... ... ...... .. ... ........ . ... ... ..... .... ... ... ... ... ... ... ... ... ... ... .. ... . ... ... .. .. ... ... . . .. ... ... .. . . ... ... .. .. . . ... ... ..... . . . . . .... ... ... ..... ....... . . . . ... . . ... ... ........ .. ... ..... . . . ..... ... .. ...... ... . ..... ..... ... . .... . . . . . . . . ..... ... ... . . ..... ... ... ... ... .... ....... .. ... .. ...... . . ...... ... . . . . . . . . .... .... ...... . . ........ ....... . . . . . .... . . . . . . . . . . ..... ..... ........ . . . . . .. .... . . . . . . . . . . . ..... ... .................... . ..... . . . . . . ..... .... ...... ............................. . . . . . . ......... ..... .. . . . . . . ..................... ....... .. . ..................... ........ .................. ..................... ............. .... . ....... ............. .............................................................................................................................................................................................................

Figure 4.18. The Wang refinement of a single triangle T , and a minimal determining set for the space S2 (TW ) defined on the Wang refinement TW of T . Reprinted with permission from Cambridge University Press [[LaiS07]].

of the degrees of freedom to one and the rest to zero and then compute all B-coefficients by multiplication by the transformation matrix A.

4.14.4 The macro-element space S2 (W ) In the previous section we described a C 2 macro-element space based on splines of degree nine. In this section we discuss a different C 2 macro-element space where the splines are of degree only five. This requires that we work with a suitably refined triangulation. Given a triangle T := v1 , v2 , v3  ∈ , let w1T :=

4v1 + 2v2 + v3 , 7

w2T :=

v1 + 4v2 + 2v3 , 7

w3T :=

2v1 + v2 + 4v3 . 7

We use these points to partition T into seven subtriangles as in Figure 4.18 (left). We write tT for the triangle w1T , w2T , w3T  in the middle of the split of T . Starting with an arbitrary triangulation , let W be the Wang refinement of  obtained by applying the above split to every triangle T ∈ . We are interested in the following Wang macro-element space: S2 (W ) := {s ∈ S52 ((W )) : s is C 3 across the edges of tT , all T ∈ }. We now describe a minimal determining set of S2 (W ) and give a formula for its dimension. For each vertex v of , let Tv be a triangle of W attached to v, and let Mv := D2 (v) ∩ Tv . For each edge e := v2 , v3  of , let Te := v1 , v2 , v3  be a triangle Te Te Te of W containing e, and let Me := {ξ122 , ξ221 , ξ212 }. These points are marked with triangles in Figure 4.18 (right). Let n and n e denote the numbers of vertices and edges of , respectively. The following theorem is well known; see, e.g., Theorem 7.13 in [[LaiS07]]. Theorem 4.39. The space S2 (W ) has dimension equal to 6n + 3n e , and 1 1 Mv ∪ Me M := v∈V

is a minimal determining set.

e∈E

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.14. Some useful macro-element spaces

129

This minimal determining set is illustrated in Figure 4.18 (right) in the case where W is the Wang refinement of a single macro triangle. We have written the following function for constructing the Wang refinement of a given triangulation. It also picks a minimal determining set and computes the corresponding transformation matrix. [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,tadj,tstart,... dof,A] = mdswang(xo,yo,v1o,v2o,v3o,e1o,e2o,e3o, ... ie1o,ie2o,trilo,triro,tstarto,tadjo) The input is the usual information about the initial triangulation . The output gives the analogous information for the refined triangulation. The function computes the transformation matrix A, which is a sparse matrix of size n c × N, where n c = #Dd, is the number of B-coefficients of splines in S2 (W ), and N = #M is the dimension of S2 (W ). The matrix A can be used to compute the vector c of B-coefficients from the vector c˜ containing the coefficients corresponding to the domain points in M; see (4.30). The output also includes a vector dof containing a list of the indices of the domain points forming the minimal determining set, where we assume the domain points are numbered according to the storage convention of section 4.9.1. Example 4.40. Find a minimal determining set for the space S2 (W ) defined on the type-1 triangulation shown in Figure 4.7, and plot some basis functions in the space. Discussion: We use the script Bmdswang, and we read the triangulation from the file type1.25. This triangulation has no = 25 vertices, neo = 56 edges, and nto = 32 triangles. The Wang refinement has n = 224 vertices, ne = 344 edges, and nt = 224 triangles; see Figure 4.19. In this case the dimension of S2 (W ) is 318 and there are a total of n c = 2841 B-coefficients. Thus, the transformation matrix A is of size 2841 × 318. In Figure 4.20 (left) we show the basis function corresponding to the 13th degree of freedom, which is the B-coefficient associated with the domain point at (.5, .5). This basis function is supported on the set of all triangles of  that share a vertex at this point. Note the rather complex shape. In Figure 4.20 (right) we show the basis function corresponding to the 251st degree of freedom. It corresponds to the 2370th domain point, which lies in a triangle along the 34th edge. Thus, the support of this basis function is the two macro triangles sharing that edge.

Figure 4.19. A type-1 triangulation and its Wang refinement.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

130

Chapter 4. Computing with Splines

Figure 4.20. Two M-basis functions in the space S2 (W ); see Example 4.40.

4.15 Degree raising Suppose s is a spline of degree d in a spline space S(). Then clearly s can also be written as a spline of degree d +1 on the same triangulation. In fact, given the B-coefficients of s as a spline of degree d, it is not hard to find the B-coefficients of s as a spline of degree d + 1. The computation is based on the following well-known result; see, e.g., Theorem 2.39 in [[LaiS07]]. Theorem 4.41. Let p be a polynomial of degree d defined on a triangle T written in the B-form (4.5). Let {ci j k }i+ j +k=d be its set of B-coefficients. Then  p= c˜i j k Bid+1 (4.46) jk , i+ j +k=d+1

where Bid+1 j k are the Bernstein basis polynomials of degree d + 1 associated with T , and where i ci−1, j ,k + j ci, j −1,k + kci, j ,k−1 , (4.47) c˜i j k := d +1 for i + j + k = d + 1. Here coefficients with negative subscripts are taken to be zero. We have implemented this algorithm in [dw,cw] = degraise(d,n,v1,v2,v3,e1,e2,e3,ie1,ie2,c) Here d is the degree of the spline, and n is the number of vertices in the triangulation . The vectors v1,. . .,ie2 describe , while c is the vector of B-coefficients of s. The output is dw := d + 1, and a vector cw of the B-coefficients of s, written as a spline of degree d + 1 on . Example 4.42. Let s be a spline of degree d on the type-1 triangulation with nine vertices. Compute the degree-raised spline, and compare the plots on a 51 × 51 grid. Discussion: We make use of the script Bdegraise, and read the triangulation from the file type1.9. The script sets d = 2 and chooses random values for the B-coefficients. It plots both the original spline and the degree-raised spline. They appear to be identical. As a further check that they are the same, we compute the maximum difference on a 51×51 grid. For this example, it is 3.33(−16). If we repeatedly degree-raise the spline, we continue to get the same plot, and the differences on the grid are all zero to machine accuracy.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.16. Subdivision

131

4.16 Subdivision For use in constructing a certain local scattered data interpolation method, we need to solve the following subdivision problem. Problem 4.43. Suppose s is a spline in S30 () with coefficients vector c. Find the coefficient vector c˜ of s written as a spline in S30 ((C T )), where (C T ) is the Clough–Tocher refinement of . This problem is easily solved using the following well-known result for subdividing a polynomial into three pieces; see Theorem 2.38 in [[LaiS07]]. Theorem 4.44. Given a triangle T , let w be a point in the interior of T with barycentric coordinates a := (a1 , a2 , a3 ). For each  = 1, 2, 3, let BiTjk,d be the Bernstein basis polynomials associated with T := w, v+1 , v+2 . Let p be a polynomial of degree d written in (0) the B-form (4.5) relative to T . Suppose {ci j k }i+ j +k=d is the set of B-coefficients of p. Then ⎧  (i) ⎪ c0 j k BiTj1k,d (v), ⎪ ⎪ ⎪ ⎪ ⎪i+ j +k=d ⎪ ⎪ ⎨  ( j) ci0k BiTj2k,d (v), p(v) = ⎪ i+ j +k=d ⎪ ⎪ ⎪  ⎪ (k) T ,d ⎪ ⎪ ci j 0 Bi j3k (v), ⎪ ⎩

v ∈ T1 , v ∈ T2 , v ∈ T3 ,

i+ j +k=d

(ν)

(ν)

where ci j k := ci j k (a) are the quantities obtained in the νth step of the de Casteljau algo(0)

rithm based on the triple a, starting with the coefficients ci j k := ci j k . Using this result and the ideas in refine, we have the following function for solving Problem 4.43: [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,cw] = ... ctsubdiv(xo,yo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro,c); The input contains information about the original triangulation , along with the coefficient vector c of s. The output gives analogous information about the Clough–Tocher refinement C T of , along with the new vector of B-coefficients of the subdivided spline. Example 4.45. Let s be a spline in S30 () where  is the type-1 triangulation with nine vertices. Rewrite s as a spline in S31 (C T ). Discussion: We make use of the script Bctsubdiv, and read the triangulation from the file type1.9. The script chooses random values for the B-coefficients of a spline in S30 () and then calls ctsubdiv to perform the subdivision. It plots both the original spline and the subdivided spline. They appear to be identical, but as a further check that they are the same, we compute the maximum difference on a 51 × 51 grid. For this example, it is 4.44(−16).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

132

Chapter 4. Computing with Splines

4.17 Remarks Remark 4.1. In section 4.9.1 we described our approach to storing a spline in Sd0 (). We simply store its set of B-coefficients using the storage convention detailed there. Alternatively, one could store a spline )d+2* s as a piecewise polynomial, i.e., for each triangle T we would store the full set of 2 B-coefficients defining the polynomial s|T . This approach would take somewhat more storage space, and does not seem to offer any particular advantages since in order to evaluate s at a point in T , we still have to extract the corresponding B-coefficients. Remark 4.2. In section 4.9.2 we described a basis for Sd0 (). In general, spline spaces have many different bases, and which one is most useful depends on the application. In general, we have focused on bases with two important properties: 1) they should be local, i.e., each basis function should have a small support, and 2) they should be stable, which means that the size of a spline is comparable to the size of its coefficients. In section 4.14 we have constructed bases for various macro-element spaces, where our choices were guided by these two principles. Remark 4.3. The basis for Sd0 () constructed in section 4.9.2 has the nice property that the basis functions are nonnegative and form a partition of unity; see Lemma 4.10. The M and N dual bases for macro-element spaces with at least C 1 smoothness discussed in section 4.14 generally do not have this property. For at least one of the macro-element spaces discussed here, the Powell–Sabin space S21 ( P S ), it is possible to construct an alternative set of basis functions which are nonnegative and form a partition of unity; see [[Die93]]. For more on these Powell–Sabin B-splines and their use, see [SpeDV08, SpeDV08b, SpeDV09, Spe10b, Spe13]. Remark 4.4. It should be emphasized that for many applications (including both Lagrange and Hermite interpolation), it is not necessary to have any explicit basis at all — one can work directly with the set of B-coefficients. In particular, none of the interpolation methods described in Chapter 5 makes any use of basis functions. Bases are needed in Chapter 6 to describe the minimal energy interpolation method, and in Chapter 7 for explaining the least-squares and penalized least-squares methods. But they are never explicitly computed in the programs. Remark 4.5. Much work has gone into understanding the properties of the general space of splines Sdr () introduced in (4.23). Despite years of work, there remain many open questions on a variety of fundamental issues such as dimension, existence of local bases, and approximation power. For example, although there is a very credible conjecture for the dimension of the space S31 () in terms of the number of vertices, edges, and triangles in , to date this formula has not been shown to hold for arbitrary triangulations. These problems explain why for many applications, it is easier to work with superspline spaces. Remark 4.6. In Definition 4.16 we introduced certain spaces of splines with a given degree of supersmoothness at each of the vertices. It is also possible to work with supersplines where the degree of supersmoothness varies from vertex to vertex; see, e.g., [[LaiS07]]. Remark 4.7. In some applications it is useful to work with superspline subspaces of Sdr () where the splines are required to satisfy certain individual smoothness conditions of the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

4.18. Historical notes

133

type described in (4.28) across some or all of the edges of the triangulation. This idea has been exploited to define various classes of smooth macro-element spaces with minimal dimension; see Chapters 6–8 of [[LaiS07]]. Remark 4.8. All of the surface plots shown in this book have been created with MATLAB. We have elected to work with wire frame plots, i.e., the surface is represented by a collection of lines. However, MATLAB also offers the possibility of working with shaded surface patches instead. This sometimes leads to more realistic looking smooth surfaces, but to use this approach effectively, one has to deal with placement of lights so that the surface can be seen clearly from all sides as it is rotated. Remark 4.9. There is, of course, a lot of commercial software available for viewing surfaces as patches with realistic lighting models. I recommend the public domain software Geomview, which was developed at the University of Minnesota in the 1990’s. Although the original project is no longer active, there remains a web site with details on the program along with instructions for downloading the software; see http://www.geomview. org/. Binaries are available for UNIX machines and for Macintoshes, but it can also run on Windows machines using the Cgwin environment. Remark 4.10. For those wanting to try Geomview, I have included the following MATLAB function: writegv(xg,yg,zg,G,fid) This function creates a file which can be read by Geomview. The input consists of arrays xg,yg,zg defining a grid on a rectangle, and a matrix G listing the vertices of the associated triangular facets to be plotted. These are precisely the output of the function valspDP described in section 4.12.2. This function requires a file identifier fid that can be defined in MATLAB with a call on fopen to set up the path and name of the file to be written. Remark 4.11. For new and more efficient quadrature rules for integrating functions over triangles, see [AinAD11].

4.18 Historical notes A discussion of the history of barycentric coordinates and Bernstein basis polynomials, and their use for representing and computing with polynomials defined on a triangle, can be found in section 2.20 of [[LaiS07]]. The key tool for computing with the Bernstein–Bézier representation of polynomials is Algorithm 4.3 of de Casteljau. Despite being discovered in the early 1960’s and described in a closely held Citroën technical report [Cas63], it was not until the 1970’s that it became more publicly known. For a detailed account of these early developments in the use of Bernstein–Bézier representations, see Chapter 1 of [[FarHK02]]. The idea of using the domain points to index the Bernstein basis polynomials seems to have been introduced in [AlfS87], where minimal determining sets were also used for the first time. The history of the conditions (4.28) describing C r smoothness across the edge shared by two polynomial patches can also be found in section 2.20 of [[LaiS07]]. The macro-element spaces discussed here (and many more) are treated in detail in Chapters 6–8 of [[LaiS07]]. For the history of their development, see the historical notes sections of those chapters. Lemma 4.23 giving explicit coefficients for the dual M basis of a spline space was observed first in [Schum08].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 5

Macro-element Interpolation Methods

In this chapter we discuss several interpolation methods based on macro-element spline spaces. All of the methods will be local in the sense that the spline at a given point will depend only on function or derivative values at nearby points. The interpolants will be constructed directly from the data without solving any systems of equations, and without making use of any basis splines.

5.1 Introduction Let V := {x i , yi }ni=1 be a set of points in R2 , and let  be the convex hull of V. Let  be a triangulation of  with vertices at the points of V. Given k ≥ 0, our aim in this chapter is to examine methods for constructing a spline s defined on the triangulation  such that νμ

Dxν D μ y s(x i , yi ) = z i ,

0 ≤ ν + μ ≤ k, i = 1, . . . , n,

νμ

(5.1)

where the z i are given real numbers. We refer to this as a Hermite interpolation problem. To solve the Hermite interpolation problem, we will make use of certain macro-element spaces S(), i.e., spaces of splines such that for every s ∈ S() and every triangle T in , s|T is uniquely determined from the Hermite data at the vertices of T , and in some cases some additional Hermite data at a few points on the edges of T . Such spaces have been studied in great detail in the literature. For a more precise definition, see section 5.10 of [[LaiS07]], and for a detailed study of a variety of macro-element spaces, see Chapters 6–8 of [[LaiS07]]. In this chapter we discuss Hermite interpolation based on a few of the most useful macro-element spaces. In addition to being of interest in their own right, the methods will be useful in solving the more common scattered data interpolation and approximation problems to be discussed in Chapters 6 and 7 below. For each of the spaces considered in this chapter, we provide the details of what data is needed, along with explicit formulae for computing the B-coefficients of the spline directly from the data without solving any systems of equations and without using any basis functions. As a means of comparing the performance of the methods, we apply each of them to 135

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

136

Chapter 5. Macro-element Interpolation Methods 1

1

0.5

0.5

0 0

0.5

0 0

1

0.5

1

Figure 5.1. The triangulations tri36 and type1.25.

the problem of interpolating the Franke test function (2.20) on the unit square  := [0, 1]2, based on data at the 36 vertices of the triangulation tri36 shown in Figure 5.1 (left). We shall also make extensive use of various type-1 triangulations such as the one shown in Figure 5.1 (right). In each example we will evaluate the interpolating spline on a grid im˜ containing the domain . For this we use the posed on the smallest rectangle [a, b] × [a, ˜ b] function valspgrid defined in section 4.12.1. Given n g , it creates a matrix g of values g g of the spline associated with equally spaced grid points defined by a = x 1 < · · · < x n g = b g g ˜ This function returns the value NaN at grid points that are not and a˜ = y1 < · · · < yn g = b. in . In order to illustrate the accuracy of the methods, we compare the spline values in g as computed by valspgrid with the values of the test function at the grid points. For this purpose we can use the function e = errg(xg,yg,g,f) introduced in section 2.4.1 for computing errors. There the domain  was a rectangle, but here it need not be. As mentioned above, when  is nonrectangular, valspgrid produces NaN values at grid points that are not in . The function errg drops such points. Thus, the output vector e is of length N, where N is the number of grid points that lie in . Using this error vector, we can compute the maximum error on the grid as norm(e,inf). A call on our function erms then produces the value of the root-mean-square (RMS) error ⎞1/2 ⎛  1 ⎝  g g g g RMS := [s(x i , y j ) − f (x i , y j )]2 ⎠ , (5.2) N 1≤i, j ≤n g

where the  on the sum indicates that the sum is taken only over values of i , j such that g g (x i , y j ) lies in . Most of the error tables in this chapter are based on a 51 × 51 grid. For each of the methods discussed in this chapter, we shall also give bounds for how well s approximates f and its derivatives. These bounds will all be stated in terms of the maximum norm on [0, 1], the smoothness of f as measured by some semi-norm, and the mesh size of the triangulation  defined by || := max |T |, T ∈

where for each triangle T in , |T | is the length of the longest edge in T .

(5.3)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.2. The C 1 Powell–Sabin interpolant

137

To illustrate these error bounds, for each method we will perform interpolation on the nested sequence of triangulations obtained from the triangulation type1.25 shown in Figure 5.1 (right) by uniform refinement. For each level of refinement, the mesh size is halved, and we can compute the order of convergence by computing the error ratios at successive levels of refinement.

5.2 The C 1 Powell–Sabin interpolant Given a triangulation , we recall from section 4.14.1 that its Powell–Sabin refinement  P S is defined as follows: 1) find the incenters u T of each triangle T in ; 2) for each T , connect u T to each of its three vertices; 3) for each pair of neighboring triangles T and T˜ ; connect their incenters; 4) for each triangle T with a boundary edge e, connect the incenter u T to the midpoint of e. Note that in forming the Powell–Sabin refinement of , each triangle is divided into six subtriangles. We refer to the original triangles in  as macro triangles. Figure 4.11 shows a triangulation and its Powell–Sabin refinement. For more on Powell–Sabin refinements, see section 4.8.2 of [[LaiS07]]. The following theorem is well known; see section 6.3 of [[LaiS07]]. Theorem 5.1. Given any triangulation  with vertices {(x i , yi )}ni=1 and any real numbers y {z i , z ix , z i }ni=1 , there exists a unique spline s ∈ S21 ( P S ) such that s(x i , yi ) = z i , Dx s(x i , yi ) = z ix , D y s(x i , yi ) =

i = 1, . . . , n.

(5.4)

y zi ,

As shown in section 6.3 of [[LaiS07]], the spline s ∈ S21 ( P S ) solving the Hermite interpolation problem (5.4) can be computed locally. Suppose T := v1 , v2 , v3  is one of the triangles in  which has been split into six subtriangles in forming  P S . Now consider the restriction s|T to the macro triangle T . It is itself a quadratic spline consisting of six quadratic polynomial pieces joined together with C 1 smoothness. This subspline is determined by 19 coefficients which we number as in Figure 5.2, where c1 , c2 , c3 are associated with the vertices v1 , v2 , v3 , respectively. We now give explicit formulae for these coefficients in terms of the data at the three vertices. Let u T = (x c , yc ) be the incenter of T , and suppose the barycentric coordinates of u T relative to T are (a1, a2 , a3 ). Let e1 := v1 , v2 , e2 := v2 , v3 , and e3 := v3 , v1  be the edges of T . For each i = 1, 2, 3, let wi := (xˆi , yˆi ) = ri vi + si vi+1 be the vertex of  P S on the edge

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

138

Chapter 5. Macro-element Interpolation Methods

c3

.... ........ ... .. ... ... ... ... ... .... ..... ... ... . ... ... ... ... ... .... ... ... ... ... ... ... ... . .... . ... . ... ... ... ... ... .... ... ... . ... ... ... ... ... . . . . ... . .. ... ... ... ... ... . . . . ... . .. ... ... ... ... ... . . . . ... . .. ... ... ... ... ... . . . . ... . ... .. ... ... ... ... . . ... . . . .. ... ... ... ... ... . . . ... . . ... .. ... ... ... ... . . . . . . ..... .. ........... ....... ..... ... ... .............. ....... . ... . . . . . ....... . ... .. ... .. ....... ....... ... ... ....... ... ........ . ... . . . ... . . . . . . . . . . ........ . .... ... .. ....... ... ....... ... ....... ....... ... . ... . . . . ... . . . . . . . . . ....... . . ... ........ ....... ... ... ....... ..... .............. ... . ... . . . . . . . . . . ........ . ... ... ................ ... ....... ... .............. ... . . ... . . . . . . ....... .. . ... ..... ....... ... ....... ... ....... ..... ....... ... . ... . . . . . . . . . . . ........ . . ... ..... ....... ... ..... ....... ... ....... ... ....... . ... . . . . . . . . . . . . ....... . ... .... .... ........ ....... ... ... ....... . ........ ... . ... . . . . . . . . . . . . . ....... .. . ... ..... ....... ... ... ....... ........ .... ....... ... . ... . . . . . . . . . . . ... ....... . ... .... ....... ... ....... ... ....... .... ........ ... . ... . . . . . . . . . . . ........ . . ... ..... ....... ... .. ....... ..... ....... ....... ... . . . . ....... ..... . . . . . . ....... .. ..... ... ........ ........ ... ................. . ... . . . . . . . . ...................................................................................................................................................................................................................................................................................................................................................................................

c10

c12

c11

c15

c18 c19

c6

c4

c7

c16 c8

c5

c1

c14

c17

c13

c9

c2

Figure 5.2. Coefficients of a C 1 Powell–Sabin spline on one macro triangle. Reprinted with permission from Cambridge University Press [[LaiS07]].

ei , where we identify v4 = v1 . Then it is known (see section 6.3 of [[LaiS07]]) that c1 = z 1 ,

c2 = z 2 ,

c3 = z 3 , y

c4 = [(xˆ1 − x 1)z 1x + ( yˆ1 − y1 )z 1 ]/2 + z 1, y

c5 = [(x c − x 1 )z 1x + (yc − y1)z 1 ]/2 + z 1, y

c6 = [(xˆ3 − x 1)z 1x + ( yˆ3 − y1 )z 1 ]/2 + z 1, y

c7 = [(xˆ2 − x 2)z 2x + ( yˆ2 − y2 )z 2 ]/2 + z 2, y

c8 = [(x c − x 2 )z 2x + (yc − y2)z 2 ]/2 + z 2, y

c9 = [(xˆ1 − x 2)z 2x + ( yˆ1 − y2 )z 2 ]/2 + z 2, y

c10 = [(xˆ3 − x 3)z 3x + ( yˆ3 − y3 )z 3 ]/2 + z 3, y

c11 = [(x c − x 3 )z 3x + (yc − y3)z 3 ]/2 + z 3, y

c12 = [(xˆ2 − x 3)z 3x + ( yˆ2 − y3 )z 3 ]/2 + z 3. Moreover, the remaining coefficients of s|T can be computed with the formulae c13 = r1 c4 + s1 c9 , c14 = r2 c7 + s2 c12 , c15 = r3 c10 + s3 c6 , c16 = r1 c5 + s1 c8 , c17 = r2 c8 + s2 c11 , c18 = r3 c11 + s3 c5 , c19 = a1 c5 + a2 c8 + a3c11 .

(5.5)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.2. The C 1 Powell–Sabin interpolant

139

We have implemented C 1 Powell–Sabin interpolation in the function [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy,c] = ... ps(xo,yo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro,z,zx,zy) The input includes information about the triangulation  as well as the data to be interpolated, which is stored in the vectors z, zx, and zy. The output updates the triangulation information to correspond to the Powell–Sabin refinement. It also returns the vector c of B-coefficients, ordered according to the storage convention in section 4.9.1. The following script can be used to test this code: % Bps [no,xo,yo,nto,TRI] = readtri; figure; triplot(TRI,xo,yo); [nbo,neo,nto,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,trilo,... triro,bdyo,vadjo,eadjo,adjstarto,tadjo,tstarto,... areao,TRI] = trilists(xo,yo,TRI); der = franke2d(xo,yo); z = der(:,1); zx = der(:,2); zy = der(:,3); [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy,c] = ps(xo,... yo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,trilo,triro,z,zx,zy); ng = 51; d = 2; xmin = min(xo); xmax = max(xo); ymin = min(yo); ymax = max(yo); [xg,yg,g] = valspgrid(d,x,y,v1,v2,v3,e1,e2,e3,ie1,c,... ng,xmin,xmax,ymin,ymax); figure; surfl(xg,yg,g’); colormap(copper); e = errg(xg,yg,g,@franke2); fprintf(’emax =%5.2e, RMS = %5.2e\n’,norm(e,inf),erms(e)); This script uses readtri to read in a triangulation  from a file. The data values are calculated from the test function franke2d which produces all derivatives up to order two at a given point for Franke’s function f . In particular, the output vector der contains the value of the function, followed by the derivatives f x , f y , f x x , f x y , and f yy in that order. Here we are not using the second order derivatives. The spline is evaluated on a 51 × 51 grid with a call on valspgrid, and the maximum and RMS errors over this grid are calculated using errg. Throughout this chapter we will also examine the x-derivative of our interpolating splines. To get values of the x-derivative on a grid, we call the function valspdergrid introduced in section 4.12.3. with the direction vector u = [1, 0]. Example 5.2. Interpolate Franke’s function (2.20) at the 36 vertices of the triangulation shown in Figure 5.1 using the C 1 quadratic Powell–Sabin spline space S21 ( P S ). Discussion: We use the script Bps, and read the triangulation from the file tri36.dat. We show a plot of the resulting spline in Figure 5.3. This figure also shows a plot of

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

140

Chapter 5. Macro-element Interpolation Methods

1.2

3

0.6

0

-3 1

0 1

1

1 0.5

0.5

0.5

0.5 0 0

0 0

Figure 5.3. The C 1 Powell–Sabin interpolant to Franke’s function based on the triangulation in Figure 5.1, and its x-derivative.

the x-derivative of the spline, which is a C 0 linear spline on the triangulation  P S . For comparison purposes, we note that the max and RMS errors for the spline fit on a 51 × 51 grid in the unit square are 1.23(−1) and 2.28(−2), respectively. For the x-derivative, the errors are 1.52 and 2.53(−1). We now explore the rate of convergence of this interpolation method by performing interpolation on a sequence of nested grids where the mesh size is successively halved. Example 5.3. Use C 1 Powell–Sabin splines to interpolate Franke’s function (2.20) at the vertices of the type-1 triangulation shown in Figure 5.1 (right). Repeat for each of the first four uniform refinements of this triangulation. Discussion: We again use the script Bps. We read the triangulations from the following files: type1.25, type1.81, . . . , type1.4225. Here is a table of the maximum and RMS errors on a 51 × 51 grid, along with the number n of vertices and the number nd of data required for each spline. n nd 25 75 81 243 289 867 1089 6267 4225 12675

emax 8.99(−2) 2.41(−2) 2.41(−3) 2.60(−4) 2.33(−5)

rms 2.15(−2) 2.62(−3) 2.71(−4) 3.02(−5) 3.62(−6)

ratios 3.73 8.21 10.00 9.67 9.27 8.97 11.16 8.34

Note that the rate of convergence seems to be O(||3 ), which is what we expect for this interpolation method; see Theorem 5.4 below. The maximum and RMS errors for the xderivative are as follows: n nd 25 75 81 243 289 867 1089 6267 4225 12675

emax 1.39(0) 7.10(−1) 2.23(−1) 4.43(−2) 1.55(−2)

rms 3.23(−1) 8.35(−2) 2.08(−2) 5.17(−3) 1.31(−3)

ratios 1.96 3.87 3.18 4.01 5.03 4.02 2.86 3.95

The rate of convergence seems to be O(||2 ), as is to be expected for a first derivative according to Theorem 5.4.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.3. The C 1 Powell–Sabin-12 interpolant

141

The following error bound for C 1 Powell–Sabin interpolation was established in Theorem 6.12 in [[LaiS07]]. Theorem 5.4. For every f ∈ C m+1 () with 0 ≤ m ≤ 2, its C 1 Powell–Sabin interpolant s satisfies (5.6) Dxα D βy ( f − s) ≤ K ||m+1−α−β | f |m+1 for all 0 ≤ α + β ≤ m. If  is convex, then the constant K depends only on the smallest angle in . If  is not convex, then K also depends on the Lipschitz constant of the boundary of . This result shows that if we interpolate data sampled from a function f in C 3 (), then we can expect the error to behave like O(||3 ) as we let || go to zero. This is the optimal order of convergence for quadratic splines. Assuming f is smoother will not lead to higher order convergence, as we saw in Example 5.3, where the data came from Franke’s function, which is C ∞ . On the other hand, if the smoothness of f is less than C 3 , we may get a lower rate of convergence; see section 5.8.

5.3 The C 1 Powell–Sabin-12 interpolant In this section we present another local method for constructing a C 1 quadratic spline satisfying (5.4). This method requires splitting each macro triangle into 12 micro triangles. This added complexity may seem unnecessary, but the resulting method has some advantages over the standard Powell–Sabin element discussed in the previous section; see Remark 5.9. Given a triangulation  of a domain , we recall that its Powell–Sabin-12 refinement  P S12 is defined as follows. For each triangle T in , 1) pick a point u T in the interior of T ; 2) connect u T to each of the three vertices of T as well as to the midpoint of each edge of T ; 3) connect the midpoints on successive edges of T to each other. Figure 5.4 shows a triangulation and its Powell–Sabin-12 refinement. For more on Powell– Sabin-12 refinements, see section 4.8.3 of [[LaiS07]]. In practice, we may take the split

Figure 5.4. A triangulation and its Powell–Sabin-12 refinement.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

142

Chapter 5. Macro-element Interpolation Methods

point u T of each triangle to be its barycenter. This gives a good control on the size of the angles in  P S12; see Lemma 4.22 in [[LaiS07]]. The space S21 ( P S12) defined on the Powell–Sabin-12 refinement of a triangulation  has dimension 3n + n e , where n and n e are the numbers of vertices and edges in ; see Theorem 6.13 in [[LaiS07]]. To use it for Hermite interpolation, in addition to the Hermite data in (5.4), we need to provide a cross derivative at the midpoint of each edge of . However, it turns out that we can get the same approximation power with the following smaller subspace: S˜21 ( P S12)) := {s ∈ S21 ( P S12)) : Dne s|e ∈ P11 for each edge e of },

(5.7)

where Dne is the directional derivative associated with the unit vector ne corresponding to rotating e 90 degrees in a counterclockwise direction. The dimension of this space is 3n. The following result is established in [AlfSS10]. Theorem 5.5. Given any triangulation  with vertices {(x i , yi )}ni=1 and any real numbers y {z i , z ix , z i }ni=1 , there exists a unique spline s ∈ S˜21 ( P S12)) satisfying (5.4). The space S˜21 ( P S12)) is a macro-element space in the sense of Definition 5.27 of [[LaiS07]]. This means that the interpolant can be computed one macro triangle at a time. Suppose T := v1 , v2 , v3  is one of the triangles in  which has been split into 12 subtriangles in forming  P S12). Now consider the restriction s|T to the macro triangle T . It is itself a quadratic spline consisting of 12 quadratic polynomial pieces joined together with C 1 smoothness. This subspline is determined by 28 coefficients. Explicit formulae for computing each of these coefficients directly from the Hermite data at the vertices of T can be found in [AlfSS10]. We have implemented this method in SplinePak as the following function: [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c] = ps12(xo,yo,... z,zx,zy,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,trilo,triro) The input includes information on the original triangulation  along with the Hermite data. The function returns the lists describing the refined triangulation  P S12, along with the corresponding vector c of B-coefficients of the interpolant. Example 5.6. Interpolate Franke’s function (2.20) at the 36 vertices of the triangulation shown in Figure 5.1 (left) using the C 1 quadratic Powell–Sabin-12 space S21 ( P S12). Discussion: We use the script Bps12, and read the triangulation from the file tri36.dat. We do not show plots of the spline and its x-derivative as they are very similar to the ones obtained in Example 5.2 using the space S21 ( P S ). Here the max and RMS errors for the spline fit on a 51 × 51 grid in the unit square are 1.13(−1) and 1.88(−2), respectively, which are slightly better than what we got with S21 ( P S ). For the x-derivative, the errors are 1.17 and 2.22(−1), which are also slightly better. We now explore the rate of convergence of Hermite interpolation with this spline space by performing interpolation at the vertices of the sequence of nested type-1 triangulations used in Example 5.3.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.4. The C 1 Clough–Tocher interpolant

143

Example 5.7. Repeat Example 5.3 using the C 1 quadratic Powell–Sabin-12 spline space. Discussion: We use the script Bps12, and read the triangulations from files type1.25, etc. Here is a table giving the maximum and RMS errors for n vertices. We also give the number nd of data required in each case. n nd 25 75 81 243 289 867 1089 3267 4225 12675

emax 8.40(−2) 2.30(−2) 1.97(−3) 1.88(−4) 1.85(−5)

rms 1.74(−2) 2.29(−3) 2.12(−4) 2.24(−5) 2.60(−6)

ratios 3.65 7.60 11.68 10.80 10.48 9.46 10.16 8.62

Comparing with the table in Example 5.3, we see that the errors here are generally slightly better, and the order of convergence is three as expected. The following table gives errors for the x-derivatives: n nd 25 75 81 243 289 867 1089 3267 4225 12675

emax 1.52(0) 5.10(−1) 1.98(−1) 4.95(−2) 9.52(−3)

rms 2.81(−1) 7.18(−2) 1.63(−2) 4.31(−3) 1.04(−3)

ratios 2.98 3.91 2.58 4.40 4.00 3.78 5.20 4.14

The errors here are comparable with those obtained with the Powell–Sabin interpolant in Example 5.3. The order of convergence is O(||2 ), as is to be expected.

5.4 The C 1 Clough–Tocher interpolant Given a triangulation , we recall that its Clough–Tocher refinement (C T ) is defined as follows: for each triangle T := v1 , v2 , v3  in , find its barycenter u T := (v1 + v2 + v3 )/3 and connect it to each of its three vertices. Note that in forming the Clough–Tocher refinement, each triangle in  is divided into three subtriangles. Figure 5.5 shows a triangulation and its Clough–Tocher refinement. For more on Clough–Tocher refinements, see section 4.8.1 of [[LaiS07]]. Let E denote the set of all edges of . For each edge e := u, v ∈ E, let ηe := (u + v)/2 be the midpoint of e, and let Dne be the directional derivative associated with the unit vector

Figure 5.5. A triangulation and its Clough–Tocher refinement.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

144

Chapter 5. Macro-element Interpolation Methods c3

.... ........ ... ... ... ... .. .... ... ... ..... ... ... ... . . . ... ... ... .... ... ... .... ... ... ... ... .. . . . ... ... ... ... . . . ... ... ... . ... . . . ... ... ... . ... . ... ... ... . . . ... ... ... ... . . . ... .. ... ... . . . . ... ... ... . ... . . ... ... ... . . . ... . .. ... . ... . . ... .. ....... ............. ... ... . . . . . . . . ........ .. ... ....... ....... ... . . ... . . . . . . ........ .. ... ....... ....... ... . . . . . ... . . . . ....... .. ... ........ ....... ... . . . . . . . . ... ....... ... ........ . ... ....... . . . . . . . . . ....... ..... . ....... .. ................. . .... . . .. .................................................................................................................................................................................................

c11 c12 c18

c10

c15

c6

c1

c16

c5

c19

c13

c4

c14

c17

c9

c8

c7

c2

Figure 5.6. The B-coefficients of a Clough–Tocher macro element. Reprinted with permission from Cambridge University Press [[LaiS07]].

ne corresponding to rotating e 90 degrees in a counterclockwise direction. We call this the cross derivative. The following theorem is well known; see, e.g., section 6.2 of [[LaiS07]]. Theorem 5.8. Given any triangulation  with vertices {(x i , yi )}ni=1 and any real numbers y {z i , z ix , z i }ni=1 and {z e }e∈E , there exists a unique spline s ∈ S31 (C T ) satisfying (5.4) at the vertices of , and Dne s(ηe ) = z e for all edges e of . The space S31 (C T ) is macro-element space in the sense of Definition 5.27 of [[LaiS07]]. This means that the interpolant can be computed one macro triangle at a time. Suppose T := v1 , v2 , v3  is one of the triangles in  which has been split into three subtriangles in forming (C T ). Now consider the restriction s|T to the macro triangle T . It is itself a cubic spline consisting of three cubic polynomial pieces joined together with C 1 smoothness. This subspline is determined by 19 B-coefficients which we number as in Figure 5.6, where c1 , c2 , c3 are associated with the vertices v1 , v2 , v3 , respectively. Then it is known (see section 6.2 of [[LaiS07]]) that c1 = z 1 , c4 c5 c6 c7 c8 c9 c10 c11 c12

c2 = z 2 ,

c3 = z 3 , y x = [(x 2 − x 1 )z 1 + (y2 − y1)z 1 ]/3 + z 1, y = [(x c − x 1)z 1x + (yc − y1 )z 1 ]/3 + z 1, y = [(x 3 − x 1 )z 1x + (y3 − y1)z 1 ]/3 + z 1, y = [(x 3 − x 2 )z 2x + (y3 − y2)z 2 ]/3 + z 2, y = [(x c − x 2)z 2x + (yc − y2 )z 2 ]/3 + z 2, y = [(x 1 − x 2 )z 2x + (y1 − y2)z 2 ]/3 + z 2, y = [(x 1 − x 3 )z 3x + (y1 − y3)z 3 ]/3 + z 3, y = [(x c − x 3)z 3x + (yc − y3 )z 3 ]/3 + z 3, y = [(x 2 − x 3 )z 3x + (y2 − y3)z 3 ]/3 + z 3.

(5.8)

Now consider the edge e := v1 , v2 , and suppose (a1 , a2 , a3 ) are the directional coordinates of n e relative to T . Then c13 =

4 1 a1 a2 z e − (c5 + c8 ) − (c1 + 2c4 + c9 ) − (c4 + 2c9 + c2 ). 6a3 2 2a3 2a3

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.4. The C 1 Clough–Tocher interpolant

145

Similar formulae hold for c14 and c15 . The remaining coefficients of s|T can be computed with the formulae c16 = (c15 + c5 + c13)/3, c17 = (c13 + c8 + c14)/3, (5.9) c18 = (c14 + c11 + c15 )/3, c19 = (c16 + c17 + c18 )/3. We have implemented C 1 Clough–Tocher interpolation in the function [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c] = ... ct(xo,yo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro,z,zx,zy,ze) This function inputs information about the initial triangulation , along with the Hermite data stored in the vectors z, zx, and zy. The vector ze contains the cross derivative values to be interpolated. The function outputs new lists describing the refined triangulation. It also produces the vector c of B-coefficients ordered according to the storage convention in section 4.9.1. This function can be tested using our script Bct, which is almost the same as Bps, except that we have to add the following calculation of the crossderivative information from the test function: x1 = xo(ie1o); x2 = xo(ie2o); y1 = yo(ie1o); y2 = yo(ie2o); bd = franke2d((x1+x2)./2,(y1+y2)./2); [dx,dy] = ucross(x1,y1,x2,y2); ze = dx.*bd(:,2) + dy.*bd(:,3); Here ucross is a function that computes cross vectors to edges. In particular, for each edge e of  with endpoints (x1, y1) and (x2, y2), it computes the unit vector with components dx and dy that is orthogonal to e and is obtained by rotating the direction of e 90 degrees in the counterclockwise direction. Example 5.9. Interpolate Franke’s function (2.20) at the 36 vertices of the triangulation shown in Figure 5.1 (left) using the C 1 cubic Clough–Tocher space S31 (C T ). Discussion: We use the script Bct, and read the triangulation from the file tri36.dat. We do not show plots of the spline and its x-derivative as they are very similar to the ones obtained in Example 5.2 using the space S21 ( P S ). Here the max and RMS errors for the spline fit on a 51 ×51 grid in the unit square are 7.72(−2) and 1.60(−2), respectively, which are somewhat better than what we got with S21 ( P S ) or S21 ( P S12). For the x-derivative, the errors are 9.00(−1) and 1.64(−1), which are also better than with the Powell–Sabin spaces. We now explore the rate of convergence of Hermite interpolation with this spline space the sequence of nested type-1 triangulations of Example 5.3. Example 5.10. Repeat Examples 5.3 and 5.7 using the C 1 Clough–Tocher spline space. Discussion: We make use of the script Bct, and read the triangulations from the files type1.25, etc. As in Examples 5.3 and 5.7, these correspond to type-1 triangulations

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

146

Chapter 5. Macro-element Interpolation Methods

with vertices at grid points. Here is a table of the maximum and RMS errors, along with the numbers n and nd of vertices and data, respectively. n nd 25 131 81 451 289 1667 1089 6403 4225 25091

emax 7.44(−2) 2.05(−2) 1.70(−3) 1.21(−4) 7.26(−6)

rms 1.60(−2) 1.92(−3) 1.39(−4) 9.17(−6) 5.80(−7)

ratios 3.63 8.33 12.06 13.81 14.05 15.16 16.67 15.81

Note that the rate of convergence seems to be O(||4 ), as is to be expected for cubic splines; see Theorem 5.11. Concerning the x-derivatives, we have n nd 25 131 81 451 289 1667 1089 6403 4225 25091

emax 9.87(−1) 5.56(−1) 7.13(−2) 9.17(−3) 1.21(−3)

rms 2.17(−1) 5.09(−2) 7.06(−3) 9.49(−4) 1.22(−4)

ratios 1.78 7.80 7.78 7.58

4.26 7.21 7.44 7.78

The rate of convergence seems to be O(||3 ), as is to be expected for a first derivative by Theorem 5.11. The following error bound for C 1 Clough–Tocher interpolation was established in Theorem 6.8 in [[LaiS07]]. Theorem 5.11. For every f ∈ C m+1 () with 0 ≤ m ≤ 3, its C 1 Clough–Tocher interpolant s satisfies (5.10) Dxα D βy ( f − s) ≤ K ||m+1−α−β | f |m+1 for all 0 ≤ α + β ≤ m. If  is convex, then the constant K depends only on the smallest angle in . If  is not convex, then K also depends on the Lipschitz constant of the boundary of .

5.5 The C 1 quintic Argyris interpolant In this section we solve a Hermite interpolation problem using the macro-element space S51,2 (); see section 4.14.2. For each edge e of , let ne be a unit vector perpendicular to the edge, and let ηe be the midpoint of e. Let E be the set of all edges of . The following theorem is well known; see, e.g., section 6.1 of [[LaiS07]]. Theorem 5.12. Let  be a triangulation with vertices {(x i , yi )}ni=1 . Suppose we are given νμ real numbers {z i }0≤ν+μ≤2 for i = 1, . . . , n, and {z e }e∈E . Then there exists a unique spline s ∈ S51,2 () satisfying νμ

Dxν D μ y s(x i , yi ) = z i ,

0 ≤ ν + μ ≤ 2, i = 1, . . . , n,

(5.11)

and Dne s(ηe ) = z e ,

all e ∈ E.

(5.12)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.5. The C 1 quintic Argyris interpolant

cT410

cT320 cT230

147

cT500

cT401 cT311 cT302

cT221

cT212

cT203

cT140 cT131 cT122 cT113 cT104 T T T T c041 c032 c023 c014 cT500

cT050

Figure 5.7. B-coefficients of a quintic polynomial.

As with the other macro-element spaces discussed in the previous sections, it is possible to compute the coefficients of the interpolating spline one triangle at a time. Suppose T := v1 , v2 , v3  is a triangle in , and let {ciTj k }i+ j +k=5 be the B-coefficients of s|T as shown in Figure 5.7. It is shown in section 6.1 of [[LaiS07]] that T c500 = z1, T = [h 2 z 110 + h˜ 2 z 101 ]/5 + z 1, c410 c T = [h 3 z 10 + h˜ 3 z 01 )]/5 + z 1, 401 T c320 T c311 T c302

1 1 2 20 T = [h 2 z 1 + 2h 2 h˜ 2 z 111 + h˜ 22 z 102 ]/20 + 2c410 − z1, 20 11 02 T T ˜ ˜ ˜ ˜ = [h 2 h 3 z 1 + (h 2 h 3 + h 3 h 2 )z 1 + h 2 h 3 z 1 ]/20 + c401 + c410 − z1, 2 20 11 2 02 T ˜ ˜ = [h 3 z 1 + 2h 3 h 3 z 1 + h 3 z 1 ]/20 + 2c401 − z 1 ,

where h i := x i − x 1 and h˜ i := yi − y1 for i = 2, 3. These are the B-coefficients of s|T in a two-disk around v1 . Similar formulae hold for the B-coefficients in the two-disks around v2 and v3 . Now consider the edge e := v2 , v3 . Using the cross-derivative information z e at the midpoint of e, we have T = c122

16 1 T T T T z e − [c140 + 4c131 + 4c113 + c104 ] 30a1 6 $ a2 # T T T T T − c050 + 4c041 + 6c032 + 4c023 + c014 6a1 $ a3 # T T T T T − + 6c023 + 4c014 + c005 c041 + 4c032 , 6a1

where (a1 , a2 , a3 ) are the directional coordinates relative to T of the unit vector perpendicular to the edge e and pointing into the triangle. Analogous formulae hold for the coefficients T and c T . We have implemented this method in the following function: c212 221 c = arg15(x,y,v1,v2,v3,e1,e2,e3,ie1,der,cross) Here der is an n × 6 vector containing the values at the vertices of  of f and its derivatives f x , f y , f x x , f x y , f yy . The input cross is a vector of length equal to the number of edges of  containing the assigned values for the cross derivatives at the midpoints of the edges of .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

148

Chapter 5. Macro-element Interpolation Methods

Example 5.13. Interpolate Franke’s function (2.20) at the 36 vertices of the triangulation shown in Figure 5.1 (left) using the space S51,2 (). Discussion: We use the script B15, and read the triangulation from the file tri36.dat. We do not show plots of the spline and its x-derivative as they are very similar to the ones obtained in Example 5.2 using the space S21 ( P S ). Here the max and RMS errors for the spline fit on a 51 × 51 grid in the unit square are 1.48(−2) and 2.73(−3), respectively, which are significantly better than what we got with the quadratic and cubic spline methods discussed above. For the x-derivative, the errors are 2.69(−1) and 3.47(−2), which are also much better. We now explore the rate of convergence of Hermite interpolation with this spline space using the sequence of nested type-1 triangulations of Example 5.3. Example 5.14. Repeat Example 5.3 using the space S51,2 (). Discussion: We again use the script B15, and read the triangles from the files type1.25, etc. The maximum and RMS errors in this case are n nd 25 206 81 694 289 2534 1089 9670 4225 37766

emax 3.97(−2) 3.81(−3) 7.89(−5) 1.53(−6) 2.24(−8)

rms 5.12(−3) 2.70(−4) 5.36(−6) 9.12(−8) 1.45(−9)

ratios 10.42 18.96 48.29 50.37 51.91 58.77 67.86 62.90

The rate of convergence seems to be O(||6 ), as is expected for this interpolation method by Theorem 5.15. The x-derivative of a C 1 quintic spline is a C 0 quartic spline on the same triangulation. Here is a table of errors for the x-derivatives of the interpolant. n nd 25 206 81 694 289 2534 1089 9670 4225 37766

emax 4.93(−1) 9.75(−2) 3.77(−3) 1.35(−4) 4.37(−6)

rms 8.03(−2) 7.70(−3) 3.00(−4) 1.04(−5) 3.34(−7)

ratios 5.06 10.43 25.86 25.67 27.93 28.85 30.89 31.14

The rate of convergence seems to be O(||5 ), which agrees with the bound in Theorem 5.15 for the first derivative. The following error bound for Argyris interpolation was established in Theorem 6.4 in [[LaiS07]]. Theorem 5.15. For every f ∈ C m+1 () with 1 ≤ m ≤ 5, its Argyris interpolant s satisfies Dxα D βy ( f − s) ≤ K ||m+1−α−β | f |m+1

(5.13)

for all 0 ≤ α + β ≤ m. If  is convex, then the constant K depends only on the smallest angle in . If  is not convex, then K also depends on the Lipschitz constant of the boundary of .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.6. The C 2 Wang interpolant

149

5.6 The C 2 Wang interpolant In this section we make use of the C 2 macro-element space S2 (W ) discussed in section 4.14.4. This is a space of splines of degree five. For each edge e := u, v of , let ne be a unit vector perpendicular to the edge; cf. section 5.5. In addition, let ηe be the midpoint of e, and define ηe1 := (2u + v)/3 and ηe2 := (u + 2v)/3. We have the following theorem; see section 7.4 of [[LaiS07]]. Theorem 5.16. Let  be a triangulation with vertices {(x i , yi )}ni=1 , and suppose we are νμ given real numbers {z i }0≤ν+μ≤2 for i = 1, . . ., n, and {z e1 , z e2 , z e3 }e∈E . Then there exists a unique spline s ∈ S2 (W ) satisfying νμ

Dxν D μ y s(x i , yi ) = z i , and

0 ≤ ν + μ ≤ 2, i = 1, . . . , n,

(5.14)

Dne s(ηe ) = z e1 , Dn2e s(ηe1 ) = z e2 ,

all e ∈ E.

(5.15)

Dn2e s(ηe2 ) = z e3 , As with the other macro-element spaces discussed in the previous sections, for each triangle T of , it is possible to compute the coefficients of the interpolating spline s associated with domain points in T directly from the given derivatives at the vertices and the cross derivatives at points on the edges of T . We do not give the formulae here. Given a triangulation , and the required derivative information, the following function computes the triangulation lists for the Wang refinement along with the vector c of B-coefficients of the interpolating spline: [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c] = wang(xo,yo,... v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,trilo,triro,der,ze) The input includes the lists for the initial triangulation , along with an n × 6 matrix der containing the derivative data at the vertices. It also includes an ne ×3 matrix ze containing the cross-derivative values for the edges of . Example 5.17. Interpolate Franke’s function (2.20) at the 36 vertices of the triangulation shown in Figure 5.1 using the C 2 spline space S2 (W ). Discussion: We use the script Bwang, and read the triangulation from tri36.dat. We show a plot of the resulting spline and its x-derivative in Figure 5.8. Note how much smoother these splines are than those in Figure 5.3. Indeed, it is clear from the figure that the derivative is now a C 1 function, as it should be. For comparison purposes, we note that the max and RMS errors for the spline fit on a 51 × 51 grid in the unit square are 1.48(−2) and 2.70(−3), respectively. For the x-derivative, the errors are 2.83(−1) and 3.55(−2). Example 5.18. Repeat Example 5.3 using the C 2 spline space S2 (W ). Discussion: We make use of the script Bwang, and read the type-1 triangulations from the files type1.25, etc. Here is a table of the maximum and RMS errors on a 51 × 51 grid.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

150

Chapter 5. Macro-element Interpolation Methods 4 1.4

0.5

0.7

-3 1

0 1 1 0.5

0.5

1 0.5

0.5 0 0

0 0

Figure 5.8. The C 2 interpolant to Franke’s function with a spline from the space S2 (W ) defined on the triangulation in Figure 5.1, and its x-derivative.

n nd emax 25 318 4.00(−2) 81 1110 3.84(−3) 289 4134 7.98(−5) 1089 15942 1.55(−6) 4225 62598 2.25(−8)

rms 5.06(−3) 2.68(−4) 5.33(−6) 9.07(−8) 1.44(−9)

ratios 10.42 18.88 48.12 50.28 51.48 58.77 68.89 62.99

This interpolation method satisfies the same error bound as the Argyris element; see Theorem 5.15. Thus, for this function we expect the rate of convergence to be O(||6 ), i.e., the error ratios should be 64. For the x-derivative we have the following table: n nd 25 206 81 694 289 2534 1089 9670 4225 62598

emax 5.65(−1) 1.08(−1) 4.26(−3) 1.52(−4) 4.84(−6)

rms 8.36(−2) 8.04(−3) 3.18(−4) 1.09(−5) 3.51(−7)

ratios 5.23 10.40 25.35 25.28 28.03 29.17 31.40 31.05

This shows the expected O(h 5 ) convergence.

5.7 A comparison of the methods In this section we summarize properties of the above methods and give a direct numerical comparison. The following table compares the dimension of the spaces and the order of approximation. It also gives the number NT of subtriangles in each macro triangle, and the order HD of the highest derivative values that must be included as part of the data. Here n and n e are the numbers of vertices and edges in , respectively. The last column gives the order of approximation of each method. Method HD Dim Bps 1 3n Bps12 1 3n Bct 1 3n + n e B15 2 6n + n e Bwang 2 6n + 3n e

NT 6 12 3 0 7

Order 3 3 4 6 6

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.8. Rate of convergence for less smooth functions

151

All of these methods produce C 1 surfaces, except for Bwang, which gives a C 2 surface. The two Powell–Sabin methods have the advantage of not requiring any derivative data on the edges of . However, as a trade-off, the other methods have higher orders of approximation. B15 has the slight advantage that no splits of the triangles of  are required. The following example gives a direct comparison of the various methods on a typical scattered data interpolation problem. Example 5.19. Use the various macro-element spline spaces in this chapter to interpolate Franke’s function (2.20) on the unit square using the triangulation shown in Figure 5.1. Discussion: This triangulation has 36 vertices, and can be read from the file tri36.dat. Here is a table of errors for the various methods. Method Bps Bps12 Bct B15 Bwang

nd 108 108 197 305 483

emax 1.23(−1) 1.13(−1) 7.72(−2) 1.48(−2) 1.48(−2)

rms 2.28(−2) 1.88(−2) 1.60(−2) 2.73(−3) 2.70(−3)

The column labelled nd shows the total number of data required for each method, including any cross derivatives. As we might expect, as nd increases, we get more accurate fits, and examining the plots, we see that the shape of the surfaces also improves. The best results are for B15 and Bwang, but of course they both require second derivative information.

5.8 Rate of convergence for less smooth functions In this chapter we have explored the rate of convergence for various macro-element methods. All of the experiments were done using Franke’s function (2.20) as the test function. Since this function is C ∞ , in all cases we got the expected optimal order of approximation, namely O(||)d+1 , where d is the degree of the spline being used. However, as can be seen by examining the error bounds given in Theorem 5.4, 5.11, and 5.15, if our test function is not sufficiently smooth, we can expect a lower order of convergence. We illustrate this with two examples using the C 1 Powell–Sabin space S21 ( P S ). The first example uses a test function that is only C 1 . Example 5.20. Interpolate the function  0, f (x, y) := (y + 2x − 1)2,

y < 1 − 2x, otherwise,

(5.16)

on a sequence of refinements of the triangulation shown in Figure 5.1. Discussion: We use the script Bpsf1, and read the triangulations from the following files: tri36.dat, tri36-1.dat, . . . , tri36-4.dat. They are successive uniform refinements of the triangulation in Figure 5.1, so the mesh size is halved at each level in the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

152

Chapter 5. Macro-element Interpolation Methods

4

2

2

1

0

0

1

1 1 0.5

1 0.5

0.5 0 0

0.5 0 0

Figure 5.9. Left: The C 1 quadratic Powell–Sabin spline interpolant to the C 1 function (5.16) at the 36 vertices of the triangulation shown in Figure 5.1. Right: The analogous spline interpolant for the C 0 function (5.17).

sequence. We show a plot of the interpolating spline for the triangulation tri36.dat in Figure 5.9 (left). Here are the max and RMS errors: level 0 1 2 3 4

emax 7.44(−3) 1.81(−3) 5.19(−4) 9.18(−5) 1.44(−5)

rms 6.87(−4) 1.48(−4) 2.40(−5) 4.29(−6) 6.19(−7)

ratios 4.11 4.64 3.49 6.17 5.65 5.60 6.38 6.93

This test function is clearly C 1 , but not C 2 , so according to Theorem 5.4, we should be getting a convergence rate of order two, i.e., the ratios should be four. It is not quite clear that we are getting exactly this order, but it certainly seems to be less than three. In our second example we use a test function that is only C 0 . Example 5.21. Interpolate the function  0, y < 1 − 2x, f (x, y) := (y + 2x − 1), otherwise,

(5.17)

on a sequence of refinements of the triangulation shown in Figure 5.1. Discussion: We use the script Bpsf0, and read the triangulations from the same files as in the previous example. This test function is C 0 . It is C 1 everywhere except for points on the line y = 1 − 2x. Although the derivative is not defined at such points, we can still interpolate with the space S21 ( P S ), provided that if a vertex falls on the line, we take a one-sided derivative. In the script we have defined the derivative at such points to be 2(y − 2x − 1). We show a plot of the interpolating spline for the triangulation tri36.dat

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.9. Interpolation on domains with holes

153

in Figure 5.9 (right). Here are the max and RMS errors for the interpolant: level 0 1 2 3 4

emax 8.32(−2) 4.16(−2) 2.08(−2) 5.53(−3) 2.67(−3)

rms 8.33(−3) 3.02(−3) 1.01(−3) 4.02(−4) 1.35(−4)

ratios 2.00 2.75 2.00 2.99 3.76 2.51 2.07 2.98

Since the test function is C 0 but not C 1 , according to Theorem 5.4, we should be getting a convergence rate of (at least) one, i.e., the ratios should be two or more. It is not quite clear that we are getting exactly this rate of convergence, but it certainly seems to be less than order two.

5.9 Interpolation on domains with holes For convenience of comparison, all of the examples in the previous sections involved triangulations of the unit square. However, it should be emphasized that all of the methods of this chapter work on triangulations of arbitrary polygonal domains which may even contain holes. Here is an example. Example 5.22. Interpolate Franke’s function (2.20) at the 36 vertices of the triangulation  shown in Figure 5.10 (left) using the spline space S31 (C T ). Discussion: We use the script Bct, and read the triangulation from trihole36.dat. Figure 5.10 (right) shows the resulting C 1 Clough–Tocher spline interpolant. The max and RMS errors for this spline are almost the same as we got with the triangulation tri36 without the hole; see Example 5.9. We can repeat this example using our scripts Bps, B15, and Bwang. However, there is a problem with the rendering when using the scripts Bps and Bps12; see Remark 5.14.

1.2

1

0.75

0.6 0.5

0 1

0.25

1 0.5

0 0

0.25

0.5

0.75

1

0.5 0 0

Figure 5.10. A triangulation  with a hole, and the spline in S31 (CT ) interpolating Franke’s function at its 36 vertices.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

154

Chapter 5. Macro-element Interpolation Methods 1.4 1

0.75

0.7

0.5

0 1

0.25

1 0.5

0 0

0.25

0.5

0.75

1

0.5 0 0

Figure 5.11. The Delaunay triangulation of a set of 39 points in the unit square, and the spline in S21 ( P S ) interpolating Franke’s function at its vertices.

5.10 Interpolation at badly spaced points We have seen in this chapter that Hermite interpolation with macro-element spline spaces works quite well if we are interpolating reasonably smooth functions, and if we choose a reasonable triangulation. In this section we give two examples to show what can happen if the interpolation points are badly spaced. Example 5.23. Interpolate Franke’s function (2.20) at the 39 vertices of the triangulation  shown in Figure 5.11 (left) using the spline space S21 ( P S ). Discussion: We use the script Bpsd which is a minor modification of the script Bps, but instead of reading in a triangulation from a file it reads in a set of data points and then constructs the corresponding Delaunay triangulation. For this example we read the data points from the data file tri39.dat. The Delaunay triangulation is shown on the left in Figure 5.11, while the resulting C 1 Powell–Sabin spline interpolant is shown on the right. As we can see from the figure, the spline is a reasonable fit in the interior of the domain, but is not very good at points near the boundary. The problem is, of course, that we have very large triangles along the boundary edges. The reader can get a better idea of what can happen with badly spaced interpolation points by running some examples where the points are chosen randomly in the unit square. Example 5.24. Interpolate Franke’s function (2.20) at a random set of n points in the unit square, using the spline space S21 ( P S ) defined on the corresponding Delaunay triangulation. Discussion: We use the script Bpsrand which reads the random data points from our file randxy.dat. The first four points in this file are the corners of the unit square. For n = 36, the Delaunay triangulation and associated spline interpolant are shown in the top row in Figure 5.12. As is typical with random points, we get some poorly shaped triangles near the boundary, which lead to some shape anomalies near the edges of the square. Things are better in the interior of the domain, but we are certainly missing some of the shape of Franke’s function. The max and RMS errors taken over the points on a 51 × 51 grid are 2.03(−1) and 3.96(−2).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.11. Scale invariance

155 1.4

0.7

0 1 1 0.5

0.5 0 0

1.4

0.7

0 1 1 0.5

0.5 0 0

Figure 5.12. Top: The Delaunay triangulation of a set of 36 random points in the unit square, and the spline in S21 ( P S ) interpolating Franke’s function at its vertices. Bottom: The same with 99 random points.

We repeated this example with n = 99. The results are shown in the bottom row of Figure 5.12. Again the Delaunay triangulation contains some very long and thin triangles near the boundary which lead to some wrinkles in the surface.

5.11 Scale invariance In this section we explore to what extent the spline interpolation methods of this chapter are invariant under scaling of the x and/or y axis. We begin with an example making use of the C 1 Powell–Sabin method of section 5.3. Example 5.25. Let R := [0, α] × [0, β], and let  be the triangulation obtained from the triangulation tri81 shown in Figure 5.13 by stretching it to fit in R. Find the spline in S21 ( P S ) interpolating the scaled Franke’s function f (x, y) = franke2(x/α, y/β)

(5.18)

at the 81 vertices of . Discussion: We make use of the script Bscaleps and read the triangulation from the file tri81.dat. First we choose α = 1 and β = 1. In this case we get the triangulation shown

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

156

Chapter 5. Macro-element Interpolation Methods 1

0.5

0 0

0.5

1

1 0.5 0 0

1

2

3

4

5

Figure 5.13. Top: The triangulation tri81. Bottom: The same triangulation stretched to fit in the rectangle [0, 5] × [0, 1].

1.2

5 4 3 2

1

1 0

0

Figure 5.14. The spline in S21 ( P S ) interpolating the function (5.18) at the 81 vertices of the triangulation in Figure 5.13 (bottom).

on the top in Figure 5.13, and the max and RMS errors measured on a 51 × 51 grid on R are 4.11(−2) and 5.05(−3). If we take α = β = 5, we get a similar triangulation of [0, 5]2 with a mesh size of .937 instead of .187. The errors remain unchanged. On the other hand, with α = 5 and β = 1, we get the triangulation shown on the bottom in Figure 5.13 with mesh size 1.06. It is not a Delaunay triangulation. The errors in this case are now 5.66(−2) and 6.44(−3), which are no longer the same as before, although they are only slightly larger. The corresponding spline is shown in Figure 5.14. If we take α = 10 and β = 1, the mesh size is 2.15, and the max and RMS errors are 5.80(−2) and 6.64(−3). If we take α = 100 and β = 1, the mesh size is 21.9, and the errors are 5.86(−2) and 6.79(−3). Definition 5.26. We say that a spline interpolation method is equi-scale invariant, provided that for any triangulation  of a polygonal domain , for any function f defined on , and for any α = β > 0, the B-coefficients of the spline interpolating f (x/α, y/β) at the vertices of the scaled triangulation obtained by multiplying the x-coordinates of its vertices by α and the y-coordinates by β are the same as those for the spline interpolating f at the vertices of . We say that the method is scale invariant if this property holds for all α > 0 and β > 0.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.12. The role of the minimal angle in error bounds

157

Scale invariance is a good property for an interpolation method to have. Indeed, for a given interpolation problem, we get scaled scattered points if we simply change the units along the x and/or y axis. The results of Example 5.25 show that the C 1 Powell–Sabin interpolant is equi-scale invariant but not scale invariant. The example also shows that we can get good error bounds even if the mesh size is very large. This does not contradict Theorem 5.4 since the term measuring the size of the derivative of the function can compensate for the large mesh size. The experiments also show that the Powell–Sabin interpolant is almost scale invariant. The small changes in accuracy when we scale with different values of α and β are due to the fact that the shapes of the triangles are slightly altered, changing the value of the constant in the error bound (5.6). With α = β, these angles do not change. We explore this phenomenon in more detail in the following section. In this section we have focused on Hermite interpolation based on the space S21 ( P S ). Similar scale-invariance results hold for the other Hermite interpolation methods discussed in this chapter.

5.12 The role of the minimal angle in error bounds The error bounds for the various Hermite spline interpolation methods in this chapter all involve three components: 1) a constant K depending on the smallest angle in the triangulation, 2) the mesh size, and 3) the semi-norm of the function being approximated. The constant K depends on the minimum angle in the triangulation, and can play a very significant role. Here is an example to illustrate this. Example 5.27. Let R be the rectangle [0, 100] × [0, 1], and consider a nested sequence of type-1 triangulations of R corresponding to a grid associated with equally spaced points 0 = x 1 < · · · < x nx = 100 and 0 = y1 < · · · < yny = 1. Explore the errors for the C 1 Powell–Sabin interpolants of Franke’s function as we hold ny fixed, but increase nx. Discussion: We make use of the script Bpsr1 which computes type-1 triangulations associated with an nx × ny grid on R. The following table gives the max and RMS errors for ny = 9 and nx = 9, 17, 33, 65. It also lists the mesh size of the associated type-1 triangulation. nx ny || emax rms ratios 9 9 1.19 2.26(−2) 3.48(−3) 17 9 5.71 1.08(−2) 1.14(−3) 2.09 3.05 33 9 2.67 8.46(−3) 9.02(−4) 1.28 1.26 65 9 1.23 1.04(−2) 1.14(−3) .81 .79 For this sequence the mesh sizes are going down by approximately a factor of two as we increase nx, but the errors decrease very slowly, and even increase in the last step. In this example, the function f is fixed, and so is its semi-norm on the rectangle R. From Theorem 5.4 we would expect the errors to decrease by a factor of eight since this function is smooth. The fact that they do not means that the constant K in the error bound is growing rapidly as we increase nx. This is due to the fact that minimum angles in the triangles are decreasing as we increase nx while holding ny fixed.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

158

Chapter 5. Macro-element Interpolation Methods

In this example we refined the mesh only in the x direction. If we refine the mesh only in the y direction, it turns out that the mesh sizes actually increase, and the errors become worse and worse. We get quite a different behavior if we refine in both directions. Example 5.28. Repeat Example 5.27, but refine the meshes in both directions. Discussion: We again make use of the script Bpsr1 starting with a type-1 triangulation with vertices on a 9 × 9 grid. The following table gives the max and RMS errors for nx = ny = 9, . . ., 65 : nx ny 9 9 17 17 33 33 65 65

|| 1.19(0) 5.96(−1) 2.98(−1) 1.49(−1)

emax 2.26(−2) 3.71(−3) 5.30(−4) 6.61(−5)

rms 3.48(−3) 4.54(−4) 5.58(−5) 6.90(−6)

ratios 6.09 7.67 7.00 8.14 8.02 8.09

As in the previous example, the mesh size is decreasing by approximately a factor of two each time we refine. In this case the errors are decreasing at the expected rate O(||3 ). The reason that we get the correct order of convergence in this example is that now the minimum angles remain constant as we increase nx = ny.

5.13 Remarks Remark 5.1. Throughout this chapter we have illustrated the performance of the various interpolation methods in the case where the interpolation points are the 36 vertices of the triangulation shown in Figure 5.1 (left). This would correspond to a typical interpolation problem in practice. Remark 5.2. To explore the order of convergence of the methods, we have also looked at interpolation at the vertices of a nested sequence of type-1 triangulations, with the number of interpolation points ranging from 25 to 4225. This is a convenient sequence for these experiments, but in practice if we had data on a grid, we probably should be using one of the tensor-spline methods of Chapter 2 rather than any of the methods in this chapter. Remark 5.3. Instead of using type-1 triangulations in the examples exploring order of convergence, we could instead have worked with the sequence of uniform refinements any initial triangulation, for example the triangulation shown in Figure 5.1 (left). This sequence of triangulations can be read from files tri36.dat, tri36-1.dat, . . . , tri36-4.dat. This leads to very similar values for the convergence orders. Remark 5.4. In our experiments on rates of convergence, we have measured the max and RMS errors on a 51 × 51 grid. We have chosen this grid as it is about the largest one that gives nice plots — using more grid lines makes it hard to see the surface. However, working with a finer grid would give more accurate estimates of the actual errors, and the ratios in our error tables would be a little closer to their nominal values. Remark 5.5. Throughout this chapter we have assumed that the data being interpolated has not been contaminated by noise. Interpolating noisy data can lead to surfaces with a lot of

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

5.13. Remarks

159

oscillations, and typically give significantly larger errors. We explore the effect of noise in more detail in section 7.7. Remark 5.6. If we are forced to work with noisy data, it is generally better to replace interpolation by a least-squares or penalized least-squares fit. We discuss these methods in detail in Chapter 7. Remark 5.7. All of the interpolation methods discussed in this chapter are based on Hermite data, i.e., in addition to values at the interpolation points, values of some derivatives at the vertices are required. In some cases additional derivative information at points along the edges of the underlying triangulation is required. Remark 5.8. It is possible to use the Hermite interpolation methods of this chapter in the case where we are given Lagrange data, i.e., at the interpolation points we are given only values to be interpolated. We can accomplish this by using the given Lagrange data to compute estimates of the missing derivatives. This approach leads to so-called two-stage methods. We discuss such methods in detail in the following chapter. Remark 5.9. The Powell–Sabin-12 space in (5.7) was first described in [AlfSS10]. It is a subspace of the classical Powell–Sabin-12 space S21 ( P S ) first introduced in [PowS77]. The advantage of the space (5.7) is that in solving Hermite interpolation problems, it does not require any cross-derivative information at points on the edges of the triangulation, but still has the same approximation power as the full space S21 ( P S ). Remark 5.10. The idea behind the definition of the subspace (5.7) of S21 ( P S12) is that along each edge e of the initial triangulation , we are requiring the cross derivative Dne s|e to be a (univariate) linear polynomial rather than a spline of degree one with a knot at the midpoint of e. Defining useful macro-element subspaces in this way is called condensation. It was conjectured in [AlfSS10] that this type of condensation might be possible for some macro-element spaces of higher smoothness defined on the Powell–Sabin-12 split. Remark 5.11. Another way to condense the macro-element space S21 ( P S12) is to require that for each edge e of the initial triangulation , the cross derivative Dne s|e should have a lower degree than it would normally have. This idea has been suggested for some classical macro-elements spaces, most notably the space S31 (C T ) of C 1 cubic splines on the Clough–Tocher split described in section 5.4. This approach to condensation can be applied to most macro-element spaces, but has the major disadvantage that it leads to spaces with reduced power of approximation. Remark 5.12. In this chapter we have discussed only macro-element spaces with smoothness up to C 2 . More smoothness is generally not needed for most applications. However, there are families of macro-elements spaces for all smoothness C r . These include elements defined on triangles, on Powell–Sabin and Powell–Sabin-12 refinements, and on Clough– Tocher refinements. For details, see Chapter 8 of [[LaiS07]] and the references therein. These spaces can be used to solve Hermite interpolation problems similar to the ones described here, but as r increases, we will require more and more derivative information. Remark 5.13. Any of the macro-element methods mentioned in the previous remark can be implemented in essentially the same way as those discussed in this chapter. In particular, since they are macro-element spaces, the B-coefficients of an interpolating spline can be

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

160

Chapter 5. Macro-element Interpolation Methods

computed one triangle at a time, so it suffices to find the formulae for the B-coefficients in a single macro triangle in terms of the Hermite data. This can be done using the formulae in sections 2.7 and 2.8 of [[LaiS07]]. Remark 5.14. Throughout this chapter we have made use of the function valspgrid discussed in section 4.12.1 to evaluate splines on a grid. This function is based on the built-in MATLAB function tsearchn to locate the triangles containing the grid points. This function seems to work perfectly well for triangulations without holes. However, we encountered problems in using the scripts Bps and Bps12 with the triangulation used in Example 5.22. For some of the points on a 51 × 51 grid, tsearchn could not identify the triangles containing them. This problem can be overcome by evaluating on domain points with valspgridh instead of with valspgrid. In place of tsearchn, it makes use of the function findtri described in section 3.7, and consequently is much slower. Remark 5.15. The interpolation methods of this chapter are all projectors, i.e., if the Hermite data is drawn from a spline s in the space being used, the interpolant should be equal to s. Since any bivariate space of splines of degree d contains the space Pd of bivariate polynomials of degree d, this means that polynomials should also be interpolated exactly. This can be easily checked with the scripts used in this chapter by replacing the test function with a polynomial. In particular, the two Powell–Sabin methods give exact fits for quadratic polynomials, while the Clough–Tocher method is exact for cubics. The Argyris and Wang elements are exact for quintics. Remark 5.16. It is possible to solve Hermite interpolation problems with certain spaces of splines that are not macro-element spaces, but have stable locally supported bases. For r,ρ example, in [DavNZ01], nodal bases for the superspline spaces Sd () with ρ = r + (r + 1)/2 and d ≥ 3r +2 were constructed and used to create Hermite interpolants with optimal order error bounds.

5.14 Historical notes Most of the macro-element spaces in this chapter were developed originally for use in solving boundary-value problems by the finite-element method; see, e.g., [CloT65, Zen70]. Applications to interpolation were not a concern. Hermite interpolation with the space S31 (C T ) was discussed along with error bounds in [Cia74]; see also [CiaR72, Per76, DougDPS79], Similarly, Hermite interpolation using the spaces S21 ( P S ) and S21 ( P S12) was discussed in [PowS77]. For S51,2 (), see [Zen70] and also [MorS75].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 6

Scattered Data Interpolation

In this chapter we discuss several methods for interpolating data at scattered points in a bivariate domain. We treat both local and global methods, and where possible, give error bounds for them. The performance of the various methods is illustrated with numerical examples.

6.1 Introduction Suppose  is a domain in R2 . The basic scattered data interpolation problem is as follows. Problem 6.1. Let {(x i , yi )}ni=1 be a set of points in , and suppose we are given associated real numbers {z i }ni=1 . Find a function s defined on  such that s(x i , yi ) = z i ,

i = 1, . . ., n.

(6.1)

Here, no derivatives are being interpolated, in contrast to the Hermite interpolation problems discussed in the previous chapter. Interpolation problems involving scattered data arise frequently in a variety of application areas. If the sample points lie on a rectangular grid, then this problem can be solved using tensor-product splines as discussed in section 2.4. However, if the points are scattered, it is generally more appropriate to work with splines on triangulations. The aim here is to exactly interpolate the data. If the z i values are contaminated by noise, it may be more appropriate to approximate rather than interpolate. We discuss methods for approximating scattered data in the following chapter. Approximation may also be more appropriate when the number of data points is very large, while the function being approximated is not too complex. The simplest approach to solving the Lagrange scattered data interpolation problem is to use C 0 linear splines. We discuss this approach in detail in section 6.2. It is very efficient, is scale invariant, and has good shape properties. However, it has two main drawbacks: 1) the splines are only continuous, and 2) the rate of convergence is relatively low. Thus, we cannot expect to get high accuracy unless we have a lot of interpolation points. This suggests that we consider using other spaces of splines of higher degree and smoothness. In section 6.3 we discuss a method based on minimizing energy which performs very well for reasonably spaced scattered data with up to about 1000 sample points. It can be 161

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

162

Chapter 6. Scattered Data Interpolation

used with many different macro-element spaces. Here we illustrate its use with the C 1 Powell–Sabin space and the C 1 Argyris space S51,2 (). Since the minimal energy method is global in nature, computational time becomes a problem for data sets with more than about 1000 sample points. For these larger problems, we recommend using local methods based on macro-element spaces. In sections 6.4–6.5 we discuss two methods based on S30 () and S31 (C T ). Any macro-element Hermite interpolation method such as the ones presented in Chapter 5 can be turned into a two-stage scattered data interpolation method by estimating the required derivatives from the data in a first stage. This is the topic of section 6.7, where we develop specific methods based on S21 ( P S ), S31 (C T ), S51,2 (), and S2 (W ). In section 6.8 we compare the various methods in head to head tests. To be useful in practice, we need methods which are scale invariant, i.e., changing the units on the x- and y-axes should not lead to problems. In section 6.9 we show that all of the methods in this chapter have this property, except for the minimal energy methods which have a weaker equi-scale property. We should also emphasize that the methods in this chapter work equally well on nonrectangular domains and on domains with holes. This is illustrated in section 6.10. To show how the local methods perform for a larger problem arising in practice, in section 6.11 we interpolate some topographic data taken from the Black Forest. In sections 6.12 and 6.13 we discuss the effect of mesh size on accuracy, and show that sometimes it is better to use a non-Delaunay triangulation.

6.2 Interpolation with S10 () In this section we show how to use the spline space S10 () to solve the scattered data interpolation problem. Suppose  is a triangulation with vertices at the points {(x i , yi )}ni=1 , and suppose we are given associated values {z i }ni=1 . Then it is clear that there is a unique spline in S10 () that interpolates these data values in the sense that (6.1) is satisfied. Indeed, on each triangle T , the linear polynomial s|T is uniquely determined by its values at the three vertices of T . Thus, the corresponding vector of B-coefficients defining s is just c = (z 1 , . . . , z n ). A script to implement this method is given below. It first reads a triangulation from a file and plots it. The values to be interpolated are then computed using the bivariate test function franke2, and then stored in the vector c which gives the B-coefficients of the spline. The call on trilists is included since we are using valspgrid to evaluate the surface on a grid. We use errg to compute the max and RMS errors at the grid points. The surface can also be plotted without a call on trilists using valspDP and trisurf, but for comparison purposes we will use the gridded plots.

6.2.1 Examples We now give several examples to illustrate the performance of scattered data interpolation with C 0 linear splines. Example 6.2. Find the spline in S10 () that interpolates Franke’s function (2.20) at scattered data points in the unit square. Discussion: We use the script B01. For the first test, we work with the triangulation shown in Figure 6.1 (left), which can be read from the file tri36.dat. We show a plot of the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.2. Interpolation with S10 ()

163

1

1

0.5 0.5

0 1

1

0.5 0 0

0.5

1

0.5 0

0

Figure 6.1. The Delaunay triangulation of a set of 36 data points and the spline in S10 () interpolating Franke’s function (2.20) at these sample points.

corresponding C 0 cubic interpolating spline in Figure 6.1 (right). The max and RMS errors on a 51 × 51 grid are 3.61(−1) and 7.48(−2), respectively. We now repeat this example with a larger number of sample points. Let  be the triangulation shown in Figure 6.2 (left). It can be read from the file tri81.dat. % B01 [n,x,y,nt,TRI] = readtri; figure; triplot(TRI,x,y); xmin = min(x); xmax = max(x); ymin = min(x); ymax = max(x); c = franke2(x,y); [nb,ne,nt,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy,vadj,... eadj,adjstart,tadj,tstart,area,TRI] = trilists(x,y,TRI); ng = 51; d = 1; [xg,yg,g] = valspgrid(d,x,y,v1,v2,v3,e1,e2,e3,ie1,c,... ng,xmin,xmax,ymin,ymax); figure; surfl(xg,yg,g’); colormap(copper); e = errg(xg,yg,g,@franke2); fprintf(’emax =%5.2e, RMS = %5.2e\n’,norm(e,inf),erms(e)); We show a plot of the C 0 linear interpolating spline in Figure 6.2 (right). The max and RMS errors are now 1.01(−1) and 2.13(−2), respectively. These errors are smaller than what we got using the 36 vertices of the triangulation in Figure 6.1 (left). The shape of the interpolating spline is also much closer to that of the true function. As a third test, consider the triangulation shown in Figure 6.3 (left). It corresponds to the file tri39.dat. This triangulation has some big triangles near the boundary of the square. As the plot in Figure 6.3 (right) shows, in this case the shape is much worse near the boundaries. Now the max and RMS errors are 3.11(−1) and 6.98(−2). We now explore the rate of convergence of this interpolation method by performing interpolation on a sequence of nested grids where the mesh size is halved at each step. We start with the type-1 triangulation shown on the top left in Figure 6.4. It has 25 vertices. The triangulation obtained by uniform refinement has 81 vertices and is shown on the bottom left in Figure 6.4. Further refinements have 289, 1089, and 4225 vertices.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

164

Chapter 6. Scattered Data Interpolation

1

1

0.5 0.5

0 1 1 0.5 0 0

0.5

1

0.5 0

0

Figure 6.2. The Delaunay triangulation of a set of 81 data points and the spline in S10 () interpolating Franke’s function (2.20) at these points.

1

1

0.5 0.5

0 1 1 0.5 0 0

0.5

1

0.5 0

0

Figure 6.3. The Delaunay triangulation of a set of 39 points and the spline in S10 () interpolating Franke’s function (2.20) at these points.

Example 6.3. Use C 0 linear splines to interpolate Franke’s function (2.20) at the vertices of the type-1 triangulation shown on the top left in Figure 6.4. Repeat for each of the first four uniform refinements of this triangulation. Discussion: We use the script B01, and read the triangulations from the following files: type1.25, type1.81, . . . , type1.4225. These files produce type-1 triangulations with n = 25, 81, . . ., 4225 vertices on an equally spaced grid. These triangulations are nested, and the mesh size is reduced by a factor of two for each refinement. The data values are produced by a call on Franke’s function franke2. Plots of the splines corresponding to n = 25 and n = 81 sample points are shown in Figure 6.4. For comparison with other interpolation methods, we now tabulate both the maximum and the RMS errors for the various values of n. n 25 81 289 1089 4225

emax 1.77(−1) 9.40(−2) 2.86(−2) 6.89(−3) 1.80(−3)

rms 5.50(−2) 2.05(−2) 5.47(−3) 1.38(−3) 3.47(−4)

ratios 1.88 2.68 3.29 3.75 4.15 3.96 3.83 3.98

Since the ratios are approaching four, we seem to be getting O(||2) convergence, as is to be expected for interpolation with linear splines, see Theorem 6.4.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.2. Interpolation with S10 ()

165

1

1

0.5 0.5

0 1 1 0.5 0 0

0.5

1

0.5 0

0

1

1

0.5 0.5

0 1 1 0.5 0 0

0.5

1

0.5 0

0

Figure 6.4. Top: A type-1 triangulation of the unit square and the corresponding C 0 linear spline interpolating Franke’s function (2.20) at its vertices. Bottom: the uniform refinement of the top triangulation, and the corresponding C 0 linear interpolant.

6.2.2 An error bound for interpolation with S10 () The following theorem gives an error bound in the maximum norm for interpolation with S10 () in terms of the mesh size of  defined in (5.3). We use the semi-norms | f |k := max Dxν D μ y f ν+μ=k

(6.2)

to measure the smoothness of functions f whose derivatives of order k are continuous. We also make use of the standard modulus of continuity of a continuous function defined by ω( f , h) = sup{| f (x, y) − f (x, ˜ y˜ )| : |(x, y) − (x, ˜ y˜ )| ≤ h}.

(6.3)

Theorem 6.4. Let  be a triangulation of a domain , and suppose f ∈ C k () with 0 ≤ k ≤ 2. Let s be the spline in S10 () that interpolates f at the vertices of . Then ⎧ ⎪ ω( f , ||), k = 0, ⎪ ⎨√  f − s ≤ (6.4) 2 || | f |1 , k = 1, ⎪ ⎪ ⎩ 1 ||2 | f | , k = 2. 2 6 Discussion: The claim for k = 0 follows immediately from the definition of√the modulus of continuity. For k = 1 it follows immediately from the fact that ω( f , ||) ≤ (2)|| | f |1 . For k = 2, it was proved in [Sub90].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

166

Chapter 6. Scattered Data Interpolation

By results on the approximation power of splines (see, e.g., [[LaiS07]]), it follows that we cannot get better than O(||2 ) no matter how smooth f might be.

6.3 Minimal energy interpolating splines In this section we present a method for solving Problem 6.1 based on minimizing a certain energy functional. Given points {(x i , yi )}ni=1 and associated values {z i }ni=1 , we are looking for a spline s such that (6.1) holds. To construct s, we first choose a triangulation 0 with vertices at the sample points {(x i , yi )}ni=1 . In practice, this could be the Delaunay triangulation. The domain  covered by the triangulation need not be convex, and may contain one or more holes. Given an integer d > 1, suppose S() is an N-dimensional linear subspace of the space Sd0 (), where 0 ⊆ . We now look for a solution of the scattered data fitting problem in the set (6.5) U := {s ∈ S() : s(x i , yi ) = z i , i = 1, . . ., n}. We assume that S() is a big enough space so that the set U is nonempty. This will require N ≥ n, but this condition alone is not sufficient. However, we will show that U is nonempty for the spaces we will be using here. Now for every s ∈ U , we define E(s) =

nt  

[(sx x )2 + 2(sx y )2 + (s yy )2 ] d x d y,

(6.6)

ν=1 Tν

where T1 , . . . , Tnt are the triangles in . We refer to this expression as the energy of the spline s. Note that (6.6) is defined for any piecewise polynomial defined on , without any assumption on smoothness. We now pose the following minimization problem. Problem 6.5. Find a spline s which minimizes E(s) over U . We call s a minimal energy interpolating spline.

6.3.1 Existence and uniqueness To show that Problem 6.5 has a unique solution, and to derive a method for computing it, N is a basis for the spline space S() with the property that suppose {φi }i=1 φi (x j , y j ) = δi j ,

i , j = 1, . . . , n,

(6.7)

and φi+n (x j , y j ) = 0,

j = 1, . . ., n,

i = 1, . . ., N − n.

(6.8)

Most macro-element spline spaces have at least one basis with this property. For explicit examples, see sections 6.3.4 and 6.3.5 below. We seek a solution of Problem 6.5 in the form n N−n   z i φi + ai φi+n . (6.9) s= i=1

i=1

Clearly, s automatically satisfies the interpolation conditions (6.1) in view of properties (6.7) and (6.8) of our basis functions.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.3. Minimal energy interpolating splines

167

We need some additional notation. For any two splines φ and ψ in S(), let nt  φ, ψ E,ν , φ, ψ E :=

(6.10)

ν=1

where

 [φx x ψx x + 2φx y ψx y + φ yy ψ yy ] d x d y.

φ, ψ E,ν := Tν

Now let M := [φi , φ j  E ]i,Nj =1 .

(6.11)

It will be convenient to rewrite M in the block form & % M11 M12 , M= M21 M22

(6.12)

where M11 is of size n × n, M12 is of size n × (N − n), M21 is of size (N − n) × n, and M22 is of size (N − n) × (N − n). Note that both M11 and M22 are symmetric. Let z := (z 1 , . . . , z n )T . Theorem 6.6. Suppose S() has a basis satisfying (6.7)–(6.8), and suppose in addition that the set (6.5) is nonempty. Then there exists a unique minimal energy interpolating spline s ∈ S(). Moreover, the coefficient vector a := (a1 , . . . , a N−n )T in the expansion (6.9) of s is the solution of the linear system of equations M22 a = r ,

(6.13)

r = −M21 z.

(6.14)

where

Proof. Given any vector a ∈ R N−n , the energy of the associated spline sa can be written as

(a) := E(sa ) =

n + i=1

z i φi +

N−n 

ai φi+n ,

i=1

n  i=1

z i φi +

N−n  i=1

ai φi+n

, E

= a T M22 a + 2a T M21 z + z T M11 z. For any a, a T M22 a = E(s0 ) ≥ 0, where s0 is the spline (6.9) that vanishes at all data points (x i , yi ). This shows that M22 is nonnegative definite. We claim that it is positive definite. To see this, suppose a T M22 a = E(s0 ) = 0. Then by the definition of E(s0 ), s0 must reduce to a linear polynomial on each triangle Tν of . But since s0 vanishes at all vertices of , it follows that s0 ≡ 0, i.e., a = 0. Having shown that M22 is positive definite, we now know that it is nonsingular, and so there is a unique solution a of (6.13).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

168

Chapter 6. Scattered Data Interpolation

It remains to show that if M22 a = r , then a minimizes (a). For any vector δ ∈ R N−n , we have

(a + δ) = (a + δ)T M22 (a + δ) + 2(a + δ)T M21 z + z T M22 z = (a) + 2δ T M22 a + 2δ T M21 z + δ T M22 δ = (a) + δ T M22 δ ≥ (a), since M22 a = r implies δ T M22 a + δ T M21 z = 0. This shows that a provides a minimum of . Now the fact that M22 is positive definite shows that (a + δ) > (a) unless δ = 0, and it follows that a is the unique minimum.

6.3.2 Assembling the matrix M Throughout this section we suppose we are given a minimal determining set M for the space S(), along with the corresponding transformation matrix A of Lemma 4.20. N be the corresponding dual M-basis; see section 4.13.4. We suppose that Let {φi }i=1 M has been chosen so that properties (6.7)–(6.8) hold. Then every spline s ∈ S() satisfying the interpolation conditions (6.1) can be written in the form (6.9). Let c˜ = (z 1 , . . . , z n , a1 , . . . , a N−n )T be the corresponding coefficients in (6.9). Let c be the vector of B-coefficients of s. It is of length n c = dim Sd0 () = #Dd,, where Dd, is the set of domain points associated with the triangulation . By Lemma 4.20, we can compute c from c˜ as c = A c. ˜ (6.15) Examples of spaces with easy to compute transformation matrices can be found in section 4.14. Transformation matrices can be computed for all of the macro-element spaces described in Chapters 6–8 of [[LaiS07]]. Note that generally A is a sparse matrix. We can now describe ) an * efficient algorithm for assembling the N × N matrix M defined in (6.11). Let m := d+2 2 , and for each T ∈ , let A(T ) be the m × N submatrix of A obtained by selecting only the rows that correspond to coefficients associated with domain points in T . We write At for its transpose. For each triangle T , let B1T , . . . , BmT be the Bernstein basis polynomials associated with T in lexicographical order. Algorithm 6.7 (Compute the energy matrix M). 1) Set M = 0 2) For every T ∈ , a) Compute the m × m matrix MT := [BiT , B jT  E,T ]m i, j =1 b) M ← M + A(T )t MT A(T ) This algorithm works by looping through the triangles of . The entries in M are obtained by an accumulation process. The m × m matrix MT in Step 2a is a full matrix. To find it requires computing integrals of the second derivatives of the Bernstein basis polynomials. For quadratic splines, which have piecewise constant second derivatives, this can be done exactly. For higher degree splines, we can use quadrature formulae on each triangle as described in section 4.6. Assuming we are using basis functions with local supports, the matrix M will be quite sparse, and can be stored in sparse matrix form.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.3. Minimal energy interpolating splines

169

6.3.3 An error bound for minimal energy interpolation Suppose S() is a C 1 space of splines with a stable local basis such that the set (6.5) is nonempty. Given any function f ∈ C(), Theorem 6.6 shows that there exists a unique minimal energy spline s interpolating f at the vertices of , i.e., s(x i , yi ) = f (x i , yi ), i = 1, . . ., n. We denote this spline by Ime f . We can consider Ime as a mapping from C() into S. The construction in Theorem 6.6 shows that this mapping is linear and Ime p = p for all p ∈ P1 . We now give an error bound for minimal energy spline interpolation. To state it, we need to introduce a constant describing the size and shape of the triangles in . Recall that the inradius ρT of a triangle T is the radius of the largest circle that can be inscribed in T . It’s center is called the incenter of T . Definition 6.8. A triangulation  is said to be β-quasi-uniform, provided that || ≤ β, ρ

(6.16)

ρ := min ρT .

(6.17)

where T ∈

The following result is proved in [GolLS02]. Theorem 6.9. Suppose  is a β-quasi-uniform triangulation, and suppose S() is a C 1 space of splines defined on  with a stable local basis. Assume S() is big enough so that 2 (), the set (6.5) is nonempty. Then given f ∈ W∞  f − Ime f  ≤ C||2 | f |2,∞ .

(6.18)

Here the constant depends only on β if  is convex, and also on the Lipschitz constant of the boundary if it is not. This theorem shows that we can expect the errors for minimal energy spline interpolation to behave like O(||2 ), regardless of what degree C 1 splines we are using. We will observe this is in the examples below. It has been conjectured that this bound is best possible in the sense that it cannot hold with a higher power of ||; see Remark 6.9.

6.3.4 Minimal energy Powell–Sabin splines In this section we take  :=  P S to be the Powell–Sabin refinement of the initial triangulation 0 of the sample points, and work with the macro-element space S21 ( P S ). As observed in Theorem 4.29, dim S21 ( P S ) = 3n, where n is the number of vertices in 0 . We constructed two different bases for this space in section 4.14.1. Here we show how to use both of them. First we discuss the case where we use the N -basis corresponding to the nodal minimal determining set N described in Theorem 4.32. The function nmdsps described in section 4.14.1 selects N and computes the corresponding transformation matrix A. For this nodal minimal determining set, the first n degrees of freedom are the values of the spline at the vertices of . This ensures that this basis satisfies (6.7)–(6.8). We have implemented

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

170

Chapter 6. Scattered Data Interpolation

minimal energy interpolation using this basis for the space S21 ( P S ) in the following function: [c,M22,t1,t2] = menps(v1o,v2o,v3o,x,y,zo,v1,v2,v3,... e1,e2,e3,ie1,A) Here v1o,v2o,v3o are the vertex lists for the initial triangulation, and the vector zo contains the data values. The rest of the triangulation parameters pertain to the Powell–Sabin refinement  P S as computed by a call on nmdsps, which also produces the transformation matrix A. The main output is the vector c of B-coefficients of the minimal energy spline, but for diagnostic purposes, we also output the matrix M22 appearing in (6.13), and the times t1 and t2 for assembling this matrix and for solving the corresponding linear system. Note that by construction, this minimal energy interpolation method fits polynomials of degree one exactly. However, it is not generally exact for quadratic polynomials. Example 6.10. Find the C 1 Powell–Sabin minimal energy interpolant of Franke’s function (2.20) based on samples at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We use the script Bmenps with the data file tri36.dat. For this example, the maximum and RMS errors are 1.07(−1) and 2.57(−2), respectively, while the condition number of the matrix of the linear system (6.13) is 83. We present a plot of the resulting surface in Figure 6.5 (left). For the x-derivative, we have errors of 1.04 and 2.76(−1). We plot the x-derivative of the spline in Figure 6.5 (right).

2 1

0 0.5

-2 0 1

1 1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 6.5. The C 1 Powell–Sabin minimal energy spline interpolating Franke’s function at the 36 vertices of the triangulation in Figure 6.1 (left), and its x-derivative.

In the following example we examine the rate of convergence of the C 1 Powell–Sabin minimal energy method by looking at a nested sequence of type-1 triangulations. Example 6.11. Interpolate Franke’s function (2.20) using the Powell–Sabin C 1 quadratic minimal energy splines based on samples of Franke’s function (2.20) at the vertices of a sequence of uniform refinements of the type-1 triangulation shown on the top left in Figure 6.4. Discussion: We again use the script Bmenps, but now read the triangulations from the files type1.25, type1.81, etc. The following table gives the maximum and RMS errors on a 51 × 51 grid for various values of the number of vertices n. It also lists the estimated

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.3. Minimal energy interpolating splines

171

condition number of the matrix M22 for each value of n, along with the computational time in seconds. n 25 81 289 1089

emax 1.40(−1) 3.42(−2) 1.61(−3) 3.22(−4)

rms condition time 4.55(−2) 29 .06 5.11(−3) 31 .09 3.43(−4) 32 .30 4.59(−5) 32 2.05

ratios 4.09 8.90 21.24 14.90 5.00 7.47

For this test function, the convergence seems to be better than the O(||2 ) guaranteed by Theorem 6.9. Note that the condition numbers are very small, and seem to remain essentially constant as n increases. For the x-derivative, we have the following table: n emax rms 25 1.72(0) 4.69(−1) 81 8.21(−1) 1.13(−1) 289 1.39(−1) 1.95(−2) 1089 4.92(−2) 6.36(−3)

ratios 2.10 4.15 5.91 5.79 2.83 3.07

Theorem 6.9 does not make any assertion about the rate of convergence of first derivatives, but we would expect at least a linear convergence. Here we seem to be doing at least as well. The C 1 Powell–Sabin minimal energy spline can also be computed using the M-basis for S21 ( P S ) corresponding to the minimal determining set M described in Theorem 4.29; see Remark 6.3.

6.3.5 Minimal energy splines with S51,2 () We now discuss minimal energy interpolation with the Argyris macro-element space S51,2 (), where  is a triangulation with vertices at the data points. As noted in section 4.14.2, the dimension of this space is 6n + n e , where n and n e are the numbers of vertices and edges in , respectively. In Theorem 4.34 we constructed a minimal determining set M for this space, and here we work with the corresponding M basis. We can use mds15 to find the list of degrees of freedom and compute the transformation matrix A. The M basis automatically satisfies properties (6.7)–(6.8) since the first n degrees of freedom are the values of the spline at the vertices of . Here is our function for computing the minimal energy spline in S51,2 (): [c,M22,t1,t2] = men15(x,y,z,v1,v2,v3,e1,e2,e3,ie1,area,A) The input includes the usual triangle information, the vector z of data values, and the transformation matrix A. Note that this function also requires a list of areas of the triangles. These are used in computing the energy of the spline via quadrature. The main output is the vector c of B-coefficients. We also output the matrix M22 appearing in (6.13), and the times t1 and t2 for assembling it and for solving the corresponding linear system. We now give two examples to illustrate the performance of the minimal energy method using the space S51,2 (). We begin with the analog of Example 6.10.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

172

Chapter 6. Scattered Data Interpolation

Example 6.12. Find the minimal energy interpolant from S51,2 () of the Franke function (2.20) based on data at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We use the script Bmen15 with tri36.dat. We get maximum and RMS errors of 2.46(−1) and 4.76(−2) for the function, and 1.60 and 3.81(−1) for the x-derivative. The condition number of the matrix M22 in (6.13) is 6.7(+4). Comparing with Example 6.10, we see that the use of Powell–Sabin splines gives smaller errors and smaller condition numbers. The programs using Powell–Sabin splines are also much faster; see the following example, and compare with Example 6.11. To explore the rate of convergence of this minimal energy method, we now solve a sequence of interpolation problems on nested triangulations. Example 6.13. Interpolate Franke’s function (2.20) using S51,2 () based on data at the vertices of a nested sequence of type-1 triangulations obtained by uniform refinement of a type-1 triangulation with 25 vertices. Discussion: We again use the script Bmen15, but now read the triangulations from the files type1.25, etc. Here is a table of the maximum and RMS errors, along with the condition numbers of the associated matrices M22. We also give the computational times to emphasize that this is a global method, and is going to be slow for large values of n. Computing the minimal determining set is quite fast. The bulk of the time is split more or less evenly between assembling the energy matrix and solving the resulting system of equations. n 25 81 289 1089

emax 9.04(−2) 4.96(−2) 3.85(−3) 4.42(−4)

rms condition time 3.06(−2) 666 .02 6.44(−3) 667 .10 4.72(−4) 671 .86 5.57(−5) 672 15.07

ratios 1.82 4.75 12.88 13.64 8.71 8.47

By Theorem 6.9, we expect the rate of convergence for this method to be O(||2 ). We seem to be getting better than that. The condition numbers are quite small in all of the cases, and seem to be essentially constant as n increases. For the x-derivative, we have the following table: n emax rms 25 1.37(0) 2.72(−1) 81 8.08(−1) 1.28(−1) 289 1.82(−1) 2.16(−2) 1089 8.81(−2) 8.97(−3)

ratios 1.70 2.13 4.44 5.93 2.06 2.41

We seem to be getting the expected order one convergence. As we have seen, minimal energy splines do a very good job of solving scattered data problems as long as we don’t have too many points, say up to around 1000. For larger sets of points, we can use the space S10 (), but it would be nice to have some local methods using splines of higher degree and higher smoothness. We describe such methods in the next several sections.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.4. A local C 0 cubic spline method

173

6.4 A local C 0 cubic spline method In this section we describe a local scattered data interpolation method based on cubic splines. Suppose we are given values {z i }ni=1 at a scattered set of points {(x i , yi )}ni=1 , and let  be a triangulation with vertices at these points, for example the Delaunay triangulation. Algorithm 6.14. For each triangle T in : 1) Find the set PT := { pi }m i=1 of vertices of  \ T that lie in the union of the 3-stars of the three vertices of T . If the cardinality of PT is greater than 20, choose the 20 points closest to the barycenter of T . 2) Compute the B-coefficients of a cubic polynomial that interpolates the data at the three vertices of T , and fits the data at the points of PT in the least-squares sense. Store these as coefficients of a spline in S30 (). Discussion: The number of points in the sets PT will vary depending on the nature of the triangulation. For a type-1 triangulation, the cardinality of PT may be as little as 10 for a triangle in the corner, around 15 for triangles with one boundary edge, and about 20 for all other triangles. We discuss Step 2 in the following lemma. Lemma 6.15. Let T be a triangle with vertices v1 , v2 , and v3 . Suppose we are given values m {z i }m i=1 associated with points { pi := (x i , yi )}i=1 . Let O := [B1 ( p j ), . . . , B10 ( p j )]m j =1 ,

(6.19)

where B1 , . . . , B10 are the cubic Bernstein basis polynomials associated with T . Suppose the submatrix O˜ obtained from O by dropping columns 1, 7, and 10 is of full rank 7. Then for any {wi }3i=1 there exists a unique cubic polynomial such that g :=

10 

ci B i

i=1

satisfies g(vi ) = wi , and minimizes

m 

i = 1, 2, 3,

(6.20)

[g( p j ) − z j ]2 .

j =1

Proof. By properties of the Bernstein basis polynomials, we can ensure (6.20) by setting ci = wi for i = 1, 2, 3. To get the remaining coefficients, we solve the overdetermined system ⎡ ⎤ c2 ⎡ ⎤ z1 ⎢ .. ⎥ ⎢.⎥ ⎢ . ⎥ ⎥ ⎢ ˜ (6.21) O ⎢c6 ⎥ = ⎣ .. ⎦ − w1 O1 − w2 O7 − w3 O10 , ⎣c ⎦ zm 8 c9

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

174

Chapter 6. Scattered Data Interpolation

where O j denotes the j th column of O. The entries of O can be computed using basisv. The overdetermined system (6.20) can be solved in MATLAB using the standard backslash operator. We make several observations concerning this algorithm. First, for each triangle T , we need to have at least 10 points in the set PT , and these points must be reasonably distributed in order for the matrix O˜ to be nonsingular. Our choice of PT using 3-stars around the vertices of T suffices for most triangulations, but it is possible to create a triangulation where it fails. Second, we note that for each interior edge e, the B-coefficients of s associated with domain points on e are determined twice. We could average them, but here we simply take the last computed values. We have implemented this algorithm in the function c = scat03(x,y,z,v1,v2,v3,e1,e2,e3,ie1,ie2,adjstart,vadj) The input includes the usual triangle information for  and the vector z of sample values. The output is the vector c of the B-coefficients of C 0 cubic spline interpolating the data. The local C 0 cubic spline interpolant of this section has many of the same properties as the C 0 linear spline interpolant. In particular, it is scale invariant; see section 6.9. It also works on nonrectangular domains, and on domains with holes; see section 6.10. In general, it will do a better job than linear splines, but for problems involving up to 1000 scattered points, the minimal energy methods of section 6.3 give better results. Hence, we do not bother to repeat the examples involving smaller data sets. Instead, we give one example exploring the convergence rate. Example 6.16. Interpolate Franke’s function (2.20) using the above local C 0 cubic spline method based on data at the vertices of a nested sequence of type-1 triangulations obtained by uniformly refining a type-1 triangulation with 289 vertices. Discussion: We make use of the script Bscat03. Since we are interested in larger problems, we begin with the type-1 triangulation with 289 vertices which can be read from the file type1.289. The following table gives the maximum and RMS errors for various values of the number of vertices n. It also lists the output of the function c1ck which checks how close the spline is to being C 1 , and in the last column shows the computational times in seconds. n 289 1089 4225 16641

emax 1.24(−2) 1.09(−3) 7.98(−5) 4.62(−6)

rms 1.34(−3) 1.07(−4) 7.04(−6) 4.53(−7)

c1ck time 2.70(−3) .13 2.40(−4) .59 1.64(−5) 3.86 1.06(−6) 9.27

ratios 11.38 12.52 13.66 15.20 17.27 15.54

For this test function, the convergence seems to be O(||4 ), which is what we expect for a cubic spline. The computational time is approximately linear in the number of data points. Note that as n increases, the splines become smoother and smoother, and are eventually essentially C 1 . This is to be expected since for larger n, they are very close to the test function, which is C ∞ . Comparing these results with what we got in Example 6.3, we see that this local C 0 cubic spline method is more accurate than C 0 linear spline interpolation, but of course

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.5. A local C 1 Clough–Tocher method

175

requires a little more time to compute. On the other hand, the errors here are not as good as what we got with minimal energy Powell–Sabin splines in Example 6.11. Thus, even though the minimal energy method is a little slower, it is to be preferred for scattered data problems with up to about 1000 points. For larger sets, we recommend a local method like the one in this section.

6.5 A local C 1 Clough–Tocher method Let  be a triangulation of the data points, and let C T be the corresponding Clough– Tocher refinement. In this section we describe an algorithm for computing a spline in S31 (C T ) interpolating at the vertices of . It is based on the local C 0 cubic spline method of the previous section. Algorithm 6.17. Let s0 ∈ S30 () be a cubic spline interpolating given values at the vertices of a triangulation . 1) Use subdivision to rewrite s0 as a spline s˜ ∈ S30 (C T ). Let c˜ be its vector of Bcoefficients. 2) Adjust the coefficients c˜ to get a C 1 spline s ∈ S31 (C T ). Discussion: The subdivision process of Step 1 can be accomplished using the function ctssubdiv described in section 4.16. We now explain how to carry out the adjustment process of Step 2 locally. Let c˜ be the vector of coefficients of s˜ , and let c be the coefficients of the desired spline s ∈ S31 (C T ). For each vertex v = (x, y) of , we need to compute the coefficients of s associated with domain points on the ring R1 (v). Let ei := v, wi , i = 1, . . ., m, be the set of edges attached to v, and let z be the value of s˜ at v. Let cei be the coefficient of s associated with the domain point located at ei ∩ R1 (v), and suppose the Cartesian coordinates of wi are (x i , yi ) for i = 1, . . ., m. Then by the results of section 4.4, 3(cei − z) = (x i − x)z x + (yi − y)z y , where (z x , z y ) is the gradient of s at v. We now choose (z x , z y ) so that the coefficients of s on the ring R1 (v) give the best least-squares approximation of those of s˜ . This amounts to finding the least-squares solution of the overdetermined system ⎡ ⎤ ⎤ ⎡ x 1 − x y1 − y % & c˜e1 − z ⎢ .. .. ⎥ z x = 3 ⎢ .. ⎥ . ⎣ . ⎣ . ⎦ . ⎦ zy c˜em − z x m − x ym − y In MATLAB we can get the least-squares solution with the usual backslash operator. To complete Step 2, we need to adjust the coefficients of s˜ to get C 1 continuity across each interior edge e of . For each such edge e, there are three C 1 conditions, but only the one in the middle needs to be enforced as the other two are covered by the C 1 continuity around the vertices of . This smoothness condition involves four coefficients, two of which lie on the edge e and are already known. We choose the other two to be as close to the corresponding coefficients of s˜ as possible in the least-squares sense. This is a simple computation.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

176

Chapter 6. Scattered Data Interpolation

1

1

0.5

0.5

0 1

1

0.5

0.5 0 0

0 1

1

0.5

0.5 0 0

Figure 6.6. The local C 1 Clough–Tocher interpolants of Franke’s function at the vertices of the triangulations shown in Figure 6.1 (left) and Figure 6.2 (left).

We have now determined the coefficients of s associated with domain points in the disks of radius one around the vertices of , as well as those within a distance one of each edge of . These determine all remaining B-coefficients of s by C 1 smoothness conditions across the interior edges of each macro triangle. We have implemented the above adjustment algorithm in the function c = ctadj(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,... xo,v1o,ie1o,ie2o,trilo,triro,c) Here xo, . . . , triro describe the initial triangulation , while x, . . . , trir are associated with the Clough–Tocher refinement (C T ). Combining these ingredients, we have the following function for computing a C 1 cubic Clough–Tocher interpolating spline locally: [x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c] = ... scatlocct(xo,yo,zo,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro,adjstarto,vadjo) The input includes the lists describing the initial triangulation, along with a vector zo with the values to be interpolated. The output gives the lists for the Clough–Tocher refinement, and the B-coefficients of the interpolating spline. Example 6.18. Redo Example 6.2 with the local C 1 cubic Clough–Tocher method of this section. Discussion: We use the script Bscatlocct, and read the triangulations from the files tri36.dat, tri81.dat, and tri39.dat. The spline interpolant for tri36 is shown in Figure 6.6 (left). Its shape is not as good as for the minimal energy spline shown in Figure 6.5, but the maximum and RMS errors are almost the same: 1.32(−1) and 3.58(−2) as compared to 1.07(−1) and 2.57(−2). The spline interpolant for tri81 is shown in Figure 6.6 (right). Now the maximum and RMS errors are 7.05(−2) and 1.10(−2) as compared to 5.10(−2) and 9.59(−3) for the C 1 Powell–Sabin minimal energy spline. The results for tri39 are much worse than for the minimal energy spline. In the following example we examine the rate of convergence of the local C 1 Clough– Tocher method by looking at a nested sequence of type-1 triangulations.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.5. A local C 1 Clough–Tocher method

177

Example 6.19. Interpolate Franke’s function (2.20) using the above local C 1 cubic Clough–Tocher method based on data at the vertices of a sequence of uniform refinements of a type-1 triangulation of the unit square. Discussion: We again use the script Bscatlocct, but now read the triangulations from the files type1.25, etc. The following table gives the maximum and RMS errors for each triangulation, where n is the number of its vertices. It also gives the computational times in seconds. n 25 81 289 1089 4225 16641

emax 2.03(−1) 6.19(−2) 7.06(−3) 3.15(−4) 1.17(−5) 6.09(−7)

rms time 5.86(−2) .017 1.03(−2) .06 6.95(−4) .24 2.78(−5) .95 9.73(−7) 3.57 5.32(−8) 14.27

ratios 3.28 5.69 8.77 14.82 22.41 25.00 26.92 28.57 19.21 18.29

For this test function, the convergence seems to be at least the O(||4 ) that we expect for a cubic spline. The table suggests that the computational time is almost linear in n. For the x-derivative, we have the following table: n 25 81 289 1089 4225 16641

emax 2.62 1.18 2.92(−1) 4.07(−2) 3.70(−3) 4.90(−4)

rms 5.74(−1) 2.26(−1) 3.12(−2) 3.33(−3) 3.36(−4) 4.01(−5)

ratios 2.22 2.54 4.04 7.24 7.17 9.37 11.00 9.91 7.55 8.38

These rates are consistent with what we expect for the derivatives of a cubic spline. The results of this example show that computing the C 1 Clough–Tocher spline is only slightly slower than the C 0 cubic spline method of the previous section, but is much more accurate. The accuracy here is slightly worse than for the minimal energy Powell–Sabin splines of Example 6.11, but the computational times are significantly smaller. Here we were able to interpolate with 4225 and 16641 data points in a reasonable amount of time, which we could not do with the minimal energy methods. In section 6.3.4 we showed that minimal energy Powell–Sabin splines are a good choice for interpolating scattered data with up to about 1000 points, but are too slow for larger data sets. So far, the local C 1 cubic Clough–Tocher method of this section seems to be our best choice for problems involving larger numbers of data points. It is based on the cubic Clough–Tocher macro-element space, and is a multi-stage method in that first a C 0 cubic spline interpolant is constructed, and then subdivided and adjusted to get the final C 1 spline interpolant. Alternatively, one could use the space S31 (C T ) directly if we had good estimates for the derivatives making up the Hermite data used in Theorem 5.8. This would constitute a two-stage method, where in the first stage we locally estimate the needed derivatives, and then interpolate the resulting Hermite data. This idea applies as well to any of the other macro-element methods discussed in Chapter 5. To explore it further, we begin by looking at the problem of estimating derivatives locally from scattered data.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

178

Chapter 6. Scattered Data Interpolation

6.6 Estimating derivatives from scattered data Considerable research has gone into the following problem. Problem 6.20. Given nonnegative integers ν and μ and a point (x, y) in R2 , find an estiμ mate for the value Dxν D y f (x, y) for some unknown function f based on samples {z i }m i=1 of f at a set P := {(x i , yi )}m i=1 of points near (x, y). To get any kind of reasonable result, we will have to assume that f is smooth in a neighborhood of (x, y) containing all the points P, say at least C 1 .

6.6.1 Local polynomial least-squares To solve Problem 6.20, we may proceed as follows: 1) Pick a positive integer d, and use the data {x i , yi , z i }m i=1 to construct a polynomial p of degree d that approximates f . μ

2) Choose Dxν D y p(x, y) as an approximation to Dxν D νy f (x, y). Let { pi }ni=1 be a basis for the space of polynomials Pd , where n := need to compute coefficients c := (c1 , . . . , cn ) such that the polynomial p=

n 

)d+2* 2 . Then we

ci p i

i=1

approximates f well. For a variety of reasons, it is not recommended to choose p by interpolation, and so we choose to look instead for the least-squares fit, i.e., we choose c to minimize the least-squares error

( p) =

m 

( p(x i , yi ) − z i )2 .

(6.22)

i=1

We need to assume that m > n. However, this condition alone is not enough. Theorem 6.21. Suppose m ≥ n, and suppose the m × n matrix O := [ p j (x i , yi )]m,n i=1, j =1

(6.23)

has full rank n. Then there exists a unique polynomial p of degree d minimizing ( p). Its coefficient vector c can be computed by solving the linear system of equations O T Oc = O T z.

(6.24)

Discussion: The assumption that O has full rank ensures that the n × n matrix O T O is nonsingular. The fact that the associated polynomial minimizes the least-squares error follows by the same arguments as used in the proof of Theorem 1.28. The matrix O in (6.23) is called the observation matrix, and the equations in (6.24) are called the normal equations. Even for moderate values of n the matrix O T O in the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.6. Estimating derivatives from scattered data

179

normal equations can be very badly conditioned, especially if the sample points are badly distributed. When using MATLAB, it is possible to avoid working with the normal equations, since when m > n and the observation matrix O has full rank, the command c = O \ z will automatically produce the coefficient vector giving the least-squares approximant. The condition number of O (see Remark 6.15) will generally be much smaller than that of O T O. For our purposes, we suggest writing p in terms of the Bernstein basis polynomials {Bidj k }i+ j +k=d of section 4.1 associated with a triangle T with vertices at the points (x, y), (x +δ, y), and (x, y +δ), where (x, y) is the point where we want to estimate derivatives, and where δ can be chosen to be any convenient value, for example the radius of the smallest disk containing the sample points. With this basis, we can immediately compute the value of p and its derivatives at v1 := (x, y). For example, writing p in the B-form (4.5), we have p(v) = cd00 and Dx p(x, y) = d (cd−1,1,0 − cd00)/δ,

D y p(x, y) = d (cd−1,0,1 − cd00)/δ;

see equation (2.36) of [[LaiS07]]. The following function uses least-squares approximation with a polynomial of degree d to estimate both the x- and the y-derivatives at a point (x, y) based on samples at nearby data: [fx,fy] = derestlsqv(d,xd,yd,zd,x,y) The data is contained in the vectors xd, yd, and zd, while x and y are the coordinates of the point of interest. Here d is the degree of polynomial to be used. Linear polynomials are not accurate enough for our purposes, but quadratic and cubic polynomials are both reasonable choices. We now give two examples to see how this method performs. We look first at a problem using a quadratic polynomial. Example 6.22. Estimate the values of f x (.5, .5) and f y (.5, .5) for Franke’s function using samples at the 12 points shown in Figure 6.7. Discussion: We use the script Bderestv12. In this experiment we use polynomials of degree d = 2, and explore how the accuracy changes as we move the points closer to 1

0.75

0.5

0.25

0 0

0.25

0.5

0.75

1

Figure 6.7. A set of 12 points to be used to estimate derivatives of a function at the point marked with a star.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

180

Chapter 6. Scattered Data Interpolation

(.5, .5), keeping their relative positions fixed. In particular, for each i = 1, . . . , 5 we scale and translate these points to lie in a square of side length L = 21−i centered at (.5, .5). The following table shows the errors ex and ey for the x- and y-derivatives. These are computed by comparing with the true values f x (x, y) = .1678 and f y (x, y) = .9974. We also give the condition numbers of the observation matrix O. L 1 .5 .25 .125 .0625

ex 5.26(−1) 8.41(−2) 6.51(−3) 2.99(−3) 6.39(−4)

ey 6.04(−1) 5.14(−1) 1.58(−1) 4.29(−2) 1.11(−2)

cond 5.28(1) 1.34(2) 4.44(2) 1.64(3) 6.31(3)

As the size of the square decreases, i.e., as the sample points get closer to (.5, .5), the errors improve and the condition numbers grow modestly. In this example the sample points were reasonably distributed relative to the evaluation point. We will get much worse results if the sample points are not well distributed. This can happen in practice, especially if the evaluation point is on the boundary of some domain and the sample points are inside. We now give a similar example using a cubic polynomial. Example 6.23. Estimate the values of f x (.5, .5) and f y (.5, .5) for Franke’s function using samples at the 20 points shown in Figure 6.8. Discussion: We use the script Bderestv20. As in Example 6.22, we want to explore how the accuracy changes as we move the points closer to (.5, .5), keeping their relative positions fixed, and so we scale them in the same way as was done there. The following table shows the errors for both the x- and the y-derivatives. As before, the true values

.9

.5

.1 .1

.5

.9

Figure 6.8. A set of 20 points to be used to estimate derivatives of a function at the point marked with a star.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.6. Estimating derivatives from scattered data

181

are f x (x, y) = .1678 and f y (x, y) = .9974. We also give the condition numbers of the observation matrix O. L 1 .5 .25 .125 .0625

ex 5.69(−1) 2.29(−1) 3.54(−2) 5.00(−3) 6.80(−4)

ey 2.86(−1) 3.20(−1) 1.32(−2) 2.86(−4) 8.36(−6)

cond 3.58(2) 1.56(3) 9.84(3) 7.37(4) 5.79(5)

As the size of the square decreases, i.e., as the sample points get closer to (.5, .5), the errors improve and the condition numbers grow modestly. The errors here are generally better than those obtained using a quadratic, particularly for the y-derivative. This can be partially explained by the way the points are distributed more vertically than in Example 6.22.

6.6.2 Estimating derivatives with radial basis functions In section 6.14 we show how to use radial basis function to interpolate scattered data. Since derivatives of radial basis functions are easy to compute, we can use them to solve our derivative estimation problem. The following function is based on the Gaussian radial basic function introduced in section 6.14 below; see (6.33). [fx,fy,M] = derestrbfv(xd,yd,zd,x,y,eps) Here x,y are the Cartesian coordinates of the point where we want to compute the estimated gradient fx,fy. The vectors xd,yd,zd contain the data points and values to be used. The parameter eps controls the shape of the Gaussian, and as explained in section 6.14 has to be chosen carefully in order to get good results. The following example shows that the method can work well for well-distributed points. Example 6.24. Use a radial basis function to estimate the values of f x (.5, .5) and f y (.5, .5) for Franke’s function using samples at the 20 points shown in Figure 6.8. Discussion: We use the script Bderestv20r which uses the Gaussian radial basic function with eps = 3. As in Example 6.23, we want to explore how the accuracy changes as we move the points closer to (.5, .5), keeping their relative positions fixed, and so we scale them in the same way as was done there. The following table shows the errors for both the x- and the y-derivatives. As before, the true values are f x (x, y) = .1678 and f y (x, y) = .9974. We also give the condition numbers of the collocation matrix used to compute the radial basis interpolant. L 1 .5 .25 .125 .0625

ex 2.19(−1) 1.01(−1) 2.24(−3) 1.38(−5) 1.43(−5)

ey cond 4.84(−1) 2.43(4) 6.13(−2) 2.07(7) 1.84(−3) 5.44(10) 1.27(−4) 1.85(14) 1.25(−5) 2.08(17)

As the size of the square decreases, i.e., as the sample points get closer to (.5, .5), the errors improve and the condition numbers grow rapidly. The errors here are better than those obtained in Example 6.23 for most of the cases, but not all.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

182

Chapter 6. Scattered Data Interpolation

Although this example shows that using radial basis functions to estimate derivatives can perform better than local least-squares with polynomials, we shall see in Example 6.26 below that there are situations where it is much better to use the polynomial approach.

6.6.3 Estimating derivatives at the vertices of a triangulation Suppose  is a triangulation with vertices {(x i , yi )}ni=1 , and that we are given samples {z i }ni=1 of an unknown function f at these points. In this section we discuss methods for computing estimates for the gradients ( f x , f y ) at these vertices. We shall apply our methods in section 6.7 below to create two-stage schemes for interpolating scattered data. Suppose now that v is one of the vertices of  where we want to estimate the gradient. We intend to estimate the gradient at v using one of the methods of the previous two sections. In order to do so, we have to select a set P of nearby vertices to use in computing the estimates. Suppose we want to use m points. There are two natural approaches to selecting them: 1) Use stars to find m vertices near v. 2) Find the m nearest vertices to v. Following the first approach, we could select P to consist of all vertices in the star of v. However, for typical triangulations, star(v) will only contain six or fewer points. To obtain more points, we can work with a higher order star, say the kth order star of v for some k > 0. We can adaptively choose k to get at least m points. Sometimes this gives too many points (which may be too far away from v), in which case we can prune the list back to m points by selecting those that are nearest v. To implement the second approach, we need a way to find nearest vertices. For this we can use the built-in MATLAB function [vlist,dis] = knnsearch([x,y],[x,y],’K’,m) Here x and y are n-vectors containing the Cartesian coordinates of the vertices of . The output is a matrix vlist of size n × m whose i th row contains the indices of the m vertices of  that are closest to the vertex vi := (x i , yi ). The function also outputs the corresponding distances in the matrix dis of the same size. Combining these ideas with the methods of the previous two sections, we can create four different schemes for estimating the gradients at all of the vertices of a given triangulation. [zx,zy] = derestlsq(x,y,z,adjstart,vadj,de,m) [zx,zy] = derestlsqk(x,y,z,de,m) [zx,zy] = derestrbf(x,y,z,adjstart,vadj,eps,m) [zx,zy] = derestrbfk(x,y,z,eps,m) For all four functions, the input variables include the coordinates x,y of the vertices of the triangulation , along with a vector z containing the sample values. All four functions

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.6. Estimating derivatives from scattered data

183

use the parameter m to control how many sample points to use in the estimates. The first two, which are based on local least-squares, use the parameter de to specify the degree of the polynomial to be used, while in the latter two the parameter eps controls the shape of the Gaussian radial basic function. The vectors adjstart,vadj contain the adjacency information for . In all cases, the output consists of two column vectors zx,zy with the desired derivative estimates. Example 6.25. Estimate the x- and y-derivatives of Franke’s function (2.20) at the vertices of a nested sequence of type-1 triangulations using the above methods. Discussion: We make use of our script Bderest, and read the triangulations from the files type1.25, etc. The following table gives the max and RMS errors measured at the vertices for both the x- and the y-derivatives, and also the computational time in seconds. derestlsq with de = 3 and m = 20 n 25 81 289 1089 4225

xmax 1.49(0) 1.02(0) 2.68(−1) 4.17(−2) 4.42(−3)

xr ms 6.51(−1) 3.39(−1) 4.79(−2) 5.30(−3) 5.13(−4)

ymax 1.78(0) 1.19(0) 3.84(−1) 6.26(−2) 7.46(−3)

yr ms time 8.69(−1) .007 3.22(−1) .03 6.81(−2) .09 6.73(−3) .33 5.62(−4) 1.3

derestlsqk with de = 3 and m = 20 n 25 81 289 1089 4225

xmax 1.62(0) 1.02(0) 2.68(−1) 4.17(−2) 4.42(−3)

xr ms 7.16(−1) 3.23(−1) 4.57(−2) 4.84(−3) 4.75(−4)

ymax 2.12(0) 9.52(−1) 2.89(−1) 6.45(−2) 7.93(−3)

yr ms 9.63(−1) 2.72(−1) 5.50(−2) 5.74(−3) 4.72(−4)

time .004 .01 .02 .07 .27

derestrbf with eps = 3 and m = 20 n 25 81 289 1089 4225

xmax 1.22(0) 5.90(−1) 7.66(−2) 1.18(−2) 1.69(−3)

xr ms 4.34(−1) 1.71(−1) 1.69(−2) 1.72(−3) 1.67(−4)

ymax 1.24(0) 6.29(−1) 1.93(−1) 1.58(−2) 2.18(−3)

yr ms time 5.06(−1) .02 1.68(−1) .05 2.91(−2) .18 2.40(−3) .63 2.48(−4) 2.5

derestrbfk with eps = 3 and m = 20 n 25 81 289 1089 4225

xmax 1.22(0) 5.90(−1) 7.66(−2) 1.18(−2) 1.69(−3)

xr ms 4.34(−1) 1.75(−1) 1.73(−2) 1.79(−3) 1.75(−4)

ymax 1.24(0) 6.29(−1) 1.93(−1) 1.58(−2) 2.18(−3)

yr ms time 5.12(−1) .01 1.70(−1) .03 2.92(−2) .09 2.41(−3) .36 2.48(−4) 1.4

In all four tables, the RMS errors give a better picture of the performance of the method, since just one poor estimate (say at a corner vertex) determines the max error. As we

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

184

Chapter 6. Scattered Data Interpolation

can see, the RBF-based methods are somewhat more accurate, but they are also somewhat slower. This example shows that all four methods work well when the sample points are well distributed. The next example shows that the methods based on knnsearch can exhibit major problems when the points are less well distributed. Example 6.26. Consider the scaled Franke’s function (5.18) on the rectangle [0, α]×[0, β], and suppose we are given sample values on an nx × ny grid. Estimate the x- and yderivatives at the vertices of the type-1 triangulation associated with the grid. Discussion: We use the script Bderestr with m = 20, de = 3, and eps = 3. Let α = 100 and β = 1, and let nx = ny = 33. Here is a table of the max and RMS errors for both the x- and the y-derivatives. method derestlsq derestlsqk derestrbf derestrbfk

xmax 5.16(−4) 3.60(0) 3.26(−2) 3.26(−2)

xr ms 9.75(−5) 1.48(0) 1.07(−2) 1.07(−2)

ymax 6.64(−2) 3.37(0) 5.53(−3) 3.21(+1)

yr ms 1.03(−2) 4.91(0) 6.21(−4) 2.07(0)

For both derestlsqk and derestrbfk, we get numerous warnings about rank deficient matrices. This is due to the fact that in these functions we are choosing sample points according to their distance to the evaluation point. For gridded data on a very thin rectangle, this means that if the sample point v lies on the bottom edge, for example, then the closest points will all be on the vertical line through v, and the observation matrix will not be of full rank. The results for the RBF-based methods can be improved somewhat by playing with the value of eps. The situation illustrated in this example gets even worse as we increase α to get even longer and thinner rectangles. In view of this example, to make the two-stage methods discussed in the next section as robust as possible, we are going to use derestlsq for estimating gradients at the vertices of a triangulation. Some of our two-stage macro-element methods will require estimating second derivatives at all of the vertices of a triangulation . This can be done with the same approach. Since estimating first derivatives is already a delicate matter, great care should be exercised with higher derivatives.

6.6.4 Estimating cross derivatives on edges Some of the macro-element spline spaces that we plan to use in two-stage scattered data interpolation methods in the next section require estimates of cross derivatives at certain points on the edges of a triangulation  of the data points. Suppose w is a point on an (oriented) edge e of . Then the unit vector u := (u x , u y ) pointing in the direction obtained by rotating e 90 degrees in the counterclockwise direction can be computed using our function ucross used in section 5.4. Then for any differentiable function f , Du f (w) = u x Dx f + u y D y f . Thus, to compute an approximation to Du f , we now need to estimate the gradient of f at w. This can be done as before using polynomial least-squares. In this case we choose the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.7. Local two-stage methods based on derivative estimation

185

sample points as the union of the two-stars around the endpoints of the edge. The functions derestct, derest15, and derestwang described in the following sections use this star approach with cubic polynomials based on m = 20 sample points.

6.7 Local two-stage methods based on derivative estimation In this section we show how to use Hermite interpolation methods to solve the scattered data interpolation problem (Problem 6.1). The idea is simple: we choose a Hermite interpolation method, such as any of those discussed in Chapter 5, and then estimate the required derivatives from the scattered data. We will illustrate this idea with three C 1 spaces and one C 2 space.

6.7.1 A two-stage Powell–Sabin method As a first example of a two-stage method using derivative estimates, we combine the function derestlsq as a first stage with Hermite interpolation based on the C 1 quadratic Powell–Sabin interpolant discussed in section 5.2. Although we are primarily interested in using two-stage methods for large data sets, we begin with an example with a relatively small number of sample points. Example 6.27. Compute the two-stage C 1 quadratic Powell–Sabin interpolant of Franke’s function (2.20) on the unit square using function values at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We make use of the script Bscatps along with the data file tri36.dat. This script uses derestlsq with de = 3 and m = 20 in the first stage to estimate the gradients at the vertices of . The max and RMS errors for the two-stage method are 2.16(−1) and 5.02(−2). These can be compared with the errors of 1.07(−1) and 2.57(−2) that we get with the Powell–Sabin minimal energy spline; see Example 6.10. A plot of the surface is shown in Figure 6.9 (left). It is not as smooth as the minimal energy spline, and exhibits a few artifacts due to the way the derivatives were estimated. As a further indication of how this method performs, in Figure 6.9 (right) we plot the x-derivative of the spline. The max and RMS errors for the spline approximation to the x-derivative of Franke’s function are 2.18 and 5.41(−1), respectively. These result should also be compared with the values 1.04 and 2.76(−1) that we get with the minimal energy Powell–Sabin spline. 1.2 2

.6 0

0

-2

1

1

0.5

0.5 0 0

1

1

0.5

0.5 0 0

Figure 6.9. The two-stage Powell–Sabin interpolant of Franke’s function based on samples at the 81 vertices of the triangulation in Figure 6.2.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

186

Chapter 6. Scattered Data Interpolation

To further illustrate the behavior of this two-stage method based on C 1 quadratic Powell– Sabin macro elements, we now look at what happens on a nested sequence of type-1 triangulations. Example 6.28. Compute the two-stage C 1 quadratic Powell–Sabin interpolants of Franke’s function (2.20) on the unit square using data at the vertices of a nested sequence of type-1 triangulations obtained by repeated uniform refinement of a type-1 triangulation of the unit square with 81 vertices. Discussion: We again use the script Bscatps, and read the triangulations from the files type1.81, type1.289, etc. Here is a table of the maximum and RMS errors for the various choices of the number of vertices n. n 81 289 1089 4225 16641

emax 6.45(−2) 5.92(−3) 3.77(−4) 2.67(−5) 3.66(−6)

rms time 1.13(−2) .03 8.01(−4) .09 4.51(−5) .36 3.89(−6) 1.40 4.67(−7) 5.54

ratios 10.90 14.11 15.70 17.76 14.12 11.60 7.30 8.33

Comparing with the table given in Example 6.11, we see that the errors are only slightly larger than those obtained when using minimal energy Powell–Sabin spline, particularly for the larger triangulations. Since we are using quadratic splines, we expect the rate of convergence to be three, which is what we are getting. Concerning the x-derivative, we have the following table: n 81 289 1089 4225 16641

emax 1.60(0) 4.92(−1) 7.28(−2) 1.80(−2) 3.70(−3)

rms 2.80(−1) 4.79(−2) 7.55(−3) 1.43(−3) 3.28(−4)

ratios 3.25 5.85 6.76 6.34 4.04 5.28 4.86 4.36

Note that even though we are using estimated derivatives, we seem to be getting quadratic convergence, which is what we expect for the derivative of a quadratic spline.

6.7.2 A two-stage Clough–Tocher method To make use of the Clough–Tocher macro-element spaces for scattered Lagrange interpolation, in addition to finding estimates for the x- and y-derivatives at the vertices of , we also have to estimate the unit normal cross derivatives at the midpoints of the edges of . Using local least-squares polynomials based on 20 sample points chosen by the method of stars discussed in section 6.6.3, we can combine these two estimation problems into the following single function: [zx,zy,ze] = derestct(xo,yo,zo,v1o,v2o,v3o,e1o,e2o,e3o,... ie1o,ie2o,adjstarto,vadjo); The input consists of the lists associated with the initial triangulation with vertices at the sample points, along with a vector zo containing the values at the vertices. The output

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.7. Local two-stage methods based on derivative estimation

187

vectors zx,zy contain the estimates of the gradient at the vertices, while ze contains the estimated cross derivatives. Example 6.29. Compute the two-stage C 1 cubic Clough–Tocher interpolant of Franke’s function (2.20) on the unit square using only function values at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We use the script Bscatct with the data file tri36.dat. The max and RMS errors using this spline are 2.01(−1) and 4.84(−2). This compares with the error values 1.07(−1) and 2.57(−3) obtained with the minimal energy Powell–Sabin spline; see Example 6.10. For the x-derivative, the max and RMS errors of the two-stage method are 2.11(0) and 5.28(−1) as compared with the values 1.04(0) and 2.76(−1) for the minimal energy Powell–Sabin spline. We do not give plots of the splines as they are very similar to those in Figure 6.9, just a little smoother looking. To explore the rates of convergence of the two-stage method based on Clough–Tocher macro elements, we now look at what happens on a nested sequence of type-1 triangulations. Example 6.30. Compute the two-stage Clough–Tocher interpolants of Franke’s function (2.20) on the unit square using data at the vertices of type-1 triangulations with n = 81, 289, 1089, 4225,16641 vertices. Discussion: We again use the script Bscatct with the triangulation files type1.25, etc. Here is a table of the maximum and RMS errors for the various values of the number of vertices n. n 81 289 1089 4225 16641

emax 6.40(−2) 6.10(−3) 3.22(−4) 1.04(−5) 6.10(−7)

rms times 1.04(−2) .11 6.79(−4) .33 2.64(−5) 1.25 1.00(−6) 4.40 5.91(−8) 17.42

ratios 10.49 15.32 18.94 25.72 30.96 26.40 17.05 16.92

Comparing with the table given in Example 6.11, we see that for the smaller data sets, the errors are slightly worse than what we got with the minimal energy Powell–Sabin splines. But for the larger data sets, the error is somewhat better than with the minimal energy spline. Since we are working with cubic splines, we expect the rate of convergence to be four, which is what we are getting. Here are the errors for the x-derivative: n 81 289 1089 4225 16641

emax 1.18 2.68(−1) 4.17(−2) 4.42(−3) 6.67(−4)

rms 2.36(−1) 3.16(−2) 3.77(−3) 4.10(−4) 5.33(−5)

This gives the expected order three convergence.

ratios 4.40 7.47 6.43 8.38 9.43 9.20 6.63 7.69

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

188

Chapter 6. Scattered Data Interpolation

6.7.3 A two-stage method using S51,2 () In this section we examine a two-stage method based on the macro-element space S51,2 (). Here  is any triangulation of the sample points. As shown in Theorem 5.12, a spline in this space is uniquely determined by derivatives up to order two at each vertex of , combined with the first order cross derivatives at the midpoint of each edge of . We can use the following function to estimate these derivatives from the scattered data. It is based on local cubic polynomial least-squares with sets of 20 samples chosen as for derestct. [der,ze] = derest15(x,y,z,v1,v2,v3,e1,e2,e3,... ie1,ie2,adjstart,vadj) In addition to the lists describing , the input includes a vector z containing the sample values. The first output of this function is a matrix der of size n × 6, where n is the number of vertices in the triangulation . The i th row of this matrix contains the estimated values of f , f x , f y , f x x , f x y , f yy at the i th vertex. The second output ze is a vector of length n e containing the estimated first order cross derivatives at the midpoints of the edges of . Example 6.31. Compute the two-stage interpolant from S51,2 () of Franke’s function (2.20) on the unit square using only function values at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We use the script Bscat15 together with the data file tri36.dat. The max and RMS errors of the spline fit are 2.09(−1) and 4.90(−2). This compares to errors of 2.46(−1) and 4.76(−2) when using the minimal energy spline in S51,2 (); see Example 6.12. The max and RMS errors for the x-derivative of the spline are 2.16 and 5.31(−1), respectively, which compares with 1.60(0) and 3.81(−1) using the minimal energy spline. This loss of accuracy is due to the fact that we cannot expect to estimate second derivatives very accurately using this small amount of data. Example 6.32. Use the two-stage method based on S51,2 () to interpolate Franke’s function (2.20) using data at the vertices of a sequence of nested triangulations obtained by repeated uniform refinement of the type-1 triangulation of the unit square with vertices on a 9 × 9 grid. Discussion: We again use the script Bscat15, and read the triangulations from the files type1.81, etc. Here is a table of the maximum and RMS errors, along with the computation times. The column labelled n gives the number of vertices of each triangulation. n 81 289 1089 4225 16641

emax 6.06(−2) 5.59(−3) 4.22(−4) 1.80(−5) 1.23(−6)

rms time 1.03(−2) .08 6.84(−4) .29 3.03(−5) .98 1.80(−6) 3.86 1.24(−7) 15.36

ratios 10.84 15.06 13.25 22.57 23.44 16.83 14.63 14.52

Using quintic splines we expect order six convergence, but here we getting only order four due to the fact that we are using cubic polynomials in the derivative estimation stage, so

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.7. Local two-stage methods based on derivative estimation

189

the method only reproduces cubics. Here is a table of the errors for the x-derivative. n 81 289 1089 4225 16641

emax 1.81(0) 4.66(−1) 1.73(−1) 8.14(−2) 3.94(−2)

rms 2.67(−1) 4.14(−2) 6.44(−3) 1.71(−3) 7.76(−4)

ratios 3.88 6.45 2.69 6.43 2.13 3.77 2.06 2.20

We seem to be getting only order one convergence.

6.7.4 A two-stage method using S2 (W ) In this section we examine a two-stage method based on the macro-element space S2 (W ) discussed in section 5.6. This space consists of C 2 quintic splines on the Wang refinement W of an initial triangulation  of the scattered data points. As shown in Theorem 5.16, a spline in this space is determined by derivatives up to order two at each vertex, combined with one first order cross derivative at the midpoint of each edge of , along with two second order cross derivatives at two other points on each edge. Given scattered data, we can estimate these derivatives using local polynomial least-squares as described above. Here is our function. [der,ze] = derestwang(x,y,z,v1,v2,v3,e1,e2,e3,... ie1,ie2,adjstart,vadj) The input is the usual information describing the initial triangulation  of the scattered data. The vector z contains the sample values. The first output of this function is a matrix der of size n × 6, where n is the number of vertices in the triangulation . The i th row of the matrix contains the estimated values of f , f x , f y , f x x , f x y , f yy at the i th vertex. To estimate these derivatives at a given vertex v, this function fits a cubic polynomial using the 20 closest vertices of  in a sufficiently large star around v. The second output is a vector ze of size n e × 3, where n e is the number of edges of . The i th row of this matrix contains the estimated values of the cross derivatives Dn2 f (η1 ), Dn f (η2 ), Dn2 f (η3 ), where η1 , η2 , η3 are the points located at the 1/3, 1/2, and 2/3 positions along the oriented i th edge of . Example 6.33. Compute the two-stage interpolant from S2 (W ) of Franke’s function (2.20) on the unit square using only function values at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We use the script Bscatwang together with the data file tri36.dat. The max and RMS errors of the spline fit are 2.08(−1) and 4.91(−2). This compares to errors of 1.07(−1) and 2.57(−2) when using the minimal energy Powell–Sabin spline. The max and RMS errors for the x-derivative of the spline are 2.26 and 5.44(−1), respectively, which compares with 1.04(0) and 2.76(−1) using the minimal energy spline. Example 6.34. Explore the convergence rate of the two-stage method based on S2 (W ) by interpolating Franke’s function (2.20) using data at the vertices of nested sequence of type-1 triangulations obtained by repeatedly refining an initial type-1 triangulation with 81 vertices.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

190

Chapter 6. Scattered Data Interpolation

Discussion: We again use the script Bscatwang, but now with the data files type1.81, etc. Here is a table of the maximum and RMS errors, along with the computational times. n 81 289 1089 4225

emax 6.13(−2) 5.77(−3) 4.22(−4) 1.83(−5)

rms times 1.03(−2) .13 6.91(−4) .43 3.10(−5) 1.62 1.83(−6) 6.34

ratios 10.62 14.91 13.68 22.29 23.06 16.94

Using quintic splines we generally expect order six convergence, but here we are using estimated derivatives based on cubic polynomials, so the method only reproduces cubic polynomials. This should give order four convergence, which is what we seem to be getting. Here are the errors in the x-derivative: n 81 289 1089 4225

emax 1.81(0) 4.66(−1) 1.73(−1) 8.14(−2)

rms 2.47(−1) 4.34(−2) 6.60(−3) 1.71(−3)

ratios 3.88 5.69 2.69 6.58 2.13 3.86

It is hard to say exactly what the order of convergence is in this case, probably one or two. This method, like the other two-stage methods above, appears to have a linear complexity, i.e., the time grows like the number of sample points.

6.8 A comparison of the methods In this section we compare the performance of the above methods for solving scattered data interpolation problems. Example 6.35. Interpolate Franke’s function (2.20) on the unit square using only data at the 36 vertices of the triangulation shown in Figure 6.1. Repeat with the triangulation shown in Figure 6.2. Discussion: For the first comparison we read the data points and initial triangulation from the file tri36.dat. Here is a table of the max and RMS errors for the function and its x-derivative for each method. We also list computation times, along with the number of B-coefficients of each spline. In all of the multi-stage methods we estimated derivatives using cubic local least-squares based on the closest 20 points in three-stars. Method B01 Bmenps Bmen15 Bscat03 Bscatlocct Bscatps Bscatct Bscat15 Bscatwang

emax 3.61(−1) 1.07(−1) 2.46(−1) 1.34(−1) 1.32(−1) 2.16(−1) 2.01(−1) 2.09(−1) 2.08(−1)

RMS Dxmax Dxrms time nc 7.48(−2) 2.44 6.44(−1) .01 36 2.57(−2) 1.04 2.76(−1) .04 681 4.76(−2) 1.60 3.81(−1) .39 716 3.99(−2) 2.22 5.00(−1) .06 268 3.68(−2) 1.43 4.39(−1) .12 754 5.00(−1) 2.18 5.36(−1) .08 681 4.84(−2) 2.11 5.28(−1) .11 754 4.90(−2) 2.16 5.31(−1) .12 716 4.91(−2) 2.26 5.44(−1) .11 4766

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.8. A comparison of the methods

191

Here are the results using the data file tri81.dat. Method B01 Bmenps Bmen15 Bscat03 Bscatlocct Bscatps Bscatct Bscat15 Bscatwang

emax 1.01(−1) 5.10(−2) 5.49(−2) 7.17(−2) 7.05(−2) 7.12(−2) 6.59(−2) 6.18(−2) 6.21(−2)

rms 2.13(−2) 9.60(−3) 7.81(−3) 1.28(−2) 1.10(−2) 1.18(−2) 1.08(−2) 1.08(−2) 1.08(−2)

Dxmax 1.81(0) 1.09(0) 6.83(−1) 1.13(0) 1.10(0) 1.36(0) 1.75(0) 1.17(0) 1.17(0)

Dxrms time 3.71(−1) .01 1.64(−1) .08 1.12(−1) 1.6 2.39(−1) .03 1.91(−1) .07 2.42(−1) .04 2.13(−1) .13 2.17(−1) .08 2.24(−1) .13

nc 81 1601 1681 625 1777 1601 1771 1681 11281

The striking thing about these tables is that in both examples, all of the methods produce similar accuracies. The C 0 linear spline method is the fastest, but produces surfaces which are only C 0 continuous, and are the least accurate of the bunch. The best accuracies and best looking fits were produced by the minimal energy splines. Since the one based on the C 1 Powell–Sabin space is faster, this is the method we recommend for scattered data interpolation with up to about 1000 data points. In the next example we compare the methods for a larger set of data points. Example 6.36. Interpolate Franke’s function (2.20) using only data given on a 33 ×33 grid on the unit square. Discussion: The Delaunay triangulation in this case is a type-1 triangulation with 1089 vertices, and can be read from the file type1.1089. We do not list results for Bmen15 because it is too slow. Here is the table of errors, times, and numbers of B-coefficients. Method B01 Bmenps Bscat03 Bscatlocct Bscatps Bscatct Bscat15 Bscatwang

emax 6.89(−3) 3.22(−4) 1.09(−3) 3.15(−4) 3.77(−4) 3.22(−4) 4.22(−4) 4.22(−4)

rms 1.38(−3) 4.59(−5) 1.07(−4) 2.78(−5) 4.51(−5) 2.64(−5) 3.03(−5) 3.11(−5)

Dxmax 4.90(−1) 4.92(−2) 7.69(−2) 4.07(−2) 7.28(−2) 4.17(−2) 1.73(−1) 1.73(−1)

Dxrms 1.07(−1) 6.36(−3) 8.73(−3) 3.33(−3) 7.55(−3) 3.77(−3) 6.44(−3) 6.60(−3)

time nc .01 1089 2.63 24833 .56 9409 .88 27841 .35 24833 1.15 27841 .98 25921 1.61 179521

In this case all of the methods produce very smooth looking surfaces, both for the function and for its x-derivative. For this rather large set of well-distributed samples, the two-stage macro-element methods are now very comparable to the C 1 Powell–Sabin minimal energy spline method, although the results for derivatives are not quite as good. Unless a C 2 surface is required, the two-stage Powell–Sabin and Clough–Tocher methods seem to be the best choices. They become even more attractive for larger data sets where the minimal energy methods become too slow. There are some other features of these scattered data interpolation methods that might be important to take account of in practice. One of these is scale invariance.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

192

Chapter 6. Scattered Data Interpolation

1 0.2 5

3

4 2

3 2

1

1 0

0

Figure 6.10. The C 0 linear spline interpolating values of the function (5.18) at the 81 vertices of the triangulation tri81 scaled to the rectangle [0, 5] × [0, 3].

6.9 Scale invariance In this section we discuss to what extent the interpolation methods of this chapter are scale invariant or equi-scale invariant in the sense of Definition 5.26. Scale invariance is an important property for a spline interpolation method to have since, in practice, the same interpolation problem can be posed with different units. For example, suppose {(x i , yi )}ni=1 are the locations of some pollution measuring stations, measured in terms of miles from some reference point. We don’t want to get different results if we use kilometers instead. Fortunately, all of the scattered data interpolation methods discussed in this chapter are at least equi-scale invariant, which means that if use the same scale factor in both the xand the y-directions, the spline coefficients do not change. We shall see that the C 0 linear spline interpolant and the local C 1 cubic Clough–Tocher method both have the stronger scale-invariance property. Example 6.37. Explore the scale invariance of scattered data interpolation with S10 (). Discussion: We make use of the script Bscale01 and read the triangulation from file tri81.dat. It is then scaled to a rectangle with scale factors α and β. We take the z values to be the values of the scaled Franke’s function (5.18) at the 81 vertices of this scaled triangulation. It turns out that the coefficients of the C 0 linear spline interpolants of these values are the same for all choices of the scale factors. This is not surprising, since the coefficients of a C 0 linear interpolating spline are given by ci = z i for i = 1, . . ., n. Of course, the fact that the B-coefficients do not change with scaling does not mean that the plots of the splines don’t change in appearance, since after all we are scaling the x- and y-values, but not the z-values. In Figure 6.10 we show the C 0 linear spline interpolating Franke’s function at the 81 vertices of the triangulation shown in Figure 6.2, scaled by α = 5 in the x-variable and β = 3 in the y-variable. MATLAB plotting routine automatically rescales plots, so in the script we have added the command axis equal when creating the plot. Our next example shows that the Powell–Sabin minimal energy interpolant is not scale invariant, but does have the weaker equi-scale invariance property.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.9. Scale invariance

193

Example 6.38. Repeat Example 6.37 using the Powell–Sabin minimal energy interpolating spline. Discussion: We make use of the script Bscalemenps. We find that for any choice of the scale factors α = β, the Powell–Sabin minimal energy spline has the same coefficients, up to a small roundoff error. Thus, we conclude that the method is equi-scale invariant. However, for some values of α = β, the coefficients are not the same, so the method does not have the stronger scale-invariance property. Theorem 6.39. The Powell–Sabin minimal energy spline is equi-scale invariant. Proof. We examine the computations for finding the B-coefficients of the spline. First, we note that the transformation matrix A for the nodal minimal determining set for S21 ( P S ) is an n c × 3n matrix, where n c is the number of B-coefficients and n is the number of sample points. After scaling with α = β > 0, the first n columns are unchanged, while the remaining are scaled by a factor of α. The matrix MT appearing in Algorithm 6.7 involves energy inner products of B-splines. Second derivatives are scaled by a factor α −2 , so MT is scaled by a factor α −4 . The energy matrix M appearing there is of size 3n × 3n. It can be partitioned into four submatrices as in (6.12). The submatrix M11 in (6.12) is scaled by α −4 , the submatrices M12 , M21 by α −3 , and M22 by α −2 . Thus, in solving (6.13), we find that the vector a is scaled by α −1 . But since the B-coefficients are given by A[z a]T , the scale factors in A cancel those in a, and we see that the coefficients are unchanged under scaling. In the remainder of this section we examine some of the other scattered data interpolation methods discussed in this chapter. Example 6.40. Repeat Example 6.37 using the local C 1 cubic Clough–Tocher interpolating method of section 6.5. Discussion: We make use of the script Bscalelocct and read the triangulation from the file tri81.dat. It is easy to check that we get the same coefficients for all positive scale factors α = β, and we conclude that the method is equi-scale invariant. However, for α = 5 and β = 3, the coefficients do change, and so we do not have scale invariance. The loss of scale invariance occurs already in the first stage where local cubic polynomials are computed based on a selection of nearby points. For each triangle T , these points are selected by taking the star of order j of T , where j is chosen to get at least 20 points. Then we take the nearest 20 of these points. This last step is sensitive to scaling. In Figure 6.11 we show the interpolating spline corresponding to α = 5 and β = 3. Theorem 6.41. The local Clough–Tocher cubic method of section 6.5 is equi-scale invariant. Proof. Suppose we scale by factors α = β > 0. We recall that the first stage of this method is to compute the coefficients of a C 0 cubic spline defined on the initial triangulation  of the sample points. This is done independently for each triangle T of . First, we have to select the points to to be used for finding a cubic associated with T . As discussed in the previous example, the choice of points does not depend on scaling as long as we keep α = β. Now we apply Algorithm 6.14, which requires solving the system (6.21). Since computing barycentric coordinates is scale invariant, the matrix O˜ appearing

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

194

Chapter 6. Scattered Data Interpolation

1.2 0.2

5

3

4 3

2

2

1

1 0

0

Figure 6.11. The C 1 local cubic spline interpolant of the function (5.18) at the 81 vertices of the triangulation in Figure 6.2, scaled to the rectangle [0, 5] × [0, 3].

in that equation is the same for all scale factors α = β, and it follows that the first stage is equi-scale invariant. The coefficients of the spline s ∈ S31 (C T ) are then computed by subdivision, followed by an adjustment process to ensure C 1 continuity. Both of these processes depend only on barycentric coordinates, and thus are also equi-scale invariant. We now give an example involving a two-stage method based on derivative estimation by local least-squares polynomials. Example 6.42. Repeat Example 6.37 using the two-stage Powell–Sabin method of section 6.6.2. Discussion: We make use of the script Bscaleps and read the triangulation from the file tri81.dat. It is easy to check that we get the same B-coefficients for all choices of α = β > 0, and we conclude that the method is equi-scale invariant. However, the coefficients do change for some values of α = β, so the method is not fully scale invariant. Theorem 6.43. The two-stage method of section 6.7.1 based on the Powell–Sabin macroelement space is equi-scale invariant. Proof. This method uses local polynomial least-squares to estimate gradients at the vertices of the initial triangulation. By Lemma 6.44 below, if we scale the sample points by α = y β > 0, then the estimated gradient values {z ix , z i }ni=1 are scaled by 1/α. Now suppose T := v1 , v2 , v3  is one of the triangles of the initial triangulation . Then by the formulae in section 5.2, we see that the coefficient corresponding to the domain point at v1 is just z 1 . Now consider the coefficients corresponding to domain points in the first ring around v1 . In the notation of section 5.2, these are c4 , c5 , and c6 , and we have c4 = [(xˆ1 − x 1)zx 1 + ( yˆ1 − y1 )zy1 ]/2 + z 1, where (xˆ1 , yˆ1 ) is the vertex of  P S lying on the edge v1 , v2 . If we scale the triangulation  by a factor α, we see that both (xˆ1 − x 1) and ( yˆ1 − y1) are scaled by α. It follows that c4 is the same for all scalings. We have now shown the B-coefficients associated with domain

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.10. Nonrectangular domains and holes

195

points at the vertices of  and in the first rings around them all remain the same under scaling. But all other coefficients are computed from C 1 smoothness conditions, so they also remain the same under scaling. The following lemma is used in the analysis in the above example of the two-stage Powell–Sabin scattered data interpolation method. Lemma 6.44. Given {(x i , yi , z i )}m i=1 , let p be the polynomial of degree d solving the leastsquares problem of minimizing (6.22). Given α > 0, let p˜ be the polynomial of degree d m solving the same problem, but with {(x i , yi )}m i=1 replaced by {(αx i , αyi )}i=1 . Then for any 2 0 ≤ ν + μ ≤ d and all (x, y) ∈ R , Dxν D μ ˜ αy) = y p(αx,

1 α ν+μ

Dxν D μ y p(x, y).

(6.25)

Proof. Let T be the triangle with vertices at (x 1 , y1 ), (x 1 + 1, y1 ), and )(x 1 , y*1 + 1), and let B1 , . . . , Bn be the associated Bernstein basis polynomials with n = d+2 < m. Let 2 ˜ n be the Bernstein basis polynomials associated with the scaled triangle T˜ , and B˜ 1 , . . . , B let p˜ = ni=1 c˜i B˜ i . Since the values of Bernstein basis functions are defined in terms of barycentric coordinates, it follows that B˜ i (αx, αy) = Bi (x, y)

for all (x, y) ∈ R2 .

˜ This implies that the entries of the observation matrices O = [B j (x i , yi )]m,n i=1, j =1 and O = m,n [ B˜ j (αx i , αyi )]i=1, j =1 are the same, and it follows that c˜ = c. This shows that p(αx, ˜ αy) = p(x, y) for all (x, y), which in turn implies (6.25) by the chain rule. The conclusion of this lemma does not hold if we scale the triangle differently in the x- and y-coordinates. Combining with the arguments in Theorem 6.43, we see that all of the two-stage methods based on estimating derivatives with local polynomial least-squares are equi-scale invariant, but not fully scale invariant. In particular, the two-stage methods based on S31 (C T ), S51,2 (), and S2 (W ) discussed in sections 6.7.2–6.7.4 are all equiscale invariant.

6.10 Nonrectangular domains and holes So far, all of our examples in this chapter have worked with Delaunay triangulations of the unit square. However, in practice we often are looking for a function defined on a more general domain which is possibly nonconvex. In addition, we often need to work with domains with holes. Fortunately, all of the methods of this chapter work equally well for more general triangulations and more general domains . In this section we give a couple of examples to illustrate the possibilities.

6.10.1 A domain with a hole Example 6.45. Interpolate Franke’s function (2.20) based on data at the vertices of the triangulation  shown in Figure 3.2.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

196

Chapter 6. Scattered Data Interpolation

1 1 0.5

0.5

0 1

0 1 1 0.5

0.5 0 0

1 0.5

0.5 0 0

Figure 6.12. Left: The C 0 linear spline that interpolates Franke’s function (2.20) at the 36 vertices of the triangulation in Figure 3.2. Right: The Powell–Sabin minimal energy interpolating spline.

Discussion: First we look for a C 0 linear spline. We make use of the script B01, and read the triangulation from the file trihole36.dat. This triangulation is the same as given by tri36.dat, except that we have removed one internal edge to create a four-sided hole. The interpolating spline is shown in Figure 6.12 (left). The jagged edges around the hole are due to the fact that we are rendering on a rectangular grid. To measure errors, we enclose the domain in a rectangle and create a 51 × 51 grid. The max and RMS errors (computed using only grid points inside the domain) are 3.61(−1) and 7.57(−2). These are almost identical to the values that we got for interpolation on the triangulation in Figure 6.1 without the hole; see Example 6.2. For comparison purposes, we repeat this experiment using the C 1 Powell–Sabin minimal energy method. Here we use the script Bmenpshole which is a modification of Bmenps where valspgrid is replaced by valspgridh. This was necessitated by the fact that valspgrid uses tsearchn which does not work properly for some triangulations with holes. The resulting interpolating spline is shown in Figure 6.12 (right). The max and RMS errors are 1.12(−1) and 2.63(−2). These differ only slightly from the errors that we got with Bmenps for the triangulation shown in Figure 6.1 without holes; see Example 6.10. We get similar results using the other methods of this chapter. To work with triangulations with holes, we suggest modifying our scripts Bscat03, Bscatct, Bscat15, and Bscatwang by replacing valspgrid with valspgridh.

6.10.2 An example on a circular domain Example 6.46. Let  be the unit disk, and let  be the triangulation shown in Figure 6.13 (left). Investigate the errors for the C 0 linear spline interpolants of the function ) * f (x, y) := cos π(x 2 + y 2)1/2 (6.26) using successive uniform refinements of . Discussion: We make use of the script B01disk, which differs from B01 only in the definition of the function being sampled. We read the triangulations from files tridisk.25, tridisk.81, etc. The triangulations with 25 and 81 vertices are shown in Figure 6.13.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.10. Nonrectangular domains and holes

197

Figure 6.13. The triangulations tridisk.25 and tridisk.81. 1

1

0

0

-1 1 1 0

1 0

0 -1

−1 1

-1

0 −1 −1

Figure 6.14. The C 0 linear spline interpolants of the function (6.26) on the triangulations shown in Figure 6.13.

Plots of the corresponding C 0 linear splines interpolating at the vertices of the triangulations are shown in Figure 6.14. The ragged edges around the bottom are due to the fact that we are plotting on a rectangular grid. Plots of the interpolating splines for the finer refinements look similar, but are even smoother. The following table gives the max and RMS errors on the set of grid points G˜ = G ∩ , where G is a 51 × 51 grid on the unit square: n 25 81 289 1089

emax 2.47(−1) 9.50(−2) 2.73(−2) 7.07(−3)

rms 1.45(−1) 4.80(−2) 1.23(−2) 3.08(−3)

ratios 2.60 3.02 3.48 3.90 3.86 4.00

The convergence rate is consistent with the order two that we expect to get with linear splines. Example 6.47. Redo Example 6.46 using C 1 Powell–Sabin minimal energy splines. Discussion: We make use of the script Bmenpsdisk, and again read the triangulations from the files tridisk.25, tridisk.81, etc. The following table gives the max and RMS errors: n emax rms ratios 25 1.45(−1) 8.72(−2) 5.69 7.27 81 2.55(−2) 1.20(−2) 4.85 5.24 289 5.26(−3) 2.29(−3) 3.98 5.52 1089 1.32(−3) 4.15(−4)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

198

Chapter 6. Scattered Data Interpolation 1

1

0.5

0.5

0

0

−0.5

−0.5

−1 1

−1 1 1 0

0 −1 −1

1 0

0 −1 −1

Figure 6.15. The C 1 Powell–Sabin minimal energy interpolants of the function (6.26) on the triangulations shown in Figure 6.13.

In Figure 6.15 we show a plot of the Powell–Sabin spline interpolating at the 81 vertices of the triangulation shown in Figure 6.13 (right). It is much smoother than the corresponding plot in Figure 6.14 for the C 0 linear interpolant. Plots of the splines on the other triangulations look almost the same. The convergence rate seems consistent with the order two that we expect from Theorem 6.9. We get similar results using the other methods of this chapter.

6.11 Interpolating at a large number of data points In the previous sections we have shown examples with up to 16641 interpolation points, and except for the minimal energy methods which are global methods, the corresponding interpolating splines could be constructed in a few seconds or less. However, scattered data problems with even more points can arise in practice. Concerning such problems, we make the following remarks: 1) When n is more than a few hundred, one has to ask whether interpolation is even appropriate. If the underlying function generating the data is reasonably smooth, it should not take a spline with a huge number of coefficients to fit it well. In such cases, it may be more appropriate to construct a least-squares fit from a smaller spline space, rather than insisting on interpolation. We discuss such methods in the following chapter. 2) When the data is subject to noise, it is generally not appropriate to interpolate. In such cases we should compute either a least-squares fit or a penalized least-squares fit. We discuss these methods in the following chapter. 3) For very large interpolation methods, it is possible to divide the domain into (overlapping) pieces. Then one interpolates on each piece and somehow puts the pieces together smoothly. Such methods have been called domain decomposition methods. For details, see [LaiS09]. We now give a typical example of a large scattered data interpolation problem involving topographic data.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.11. Interpolating at a large number of data points

199

12755

0 0

12755

Figure 6.16. The Delaunay triangulation of 15885 scattered points where elevations were measured in the Black Forest.

Example 6.48. The file bk.dat contains elevation measurements taken in the Black Forest of Germany at 15888 scattered points in a square of side length 12775 meters. Interpolate this data with a spline in S10 (). Discussion: We make use of the script B01dat. It is a variant of B01 where instead of reading a triangulation, we use the function readxyz to read the data points, and then construct the corresponding Delaunay triangulation. For this example, we read the data from the file bk.dat. The corresponding Delaunay triangulation contains 31456 triangles, and is shown in Figure 6.16. As the figure shows, the points are quite irregularly spaced within the domain, being rather far apart in areas where the terrain is relatively flat, and quite close together where there are steep changes. The corresponding C 0 linear spline interpolating this data is shown in Figure 6.17. Since this is a relatively low resolution plot for such a large area, in Figure 6.18 we zoom in on the part of the surface lying in the rectangle [3000, 6000]2. The coefficients of the interpolating spline are equal to the given height measurements, so no time is needed to find them. Our rendering program requires running trilists, which takes 1.4 seconds. The time required for the rendering itself depends on how much of the domain we want to render. For the full domain with 31456 triangles, it took .48 seconds.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

200

Chapter 6. Scattered Data Interpolation

1200 12755 12755 8000 8000 4000 4000 0

0

Figure 6.17. The C 0 linear spline interpolant of the data of Example 6.48, plotted on the square [0, 12775]2 .

800 400 6000 6000 4500 4500

3000

3000

Figure 6.18. The C0 linear spline interpolant of the data of Example 6.48, plotted on the subdomain [3000, 6000]2 .

We now solve the same interpolation problem using some of the other local spline methods of this chapter. Example 6.49. Repeat Example 6.48 using some of the other local spline methods of this chapter. Discussion: We make use of scripts Bscat03dat, Bscatlocctdat, Bscatpsdat, Bscatctdat, Bscat15dat, and Bscatwangdat combined with data file bk.dat. In all cases the time to compute the Delaunay triangulation and triangulation list was about 1.6 seconds. In the following table we give the computational times for 1) estimating the derivatives (if needed), 2) computing the B-coefficients, 3) creating a plot on [0, 12755]2 using a 51 × 51 grid.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.11. Interpolating at a large number of data points

900

201

900

400 400

6000

6000

6000

6000 5000

5000

5000 5000

900

900

400

400

6000

6000

6000 5000

5000

6000 5000

5000

Figure 6.19. Plots on [5000, 6000]2 of the splines obtained by the local methods S01, scatps, scat15, and scatwang for the Black Forest data.

The first three methods in the table do not require estimating derivatives. The last column in the table gives the number nc of coefficients of the interpolating spline. Method derivs coefs plot nc S01 0 0 .48 15888 scat03 0 8.76 .47 142030 locct 0 13.94 .19 425134 scatps 5.14 .18 .16 378109 scatct 16.25 .82 .20 425134 scat15 14.02 .86 .86 393996 scatwang 18.15 6.58 .30 2753196 We do not show plots of these splines on the full domain [0, 12775]2 since at this resolution, they do not look much different from the C 0 linear spline interpolant shown in Figure 6.17. Instead, in Figure 6.19 we show plots on [5000, 6000]2 for the four methods S01, scatps, scat15, and scatwang. While all of these plots are very similar, we can see the additional smoothness of the last two splines. The fastest method, and the one using the least number of B-coefficients, is the C 0 linear spline. Of the C 1 two-stage methods, scatps is the fastest and uses the least number of coefficients. If a C 2 surface is desired, we can use scatwang which, although it uses many more coefficients, is not too much slower than the others.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

202

Chapter 6. Scattered Data Interpolation

6.12 The error as a function of mesh size According to the error bound for C 0 linear spline interpolation given in Theorem 6.4, for C 2 functions, the interpolating spline satisfies the error bound  f − s ≤ C||2 | f |2,∞ ,

(6.27)

where || is the mesh size of the triangulation . Based on this error bound, it might be expected that to make the error small, we have to choose a triangulation with a small mesh size. But as the following example shows, depending on the function being interpolated, we can get good error bounds with large mesh sizes. Example 6.50. Let  be the triangulation obtained by scaling the triangulation in Figure 6.2 to fit in the square R := [0, 100]2. Let s ∈ S10 () be the C 0 linear spline interpolating the function franke2(x/100,y/100) at the vertices of this triangulation. Discussion: We can use script Bscale01 and read the triangulation from tri81.dat. Scaled by a factor of 100, it has mesh size 23.74. Despite this large mesh size, the max and RMS errors for the spline fit of f , measured on a 51 × 51 grid imposed on R, are 1.01(−1) and 2.13(−2). These are exactly the same errors that we got when we interpolated Franke’s function on the unit square with the unscaled triangulation tri81. This is, of course, no surprise as we know from the results of section 6.9 that C 0 linear spline interpolation is scale invariant. What is happening in this example is that the large value of || in (6.27) is being compensated for by the small value of the semi-norm of the test function. The error bound (6.27) also tells us that if we refine a given triangulation to reduce its mesh size by a factor of two, we should get an improvement in the error of approximately four. This is what we observed in Example 6.3 for interpolation of Franke’s function at the vertices of a nested sequence of type-1 triangulations on the unit square. We now show that we get the same behavior even if we start with a triangulation with a large mesh size. Example 6.51. Let  be the triangulation obtained by scaling the type-1 triangulation shown on the top left of Figure 6.4 to fit in the rectangle R := [0, 100] × [0, 100]. Investigate the errors for the C 0 linear spline interpolants of the scaled Franke’s function franke2(x/100,y/100) as we repeatedly apply uniform refinement to . Discussion: We again use the script Bscale01, where we read the triangulations from the files type1.25, type1.81, etc., and then scale them up by a factor of 100. The scaled triangulation type1.25 has a mesh size of 35.35, and each step of refinement reduces this by a factor of two. Here is a table of the max and RMS errors measured on a 51 × 51 grid imposed on R. The first column gives the number of vertices of the triangulation. n || emax rms 25 35.35 1.77(−1) 5.50(−2) 81 17.67 9.40(−2) 2.05(−2) 289 8.84 2.86(−2) 5.47(−3) 1089 4.42 6.89(−3) 1.38(−3) 4225 2.21 1.80(−3) 3.47(−4) These errors are decreasing at the expected rate O(||2 ).

ratios 1.88 2.68 3.29 3.75 4.15 3.96 3.83 3.98

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.13. Non-Delaunay triangulations

203

10 5 0 0

25

50

75

100

Figure 6.20. A type-1 triangulation with vertices on a 5 × 9 grid on the rectangle [0, 100] × [0, 10].

This example shows that for a fixed function, the error of C 0 linear spline interpolation decreases by a factor of four whenever we decrease the mesh size || by a factor of two. The following example shows a surprising situation where we do not observe this behavior. Example 6.52. Let R be the rectangle R := [0, 100] × [0, 10], and suppose  is the type-1 triangulation corresponding to an n x × n y grid imposed on R. Suppose we interpolate the scaled Franke’s function franke2(x/100,y/10) at the vertices of this grid with a C 0 linear spline. Investigate the errors as we increase n x to get triangulations with smaller mesh size. Discussion: We make use of the script B01r1 which prompts for positive integers n x and n y , and then computes the type-1 triangulation associated with the n x × n y grid on R. We begin with n x = 5 and n y = 9, in which case the mesh size of the type-1 triangulation, shown in Figure 6.20, is 25.03. It has a lot of long thin triangles. To reduce the mesh size by a factor of approximately two (and to improve the shape of the triangles), we successively double n x to 9, 17, etc. The following table gives the corresponding max and RMS errors, measured on a 51 × 51 grid imposed on R. The table also gives the mesh sizes of the triangulations. nx n y 5 9 9 9 17 9 33 9 65 9

|| 25.03 12.56 6.37 3.37 2.00

emax 1.67(−1) 9.40(−2) 6.38(−2) 5.36(−2) 5.16(−2)

rms 3.88(−2) 2.05(−2) 1.35(−2) 1.22(−2) 1.20(−2)

ratios 1.78 1.89 1.47 1.52 1.19 1.11 1.03 1.02

We see that the mesh sizes are decreasing by approximately a factor of two at each step, but the errors are barely decreasing. How can we explain these errors in terms of the error bound in (6.27)? The term involving the semi-norm of the test function is the same for all choices of n x , and the mesh sizes are decreasing. But the constant is not the same for all n x . It depends on the smallest angle in the triangulation. In this section we examined how the errors associated with interpolating a fixed function depend on the mesh size. Here we have focused on C 0 linear spline interpolation, but we get similar results with the other scattered data interpolation methods of this chapter.

6.13 Non-Delaunay triangulations In the examples above we have worked only with Delaunay triangulations. The rationale is that they give well-shaped triangulations in the sense that they maximize the smallest

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

204

Chapter 6. Scattered Data Interpolation

angle in the triangulations, thus avoiding long thin triangles. But we may get much better fits if we interpolate on a different triangulation. To construct a better triangulation, we need some additional information about the function f being interpolated. For example, if in addition to values at the points where we want to interpolate, suppose we have values of f on a grid of points covering the domain. Then we can adjust the triangulation to try to minimize the least-squares error over this grid. The idea is to start with the Delaunay triangulation, and swap edges in the triangulation whenever it reduces the least-squares error computed on the grid. Here is a function that implements this idea for interpolation with the space S10 (). [v1,v2,v3] = swap01(v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,x,y,z,ng,f); The input to this function includes the lists describing the initial triangulation, a vector z giving the values being interpolated at the vertices of this triangulation, an integer ng controlling the number of grid points to be used in computing errors, and the name f of the function that we are trying to fit. The output consists of the lists v1,v2,v3 giving the indices of the triangles in the new triangulation. Example 6.53. Suppose we want to approximate the function f (x, y) := (x 2 + y 2 − 1)3+

(6.28)

on the unit square by a spline s ∈ S10 () that interpolates at the 25 vertices of the type-1 triangulation shown on the top left in Figure 6.21. Discussion: We use the script B01swap with the file type1.25. With this triangulation (which is a Delaunay triangulation), we get the interpolating spline shown on the bottom left in Figure 6.21. The script makes use of the function swap01 to generate the triangulation shown on the top right in the figure. This gives the interpolating spline shown on the bottom right. The max and RMS errors measured on a 51 × 51 grid with the Delaunay triangulation are 3.62(−1) and 5.28(−2), respectively. The error of the C 0 linear spline interpolating the same values at the vertices of the swapped triangulation are 1.54(−1) and 2.40(−2). Clearly, the shape of the spline on this triangulation is much closer to that of the test function. Using edge swapping algorithms to get triangulations with improved fits can be applied; with other spline interpolation methods, and has been studied extensively in the literature; see Remark 6.19.

6.14 Scattered data interpolation with radial basis functions As before, we assume we are given data {z i }ni=1 at scattered points {(x i , yi )}ni=1 . Let φ be a nonnegative function defined on [0, ∞), and let ) * φi (x, y) = φ [(x − x i )2 + (y − yi )2 ]1/2 , i = 1, . . ., n. (6.29) We call φ a radial basic function, and refer to the functions φi as the radial basis functions associated with φ and the centers {(x i , yi )}ni=1 . To solve the scattered data interpolation

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.14. Scattered data interpolation with radial basis functions

1

205

1

0 1

0 1

1

0.5 0

1

0.5

0.5

0.5 0

0

0

Figure 6.21. Top: Two triangulations with the same 25 vertices. Bottom: The splines in S10 () interpolating the function (6.28) using these triangulations.

problem, we need to find a coefficient vector c = (c1 , . . . , cn )T such that the function g(x, y) :=

n 

ci φi (x, y)

(6.30)

i=1

satisfies g(x i , yi ) = z i ,

i = 1, . . . , n.

(6.31)

Inserting (6.29) in these equations, we see that c must satisfy Mc = z, where z := (z 1 , . . . , z n )T is the vector of values to be interpolated, and M := [φ j (x i , yi )]ni, j =1 .

(6.32)

Clearly, the matrix M is symmetric, but we need to check whether it is nonsingular. It is known that if φ is strictly positive definite, then M will be nonsingular for any choice of scattered points. For details, see the book of [[Fass07]]. There are many examples of strictly positive definite radial basic functions; see Remark 6.22. Here we shall focus on the Gaussian function 2 2 φ(r ) := e−ε r , (6.33) where ε is a parameter that controls how sharp a peak is formed by φ. This parameter plays a critical role in determining the quality of interpolants, as we shall see below. In particular, the condition number of M, which is often very large, will depend heavily on the value of ε along with the way the data points are distributed.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

206

Chapter 6. Scattered Data Interpolation

1.4

4 0

0

-4

1

1

0.5

1

1

0.5

0.5 0 0

0.5 0 0

1.4 2

-2

0 1

1

0.5

0.5 0 0

1

1

0.5

0.5 0 0

Figure 6.22. The radial basis interpolants and their x-derivatives for Franke’s function (2.20) sampled at the 36 data points in Figure 6.1, using the parameter values eps = 1 (top) and eps = 4 (bottom).

We have written the following function to perform RBF interpolation using a general radial basis function rbf involving a parameter eps: c = rbfinterp(x,y,z,eps,rbf) Example 6.54. Compute a radial basis interpolant to Franke’s function (2.20) on the unit square using function values at the 36 vertices of the triangulation shown in Figure 6.1 (left). Discussion: We use the script Brbf along with the data file tri36.dat. This script reads the data locations, and then computes the values z to be interpolated by sampling our test function franke2. To show the strong effect of the parameter eps, we solve the problem with both eps = 1 and eps = 4. With eps = 1, we get the very large condition number 1.42(+11), and the max and RMS errors for the function are 2.05(−1) and 5.75(−2), and for the x-derivative are 5.36 and 7.62(−1). The plots are shown in the top row of Figure 6.22, and are not very good as compared with the plots obtained with the various multi-step methods in the previous sections. On the other hand, with eps = 4, the max and RMS errors are 9.82(−2) and 2.40(−2) for the function, and 9.92(−1) and 2.50(−1) for the x-derivative. The condition number in this case was 6.62(+2), and the plots shown in the bottom row of Figure 6.22 are much better. Larger values of eps give smaller condition numbers, but worse errors and worse plots. Here is another example showing the bad effects of using the wrong value of eps. For this example we take uniformly spaced sample points. Example 6.55. Compute a radial basis interpolant to Franke’s function (2.20) on the unit square using function values at the 81 vertices of a 9 × 9 uniform grid on the unit square.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.14. Scattered data interpolation with radial basis functions

207

1.4

1.4

0 1

1

0.5

0 1

1

0.5

0.5 0 0

0.5 0 0

Figure 6.23. The radial basis interpolants with eps = 1 and eps = 4 of Franke’s function on the unit square using samples on a uniform grid of 81 points.

Discussion: We use the script Brbf along with the data file type1.81. With eps = 1, we have a condition number of 6.10(+18), and the max and RMS errors are 2.41(−1) and 6.76(−2). As shown in Figure 6.23, the corresponding surface, despite being a C ∞ function, has a very choppy look. Choosing eps = 4, we get a condition number of 2.03(+6), and max and RMS errors of 2.44(−2) and 4.73(−3), respectively. We now get the very nice surface shown in Figure 6.23 (right). These examples show that radial basis interpolation can give very good results if the correct value of the parameter eps is used. It has been suggested to use the condition numbers of the systems being solved as a guide to selecting eps. We have not had good success with this approach; see Example 6.56 below. For other approaches for automatically selecting eps, see Remark 6.22. In these two examples we took the radial basic function to be the Gaussian. We get similar results with the other commonly used radial basic functions mentioned in Remark 6.22. We now give an example where there is no good choice of the parameter eps at all. Example 6.56. Let R := [0, 5] × [0, 1], and consider the 81 data points obtained by mapping the vertices of the triangulation shown in Figure 6.2 (left) to fit in R. Define the associated sample values by evaluating Franke’s function franke2(x/5,y) at these 81 points. Find the radial basis interpolants for various choices of the parameter eps. Discussion: We make use of the script Bscalerbf which reads data points in the unit square and then scales them. For this example we take the 81 data points from the file tri81.dat. Here is a table of the max and RMS errors measured on a 51 × 51 grid imposed on R. The table also shows the condition numbers of the matrix M. eps 1 2 3 4 5

emax 4.70(0) 3.52(−1) 2.48(−1) 4.22(−1) 6.91(−1)

rms 8.47(−1) 7.40(−2) 5.22(−2) 8.83(−2) 1.43(−1)

cond 7.49(12) 5.54(7) 8.64(4) 1.63(3) 1.38(2)

According to this table, the best fit from the RMS standpoint is for eps = 3. We show the corresponding RBF surface in Figure 6.24 (left). For comparison, we use Bscalemenps to find the Powell–Sabin minimal energy spline shown in Figure 6.24 (right). The errors for that spline are 7.63(−2) and 1.07(−2).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

208

Chapter 6. Scattered Data Interpolation

1

5

0.2

2.5

1

1

5

0.2

2.5

1 0

0

0

0

Figure 6.24. Left: The radial basis interpolant with eps = 3 based on 81 samples of the scaled Franke’s function in the rectangle [0, 5] × [0, 1]. Right: The corresponding minimal energy Powell–Sabin interpolant.

This example shows that with RBF interpolation we cannot choose the best eps by simply looking at the condition number of M, and that we might not get good results no matter what value we choose. By varying the size of the rectangle used in the example, we find that RBF interpolation is also not scale invariant. We can now summarize the pros and cons of RBF interpolation: 1) (+) It produces a C ∞ surface. 2) (+) It can be very accurate if the data is well distributed and the correct parameter is chosen. 3) (−) It is a global method, which means that for a large number of sample points we will have to solve a large linear system. 4) (−) The best choice of the parameter controlling the shape of the radial basic function does not seem to be related to the size of the condition number of M, and there does not seem to be any other reasonable criterion for selecting it. 5) (−) For some problems there may be no good choice of ε at all. 6) (−) The method is not scale invariant. 7) (−) When using a large number of centers, evaluation of the RBF becomes expensive unless a locally supported radial basic function is used, or special tricks are used. There is another feature of the above RBF interpolation method which should be noted, namely it does not fit polynomials exactly. However, this can be overcome by adding a polynomial to the RBF; see Remark 6.23.

6.15 Almost interpolation with tensor-product splines In section 2.4 we discussed how to use tensor-product splines to solve certain interpolation problems involving data given on a grid. However, tensor-product splines cannot be used directly to solve the interpolation problem when the data points are scattered. But if we are working on a rectangle, there is a fairly simple way to start with scattered data, and end up with a tensor-product spline that almost interpolates: we first compute an interpolating spline s defined on a triangulation of the data, and then approximate s with a tensor-product

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.15. Almost interpolation with tensor-product splines

209

spline. To construct the tensor-product spline, we suggest using a quasi-interpolant such as the one discussed in section 2.6. In particular, we can use the function cubquasitp described there. We now outline a specific algorithm. ˜ with vertices at a set of Suppose  is a triangulation of a rectangle R := [a, b] × [a, ˜ b] scattered data points {(x i , yi )}ni=1 . Given positive integers n x and n y , let tx (i ) = a + (i − 1)(b − a)/(n x − 1),

i = 1, . . ., n x ,

(6.34)

t y (i ) = a˜ + (i − 1)(b˜ − a)/(n ˜ y − 1),

i = 1, . . ., n y .

(6.35)

and Suppose the values that we want to interpolate at the scattered data points are {z i }ni=1 . Algorithm 6.57. Let s be a spline interpolating the values {z i }ni=1 at the vertices of the triangulation . 1) Pick some grid sets tx and t y as in (6.34)–(6.35). 2) Evaluate s at the grid points defined by tx and t y . 3) Use cubquasitp to construct a bicubic spline based on these grid values. The bicubic spline sˆ computed by this algorithm will not interpolate the scattered data exactly. However, if we pick n x and n y sufficiently large, we can get it to almost interpolate in the sense that the norm of the discrepancy vector e is arbitrarily small, where ei := sˆ (x i , yi ) − z i ,

i = 1, . . . , n.

This is what we mean we when say that sˆ almost interpolates. We have written the following function to carry out Algorithm 6.57: [xe,ye,c] = sp2tp(d,x,y,v1,v2,v3,e1,e2,e3,ie1,c,... a,b,aw,bw,nx,ny) Here d is the degree of the spline to be approximated by the tensor spline, and c is its set of B-coefficients. The inputs x,. . .,ie1 describe the triangulation on which s is constructed, which may be a refinement of an initial triangulation with vertices at the data points. Finally, the parameters a,b,aw,bw describe the rectangle on which the tensorproduct spline is to be constructed, and nx, ny give the number of interior knot lines to use in the x- and y-directions. The output of this function includes the extended knot vectors xe, ye and the matrix c of coefficients of the tensor-product spline. Example 6.58. Suppose we are given the values of Franke’s function (2.20) at the 36 vertices of the triangulation shown in Figure 6.1 (left). Starting with the C 1 Powell–Sabin minimal energy spline interpolating this data, use Algorithm 6.57 to find a tensor-product spline that almost interpolates the data. Discussion: We make use of the script TPscatmenps, and read the triangulation from the file tri36.dat. It is a triangulation of the unit square R. We compute the bicubic spline s for a sequence of values of n x and n y . Here is a table of the max and RMS errors

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

210

Chapter 6. Scattered Data Interpolation

1.2

1.2

0 1

1

0.5

0 1

0.5

1

0.5

0 0

0.5 0 0

Figure 6.25. The bicubic splines fitting Franke’s function based on samples at the 36 vertices of the triangulation shown in Figure 6.1 with bicubic spline using 9 and 17 knots.

measured on a 51 × 51 grid on R, along with the max and RMS values for the differences between s at the data points and the given values {z i }ni=1 . nx n y 5 5 9 9 17 17 33 33 65 65

emax 1.58(−1) 1.13(−1) 1.07(−1) 1.07(−1) 1.07(−1)

rms 5.23(−2) 2.74(−2) 2.56(−2) 2.57(−2) 2.57(−2)

maxdiff 7.45(−2) 2.75(−2) 3.54(−3) 4.03(−4) 6.33(−5)

rmsdiff 3.38(−2) 7.97(−3) 1.02(−3) 1.21(−4) 2.07(−5)

As we increase n x and n y , we know that the bicubic spline is converging to the C 1 Powell– Sabin minimal energy spline. The max and RMS errors for it are 1.07(−1) and 2.57(−2); see Example 6.10. Moreover, as we increase n x and n y , the measures of how close the bicubic spline comes to interpolating at the scattered data points decrease towards zero. Except for n x = n y = 5 , the plots of the bicubic splines look very much like the plot of the first-stage C 1 Powell–Sabin interpolant (see Figure 6.5), and are virtually identical for the larger values of n x and n y . The plot for n x = n y = 5 is a bit flattened out; see Figure 6.25 (left). In Example 2.13 we tabulated the max and RMS errors that arise if we construct a bicubic spline directly from the values of Franke’s function. For n x = n y = 5, our errors here are somewhat worse than we got there. On the other hand, for larger values of n x and n y , our errors here are much worse. But that is to be expected since the accuracy here is limited by the accuracy of the first stage. This raises the question of what are good choice of n x and n y for a given scattered data problem. If we choose them too small, we don’t get a good fit, but if we choose them too large, than we are wasting our time as we could have gotten essentially the same accuracy with smaller n x and n y . In practice, we won’t have the errors to guide us, and will just have to estimate how many knot lines are needed for the bicubic spline to fit the data at hand. In the previous example we used the C 1 minimal energy spline produced by menps for the first stage. As mentioned above, it could be replaced by any of the scattered data interpolation methods of this chapter. Example 6.59. Repeat Example 6.58, replacing the first stage with scatps. Discussion: We make use of the script TPscatps, and read the triangulation from the file tri36.dat. Here is a table of the max and RMS errors measured on a 51 × 51 grid,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.15. Almost interpolation with tensor-product splines 1.2

211

1.2

0 1

1

0.5

0 1

0.5

1

0.5

0 0

0.5 0 0

Figure 6.26. Left: The C 1 Powell–Sabin spline produced by scatps, based on samples at the 36 vertices of the triangulation shown in Figure 6.1. Right: the second stage bicubic spline fit using nine knot lines in each variable.

along with the max and RMS values for the differences between s at the data points and the given values {z i }ni=1 . nx n y 5 5 9 9 17 17 33 33 65 65

emax 1.66(−1) 2.13(−1) 2.16(−1) 2.16(−1) 2.16(−1)

rms 5.19(−2) 5.20(−2) 4.99(−2) 5.01(−2) 5.02(−2)

maxdiff 1.22(−1) 7.23(−2) 2.07(−2) 1.61(−3) 9.41(−5)

rmsdiff 3.94(−2) 1.86(−2) 4.27(−3) 3.47(−4) 3.59(−5)

As we increase n x and n y , we know that the bicubic spline is converging to the C 1 Powell– Sabin interpolating spline produced by the two-stage method scatps. The max and RMS errors for it are 2.16(−1) and 5.02(−2). As in the previous example, as we increase n x and n y , the measures of how close the bicubic spline comes to interpolating at the scattered data points also decrease, but are never quite zero. In Figure 6.26 we show the first-stage Powell–Sabin interpolant along with the second-stage bicubic spline fit for n x = n y = 9. As we can see from the table, these two splines have about the same errors, but the shape of the tensor-product spline is better. For large sets of scattered data, using sp2tp to approximate a first-stage interpolating spline s by a tensor-product spline can be a very effective way to get splines that almost interpolate, but which have many fewer coefficients than s. Here is an example involving the topographic data for the Black Forest of Germany discussed in section 6.11. Example 6.60. Use the above two-stage method based on scatps coupled with sp2tp to create a bicubic spline on the rectangle R = [0, 12775]2 that almost interpolates the elevation data for the Black Forest discussed in section 6.11. Discussion: We use the script TPscatpsdat, and read the data from the file bk.dat. The script then produces the Delaunay triangulation shown in Figure 6.16. The computation of the first-stage C 1 Powell–Sabin spline using scatps takes 6.76 seconds. The time required to compute the bicubic spline depends on the numbers n x , n y of knot lines to be used. The following table shows the maximum and RMS differences between the spline and the sample values at the 15,888 vertices of , along with the time required to compute

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

212

Chapter 6. Scattered Data Interpolation

1000

1000

200 6000

200 6000 6000

6000 3000 3000

3000 3000

Figure 6.27. Left: The bicubic spline computed with 251 grid lines in each direction, where the first stage uses a C 1 Powell–Sabin spline with estimated derivatives in the first stage. Right: The analogous spline where the first stage uses the local C 1 Clough–Tocher method of section 6.5.

the bicubic spline. The column labelled n c lists the number of coefficients of the associated bicubic spline. n x n y maxdis rmsdis nc time 101 101 103 10.9 10609 .67 151 151 50.7 4.88 23409 1.39 201 201 47.5 2.99 41209 2.4 251 251 29.3 2.00 64009 3.71 301 301 22.8 1.43 91809 5.25 As we expect, the max and RMS differences between the values of the bicubic spline at the data points and the given z values decrease in both the max norm and RMS norm as we increase n x , n y . The number of coefficients of the bicubic spline also grows, but even with n x = n y = 301, we are using only 91,809 coefficients rather than the 378,109 required to describe the first-stage Powell–Sabin interpolant. Of course this bicubic spline does not interpolate, but the RMS difference at the data points is only 1.43 meters. This is rather small considering that the maximum z value is 1387 meters. If we can tolerate a little larger error at the data points, we can get by with many fewer coefficients. As the table shows, the computation of the bicubic spline in the second stage is quite fast, and the time is approximately linear in the number of coefficients. In Figure 6.27 (left) we show a plot of this tensor-product spline on the rectangle [3000, 6000]2. It should be compared with the plot of the C 0 linear spline interpolating the same data shown in Figure 6.18. We should note that there is one other advantage to converting the first-stage Powell– Sabin spline to a bicubic spline: instead of a C 1 surface, we now have one which is C 2 . In the next example we see what happens if we use the C 1 Clough–Tocher scattered data interpolant in the first stage. Example 6.61. Repeat Example 6.60 where the first stage scatps is replaced by the function scatlocct. Discussion: We use the script TPctdat, and again read the data from the file bk.dat. Computing the Delaunay triangulation, we get the triangulation shown in Figure 6.16. The

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.16. Remarks

213

computation of the first-stage C 1 Clough–Tocher spline using scatct takes 14.2 seconds. Here are the maximum and RMS differences between the spline and the sample values at the 15,888 vertices of , along with the time to compute the bicubic spline from the C 1 Clough–Tocher interpolating spline. nx 101 151 201 251 301

n y maxdis rmsdis nc time 101 103 11.0 10609 .67 151 49.9 4.87 23409 1.39 201 47.0 2.90 41209 2.4 251 28.3 1.90 64009 3.71 301 19.7 1.32 91809 5.25

The results are very similar to those obtained in Example 6.60 using the Powell–Sabin spline in the first stage. In Figure 6.27 (right) we show a plot on [3000, 6000]2 of the tensor-product spline with 251 knot lines in both directions.

6.16 Remarks Remark 6.1. Interpolation of scattered data with polynomials is really not viable for several reasons. First, we have to match the number of parameters to the number ) * of data points. The space of bivariate polynomials of degree d has dimension n := d+2 2 , so for a given number of scattered interpolation points, generally there will be no choice of d that will match. Furthermore, even if we had exactly n data points, in general the matrix of the system of n interpolation conditions for the coefficients of the interpolating polynomial will be singular for many locations of the points. A lot of work has gone into trying to find conditions on the location of the sample points to ensure the nonsingularity of this matrix, but the results are still very restrictive. Finally, as we know already from the univariate case, polynomials simply are not flexible enough to do a good job of fitting a typical function. They tend to have significant oscillations. Remark 6.2. The energy expression (6.6) used in section 6.3 for constructing minimal energy splines is based on second derivatives, and essentially measures the potential energy stored in a deformed shell. Thus, this minimal energy spline is a kind of analog of the univariate natural cubic spline, where the energy expression involves the integral of the square of the second derivative. Remark 6.3. In section 6.3.4 we created a C 1 Powell–Sabin minimal energy method using the nodal basis for S21 ( P S ), which allows for an efficient construction of the energy matrix. As an alternative, we could also compute with the M-basis for S21 ( P S ) corresponding to the minimal determining set M described in Theorem 4.29. For comparison purposes, we have included the function menpsm along with the script Bmenpsm for testing it. The errors produced by this code are exactly the same as what we got in Example 6.11. But the condition numbers are now slightly larger, and the code is slower. Remark 6.4. Minimal energy splines can be constructed using just about any of the macroelement spaces described in Chapters 6–8 of [[LaiS07]]. Here we have examined only the spaces S21 ( P S ) and S51,2 (). For some numerical examples based on C 1 cubic splines on triangulated quadrangulations as well as C 2 quintic splines on Powell–Sabin triangulations, see [GolLS02]. Several other test functions are also considered there.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

214

Chapter 6. Scattered Data Interpolation

Remark 6.5. Since the space Sd0 () has a stable local basis, we can easily compute the corresponding minimal energy spline. However, this is not a useful exercise since the measure of energy (6.6) forces the spline to be piecewise linear, and so the minimal energy spline in this case reduces to the C 0 linear spline in S10 () interpolating the data at the vertices. Remark 6.6. It is possible to define the energy of a spline in different ways using other derivatives, or replacing the 2-norm by something else such as the 1-norm. For a discussion of minimal energy splines interpolating Hermite data where the energy is measured in terms of higher order derivatives, see [ZhoHL08, ZhoH09, ZhoL13]. Remark 6.7. If we replace the derivatives in the energy expression (6.6) by first derivatives, the resulting minimal energy spline has been called a tension spline. For an error bound in this case, see Theorem 8.1 of [GolLS02]. They can have some desirable shape properties. Remark 6.8. Theorem 6.9 gives a bound on the error in the maximum norm for the minimal energy interpolating spline. As pointed out in [GolLS02], it is also possible to give error bounds in the L p norms. Remark 6.9. It is clear from the definition of minimal energy splines that Ime p = p for all p ∈ P1 . However, with the energy expression (6.6), minimal energy methods generally do not reproduce quadratic polynomials. This shows that the error bound in Theorem 6.9 cannot be replaced with one involving the semi-norm | f |3,∞ . It does not exclude the possibility that there is a bound with a higher power of ||, but it is generally agreed that this is not likely. Remark 6.10. In the univariate case it is known that the natural cubic spline on an interval [a, b] has only second order convergence as the mesh size goes to zero. However, it is also known that the order of convergence becomes four on any compact subinterval [c, d] with a < c < d < b. It has been conjectured in [GolLS02] that the bivariate minimal energy spline may exhibit a similar behavior, i.e., the order of convergence may be higher in the interior of  for splines in Sdr () with r ≥ 1 and d ≥ 2. Remark 6.11. In sections 6.4 and 6.5 we have solved the scattered data interpolation problem with the cubic spline spaces S30 () and S31 (C T ), respectively. We do not have a method based on S31 (). Indeed, for given data points, it remains an open question as to whether such an interpolating spline even exists; see [PetS92]. We can’t use S21 () for the same reason. Remark 6.12. Working with the spaces S21 () and S31 () is complicated for another reason — we also don’t know their dimensions. Finding a formula for the dimension of S31 () for general triangulations remains one of the most challenging open problems in the theory of splines. Remark 6.13. For estimating derivatives from nearby data, we have advocated using either a least-squares polynomial fit or a radial basis interpolant. Using an interpolating polynomial to estimate derivatives does not work well due to the various problems mentioned in Remark 6.1.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.16. Remarks

215

Remark 6.14. A hybrid method for estimating derivatives for the purpose of scattered data fitting was studied in [DavMS03, DavMS05, DavMS06]. It is based on local least-squares using a combination of polynomials and radial basis functions. Remark 6.15. It is possible to define the condition number of a nonsquare matrix in terms of its singular values, and MATLAB has the capability of estimating condition numbers for such matrices. This situation arises in solving least-squares fitting problems directly from the observation equations. Remark 6.16. Most of the methods of this chapter will have problems when the number of data points is very small, say less than 20. This is the case with all of the methods that rely on local least-squares cubic polynomials. However, C 0 linear interpolation and minimal energy interpolation both work with as few as three data points, although we are not going to get a good fit to the underlying function f generating the sample values unless it is a very simple function such as a constant or a linear polynomial. Remark 6.17. If the z-values in a scattered data interpolation problem are taken as samples of a linear polynomial p (which could be a constant), then all of the spline methods discussed in this chapter will give an exact fit of p, i.e., s ≡ p. The minimal energy methods do not reproduce polynomials of higher degree. The local methods using cubic splines discussed in sections 6.4 and 6.5 both reproduce cubic polynomials. For two-stage methods, the degree of reproduction is limited not only by the degree of polynomials used to estimate derivatives, but also by the degree of the spline space used. Thus, the two-stage scattered data method using S21 ( P S ) reproduces only quadratics, but not cubics. The two-stage methods based on S31 (C T ), S51,2 (), and S2 (W ) all reproduce cubics. Radial basis interpolation does not even reproduce constants, unless it is modified as discussed in Remark 6.23. Remark 6.18. If an interpolation method does not reproduce polynomials of degree m, then an error bound of the form C||m+1 | f |m+1 is impossible since the semi-norm of order m + 1 of any polynomial of degree m is zero. Thus, the reproduction properties discussed in the previous remark have implications for the order of accuracy of the various methods. Remark 6.19. The idea of applying a swap algorithm to adjust a triangulation while keeping its vertices fixed can be applied with various optimization criteria. Here we used the fit at extra data points. For an example where curvature was used, see [QuaS89, QuaS90, Rip92, DynHKL00]. In section 8.5.1 we use convexity. For other methods and references, see [DynR92, DynR93]. For an application to image fitting, see [DemI11]. One can also use simulated annealing to avoid getting stuck at local minima; see, e.g., [BasS90, Schum93, HahK97]. Remark 6.20. The idea of using radial basis functions for interpolation has been around for quite a long time, and was first explored in the geophysics community where the multiquadrics were suggested as a good choice for a radial basic function. Remark 6.21. If we minimize an energy expression like the one in (6.6) over all appropriately smooth functions defined on all of R2 rather than over a finite dimensional spline space as we did in section 6.3, we don’t get piecewise polynomials at all. Instead, we get

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

216

Chapter 6. Scattered Data Interpolation

certain radial basis functions called thin plate splines, They are generated by the radial basic function φ(r ) := r 2 log(r ). For details, see [Har72, Duc76, Fra82] and the books [[Wen05, Fass07]]. Remark 6.22. Our examples of radial basis interpolation have been based on choosing the radial basic function to be the Gaussian given in (6.33). It is possible to characterize the class of radial basic functions for which that matrix in (6.32) is nonsingular for all choices of centers. Besides, the Gaussian, there are many other simple functions that belong to this class, including the thin plate splines, multi-quadrics, and the associated inverse multiquadrics. In addition, there area also families of compactly supported radial basic functions that can be used for interpolation; see [[Wen05, Fass07]] and references therein. One might hope that by choosing one of these other radial basic functions, we could avoid the problems of selecting the parameter eps controlling the shape of the Gaussian. But unfortunately, they all depend on a similar critical parameter. Remark 6.23. The interpolation method based on radial basis functions discussed in section 6.14 can be modified to get a method that reproduces polynomials up to any prescribed degree d. For example, to get linear polynomial reproduction, we look for a function as in (6.30) but with an added term of the form a0 + a1 x + a2 x 2 . Then instead of the system n equations for finding the coefficients {ci }ni=1 , we get an expanded system of n + 3 equations involving certain side conditions on a0 , a1 , a2 . For details, see [[Fass07]]. Remark 6.24. In section 6.6.2 we observed that it is possible to estimate derivatives locally using radial basis interpolation. To do this efficiently, we need simple formulae for computing derivatives. Fortunately, there are such formulae for the radial basis functions φi associated with a given radial basic function φ: Dx φi (x, y) =

(x − x i ) Dr φ(r ), r

D y φi (x, y) =

(y − yi ) Dr φ(r ), r

(6.36)

where r = [(x − x i )2 + (y − yi )2 ]1/2 . For the Gaussian with parameter ε, this gives Dx φi (x, y) = −2ε2 (x − x i )φi (x, y),

D y φi (x, y) = −2ε2 (y − yi )φi (x, y).

Remark 6.25. A Lipschitz domain  can be thought of as a domain whose boundary behaves locally like the graph of a Lipschitz continuous function. Then the Lipschitz constant of the boundary of  can be defined in terms of the Lipschitz constants of these local mappings; see any standard book on Sobolev spaces. Here we are working on polygonal domains, and thus their boundaries consist of a finite set of straight line segments. Thus, in our setting, the Lipschitz constant is related to the size of the jump in the tangent lines on either side of a given boundary point. Large Lipschitz constants correspond to narrow reentrant corners, or to triangles with very small internal angles at one of their boundary vertices.

6.17 Historical notes The fact that the univariate natural spline minimizes a certain measure of energy suggests that one should look for minimal energy surfaces in the bivariate case. Indeed, some of the earliest work on scattered data fitting involved minimizing an energy expression like (6.6)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

6.17. Historical notes

217

over an appropriate space of smooth functions; see [HarD72, Duc76, Fra82]. However, this variational approach to splines leads to certain radial basis functions, not to piecewise polynomials. To get a piecewise polynomial, we can minimize over a given finite dimensional linear space of splines, which is what we do in section 6.3. Minimal energy splines of this type were constructed in [SchmidtR82, Alf85, Gme87] using C 1 cubics or quintics, usually with the help of Lagrange multipliers. Error bounds for minimal energy splines were established in [GolLS02]. The efficient calculation of the energy of cubic splines was studied in [QuaS90b]. Several authors have looked at methods for estimating derivatives as a first step in constructing splines interpolating scattered data. Local least-squares based on polynomials was used in [Aki74, Law77, Aki78, Aki78b, Aki84, RenC84, Gmel87b, DavMS04, DavZ04]. Some hybrid methods using a combination of radial basis functions and polynomials were considered in [DavMS03, DavMS06]. There are many ways to combine different interpolation and approximation schemes to create a method for interpolating scattered data, and here we have discussed only a select few. For some others, see [Schum76b, Fol84, Fol86, SinS92, FlloI96]. For some of earliest work on the use of radial basis functions for fitting scattered data, one has to look in the Geophysics literature for papers on multi-quadrics and Kriging; see, e.g., [Hard71, Hard75] and the survey [Hard90]. Mathematicians became much more interested when Micchelli [Mic86] identified classes of radial basic functions for which the matrix involved in interpolation of data at scattered points is always nonsingular. For a review of early work on scattered data interpolation with radial basis functions, see [Dyn87]. For a detailed account of both the theory and application of radial basis functions, along with further references, see the books [[Wen05, Fass07]]. The latter includes a disk with MATLAB programs. In section 6.8 we have presented a comparison of the various methods discussed here for interpolating scattered data. For a detailed comparison of methods known in the early 1980’s, see [Fra82b]. That study included not only splines and radial basis function methods, but several other methods as well.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 7

Scattered Data Fitting

In this chapter we discuss some methods for fitting scattered data where interpolation is not required or desired. The methods are based on minimizing a quadratic functional over a space of splines with a stable local basis.

7.1 Least-squares fitting There are two data fitting situations where interpolation is usually not advisable: 1) when there are a large number of data points, 2) when the measurements are subject to noise. In this section we discuss an alternative to interpolation which is generally more suitable in such situations. nd Suppose that we are given samples {z ν }ν=1 of a bivariate function f at n d points nd {(ξν , ην )}ν=1 in a domain . Fix d ≥ 1, and let  be any triangulation of , where the vertices of  need not be chosen from among the sample points. Let S() be an Nd dimensional subspace of Sd0 () with N ≤ n d , and let {wν }nν=1 be a set of positive weights. Our aim is to approximate f by a spline in S() which fits f in the following weighted least-squares sense. Problem 7.1. Find a spline s in S() which minimizes F(s) :=

nd 

wν [s(ξν , ην ) − z ν ]2 .

(7.1)

ν=1

We call a spline s minimizing F a weighted discrete least-squares approximation to the d data. The weights {wν }nν=1 can be used to force the spline to fit better at some points than others. The higher the value of wν , the better the fit at (x ν , yν ). In practice, we usually choose all weights to be one, and all of the examples in this chapter are based on this choice, although the codes in our package SplinePak allow arbitrary weights. 219

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

220

Chapter 7. Scattered Data Fitting

7.1.1 Existence and uniqueness In this section we give conditions that ensure that Problem 7.1 has a unique solution, and N is a basis for the spline space S(). We seek a show how to compute it. Suppose {φi }i=1 solution of Problem 7.1 in the form s=

N 

c i φi .

(7.2)

i=1



Let

φ1 (ξ1 , η1 ) ⎢ .. O := ⎣ . φ1 (ξnd , ηnd )

... .. . ...

⎤ φ N (ξ1 , η1 ) ⎥ .. ⎦. . φ N (ξnd , ηnd )

(7.3)

This is called the observation matrix. Let G := O T W O, where W is the n d ×n d matrix with w1 , . . . , wnd on its diagonal. The matrix G is called the Gram matrix. Let z = (z 1 , . . . , z nd )T . Theorem 7.2. Suppose the data in Problem 7.1 is sufficiently well distributed so that the observation matrix (7.3) has full rank N. Then there exists a unique spline s ∈ S() minimizing (7.1). Moreover, its coefficient vector c in the expansion (7.2) is the solution of the linear system of equations Gc = r , (7.4) where r = O T W z. Proof. Suppose O has full rank. Then there exists an N × N submatrix O˜ that is nonsingular. Clearly, G is symmetric. We now show that it is positive definite. Given any vector c of coefficients, let sc be the associated spline in S() defined by (7.2). Then c T Gc := (W 1/2 Oc)T W 1/2 Oc ≥ 0. This shows that G is nonnegative definite. Now suppose c is such that c T Gc = c T O T W Oc = (Oc)T W Oc = 0. ˜ = 0, which implies c = 0. We have shown that G is This implies Oc = 0. But then Oc positive definite, and it follows that G is nonsingular. We now know that the system (7.4) has a unique solution c. It remains to show that the corresponding spline minimizes (7.1). Inserting (7.2) in (7.1) and expanding, we get a quadratic function of the N variables c1 , . . . , c N which can be written in the form

(c) := c T Gc − 2c T r + z T W z, Now let δ ∈ R N . Then

(c + δ) = (c + δ)T G(c + δ) − 2(c + δ)T r + z T W z = (c) + 2δ T Gc + δ T Gδ − 2δ T r = (c) + δ T Gδ. The positive definiteness of G implies δ T Gδ ≥ 0, and so (c + δ) ≥ (c). This shows that c gives a minimum of . Now by the positive definiteness of G, δ T Gδ = 0 only if δ = 0, and it follows that c is the unique minimum.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.1. Least-squares fitting

221

Least-squares fitting can also be understood as an approximation in an appropriate inner-product space. Given any two functions φ and ψ defined on the data points, let φ, ψw :=

nd 

wν φ(ξν , ην ) ψ(ξν , ην ).

(7.5)

ν=1

Then the entries of the Gram matrix are given by G i j := φi , φ j w ,

i , j = 1, . . . , N,

(7.6)

while the vector r in (7.4) has components ri :=

nd 

wν z ν φi (ξν , ην ),

i = 1, . . ., N.

(7.7)

ν=1

7.1.2 Computing the least-squares spline by solving the normal equations Given a spline space S(), suppose that we have computed its transformation matrix A, i.e., the n c × N matrix such that (6.15) holds. Examples of spaces with known transformation matrices can be found in section 4.14, along with MATLAB functions for computing them. We now describe an efficient algorithm ) * for assembling the N × N matrix G and righthand side vector r in (7.4). Let m := d+2 2 , and for each triangle T in , let A(T ) be the m × N submatrix of A obtained by selecting only the rows that correspond to B-coefficients associated with domain points in T . We write A(T )t for its transpose, and let B1T , . . . , BmT be the Bernstein basis polynomials associated with T in lexicographical order. Set ⎛ ⎞t   r (T ) := ⎝ wν z ν B1 (ξν , ην ), . . ., wν z ν Bm (ξν , ην )⎠ , ν∈AT

where

ν∈AT

AT := {ν : (ξν , ην ) ∈ T }.

(7.8)

Algorithm 7.3 (Compute G and r in (7.4)). 1) Set G = 0 and r = 0. 2) For all T ∈ , a) Compute the m × m matrix G(T ) := [BiT , B jT w ]m i, j =1 and the m-vector r(T ). b) G ← G + A(T )t G(T ) A(T ) c) r ← r + A(T )t r (T ) This algorithm works by looping through the triangles of  and filling in the entries in G and r by an accumulation process. The entries in the matrices G(T ) are sums involving values of the Bernstein basis polynomials. They can be computed using our function basis or the vectorized form of it, basisv. When the basis functions associated with A have small supports, there will generally be a considerable number of zeros in G, and so it should be stored in sparse matrix form.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

222

Chapter 7. Scattered Data Fitting

Suppose we now write c˜ for the vector of coefficients in the expansion (7.2) of the leastsquares spline s. They are computed by solving the system G c˜ = r , and correspond to the B-coefficients of s with indices in the minimal determining set for the spline space. Then the vector c of all B-coefficients of s is given by c = Ac; ˜ see Lemma 4.20. The following function finds the B-coefficients of a least-squares spline: c = lsqbiv(d,x,y,v1,v2,v3,e1,e2,e3,ie1,A,xd,yd,zd,wd) The input includes the usual information about the triangulation, along with the transformation matrix A. The vectors xd and yd should contain the coordinates of the data points, and the vectors zd and wd should contain the sample values and weights. The output is the vector c of B-coefficients of the least-squares spline. These are not the coefficients in (7.2). This function can be used with any of the macro-element spaces discussed in section 4.14 (see also section 6.7), where those spaces were used to create two-stage local interpolation methods. It is also possible to compute the coefficient vector c directly from the overdetermined observation equations Oc = z, since in MATLAB, using the backslash operator automatically gives a least-squares solution. This has some advantages and disadvantages; see Remark 7.5. In lsqbiv we have worked with the normal equations.

7.1.3 Error bounds In this section we suppose S() is a spline space defined on a β-quasi-uniform triangulation  of a domain ; see Definition 6.8. Given a smooth function, suppose we sample d it at some scattered points D := {(ξν , ην )}nν=1 in . We suppose these data points satisfy the condition in Theorem 7.2 that guarantees there is a unique least-squares spline fitting d . We write Ilsq f for the least-squares fit of this data the data values {z ν = f (ξν , ην )}nν=1 from the space S(). Clearly, Ilsq defines a linear operator mapping continuous functions defined on  into the spline space S(). This operator is in fact a linear projector, i.e., Ilsq s = s for every s ∈ S(). We now give an error bound for how well Ilsq f approximates f . To state it, we need to make an assumption about how the data points are distributed throughout the triangulation. Suppose that there exists a positive constant K 1 such that for every triangle and every spline s ∈ S(), T ∈ ,  s(ξν , ην )2 ≥ K 1 sT . (7.9) (ξν ,ην )∈T

Let n max := max #(D ∩ T ). T ∈

(7.10)

Theorem 7.4. Suppose f ∈ C m+1 () for some 0 ≤ m ≤ d. Then  f − Ilsq f  ≤ C||m+1 | f |m+1,∞ .

(7.11)

If  is convex, the constant c depends only on d, β, K 1 , and n max . If  is nonconvex, it may also depend on the Lipschitz constant of the boundary of . Proof. To prove this error bound, it suffices to bound the norm of the projector Ilsq . This can be done by applying Theorem 8.1 in [GolS02].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.2. Least-squares fitting with C 0 splines

223

In the next few sections we show how some of the macro-element spaces introduced in Chapter 4 and used in Chapters 5 and 6 for Hermite and scattered data interpolation can be used for least-squares fitting with scattered data.

7.2 Least-squares fitting with C 0 splines As noted in section 4.9, the dimension of Sd0 () is given by   d −1 0 N := dim Sd () = n + (d − 1)n e + nt , 2

(7.12)

where n, n e , and n t are the numbers of vertices, edges, and triangles in , respectively. To solve the least-squares fitting problem with Sd0 (), we use the local basis described in Theorem 4.9. Rather than call on the function lsqbiv described in section 7.1.2, we have written the following special code for finding the least-squares fit in Sd0 (): [c,G] = lsq0d(d,x,y,v1,v2,v3,e1,e2,e3,ie1,nd,xd,yd,zd,wd) The input here is the usual triangulation information along with the vectors xd and yd giving the coordinates of the sample points. It also includes the vectors zd and wd of data values and weights. The output is the vector c of B-coefficients and the Gram matrix G. Example 7.5. Fit Franke’s function (2.20) with least-squares splines in the spaces S10 () and S20 () on the triangulation shown in Figure 7.1 (left), based on sample points on grids of 81 and 289 points in the unit square. Discussion: We use the script Blsq0d, and read the triangulation from file tri36.dat. On this triangulation, the space S10 () has dimension 36, and so we need at least 36 data points. First we try a grid of 81 data points which we read from the file gridpts.81. Figure 7.1 (left) shows the triangulation and the data points. The corresponding leastsquares spline and its x-derivative are shown in the top row of Figure 7.2. The max and RMS errors on a 51 × 51 grid are 1.99(−1) and 4.30(−2) for the function, and 3.77 and 7.51(−1) for the x-derivative. The condition number of the Gram matrix G is 28.8. We can clearly see in the plots that the spline is only C 0 , while its derivative is discontinuous. We repeated the example using a grid of 289 points taken from gridpts.289. These points are shown in Figure 7.1 (right). Using 289 grid points gives a slight improvement in the errors: now the max and RMS errors on a 51 × 51 grid are 1.81(−1) and 3.76(−2) for

Figure 7.1. The triangulation tri36 with superimposed grids of 81 and 289 data points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

224

Chapter 7. Scattered Data Fitting

1.5

3

1 0.5

-2

0 1

1

1 0.5

1

0.5

0.5 0 0

0.5 0 0

1.2

4

0

0 1

1

0.5

0.5 0 0

-4 1

1

0.5

0.5 0 0

Figure 7.2. Top: the least-squares fit of Franke’s function (2.20) and its derivative using a C 0 linear spline on the triangulation tri36, based on data at 81 grid points. Bottom: the fit using a C 0 quadratic spline on , based on data at 289 grid points.

the function, and 3.22 and 6.45(−1) for the x-derivative. The condition number dropped to 7.23. For d = 2, it turns out that 81 data points are not enough, since the dimension of S20 () is 125. In this case, the function lsq0d reports a singular matrix, and no coefficients are computed. With 289 grid points we get the spline and its x-derivative shown in the second row in Figure 7.2. The condition number of the Gram matrix G in this case is 297. The max and RMS errors are 4.12(−2) and 6.85(−3) for the function, and 1.55 and 2.38(−1) for the x-derivative. Note that although the spline is only C 0 , its plot looks relatively smooth due to the fact that it is a good approximation of Franke’s function, which is C ∞ . Of course, the x-derivative is still discontinuous. Least-squares approximation is particularly useful in the case where we have very large data sets. In the following example, we examine the behavior of the least-squares fits using Sd0 () on the triangulation tri36 as d increases, where in all cases we use a grid of 16641 points. Example 7.6. Fit Franke’s function (2.20) with a least-squares spline in the space Sd0 () on the triangulation tri36 shown in Figure 7.1 for various values of d, using sample points located on a grid of 16641 points in the unit square. Discussion: We use the script Blsq0d, where we read the triangulation from the file tri36.dat and the data points from the file gridpts.16641. For comparison, we compute the least-squares splines for d = 1, . . . , 6. A plot of the least-squares spline in S60 () is shown in Figure 7.3, along with its x-derivative. In the following table we give

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.2. Least-squares fitting with C 0 splines

225 4

1.4

-2 0 1

1 1

0.5

0.5

1

0.5

0.5 0 0

0 0

Figure 7.3. The least-squares fit of Franke’s function and its derivative using S60 () on the triangulation in Figure 7.1 using data on a grid of 16641 points.

the dimension of the spline spaces, and the max and RMS errors for both the function and its x-derivative on a 51 × 51 grid. The table also gives the condition numbers of the associated Gram matrices, and the times for the computation. d dim 1 36 2 125 3 268 4 465 5 716 6 1021

emax 2.14(−1) 3.92(−2) 2.12(−2) 2.97(−3) 9.38(−4) 2.80(−4)

rms 3.71(−2) 6.26(−3) 2.04(−3) 3.79(−4) 8.84(−5) 2.13(−5)

Dxmax 3.06(0) 1.62(0) 7.09(−1) 3.11(−1) 8.81(−2) 3.43(−2)

Dxrms 6.43(−1) 2.34(−1) 8.13(−2) 2.38(−2) 6.69(−3) 1.87(−3)

cond time 7.6(0) .96 4.4(1) 1.04 3.1(2) 1.11 1.3(3) 1.23 5.0(3) 1.37 2.0(4) 1.62

The table shows that the accuracy increases quite quickly with increasing d. For the larger values of d, the plots of the splines are virtually indistinguishable from a plot of Franke’s function itself, even though the spline is only C 0 , and its x-derivative is actually discontinuous. It is worth noting that the condition numbers are growing quite quickly with increasing d, but the computational time is growing approximately linearly. We now give an example to explore the rate of convergence of least-squares fitting using C 0 linear splines. We take a fairly large set of gridded data, and use a nested sequence of type-1 triangulations whose mesh sizes are going down by a factor of two. Example 7.7. Suppose we are given values of Franke’s function (2.20) on a grid of 4225 points in the unit square. Find the errors for the least-squares fits using C 0 linear splines based on a given type-1 triangulation, and its successive refinements. Discussion: We use the script Blsq0d, and read the triangulations from the following files: type1.25, . . . , type1.1089. These files produce type-1 triangulations with n = 25, 81, . . ., 1089 vertices on an equally spaced grid. They are nested, and the mesh size is reduced by a factor of two for each refinement step. We read the sample points from gridpts.4225. In the following table we give the max and RMS errors on a 51 × 51 grid, along with the conditions numbers of the associated Gram matrices. n 25 81 289 1089

emax 1.34(−1) 6.07(−2) 1.31(−2) 3.75(−3)

rms condition 3.81(−2) 10.0 1.21(−2) 8.8 2.45(−3) 6.0 6.63(−4) 3.0

ratios 2.21 3.15 4.63 4.94 3.49 3.70

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

226

Chapter 7. Scattered Data Fitting

Since the ratios are approximately four, we seem to be getting O(||2 ) convergence, as is to be expected for interpolation with linear splines; see Theorem 7.4. Here is a similar table for the x-derivatives. n 25 81 289 1089

emax 2.63(0) 1.99(0) 1.02(0) 4.90(−1)

rms 6.35(−1) 4.43(−1) 2.18(−2) 1.07(−1)

ratios 1.32 1.43 1.95 2.03 2.08 2.04

Theorem 7.4 does not make any assertion about the rate of convergence of derivatives of the least-squares splines, but this table shows that with linear splines, we are getting the expected linear rate of convergence. The above examples are based on gridded data. In the following example we see what happens if we are given data points which are less uniformly spaced. Example 7.8. Fit Franke’s function (2.20) with a least-squares spline in the space S20 () on the triangulation in Figure 7.1, using randomly scattered data points in the unit square. Discussion: We use the script Blsq0drand, and read the triangulation from the file tri36.dat. The random data points are read in using randxy which makes use of the file randxy.dat. We read in the points rather than generating them with a call on rand to ensure reproducibility. This means that every time we run the script with a given number nd, we get the same set of points. We first try nd = 289. This gives the data points shown on the top left in Figure 7.4 (left). The corresponding least-squares fit in S20 () is shown on the top right. The max and RMS errors are 1.75(−1) and 1.34(−2) for the function, and 6.92 and 4.59(−1) for the x-derivative. These values are all considerably larger than what we obtained in Example 7.5 using a uniform grid of 289 data points, and the plot definitely shows some shape anomalies. The condition number of the Gram matrix is 20367. If we repeat this example with nd = 250, we get a Gram matrix with condition number 5.0(+17), i.e., a matrix which is very close to being singular. Nevertheless, MATLAB was able to produce some coefficients giving a reasonable least-squares spline in S20 (). Now the max and RMS errors are 2.33(−1) and 1.95(−2). The corresponding plot shows some bumpy spots; see the bottom row of Figure 7.4. If we take even smaller values for nd, we get warnings about a singular matrix, and the errors and plots get progressively worse. With 150 points or less, the program still runs, but the fit becomes useless.

7.3 Least-squares fitting with C 1 splines In this section we perform least-squares fitting using some of the C 1 macro-element spaces discussed in section 4.14, and used in Chapter 6 for scattered data interpolation.

7.3.1 Least-squares fitting with C 1 Powell–Sabin splines We begin with the C 1 macro-element space S21 ( P S ), where  P S is the Powell–Sabin refinement of some initial triangulation with n vertices. As noted in Theorem 4.29, N := dim S21 ( P S ) = 3 n. To compute with S21 ( P S ), we can call on the function psmds de-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.3. Least-squares fitting with C 1 splines

227 1.4

0 1

1

0.5

0.5 0 0

1.4

0 1

1

0.5

0.5 0 0

Figure 7.4. Top: A set of 289 random data points in the unit square imposed on a triangulation with 36 vertices, and the least-squares fit of Franke’s function from the space S20 () based on this data. Bottom: A set of 250 random data points in the unit square imposed on a triangulation with 36 vertices, and the least-squares fit of Franke’s function from the space S20 () based on this data.

scribed in section 4.14.1 to create the Powell–Sabin refinement, and construct a transformation matrix A. This code chooses a minimal determining set M for S21 ( P S ). Although behind the scenes we are working with the corresponding M-basis, the least-squares code lsqbiv described above does not make any direct use of M or the corresponding basis functions. All the information we need is encoded in the transformation matrix A. Alternatively, we can call on the function nmdsps described in section 4.14.1 to choose a nodal basis N for S21 ( P S ). It also creates the refined triangulation and computes an associated transformation matrix A. Example 7.9. Fit Franke’s function (2.20) with a least-squares spline in the space S21 ( P S ) associated with the initial triangulation tri36, and using 289 sample points located on a grid in the unit square. Discussion: We use the script Blsqps, and read the triangulation from the data file tri36.dat. The data points are read from the file gridpts.289. The triangulation and the data points are shown Figure 7.1 (right). For this triangulation, the dimension of S21 ( P S ) is 108. The script uses the M basis. The max and RMS errors are 3.42(−2) and 6.91(−3), while for the x-derivative they are 1.09 and 1.89(−1). These errors can be compared with those in Example 7.5 for the space S20 (). The errors here are essentially the same, but now we are getting a C 1 spline instead of one that is only C 0 . The spline and its x-derivative are shown in Figure 7.5. The script can easily be modified to work with the nodal basis by replacing the call on mdsps with a call on nmdsps. Although we get the same spline with either basis,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

228

Chapter 7. Scattered Data Fitting 1.4

3

-3

0 1

1

0.5

1

0.5 0 0

1

0.5

0.5 0 0

Figure 7.5. Left: The C 1 Powell–Sabin spline defined on the triangulation tri36 fitting Franke’s function based on samples on a grid of 289 points. Right: Its x-derivative.

for least-squares fitting the M basis is to be preferred as it runs faster, and gives smaller condition numbers. For this example, the condition number of the Gram matrix using the M basis was only 764, while with the N basis it was 4.12(+5). Thus, for least-squares fitting with S21 ( P S ), the M basis is to be preferred. This is the opposite of what we found in computing minimal energy splines where the N basis was faster and led to matrices with smaller condition numbers; see Remark 6.3. Repeating this example using 1089 grid points gives almost the same least-squares spline with very little change in the errors or the condition number of the Gram matrix. This shows that once we have enough well-distributed points to get a good approximation, adding more points does not necessarily improve the approximation very much. We now explore the rate of convergence of least-squares fitting with S21 ( P S ). To this end, we compute spline fits for a sequence of nested triangulations where the mesh size is halved at each step. Example 7.10. Find the least-squares approximation of the function (2.20) based on nd = 4225 grid points in the unit square using the spline space S21 ( P S ) associated with a nested sequence of type-1 triangulations obtained by repeated uniform refinement. Discussion: We use the script Blsqps, and read the triangulations from the files type1.9, etc. The data is read from the file gridpts.4225. The following table shows the results for the various triangulations. It gives the dimension of the spaces, along with the maximum and RMS errors for the function as well as the condition numbers of the Gram matrices. n dim emax rms cond 9 27 2.82(−1) 3.47(−2) 112 25 75 5.60(−2) 1.31(−2) 97 81 243 1.01(−2) 1.33(−3) 67 289 867 1.26(−3) 1.58(−4) 40

ratios 5.04 2.65 5.54 9.85 8.02 8.42

We show plots of the fits for n = 9 and n = 25 in Figure 7.6. This experiment shows that the condition numbers are quite small, and that they improve as we increase n. These condition numbers can be compared with those obtained in Example 7.9 using the triangulation corresponding to tri36.dat. The better condition numbers obtained here are due to the uniformity of the triangulations. According to Theorem 7.4, we expect the errors to be of order three, which is what we are getting. We can also check the rate of convergence

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.3. Least-squares fitting with C 1 splines

229

1.2 1.2

0 1

1

0.5

0.5

0 1

1

0.5

0.5

0 0

0 0

Figure 7.6. The least-squares fits to Franke’s function based on 4225 grid points in the unit square using the space S21 ( P S ) on type-1 triangulations with 9 and 25 vertices.

of the x-derivatives of the splines. Here is the corresponding table. n dim emax 9 27 3.41(0) 25 75 1.33(0) 81 243 4.77(−1) 289 867 1.42(−1)

rms 5.63(−1) 2.57(−1) 5.85(−2) 1.40(−2)

ratios 2.56 2.19 2.79 4.39 3.36 4.18

Although Theorem 7.4 makes no assertion about derivatives, we do expect the errors to be of order two, which is what we are getting.

7.3.2 Least-squares fitting with the space S51,2 () In this section we discuss least-squares fitting with the Argyris macro-element space S51,2 (). As shown in Theorem 4.34, N := dim S51,2 () = 6n + n e ,

(7.13)

where n and n e are the numbers of vertices and edges in , respectively. To compute with this space, we use the minimal determining set described in Theorem 4.34. It can be computed using the function mds15 described in section 4.14.2, which also provides the transformation matrix A. Once we have A, we can call lsqbiv to compute the spline coefficients, just as we did in the previous section with the space S21 ( P S ). Example 7.11. Fit Franke’s function (2.20) with a least-squares spline in the space S51,2 () on the triangulation shown in Figure 7.1 using sample points located on a grid of 1089 points in the unit square. Discussion: We use the script Blsq15, and read the triangulation from tri36.dat. The point set can be read from gridpts.1089. We have used this point set rather than gridpts.289 since the dimension of S51,2 () in this case is 305, and thus we need at least 305 data points. The max and RMS errors are 2.55(−3) and 3.41(−4), and the condition number of the Gram matrix is 2.1(+6). These errors are significantly better than what we got using the spline space S21 ( P S ) — see Example 7.9 which used 289 grid points, but there is little change in the errors with 1089 grid points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

230

Chapter 7. Scattered Data Fitting

We now explore the rate of convergence of least-squares fitting with the spline space S51,2 (). To this end, we compute the least-squares splines for a nested sequence of triangulations where the mesh size is halved at each step. Example 7.12. Fit the test function (2.20) on the unit square using the spline spaces S51,2 () with vertices on a nested sequence of uniform grids based on samples on a grid of 16641 points. Discussion: We use the script Blsq15, and read the triangulations from type1.9, etc. The sample points are read from gridpts.16641. We tabulate both the maximum and the RMS errors, along with the condition numbers of the Gram matrices and the dimensions of S51,2 () for each triangulation. n dim emax 9 70 1.08(−1) 25 206 6.73(−3) 81 694 5.27(−4) 289 2534 1.31(−5) 1089 9670 1.80(−7)

rms 9.10(−3) 1.12(−3) 5.26(−5) 1.55(−6) 1.58(−8)

cond 9.9(+4) 1.0(+5) 7.6(+4) 5.4(+4) 1.7(+5)

ratios 16.05 8.13 12.77 21.29 40.23 33.94 72.78 98.10

This experiment shows that the condition numbers do not vary much as we increase the number of vertices. According to Theorem 7.4, we expect the errors to behave like O(||6 ), which corresponds to ratios of 64. The table indicates we are achieving that rate. In this example we used very regular data. We now examine what happens if we use randomly chosen data points. Example 7.13. Repeat Example 7.12 using data at 16641 random points instead of grid points. Discussion: We can use the script Blsq15rand, which is the same as Blsq15 except that the data is now read from the file randxy.dat. Here are the max and RMS errors, along with the condition numbers: n 9 25 81 289 1089

emax 1.21(−1) 6.74(−3) 5.93(−4) 2.63(−5) 1.42(−5)

rms 9.24(−3) 1.14(−3) 5.48(−5) 1.81(−6) 2.97(−7)

cond 1.1(+5) 1.3(+5) 1.8(+5) 4.7(+5) 1.2(+13)

ratios 17.95 8.11 11.37 20.80 22.55 30.28 1.85 6.10

For the first four triangulations, the errors are close to those obtained with gridded data in Example 7.12, although the condition numbers are slightly larger. On the other hand, for n = 1089, the condition number is very bad, which reduces the accuracy. This is due to the fact that on this large triangulation, some of the basis functions don’t have enough data points in their support. The rate of convergence ratios are also affected by the random nature of the data. To close this section, we should make a few comments about computational times. The largest of the problems in Example 7.13 uses a triangulation with 1089 vertices cou-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.4. Least-squares fitting with C 2 splines

231

pled with 16641 sample points. For this problem, assembling the Gram matrix took 7.58 seconds, and solving the resulting linear system took .17 seconds. Some experimentation shows that the growth in computational time is approximately linear in the number of sample points. However, it grows faster than linear in the number of vertices. We should emphasize that least-squares fitting with splines is a global method, and thus may become impracticable for very large problems.

7.4 Least-squares fitting with C 2 splines In this section we solve the least-squares fitting problem with some C 2 macro-element spaces.

7.4.1 Least-squares fitting with the space S2 (W ) Let S2 (W ) be the C 2 quintic spline space defined on the Wang refinement of a triangulation; see section 4.14.4. To use this space, we first call on mdswang to choose a minimal determining set, and to compute the corresponding transformation matrix. Then the B-coefficients of the least-squares spline can be computed using lsqbiv. Example 7.14. Fit Franke’s function (2.20) with a least-squares spline in the space S2 (W ) with the triangulation shown in Figure 7.1, based on sample points located on a grid of 1089 points in the unit square. Discussion: We make use of the script Blsqwang, and read the triangulation from the file tri36.dat and the data points from the file gridpts.1089. For this triangulation, the dimension of S2 (W ) is 483. The max and RMS errors of 2.60(−3) and 3.07(−4). The condition number of the Gram matrix is 8.2(+10), which is quite a bit larger than what we got with the C 1 spaces of the previous section, but we are still getting much better accuracy. The errors and condition number are only slightly improved if we use more data points. For example, with 16641 data points from the file gridpts.16641, the max and the RMS errors become 2.59(−3) and 2.70(−4), respectively, with a condition number of 2.96(+9). We now look at the rate of convergence for least-squares fitting with S2 (W ). Example 7.15. Fit the test function (2.20) on the unit square using the space S2 (W ) with vertices on a nested sequence of type-1 triangulations obtained by successive uniform refinement of a type-1 triangulation with nine vertices. Discussion: We use the script Blsqwang, and read the type-1 triangulations from the files type1.9, type1.25, etc. For sample points we use the 16641 points on a grid contained in gridpts.16641. We tabulate both the maximum and the RMS errors, as well as the dimension of S2 (W ) for each case considered. n dim emax 9 102 1.07(−1) 25 318 6.77(−3) 81 1110 4.74(−4) 289 4134 1.33(−5)

rms 7.72(−3) 8.66(−4) 4.09(−5) 1.37(−6)

cond 5.42(+7) 5.18(+7) 3.83(+7) 1.44(+8)

ratios 15.81 8.92 14.28 21.17 35.64 29.85

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

232

Chapter 7. Scattered Data Fitting

This experiment shows that the condition numbers do not vary much as we increase the number of vertices, but are larger than for the C 1 spaces used in the previous two sections. According to Theorem 7.4, we expect the errors to behave like O(||6 ).

7.4.2 Least-squares fitting with the space S2 (CT ) As an alternative to the space S2 (W ) of the previous section, we can instead use the space S2 (C T ); see section 7.2 of [[LaiS07]]. It is based on the Clough–Tocher split, and uses polynomial pieces of degree seven instead of degree five as used in the Wang macroelement space. The dimension of this space is 10n + 3n e , where n is the number of vertices and n e is the number of edges in the triangulation . To use this space, we can call on the function mdsct2 to choose a minimal determining set and compute the corresponding transformation matrix. The B-coefficients of the least-squares spline can then be computed using lsqbiv. Example 7.16. Fit Franke’s function (2.20) with a least-squares spline in the space S2 (C T ) on the triangulation shown in Figure 7.1 using sample points located on a grid of 1089 points in the unit square. Discussion: We make use of the script Blsqct2, and read the triangulation from the file tri36.dat. The sample points are read from the file gridpts.1089. For this triangulation, the dimension of S2 (C T ) is 627. The max and RMS errors in this case are 4.22(−4) and 4.52(−5) for the function, and 3.59(−2) and 4.10(−3) for the x-derivative. These are very good fits, despite the fact that the condition of the Gram matrix in this case is 2.4(+11). The errors are only slightly improved if we use more data points. For example, with 16641 data points from the file gridipts.16641, the max and RMS errors for the function become 2.80(−4) and 2.94(−5), and for the x-derivative are 1.99(−2) and 2.01(−3), respectively. At 2.19(+10), the condition number is still very large. We now look at the rate of convergence for least-squares fitting with S2 (C T ). Example 7.17. Fit the test function (2.20) on the unit square using the space S2 (C T ) with vertices on a nested sequence of uniform grids. Discussion: We use the script Blsqct2, and read type-1 triangulations from the files type1.9, type1.25, etc. For sample points we use the 16641 points on a grid contained in gridpts.16641. We tabulate both the maximum and the RMS errors, as well as the dimension of S2 (C T ) for each case considered. n dim emax 9 138 1.83(−2) 25 418 1.27(−3) 81 1434 3.50(−5) 289 5290 1.14(−7)

rms 3.17(−3) 1.73(−4) 3.99(−6) 1.17(−8)

cond 2.7(+8) 2.5(+8) 1.9(+8) 3.1(+8)

ratios 14.41 18.32 36.29 43.36 307.01 341.03

This experiment shows that the condition numbers are nearly constant as we move to finer and finer triangulations. According to Theorem 7.4, we expect the errors to behave like O(||8 ), which is approximately what we are getting.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.5. Scale invariance of least-squares fitting

233

7.4.3 Least-squares fitting with the space S92,4 () In this section we explore least-squares fitting with the C 2 spline space S92,4 (); see section 4.14.3. This space has dimension 15n + 3n e + n t , where n, n e , and n t are the numbers of vertices, edges, and triangles in . To use this space, we can call on mds29 to choose a minimal determining set and compute the corresponding transformation matrix A. Example 7.18. Fit Franke’s function (2.20) with a least-squares spline in the space S92,4 () on the triangulation shown in Figure 7.1 using sample points located on a grid of 1089 points in the unit square. Discussion: We make use of the script Blsq29, and read the triangulation from the data file tri36.dat. The sample points are read from the file gridpts.1089. Then the dimension of S92,4 () is 861. In this case the max and RMS errors for the function are 9.21(−3) and 3.98(−4), and 5.43(−1) and 2.73(−2) for the x-derivative, despite the fact that the condition number of the Gram matrix is 3.2(+15). Rerunning the problem with gridpoints read from gridpts.4225 gives max and RMS errors for the function of 3.18(−5) and 3.41(−6), and 4.42(−3) and 2.69(−4) for the x-derivative. The condition of the Gram matrix is now a more manageable 2.45(+11), and we are getting much better errors. The errors and condition number are almost identical if we use 16641 data points. We now look at the rate of convergence for least-squares fitting with S92,4 (). Example 7.19. Fit the test function (2.20) on the unit square using the space S92,4 () with vertices on a nested sequence of type-1 triangulations. Discussion: We use the script Blsq29, and read the type-1 triangulations from the files type1.9, type1.25, etc. For sample points we use the 16641 points on a grid contained in gridpts.16641. We tabulate both the maximum and the RMS errors, as well as the dimension of S92,4 () for each case considered. n dim emax 9 191 1.01(−2) 25 575 2.49(−4) 81 1967 1.24(−6) 289 7247 3.65(−9)

rms 1.43(−3) 4.00(−5) 1.33(−7) 3.34(−10)

cond 3.0(+8) 2.9(+8) 2.6(+8) 1.0(+9)

ratios 40.16 35.75 202.44 300.75 337.00 398.20

This experiment shows that the condition numbers do not vary too much as we increase the number of vertices. According to Theorem 7.4, we expect that asymptotically, the errors should behave like O(||10 ). We are not quite reaching that here. Note that the computation of the condition numbers for larger n is quite slow.

7.5 Scale invariance of least-squares fitting Suppose we want to find a spline s in a spline space S() that fits given data {x ν , yν , z ν }nν=1 in the least-squares sense. In this section we explore to what extent this process is scale invariant in the sense that if we scale both the knot locations and the sample locations in the same way, then the coefficients of the spline remain unchanged.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

234

Chapter 7. Scattered Data Fitting

Definition 7.20. Let s be the least-squares fit of the data {x ν , yν , z ν }nν=1 from the space ˜ where S(), and suppose s˜ is the least-squares fit of the data {αx ν , βyν , z ν }nν=1 in S(), ˜ are obtained by scaling by α in the x-variable and β in the y-variable. the vertices of  If the B-coefficients of s and s˜ are the same for all choices of α = β > 0, then we say that the method is equi-scale invariant. If the B-coefficients remain the same for all α > 0 and β > 0, then we say that the method is scale invariant. Note that in this definition we are not scaling the z-values. The fact that the coefficients of s and s˜ are the same means that for any point (x, y) in the domain  associated with s, the value of s(x, y) is the same as the value of s˜ (αx, αy). Scale invariance is an important property for a spline approximation method to have since, in practice, the location of points in the plane can be described with different units. For example, suppose {(x ν , yν )}nν=1 are the locations of some pollution measuring stations, measured in terms of miles from some reference point. We don’t want to get different results if we use kilometers instead. Fortunately, all of the fitting methods discussed in this chapter are scale invariant in this sense. Here is an example based on C 0 splines. Example 7.21. Explore the scale invariance of least-squares fitting with Sd0 (). Discussion: We make use of the script Bscalelsq0d with d = 2, and read a triangulation from the file tri36.dat and data points from the file gridpts.289. We then choose scale factors α > 0 and β > 0, and scale both the vertices and sample points. As a test function we use the scaled Franke’s function franke2(x/α,y/β) For all d, we find that the B-coefficients are the same for all choices of α > 0 and β > 0, i.e., we have scale invariance. In Figure 7.7 we show the scaled triangulation and data points scaled with α = 10 and β = 3. The corresponding C 0 quadratic least-squares spline fit is shown in Figure 7.8. This scale invariance also holds for other values of d. We get similar results for least-squares fitting with all of the other spline spaces discussed in this chapter, i.e., they are all scale invariant.

7.6 A comparison of the methods We now compare the performance of the various methods discussed in sections 7.2–7.4 for solving the least-squares fitting problem. We focus on spline spaces defined on the triangulation shown in Figure 7.1, or on an appropriate macro-element refinement of it.

Figure 7.7. The triangulation in Figure 6.1 and 289 points on a uniform grid, both scaled to fit in the rectangle [0, 10] × [0, 3].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.6. A comparison of the methods

235

10 1 0.2 5

3 0

0

Figure 7.8. The C 0 quadratic spline fitting the scaled Franke’s function for the triangulation and data points of Figure 7.7.

Example 7.22. Fit Franke’s function (2.20) on the unit square using data at the vertices of a grid of 1089 data points using spline spaces defined on the triangulation tri36 shown in Figure 7.1. Discussion: This triangulation corresponds to the file tri36.dat. We now give a table of the max and RMS errors for the splines and their x-derivatives on a 51 × 51 grid defined on the unit square. To avoid getting a nearly singular Gram matrix, for the space S92,4 () we used a grid of 4225 data points. Space dim emax rms Dxmax Dxrms time 0 S2 () 125 4.21(−2) 6.25(−3) 1.61(0) 2.34(−2) .09 1.85(−1) .11 S21 ( P S ) 108 3.45(−2) 6.61(−3) 1.17(0) S51,2 () 305 2.55(−3) 3.41(−4) 1.54(−1) 1.51(−2) .06 S2 (W ) 483 2.60(−3) 3.07(−4) 3.65(−1) 3.49(−2) .19 S2 (C T ) 627 4.22(−4) 4.52(−5) 3.59(−2) 4.10(−3) .42 S92,4 () 861 3.18(−5) 3.41(−6) 4.42(−3) 2.69(−4) .24 The error bounds for the two spaces S20 () and S21 ( P S ) are very similar, as are the computational times, but S21 ( P S ) has the advantage of being C 1 . The C 1 space S51,2 () gives significantly better errors, and is even faster than the first two. The last three spaces are all C 2 , and take about the same amount of computational time. The space S2 (W ) gives results which are not much different from what we got with S51,2 (), but it has the advantage of being C 2 . The last two spaces show dramatic improvements in accuracy at very little extra cost. In studying this example, we should keep in mind the following: 1) This experiment was done with sample points that are quite regularly distributed in the unit square. If the data points were badly distributed, we certainly would not get such good results. 2) There is added complexity in storing and evaluating the splines defined on refinements of . This is a slight disadvantage for the macro-element spaces using splits, since it means that in evaluating the spline there is an added cost in searching for the triangles containing the evaluation points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

236

Chapter 7. Scattered Data Fitting

7.7 The effect of noise In practical data fitting situations, the measurements are almost always contaminated by noise. This can have a considerable effect on the performance of the above least-squares spline methods, although in general, if the number of data points is sufficiently large compared to the dimension of the spline space, the effect of noise is somewhat mitigated. The best way to see how noise affects our methods is to look at some examples. Example 7.23. Fit Franke’s function (2.20) on the unit square based on noisy data sampled on a nested sequence of grids. Use the spline space S51,2 () on a type-1 triangulation with 25 vertices on a uniform grid. Discussion: We use the script Blsq15, where the triangulation is read in from the file type1.25, and the data points from the files gridpts.289, etc. We sample Franke’s function, and add noise consisting of random numbers in the interval [−1, 1], scaled by a factor ε, which we choose to be .1. The following table gives the max and RMS errors for the function and the x-derivative for the various choices of the number nd of data points. nd 289 1089 4225 16641

emax 1.99(−1) 1.08(−1) 1.00(−2) 6.69(−2)

rms Dxmax Dxrms 5.42(−2) 14.53(0) 1.81(0) 2.03(−2) 8.23(0) 7.09(−1) 1.03(−2) 8.29(0) 3.78(−1) 5.45(−3) 4.72(0) 1.93(−1)

Plots of the corresponding splines and their x-derivatives are shown in Figure 7.9. The introduction of noise leads to much worse errors than what we get without noise. For example, with nd = 1089 and ε = 0, the max and RMS errors for fitting the function are 6.98(−3) and 1.11(−3), and for the x-derivative are 2.26(−1) and 3.45(−2). Both the table and the plots show that it is beneficial to use more data points when fitting noisy data, since doing so has a tendency to smooth out some of the noise. However, even with 16641 data points, the fit of the x-derivative is still not very good. In the following section we introduce a method which is very well suited for fitting of noisy data.

7.8 Penalized least-squares fitting A useful way to deal with noisy data is to modify the least-squares method of section 7.1 by including a penalty term involving the energy of the spline in the minimization problem. d d at scattered points {(ξν , ην )}nν=1 in a domain  as in Suppose we are given data {z ν }nν=1 nd the previous sections. Let {wν }ν=1 be given nonnegative weights, and let S() be a spline subspace of Sd1 () corresponding to a triangulation with vertices at {(x i , yi ))}ni=1 . Problem 7.24. Fix λ ≥ 0. Find a spline s in S() which minimizes E λ (s) :=

nd 

wν [s(ξν , ην ) − z ν ]2 + λE(s),

(7.14)

ν=1

where E(s) is the energy of s as defined in (6.6). We call such a spline a penalized leastsquares fit to the data.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.8. Penalized least-squares fitting

237

1.2

15

0

-5

1

1

1

0.5 0 0

0 0

10 1.2

-4

0 1

1

0.5

1

1

0.5

0 0

0 0

4 1.2

-6 0 1

1

0.5

1

1

0.5

0 0

0 0

4 1.2

-4

0 1

1

0.5 0 0

1

1

0.5 0 0

Figure 7.9. Fits to Franke’s function (2.20) based on noisy data using the spline space S51,2 () on a type-1 triangulation of the unit square with 25 vertices. The plots show the improvements obtained for both the function and its x-derivative as the number of data points increases from 289 to 16641; see Example 7.23.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

238

Chapter 7. Scattered Data Fitting

7.8.1 Existence and uniqueness In this section we show that Problem 7.24 has a unique solution under fairly weak condiN tions on S() and the set of sample points. Let {φi }i=1 be a basis for S(). Then any spline s ∈ S() has a unique expansion of the form (7.2) for some coefficient vector c. Theorem 7.25. Fix λ > 0, and let S() be a space of C 1 splines. Suppose n d ≥ 3, and not all of the data points lie on one straight line. Then there is a unique spline s ∈ S() solving Problem 7.24. Moreover, writing s as in (7.2), its coefficient vector c is the solution of the nonsingular linear system (G + λM)c = r , where G and r are as in Theorem 7.2, and M is the N × N matrix with entries Mi j := φi , φ j  E ,

i , j = 1, . . ., N,

(7.15)

where the energy inner product is defined in (6.10). Proof. Given c ∈ R N , let sc be the corresponding spline in (7.2). Then

λ (c) := E λ (sc ) = c T H c − 2c T r + z T z, where H := G + λM and z is the vector of data values. Both G and M are symmetric, and thus H is also symmetric. Since c T Gc =

nd 

wν sc (ξν , ην )2 ≥ 0

ν=1

and c T Mc = E(sc ) ≥ 0, it follows that H is nonnegative definite. Now suppose c T H c = 0 for some c, and let sc be the corresponding spline. Then E(sc ) = 0 and sc (ξν , ην ) = 0 for all ν = 1, . . ., n d . By the definition of energy and the fact that sc ∈ C 1 (), it follows that sc is a linear polynomial on all of . Since not all of the data points lie on one straight line, we conclude that sc ≡ 0, i.e., c = 0. We have shown that H is positive definite and thus nonsingular. It remains to show that if H c = r , then c minimizes λ (c). For any vector δ ∈ R N , we have

λ (c + δ) = (c + δ)T H (c + δ) − 2(c + δ)T r + z T z = λ (c) + 2δ T H c + δ T H δ − 2δ T r = λ (c) + δ T H δ. Since δ T H δ ≥ 0, it follows that λ (c + δ) ≥ λ (c). This shows that c provides a minimum of . Now by the positive definiteness of H , δ T H δ = 0 only if δ = 0, and it follows that c is the unique minimum.

7.8.2 Implementing penalized least-squares fitting Suppose S() is a spline space with a minimal determining set M and a transformation matrix A. Suppose we choose the basis for S() to be the corresponding M-basis of Theorem 4.22. Then the matrix H := G + λM can be assembled using Algorithms 7.3

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.9. Penalized least-squares fitting with macro-element spline spaces

239

and 6.7, where now in Algorithm 6.7 we perform Step 2 for all ξ , η ∈ M. Let c˜ be the coefficients in the expansion (7.2). These are computed by solving the system H c˜ = r described in Theorem 7.25. They are the B-coefficients of the penalized least-squares spline s with indices in the minimal determining set for the spline space. The full vector of Bcoefficients of s is then given by c = Ac; ˜ see Lemma 4.20. We have implemented penalized least-squares in the function c = penlsqbiv(d,x,y,v1,v2,v3,e1,e2,e3,ie1,A,... xd,yd,zd,wd,lambda) The input is the usual triangle information, the data vectors xd,yd,zd, the vector wd of weights, the transformation matrix A, and the smoothing parameter lambda. The output is the vector c of B-coefficients. Penalized least-squares can be carried out with any of the macro-element spaces discussed in section 4.14, and with any of the others discussed in Chapters 6–8 of [[LaiS07]].

7.9 Penalized least-squares fitting with macro-element spline spaces It is clear from the previous section that to get a script for penalized least-squares fitting with any of the spaces used for least-squares fitting in sections 7.3–7.4, all we need to do is replace the call on lsqbiv in the corresponding least-squares script by a call on penlsqbiv. To illustrate the behavior of penalized least-squares, here we examine just two of the spaces, S51,2 () and S92,4 ().

7.9.1 Penalized least-squares fitting with S51,2 () In this section we discuss penalized least-squares fitting with the space S51,2 (). Example 7.26. Fit Franke’s function (2.20) on the unit square with noisy measurements taken on a uniform grid of 1089 points in the unit square. Use the spline space S51,2 () on a type-1 triangulation  with 25 vertices on a uniform grid. Discussion: We use script Bpenlsq15, and read the triangulation from file type1.25. The data points are read from the file gridpts.1089. Random noise values in [−1, 1] are read from the file noise.dat. These are scaled by ε = .1 and added to the sample values to get the data values. The following table shows the results for various values of λ. The choice λ = 0 gives the least-squares fit. In Figure 7.10 we show the penalized least-squares fits of the function and its x-derivative for λ = 0, .003, .1, 100. With λ = .003 we see that most of the noise has been removed, both for the fit of the function and its x-derivative. These splines should be compared with those in the last row of Figure 7.10, which were obtained by performing a least-squares fit of Franke’s function using S51,2 () on the triangulation tri36 with the same set of 1089 grid points, but with no noise. The second and third rows of Figure 7.10 show what happens when we take λ too large — we get smoother surfaces, but with larger errors. The plot for λ = 100 shows what happens as λ goes to ∞, namely, the spline approaches a linear surface.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

240

Chapter 7. Scattered Data Fitting

1.2

8

0

-4

1

1

0.5

1

1

0.5

0 0

0 0

1.2 3

-2 0 1

1

0.5

1

1

0.5

0 0

0 0

2

1.2

-0.5 0 1

1

0.5

1

0 0

0 0

1

0.52

0

0.48

1

1

0.5 0 0

1

0.5

1

1

0.5 0 0

Figure 7.10. Penalized least-squares fits (and their x-derivatives), based on noisy samples of Franke’s function (2.20) on a grid of 1089 points, using the space S51,2 () on the type-1 triangulation with 25 vertices. The plots correspond to λ = 0, .003, .1, 100.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.9. Penalized least-squares fitting with macro-element spline spaces

241

.02

.016

.012 0

2

4

6 10

-3

Figure 7.11. Graph of the RMS error in fitting noisy samples of Franke’s function with a spline in S51,2 (), using penalized least-squares for values of λ in the interval [0, .006].

In the following table we give the max and RMS errors for the function and its xderivative for various values of λ. For each value of λ, we also give the condition number of the 206 × 206 matrix H := G + λM used to compute the spline coefficients; see Problem 7.24. λ 0 .00001 .0001 .001 .002 .003 .004 .005 .01 .1 100

emax 1.08(−1) 1.01(−1) 7.50(−2) 4.78(−2) 4.26(−2) 4.62(−2) 5.17(−2) 5.62(−2) 7.10(−2) 2.25(−1) 4.92(−1)

rms 2.03(−2) 1.88(−2) 1.51(−2) 1.12(−2) 1.11(−2) 1.16(−2) 1.24(−2) 1.34(−2) 1.80(−2) 5.65(−2) 1.51(−1)

Dxmax 8.23(0) 6.47(0) 3.61(0) 1.53(0) 1.06(0) 8.33(−1) 7.79(−1) 8.24(−1) 9.62(−1) 1.96(0) 3.09(0)

Dxrms 7.09(−1) 6.10(−2) 3.71(−1) 1.84(−1) 1.62(−1) 1.59(−1) 1.63(−1) 1.69(−1) 2.13(−1) 5.90(−1) 9.95(−1)

cond 1.63(+4) 1.21(+4) 4.37(+3) 1.26(+3) 9.08(+2) 7.83(+2) 7.23(+2) 6.89(+2) 6.44(+2) 1.60(+3) 1.14(+6)

The minimal RMS error occurs for λ between .001 and .002. Note that the condition numbers of the matrices are lowest for values of λ that produce good fits. Example 7.27. Graph the RMS errors obtained for the fitting problem in Example 7.26 for values of λ in the interval [0, .006]. Discussion: We use the script Bpenlsq15g. It computes the RMS error for a set of 21 equally spaced values of λ in [0, .006]. These error values are then interpolated using the not-a-knot cubic spline of section 1.4.3. The plot is shown in Figure 7.11. It shows that the minimal RMS error occurs for λ ≈ .0015. For a fixed λ, the penalized least-squares method defines a linear operator I mapping C() into S(). Due to the nature of the penalty term, it is exact for linear polynomials, i.e., I p = p for all p ∈ P1 . However, I does not fit quadratic polynomials exactly, as is easily checked numerically.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

242

Chapter 7. Scattered Data Fitting

7.9.2 Penalized least-squares fitting with S92,4 () In this section we show that doing penalized least-squares with the space S92,4 () gives very similar results to those obtained with S51,2 (). Example 7.28. Fit Franke’s function (2.20) on the unit square with noisy data based on a uniform grid of 1089 points in the unit square. Use the spline space S92,4 (), where  is a type-1 triangulation with 25 vertices on a uniform grid. Discussion: We make use of the script Bpenslq29, and read the triangulation from type1.25 and the data from gridpts.1089. We add noise to the samples in the same way as in Example 7.26 with ε = .1. The following table gives the max and RMS errors, along with the condition numbers of the matrix H = G + λM in Theorem 7.25. λ 0 .0001 .0005 .001 .0015 .002 .0025 .003 .005 .01 .05 .1 1 10

emax 2.85(−1) 9.06(−2) 6.21(−2) 5.45(−2) 5.03(−2) 4.74(−2) 4.55(−2) 4.56(−2) 5.45(−2) 6.98(−2) 1.68(−1) 2.25(−1) 3.88(−1) 4.67(−1)

rms 4.72(−2) 2.08(−2) 1.37(−2) 1.19(−2) 1.14(−2) 1.13(−2) 1.14(−2) 1.17(−2) 1.33(−2) 1.79(−2) 4.14(−2) 5.65(−2) 1.09(−1) 1.39(−1)

Dxmax 7.27(1) 4.63(0) 2.36(0) 1.64(0) 1.30(0) 1.09(0) 9.51(−1) 8.47(−1) 8.01(−1) 9.52(−1) 1.50(0) 1.95(0) 3.01(0) 3.13(0)

Dxrms 5.76(0) 6.42(−1) 3.09(−1) 2.26(−1) 1.93(−1) 1.78(−1) 1.70(−1) 1.66(−1) 1.71(−1) 2.12(−1) 4.49(−1) 5.90(−1) 9.10(−1) 9.80(−1)

cond 1.04(+9) 1.83(+7) 6.00(+6) 4.26(+6) 3.66(+6) 3.36(+6) 3.18(+6) 3.06(+6) 2.82(+6) 2.65(+6) 2.51(+6) 2.49(+6) 2.70(+6) 2.46(+7)

The choice λ = 0 gives the least-squares fit of the noisy data from S92,4 (). A plot of it and its x-derivative is shown in the top row of Figure 7.12. The minimal RMS error occurs for λ around .002, but the spline and its x-derivative still have some small oscillations; see the middle row of Figure 7.12. By increasing λ to .01, we get the smoother surface shown in the last row of Figure 7.12 with only a very minor loss in accuracy. Note that the condition numbers of the matrices improve with increasing values of λ, up to λ = 1. As λ increases beyond 1, the surface approaches a linear polynomial, as is to be expected from the nature of the energy functional. Example 7.29. Graph the RMS errors obtained for the fitting problem in Example 7.28 for values of λ in the interval [0, .01]. Discussion: We use the script Bpenlsq29g. It computes the RMS error for a set of 21 equally spaced values of λ in [0, .01]. We then interpolate these error values using a not-aknot cubic spline. The plot is shown in Figure 7.13. It shows that the minimal RMS error occurs for λ ≈ .002.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.10. Nonscale invariance of penalized least-squares fitting

1.2

60

0

-60

1

1

0.5

243

1

1

0.5

0 0

0 0

3

1.2

-2 0 1

1

0.5

1

1

0.5

0 0

0 0

1.2 2

-2 0 1

1

0.5 0 0

1

1

0.5 0 0

Figure 7.12. Penalized least-squares fits and their x-derivatives based on noisy samples of Franke’s function at 1089 grid points in the unit square, using the spline space S92,4 () on a type-1 triangulation with vertices on a 5 × 5 grid. The plots correspond to values of λ equal to 0, .002, and .01 (top to bottom).

7.10 Nonscale invariance of penalized least-squares fitting In section 7.5 we saw that all of the least-squares methods discussed in this chapter are scale invariant. This is no longer the case for penalized least-squares fitting. The addition of the energy term destroys this property. In fact, our penalized least-squares methods are not even equi-scale invariant. Nevertheless, the shapes of the splines obtained with scaling are quite similar to those obtained without scaling. Example 7.30. Explore the scale invariance of penalized least-squares fitting with S51,2 (). Discussion: We make use of the script Bscalepenlsq15. For this test we choose the triangulation tri36 shown in Figure 6.1, and sample Franke’s function (2.20) at 1089 grid points in the unit square. These can be read in from the file gridpts.1089. For

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

244

Chapter 7. Scattered Data Fitting 0.05

0.04

0.03

0.02

0.01 0

0.002

0.004

0.006

0.008

0.01

Figure 7.13. Graph of the RMS error as a function of λ when fitting noisy samples of Franke’s function on a grid of 1089 points using the spline space S92,4 (). 1.2

1.2

0 1

1

0.5

0.5 0 0

0 2

1.5

1

0.5

0 0

0.5

1

1.5

2

Figure 7.14. Left: The penalized least-squares spline in the space S51,2 () on the triangulation in Figure 6.1 based on noisy samples of Franke’s function at 1089 points on a uniform grid in the unit square. Right: The spline obtained for the scaled Franke’s function with the triangulation and data scaled to the rectangle [0, 2] × [0, 2].

this experiment we take ε = .1, and choose λ = .001. In Figure 7.14 we compare the spline obtained with α = β = 1 with that corresponding to α = β = 2. As we can see, the shape of the splines are different, although the max and RMS errors are not very different. With α = β = 1, they are 4.99(−2) and 1.14(−2), respectively, while for α = β = 5, they are 8.91(−2) and 1.91(−2). We get similar results for penalized least-squares fitting using the space S92,4 ().

7.11 Remarks Remark 7.1. We have formulated the least-square problem (Problem 7.1) with weights, and all of the functions in SplinePak for computing least-squares splines in this chapter allow for general positive weights. However, in the vast majority of practical problems, we will choose all of the weights to be one. Remark 7.2. In doing weighted least-squares, if we include all the vertices in the set of sample points and make the associated weights very large, we will get a least-squares fit which nearly interpolates at the vertices.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

7.11. Remarks

245

Remark 7.3. The condition that the observation matrix O in (7.3) be of full rank N is equivalent to the existence of integers 1 ≤ ν1 < · · · < ν N ≤ n d such that the submatrix [φ j (ξνi , ηνi )]i,Nj =1 is nonsingular. The spline spaces we have used in this chapter to solve the least-squares problem all have locally supported bases, and so this condition requires not only that there be enough data points, but that they be reasonably well distributed across the triangulation. Remark 7.4. Our function lsqbiv computes the Gram matrix G appearing in (7.4) by the accumulation process described in Algorithm 7.3. This allows us to work with sparse matrices. Alternatively, we could compute G as O T O, where O is the observation matrix. This would be a faster way to find G, but uses full matrices. Remark 7.5. Given an overdetermined linear system Oc = z, writing O\z in MATLAB produces a vector c that minimizes (Oc − z)T (Oc − z). Thus, the least-squares problem discussed in section 7.1 can be solved without constructing the Gram matrix. This has some advantages, since it is well known that Gram matrices tend to be very badly conditioned. Generally the condition number of O (see Remark 7.6) is much smaller than that of the Gram matrix. On the other hand, G is a matrix of size N × N, whereas O is a matrix of size n d × N, where n d can be much larger than N. Thus, directly solving for c with the observation equation can actually be much slower than using the Gram matrix, especially for large n d . Since MATLAB is capable of solving linear systems with very large condition numbers, we have used the normal equations in our function lsqbiv. Remark 7.6. The condition number of a rectangular matrix A is defined to be the ratio of the maximum singular value to the minimum singular value, and this is what MATLAB returns when you ask for cond(A). Remark 7.7. For some of the larger examples in this chapter, the computation of condition numbers can be quite slow. We generally have not reported these times, but the user may want to comment out this computation in some of our scripts when working on larger problems. Remark 7.8. It is clear from the formulation of the least-squares fitting problem that if we are using a space S of splines of degree d which contains polynomials up to degree d, then if the function f being fit is such a polynomial, we should get an exact fit. It is easy to check that this holds for all of the spaces discussed in sections 7.2–7.4. All that is needed is to replace Franke’s function in the various scripts by a polynomial of the degree to be checked. Remark 7.9. In formulating the least-squares fitting problem, we have two different sets of points: 1) the set {(x i , yi )}ni=1 of vertices of the spline space being used, and 2) the set nd {(ξν , ην )}ν=1 of sample points, where n d ≥ n. These sets can be completely different, but often in practice, the vertices will be data points. Remark 7.10. It is also possible to do a kind of Hermite least-squares in which we fit not only function values, but also derivatives at given data points. Remark 7.11. The energy expression used in section 7.8 for penalized least-squares is based on second derivatives, and essentially measures the potential energy stored in a deformed shell. It is possible to define other measures of energy, for example using higher derivatives.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

246

Chapter 7. Scattered Data Fitting

Remark 7.12. Error bounds for fitting functions using the penalized least-squares method with splines have been obtained in [GolS02]. Remark 7.13. For convenience, in all of the examples in this chapter we have worked with triangulations covering the unit square or a rectangle. However, all of our least-squares routines work equally well for arbitrary shaped domains, with or without holes; see section 6.10 for some examples with scattered data interpolation. As before, for when working with domains with holes, it is advisable to use valspgridh and valspdergridh instead of valspgrid and valspdergrid to avoid problems with the triangle search. Remark 7.14. As was the case for scattered data interpolation (see section 6.13), sometimes we can get better least-squares fits with splines if we use a non-Delaunay triangulation. One way to get better fits is to swap edges using a least-squares fit criterion; see section 3.12 and [QuaS90, Rip92]. Simulated annealing can be used to avoid getting stuck in a local minimum; see, e.g., [BasS91, Schum93, HahK97]. Remark 7.15. Least-squares fitting by splines has found application in multivariate regression, but it seems only using tensor-product splines. See [Koh97, Koh98] as well as the book [[GreeS94]] and references therein. Remark 7.16. It is of course possible to do least-squares fitting of scattered data with radial basis functions. A key problem in this case is to construct an algorithm for choosing the centers, given the sample values. Here are a few references: [McMaF92, Buh93, SivW93, FraHN94].

7.12 Historical notes Least-squares is a natural approach to fitting scattered data with splines on triangulations, but there is not much literature on it, perhaps because the standard approach requires explicit use of basis functions. Using the Bernstein–Bézier approach, we have shown how to compute least-squares fits directly with the B-coefficients, even for spline spaces with higher order smoothness. There is also little in the literature on error bounds. The results quoted here come from [GolS02]. Our results on penalized least-squares using splines on triangulations are drawn from [GolS90, GolS02b].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 8

Shape Control

In some scattered data interpolation and fitting problems, it may be important that the computed surface have some particular shape property such as nonnegativity or positivity, monotonicity in some directions, or convexity. In this chapter we show how to compute splines with each of these properties.

8.1 Nonnegative interpolation Problem 8.1. Given a set of scattered data points {vi := (x i , yi )}ni=1 in a domain  ⊂ R2 and corresponding nonnegative data values {z i }ni=1 , find a function s defined on  such that s(x i , yi ) = z i for i = 1, . . . , n, and s(x, y) ≥ 0 for all (x, y) ∈ . There is a considerable literature on this problem. Here we consider just two of the methods.

8.1.1 Nonnegative interpolation with the space S10 () The following lemma is obvious. Lemma 8.2. Let  be a triangulation with vertices {(x i , yi )}ni=1 , and suppose we are given nonnegative values {z i }ni=1 . Let s be the spline in S10 () that interpolates these values in the sense that s(x i , yi ) = z i for i = 1, . . ., n. Then s is nonnegative on . This result provides a simple way to solve Problem 8.1 using the space S10 (), since the interpolant is automatically nonnegative if the data values are. For test purposes, let f (x, y) = [1 + 4r (x, y)][1 − 2r (x, y)]2+,

(8.1)

where r (x, y) = [(x − .5)2 + (y − .5)2]1/2 , and the subscript [ · ]+ means that the expression inside the brackets is taken to be zero whenever it is negative. For convenience, we have programmed this function as b = hill(x,y) 247

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

248

Chapter 8. Shape Control 1

0.9

0 1

0 1

1

0.5

1

0.5

0.5 0 0

0.5 0 0

Figure 8.1. A plot of the nonnegative function (8.1), and the C 0 linear spline interpolating it on the triangulation tri36 in Figure 6.1 (left).

The input to hill is a pair of real numbers x and y giving the Cartesian coordinates of a point in the plane. The output is a vector b with three components containing the value, x-derivative, and y-derivative of the function (8.1) at (x, y). Note that unlike some of our other test functions such as franke2, this function does not work for vector inputs. Example 8.3. Let  be the triangulation tri36 shown in Figure 6.1 (left). Find the spline in S10 () that interpolates the function (8.1) at the 36 vertices of this triangulation. Discussion: We make use of the script Bpos01, and read the triangulation from the file tri36.dat. The values to be interpolated are computed with a call on our function hill. We show a plot of this function in Figure 8.1 (left). By construction, it is a radial function with support on the disk of radius .5 around the point (.5, .5). It is clearly C 1 , and is nonnegative on the unit square. By Lemma 8.2, the C 0 linear interpolating spline s in S10 () must also be nonnegative. It is shown in Figure 8.1 (right). For comparison purposes, we note that the max and RMS errors on a 51 × 51 grid are 2.74(−1) and 6.74(−2), respectively. There are two drawbacks to using S10 () for constructing nonnegative spline interpolants: 1) they are only C 0 , and 2) they are not very accurate. We now describe a method to compute a nonnegative interpolating spline using the macro-element space S21 ( P S ).

8.1.2 Nonnegative interpolation with the space S21 ( P S ) We recall from Theorem 5.1 that given any triangulation  with vertices at the points y {(x i , yi )}ni=1 and any real numbers {z i , z ix , z i }ni=1 , there exists a unique spline s ∈ S21 ( P S ) such that s(x i , yi ) = z i , Dx s(x i , yi ) = z ix , i = 1, . . . , n. (8.2) y

D y s(x i , yi ) = z i , In general, an interpolating spline s constructed in this way will not be nonnegative, even if all of the z i are nonnegative. There have to be some restrictions on the values of the y gradient values {z ix , z i }ni=1 . Indeed, even if we sample the function values and gradients from a nonnegative function, there is no guarantee that the interpolating spline will be

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.1. Nonnegative interpolation

249

nonnegative; see Example 8.7 below. Here is one choice of gradients that will always lead to a nonnegative spline. Theorem 8.4. Suppose {z i }ni=1 are such that z i ≥ 0 for all 1 ≤ i ≤ n, and let y

z ix = z i = 0,

i = 1, . . . , n.

(8.3)

Then the associated interpolating spline in S21 ( P S ) is nonnegative on . Proof. By the formulae for the B-coefficients of the C 1 Powell–Sabin macro-element given in section 5.2, we see that if (8.3) is satisfied, all B-coefficients of the interpolating spline s are nonnegative. This immediately implies s(x, y) ≥ 0 for all (x, y) ∈ . This result shows that we can get a nonnegative C 1 Powell–Sabin interpolating spline by setting the gradients to zero at each of the data points. However, in general, this causes undesirable flat spots at every data point, and the spline will exhibit considerable oscillation; see the spline shown on the top left in Figure 8.2. We can avoid this problem by making a better choice of gradients. y Suppose we are given either true or estimated gradients (z ix , z i ) at every data point (x i , yi ). The following algorithm adjusts these gradients so that the corresponding Powell– Sabin Hermite interpolating spline interpolates the given values at the data points and is i also nonnegative, i.e, solves Problem 8.1. For each vertex vi of , let {ei j := vi , vi j }nj =1 1

0.9

0 0 1

1

0.5

1

1

0.5

0.5 0 0

0.5 0 0

1

1

0 1

1

0.5

0.5 0 0

0 1

1

0.5

0.5 0 0

Figure 8.2. C 1 Powell–Sabin interpolants of the nonnegative function (8.1) on the triangulation tri36 shown in Figure 8.3 (left). The top row shows the splines with zero gradients on the left, and true gradients on the right. The second row shows the splines with estimated gradients on the left, and with adjusted estimated gradients on the right.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

250

Chapter 8. Shape Control

be the set of edges of  P S attached to vi . Note that vi j will either lie inside of a triangle of , or in the interior of an edge of . Suppose the Cartesian coordinates of vi j are (x i j , yi j ), y and let di j := (x i j − x i )z ix + (yi j − yi )z i . Algorithm 8.5. For each i = 1, . . ., n: 1) set γi = 1, 2) for j = 1, . . ., n i : if di j < 0, set γi = min{γi , −2z i /di j }, y

y

3) set z˜ ix = γi z ix and z˜ i = γi z i . It is easy to see that the {γi }ni=1 obtained by this algorithm satisfy 0 ≤ γi ≤ 1 for all i . The following result was established in [SchumS10]. Theorem 8.6. Given a set of scattered data points {vi }ni=1 in R2 , let  be a triangulation with vertices, at these points, and let  P S be the associated Powell–Sabin refinement. Supy y pose we are given {z i , z ix , z i }ni=1 with z i ≥ 0 for i = 1, . . . , n. Let {˜z ix , z˜ i }ni=1 be the adjusted 1 gradients produced by Algorithm 8.5. Then the spline s ∈ S2 ( P S ) that interpolates this adjusted data solves Problem 8.1. Here is our code for Algorithm 8.5. [zx,zy] = adjgradpspos(x,y,z,ie1,ie2,zx,zy) The input is the usual information about the triangulation, together with values z and derivatives zx and zy. The output consists of the adjusted values of these derivatives. To see how it performs, we look at a simple example. Example 8.7. Compute a C 1 quadratic Powell–Sabin spline that interpolates the function (8.1) at the vertices of the triangulation shown in Figure 6.1 (left). Discussion: We make use of the script Bposps, and read the triangulation from the file tri36.dat. This script has the options of using zero gradients, true gradients, or estimated gradients. It also has the option of adjusting the gradients with adjgradpspos. The B-coefficients of the spline are computed with a call on our function ps discussed in section 5.2. First we compute the Powell–Sabin interpolant based on zero gradients. The corresponding Powell–Sabin spline interpolant is shown on the top left in Figure 8.2. It is nonnegative, but has very poor shape properties due to the flat spots induced by the zero gradients. The max and RMS errors are 3.06(−1) and 6.63(−2). Next we compute the Powell–Sabin interpolant using the true gradients of f without any adjustment. The resulting spline is shown on the top right in Figure 8.2. It is a very good fit of f , but is not quite nonnegative. Its max and RMS errors are 5.59(−2) and 1.22(−2), and its minimum on a 51 × 51 grid is −1.81(−2). Next we choose the option of using estimated gradients at the vertices using the function derestlsq described in section 6.6.3. This gives the spline shown on the bottom left in the figure. Its max and RMS errors are 1.30(−1) and 4.09(−2), and its minimum on the grid is −1.10(−1). Finally, we run the script with the option of adjusted estimated derivatives as produced by adjgradpspos. This gives the spline shown on the bottom right in the figure. It is

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.2. Nonnegative least-squares

251

nonnegative and the max and RMS errors for this spline on a 51 × 51 grid are 1.16(−1) and 2.31(−2), respectively. Note that this spline is calculated from the same scattered data as the C 0 nonnegative linear spline interpolant in Example 8.3, and is not only more accurate, but has much better overall shape properties.

8.2 Nonnegative least-squares As we know from the discussion in section 7.1, if the number of data points is large, or if the sample values are noisy, then interpolation may not be appropriate. In this case, we d can turn to least-squares fits. Suppose we are given samples {z ν }nν=1 of a bivariate function nd f at n d points {(ξν , ην )}ν=1 in a domain . Let  be a triangulation of  with vertices {(x i , yi )}ni=1 , and suppose S() is a subspace of Sd0 (). Then as discussed in section 7.1, one way to approximate f is to find the spline in S() that best fits the data in the leastnd are nonnegative, the squares sense. However, in general, even if the data values {z ν }ν=1 least-squares spline fit may not be. We will have to make some adjustment to the spline to make it nonnegative. In this section we examine two methods for doing this.

8.2.1 Nonnegative least-squares with S10 () N Suppose s ∈ S10 () is a least-squares fit to some data. Let {ci }i=1 be its set of B-coefficients, where N is the number of vertices in . Then in view of Lemma 8.2, to turn s into a nonnegative spline all we have to do is replace all negative values of ci by zero. In general, this changes only a few of the coefficients, and the resulting nonnegative spline will be close to the original least-squares spline. Here is an example to show how this works.

Example 8.8. Fit the hill function (8.1) on the unit square based on samples at 1000 random points in the unit square. Use a C 0 linear spline defined on the triangulation tri36 shown in Figure 6.1. Discussion: We use the script Bposlsq01, where the triangulation is read from the file tri36.dat. We read the random points from the file randpts.dat with a call on randpts. A plot of the data points imposed on the triangulation is shown in Figure 8.3. The least-squares fit using C 0 linear splines is shown on the top left in Figure 8.4, while its nonnegative counterpart is shown on the right. The plots in the bottom row of the figure are rotated to show clearly that the one on the left takes negative values, while the one on

Figure 8.3. The triangulation tri36 with 1000 random points in the square.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

252

Chapter 8. Shape Control 1

1

0 1

1

0.5

0 1

1

0.5

0.5 0 0

0.5 0 0

1 1

0 0 0

0.5

1

0

0.5

1

Figure 8.4. C 0 linear spline fits to the nonnegative function (8.1) on the triangulation tri36 based on 1000 random points in the unit square. The top row shows the least-squares spline, together with its nonnegative counterpart. The bottom row shows the same splines from a different angle to emphasize that the one on the left has negative values, while the one on the right does not.

the right is nonnegative. The max and RMS errors for the least-squares spline are 1.81(−1) and 3.86(−2), respectively. This spline is not quite nonnegative, since it has a minimum value on a 51 × 51 grid of approximately −9.49(−2). The nonnegative spline has max and RMS errors of 1.81(−1) and 4.62(−2), respectively. Thus, with a small loss in accuracy, we were able to get a nonnegative spline. We repeated the example where now the data is corrupted by random noise. As in section 7.7 this noise was generated by adding random values εri to the sample values, where the {ri }1000 i=1 are read from our file noise.dat. Here we take ε = .02. The max and RMS errors for the least-squares spline are 1.82(−1) and 3.87(−2), respectively. As before, this spline is not nonnegative, since it has a minimum value of approximately −9.49(−2). The nonnegative spline has max and RMS errors of 1.82(−1) and 4.65(−2), respectively. Thus, with a small loss in accuracy, we were again able to get a nonnegative spline.

8.2.2 Nonnegative least-squares with S21 ( P S ) The adjustment process of Algorithm 8.5 can be used to construct nonnegative splines for least-squares data fitting using the space S21 ( P S ). Suppose we are given samples nd nd of a bivariate function f at n d points {(ξν , ην )}ν=1 in a domain . Let  be a {z ν }ν=1 n triangulation of  with vertices {(x i , yi )}i=1 , and suppose  P S is the associated Powell–

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.2. Nonnegative least-squares

253

Sabin refinement. To construct a nonnegative spline sˆ in S21 ( P S ) fitting the data, we proceed in two steps. In the first step we find a spline s ∈ S21 ( P S ) that minimizes F(s) :=

nd 

wν [s(ξν , ην ) − z ν ]2 .

ν=1

Next, we set all negative B-coefficients of s to zero, and then calculate the gradients at the vertices of  for the resulting spline. Finally, we use the function adjgradpspos discussed in section 8.1.2 to adjust the gradients to get a nonnegative spline in S21 ( P S ). Here are the details. Step 1: To calculate a least-squares fit from S21 ( P S ), we can proceed as follows; cf. our script Blsqps. First we call the function nmdsps described in section 4.14.1 to perform the refinement of  and find the transformation matrix A associated with the space. Then the vector c of B-coefficients of the least-squares spline can be computed with a call on the function lsqbiv described in section 7.1.2. Step 2: Set c˜i = min(0, ci ) for i = 1, . . ., n, where n is the number of vertices in the original triangulation . Next, compute the gradients of the corresponding spline s˜ at the vertices of . For this purpose, we have written the function [zx,zy] = gradps(no,nto,x,y,ie1o,ie2o,eadjo,adjstarto,cw) Here no,nto and the other parameters ending in o pertain to the original triangulation . The vectors x,y contain the Cartesian coordinates of the vertices of the Powell–Sabin refinement, and the vector cw contains the B-coefficients of the Powell–Sabin spline whose gradients are being calculated. Once we have the gradients, we can apply the function adjgradpspos of section 8.1.2 to adjust these gradient values. Now we compute the B-coefficients of our nonnegative spline using Lemma 4.26. Explicitly, they are given by y y cˆ = A c, ˜ where c˜ := (c˜1 , . . . , c˜no , z˜ 1x , . . . , z˜ nx o , z˜ 1 , . . . , z˜ no ) is the nodal data formed with the adjusted gradient values, and A is the transformation matrix computed in Step 1. Example 8.9. Fit the hill function (8.1) on the unit square based on samples at 1000 random points in the unit square. Use a C 1 quadratic spline defined on the Powell–Sabin refinement of the triangulation tri36.dat shown in Figure 6.1 (left). Discussion: We make use of the script Bposlsqps, and read the triangulation from the file tri36.dat. The random data points are read from the file randxy.dat. The unadjusted least-squares C 1 Powell–Sabin spline is shown on the top left in Figure 8.5. Its nonnegative counterpart is shown on the right. The max and RMS errors for the least-squares spline are 3.91(−2) and 4.57(−3), respectively. This spline is not quite nonnegative, and has a minimum value on a 51 × 51 grid of approximately −1.08(−2). The nonnegative spline has max and RMS errors of 3.91(−2) and 1.28(−2), respectively. Thus, with a small loss in accuracy, we were able to get a truly nonnegative spline. We repeated the example where the data is corrupted by random noise. As in Example 8.8, this noise was generated by adding random values εri to the sample values, where the {ri }1000 i=1 are read from our file noise.dat. Here we use ε = .02. The least-squares fit is shown on the bottom left in Figure 8.5, while its nonnegative counterpart is shown on the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

254

Chapter 8. Shape Control 1

1

0 1

1

0.5

0 1

1

0.5

0.5 0 0

0.5 0 0

1

1

0 1

1

0.5

0.5 0 0

0 1

1

0.5

0.5 0 0

Figure 8.5. C 1 Powell–Sabin fits of the nonnegative function (8.1) on the triangulation tri36 based on 1000 random points in the unit square. The top row shows the leastsquares spline together with its nonnegative counterpart. The splines in the bottom row are the result of adding noise of size ε = .02 to the random data. Again, the least-squares spline is on the left, and the nonnegative spline is on the right.

right. The max and RMS errors for the least-squares spline are 5.26(−2) and 6.88(−3), respectively. This spline is not quite nonnegative, and has a minimum value of approximately −3.02(−2). The nonnegative spline has max and RMS errors of 4.52(−2) and 1.49(−2), respectively. Thus, with a small loss in RMS accuracy (and a slight improvement in the maximum error), we were again able to get a spline that is nonnegative.

8.3 Monotone interpolation In this section we discuss methods to interpolate prescribed values at scattered data points with a monotone increasing spline. Before starting, we should explain what we mean by a monotone bivariate function. Definition 8.10. Suppose f is a continuous function defined on a domain . Then we say that f is monotone, provided that f (x 1 , y1 ) ≤ f (x 2 , y2 ) for any pair of points (x 1 , y1 ) and (x 2 , y2 ) in  with x 2 ≥ x 1 and y2 ≥ y1 . If f is a C 1 function, then this property is the same as saying that for all direction vectors u pointing into the first quadrant, the corresponding directional derivative Du f is nonnegative at all points in .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

255

Lemma 8.11. Suppose f is a C 1 function defined on a domain , and suppose the derivatives Dx f and D y f are both nonnegative for all points in . Then f is monotone. Proof. Let u 1 := (1, 0) and u 2 := (0, 1) be the unit vectors pointing in the directions of the x- and y-axis, respectively, Suppose u = a1 u 1 + a2 u 2 with nonnegative a1 and a2 . This vector points into the first quadrant, and by the hypotheses, Du f = a1 Du 1 + a2 Du 2 will be nonnegative at all points in , which means that f is monotone. This lemma can be used to check whether a C 1 spline is monotone or not. It remains valid for splines that are only continuous if we ignore points that lie on the edges of the triangulation. The first quadrant can be considered as a cone. Definition 8.10 can be generalized to general cones, and Lemma 8.11 also holds in this case; see Remark 8.5. We first discuss the construction of monotone splines in the case where the data points lie on a grid. The more general case of scattered points is treated in section 8.3.2.

8.3.1 Monotone interpolation of gridded data ˜ and suppose that the data points In this section we work on a rectangle R := [a, b] × [a, ˜ b], lie on the rectangular grid # $n x ,n y G := (x i , y j ) i=1, (8.4) j =1 defined by the sets of points a = x 1 < · · · < x n x = b, ˜ a˜ = y1 < · · · < yn y = b. n ,n

Now suppose {z i j }i,xj =1y are given real numbers that are consistent with a monotone interpolant, i.e., for each 1 ≤ i ≤ n x , the values z i1 , . . . , z i,n y are monotone increasing, and for each 1 ≤ j ≤ n y , the values z 1 j , . . . , z n x , j are monotone increasing. Problem 8.12. Find a spline s defined on the rectangle R such that s(x i , y j ) = z i j ,

1 ≤ i ≤ nx , 1 ≤ j ≤ n y ,

(8.5)

and Dx s(x, y) and D y s(x, y) are both nonnegative for all (x, y) ∈ R. We introduce the following function for testing various monotone spline methods: 2 1 (8.6) f (x, y) = [1 + 2e−3(9r−6.7)]− 2 , r = x 2 + y 2 . This function is monotone on the unit square; see the plot on the top left in Figure 8.6. For convenience, we have programmed this function as val = sigmoid(x,y) The input to sigmoid can be a pair of real numbers, or vectors giving the Cartesian coordinates of a set of points in the plane. The output is either a single value, or a vector of the values of (8.6) at the input points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

256

Chapter 8. Shape Control

1

1

0 1

1

0.5

0 1

1

0.5

0.5 0 0

0.5 0 0

1

4 3 2 1

0 1

1

0.5

0.5

0 1

1

0.5

0 0

0.5 0 0

Figure 8.6. Top: A plot of the monotone function (8.6) on the unit square, and the C 0 linear spline interpolating it at the 25 vertices of the type-1 triangulation on a 5 × 5 grid. Bottom: the interpolant for a 9 × 9 grid, and a plot of its x-derivative.

8.3.1.1 Monotone interpolation of gridded data with S10 ()

The following theorem provides a simple approach to solving Problem 8.12. Theorem 8.13. Let  be the type-1 triangulation obtained from the grid G by inserting the northeast diagonal in each subrectangle. Then there exists a unique C 0 linear spline s ∈ S10 () that interpolates the data as in (8.5). Moreover, it is monotone. Proof. Let T be some triangle in . Then Dx s|T and D y s|T are both constant on T , and it follows from the assumption that the data values {z i j } are consistent with monotonicity that both of these derivatives are nonnegative on T , and so s is monotone on T . But then since s is continuous, we conclude that s is monotone on all of the rectangle R. Example 8.14. Interpolate the monotone function (8.6) on the unit square based on samples on a rectangular grid using the space S10 (), where  is the type-1 triangulation with vertices at the grid points. Discussion: We make use of the script Bmon01. First we try a 5 × 5 grid, where the corresponding type-1 triangulation can be read in from the file type1.25. In this case, we get the spline shown on the top right in Figure 8.6. Next we try a 9 × 9 grid, where the type-1 triangulation can be read in from the data file type1.81. The interpolating

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

257

spline in this case is shown on the bottom left in the figure. For later comparison purposes, we note that the max and RMS errors on a 51 × 51 grid of this spline are 1.29(−1) and 3.08(−2), respectively. To check the monotonicity of these splines, we can plot their x- and y-derivatives. The x-derivative of the spline on the bottom-left is shown on the bottom right. It is clearly nonnegative. 8.3.1.2 Monotone interpolation of gridded data with C 1 cubic splines

In this section we describe a method for interpolating gridded data based on a special space of C 1 cubic splines. Given a grid G as in (8.4), let  be the type-2 triangulation obtained by drawing in both diagonals in each subrectangle [x i , x i+1 ] × [y j , y j +1]. Let E be the set of horizontal and vertical edges of . We will construct our interpolating spline in the following space: (1) S˜31 () := {s ∈ S31 () : De s ∈ P1 for each e ∈ E},

(8.7)

(1)

where P1 is the space of univariate linear polynomials, and for each edge e ∈ E,  Dx , e is vertical, De := D y , e is horizontal. y n ,n

x y Theorem 8.15. Given real numbers {z i j , z ixj , z i j }i=1, j =1 , there exists a unique spline s ∈ 1 ˜ S3 () such that

y

Dx s(x i , y j ) = z ixj ,

s(x i , y j ) = z i j ,

D y s(x i , y j ) = z i j

(8.8)

for all 1 ≤ i ≤ n x and 1 ≤ j ≤ n y . The space S˜31 () is a macro-element space since the spline s in Theorem 8.15 can be computed one rectangle at a time. Indeed, consider the rectangle [x i , x i+1 ] × [y j , y j +1 ], and suppose the B-coefficients of s are numbered as in Figure 8.7. Let h ix := x i+1 − x i for all c10

c4 c11 c12

c16

c24

c15 c8

c23 c22

c21

c18

c7

c14

c17 c5

c3

c19 c25

c20 c13

c1

c9

c6

c2

Figure 8.7. Coefficients of a C 1 cubic spline on a single macro rectangle.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

258

Chapter 8. Shape Control y

1 ≤ i ≤ n x − 1, and let h j := y j +1 − y j for all 1 ≤ j ≤ n y − 1. Then (see Theorem 6 in [HanS97]), c1 = z i j , c5 = c7 = c9 = c11 =

c2 = z i+1, j ,

c3 = z i+1, j +1 , c4 = z i, j +1 , x x x z i j + h i z i j /3, c6 = z i+1, j − h ix z i+1, j /3, y y y y z i+1, j + h j z i+1, j /3, c8 = z i+1, j +1 − h j z i+1, j +1 /3, x x x z i+1, j +1 − h ix z i+1, j +1 /3, c10 = z i, j +1 + h i z i, j +1 /3, y y y y z i, j +1 − h j z i, j +1 /3, c12 = z i j + h j z i j /3,

c13 = (c5 + c12)/2,

c14 = (c6 + c7 )/2,

c15 = (c8 + c9 )/2,

c16 = (c10 + c11)/2,

c17 = (2c13 + 2c14 + c5 + c6 − c1 − c2 )/4, c18 = (2c14 + 2c15 + c7 + c8 − c2 − c3 )/4, c19 = (2c15 + 2c16 + c9 + c10 − c3 − c4 )/4, c20 = (2c16 + 2c13 + c11 + c12 − c4 − c1)/4, c21 = (c17 + c20 )/2,

c22 = (c17 + c18)/2,

c23 = (c18 + c19 )/2,

c24 = (c19 + c20)/2,

c25 = (c21 + c23 )/2 = (c22 + c24)/2. We have implemented this interpolation method in the function c = cubsib(x,y,z,zx,zy,e1,e2,e3) Here the vectors x and y define the grid lines, while z, zx, zy are matrices containing the values and gradients at the grid points. The vectors e1,e2,e3 are the lists of edges of the triangles in the type-2 triangulation . To apply Theorem 8.15 to solve the monotone interpolation problem (Problem 8.12), y n x ,n y we need to choose values for the gradients {z ixj , z i j }i=1, j =1 in such a way that the spline s in the theorem is monotone on the rectangle R. By examining one grid line at a time, it is clear that a necessary condition for monotonicity is that z ixj ≥ 0 and

y

zi j ≥ 0

(8.9)

for all 1 ≤ i ≤ n x and 1 ≤ j ≤ n y . However, these conditions are not in general sufficient. In this connection, we have the following result; see Theorem 8 in [HanS97]. n ,n

x y Theorem 8.16. Suppose the values {z i j }i=1, j =1 are monotone-consistent, and that we are

y n ,n

x y given {z ixj , z i j }i=1, j =1 satisfying (8.9) such that for all 1 ≤ i ≤ n x − 1 and 1 ≤ j ≤ n y − 1,

x x z ixj + z i+1, j ≤ 5(z i+1, j − z i j )/2h i ,

z ixj x z i+1, j +1

≤ ≤

z i,x j +1 + x z i+1, j+

(8.10)

Ai j / h ix ,

(8.11)

Ai+1, j / h ix ,

(8.12)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

where

259

3 4 y y y Ai j := min 3 (z i, j +1 − z i j )/2, 6 (z i, j +1 − z i j ) − 2h j max[z i j , z i, j +1 ] , y

with h ix := x i+1 − x i and h j := y j +1 − y j . In addition, suppose that similar conditions hold for the y partial derivatives. Then the spline s ∈ S that interpolates as in (8.8) is monotone on the rectangle R. The simplest way to choose gradients satisfying the conditions of Theorem 8.16 is to take them to be zero at all grid points. Example 8.17. Interpolate the monotone function (8.6) on the unit square based on samples on a 9 × 9 rectangular grid using a C 1 cubic spline on the associated type-2 triangulation, and using zero gradients. Discussion: We make use of the script Bmongridhs. It asks the user for values of nx and ny to define the grid. It then creates the values z i j by sampling the test function sigmoid defined in (8.6); see also Figure 8.6. It then sets the gradients at the grid points to zero. The coefficients of the interpolating spline are computed from a call on the function cubsib described above. For nx = ny = 9, the type-2 triangulation of the grid points is shown on the top left in Figure 8.8, and the corresponding monotone C 1 cubic spline interpolating the grid values of the function (8.6) with zero gradients is shown on the top right. It shows significant oscillations due to the flat spots introduced by the zero gradients. This spline is monotone, however, as can be checked by looking at the minimum values for the x-

1

0 1

1

0.5

0.5 0 0

7

7

0

0

1

1

1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 8.8. Top: A type-2 triangulation of the unit square and the monotone C 1 cubic spline interpolating the grid values of the function (8.6) with zero gradients. Bottom: The xand y-derivatives of the spline.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

260

Chapter 8. Shape Control

and y-derivatives. These derivatives are shown in the bottom row of the figure. These plots confirm the oscillatory nature of the interpolating spline. For later comparison, we note that the max and RMS errors on a 51 × 51 grid for this spline fit are 1.07(−1) and 2.77(−2), respectively. To get better results, we need better values for the gradients at the grid points. The following example shows what happens if we take them to be the true gradients of the function (8.6). Example 8.18. Repeat Example 8.17 but using the true gradient values sampled from the sigmoidal function (8.6) at the grid points. Discussion: We again use the script Bmongridhs with nx = ny = 9, but this time we take the true gradients as computed with the function sigmoider. As before, the coefficients of the C 1 cubic interpolating spline are computed from a call on the function cubsib. The minimum values of the x- and y-derivatives are both around −3.71(−2), so the spline s is almost monotone but not monotone. For this spline fit of (8.6), the max and RMS errors on a 51 × 51 grid are 2.24(−2) and 3.84(−3), respectively. The fact that the spline in this example is not monotone means that the gradients used (which were in fact the true gradients of the test function) do not satisfy the sufficient conditions of Theorem 8.16. The following algorithm was proposed in [HanS97] for adjusting the gradients to ensure that they satisfy the sufficient conditions. Let h ix := x i+1 − x i for i = 1, . . . , n x − 1. Algorithm 8.19. Adjust z ixj to get monotonicity 1. Adjust z ixj to satisfy (8.9) for i=1 to nx for j=1 to ny z ixj = max(z ixj , 0) 2. Adjust z ixj to satisfy (8.10) for j=1 to ny for i=1 to nx-1 x x if z ixj + z i+1, j > ri j := 5(z i+1, j − z i j )/2h i then x z ixj = ri j z ixj /(z ixj + z i+1, j) x x x x z i+1, j = ri, j z i+1, j /(z i j + z i+1, j) endif 3. Adjust z ixj to satisfy (8.11) for i=1 to nx-1 for j=ny-1 to 1 step -1 if z ixj > z i,x j +1 + Ai j / h ix then z ixj = z i,x j +1 + Ai j / h ix 4. Adjust z ixj to satisfy (8.12) for i=2 to nx for j=1 to ny-1 x x if z i,x j +1 > z ixj + Ai j / h i−1 then z i,x j +1 = z ixj + Ai j / h i−1

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

261

(0, rij ) x,1 x,1 (zij , zi+1,j ) x,2 x,2 (zij , zi+1,j )

(0, 0)

(rij , 0)

Figure 8.9. The adjustment of Step 2.

All of these adjustments involve reducing the size of gradient values. The adjustment x,1 made in Step 2 is illustrated in Figure 8.9 where the pair (z ix,1 j , z i+1, j ) is radially projected x,2 into the acceptable region to give (z ix,2 j , z i+1, j ). To get gradients that lead to a monotone spline, we must also apply this algorithm to y the values of {z i j }. Since the x- and y-derivatives interact in the steps of the algorithm, it is not immediately clear that at the end they satisfy all of the conditions of Theorem 8.16. However, this is indeed the case as was shown in Theorem 10 of [HanS97]. We have written the following function to carry out this algorithm:

[zx,zy] = hsadj(x,y,z,zx,zy) The input consists of the vectors x,y describing the grid, along with the initial values and gradients at the grid points. The function outputs the adjusted gradients. Example 8.20. Repeat Example 8.18 with true gradient values that have been adjusted according to Algorithm 8.19. Discussion: We can again use the script Bmongridhs, but now choose the option to adjust the true gradients with hsadj. Since the spline from Example 8.18 was almost monotone, these adjusted gradients differ only slightly from the true gradients used there, and the two splines are almost the same. However, now the minimums of both the x- and y-derivatives are both zero, and we have a truly monotone spline fit. We show our monotone C 1 cubic spline fit and its y-derivative in the top row of Figure 8.10. The max and RMS errors on a 51 × 51 grid are now 3.83(−2) and 7.18(−3), respectively. The corresponding errors for both the x- and the y-derivatives are 1.13 and 1.62(−1). These errors are only slightly larger than those in Example 8.18, where the unadjusted gradients were used. In this example we computed gradients from the test function. In practice, gradients will not generally be available, and we will have to estimate them using only the sample values {z i }ni=1 . This can be done with the function derestlsq described in section 6.6 based on local least-squares polynomial fitting. Alternatively, since we are working with gridded data, it can be done with standard finite difference formulae. Here is some code based on standard four point differentiation formulae: [zx,zy] = gradgrid(x,y,z) Here x and y are vectors containing the coordinates of the grid lines, and z is a matrix of values at the grid points. The resulting gradient values will usually not satisfy the suffi-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

262

Chapter 8. Shape Control 6 1

0 1

0 1

1

0.5

1

0.5

0.5

0.5 0 0

0 0

6 5 4 3 2 1 0 1

1

0 1

1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 8.10. Top: the monotone C 1 cubic spline interpolating values of the function (8.6) on the 9 × 9 grid in Figure 8.8 using adjusted true gradients, and the y-derivative of the spline; see Example 8.20. Bottom: the monotone C 1 cubic interpolating spline using adjusted estimated gradients, and its y-derivative; see Example 8.21.

cient conditions of Theorem 8.16, but we can apply our function hsadj based on Algorithm 8.19 to make them do so. Example 8.21. Repeat Example 8.17 using estimated gradients which have been adjusted with Algorithm 8.19. Discussion: We again use the script Bmongridhs, where now we choose the options to estimate the derivatives using gradgrid, and then adjust them with hsadj. This leads to the C 1 cubic monotone spline shown on the bottom in Figure 8.10, along with its yderivative. These plots should be compared with those in Figure 8.8. The max and RMS errors on a 51 × 51 grid are now 4.53(−2) and 1.05(−2), respectively. The corresponding errors for both the x- and the y-derivatives are 1.37 and 2.19(−1). These errors are only slightly larger than those in Example 8.20, where the adjusted true gradients were used. To conclude this section, we examine the rate of convergence for fitting a given monotone function based on samples on a sequence of nested grids, and using adjusted estimated derivatives. The method reproduces quadratics, but due to the use of linear cross derivatives in the spline space (8.7), it does not reproduce cubics. Thus, although it is based on cubic splines, we cannot expect the usual order 4 convergence. However, it is shown in Theorem 14 of [HanS97] that if the estimated gradients have order 2 accuracy, then so does the monotone spline. Here is an experiment to see what happens in practice.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

263

Example 8.22. Fit the sigmoidal function (8.6) on a sequence of nested grids defined on the unit square using C 1 cubic splines on the associated type-2 triangulations, and using estimated gradients which have been adjusted with Algorithm 8.19. Discussion: We use the script Bmongridhs, and work with the nested grids that correspond to the values n := nx = ny = 5, 9, 17, 33, 65. Here is a table of the max and RMS errors: n emax rms ratios 5 1.92(−1) 5.19(−2) 9 4.53(−2) 1.05(−2) 4.24 4.94 17 6.93(−3) 1.19(−3) 6.54 8.82 33 4.13(−4) 7.16(−5) 16.78 16.62 65 3.22(−5) 4.95(−6) 12.83 14.47 The table shows that we are getting a convergence rate of at least three. The following table shows the max and RMS errors for the x-derivative: n 5 9 17 33 65

emax 3.04(+0) 1.37(+0) 3.09(−1) 6.91(−2) 1.26(−2)

rms 5.70(−1) 2.20(−1) 4.86(−2) 8.26(−3) 1.47(−3)

ratios 2.22 2.59 4.43 4.53 4.47 5.88 5.48 5.62

These numbers confirm our expectation that the convergence rate for the derivative should be two.

8.3.2 Monotone interpolation of scattered data Suppose we are given values {u i }ni=1 at scattered data points {(ξi , ηi )}ni=1 in some domain . In this section we discuss the problem of finding a spline s defined on  such that s is monotone and i = 1, . . ., n. (8.13) s(ξi , ηi ) = u i , This will only be possible when the data is consistent in the following sense. Definition 8.23. The data set {(ξi , ηi , u i )}ni=1 is said to be monotone-consistent, provided that u j > u i for all i , j such that ξ j ≥ ξi and η j ≥ ηi . (8.14) 8.3.2.1 Interpolation with S10 () may not be monotone

As we saw in section 8.3.1.1, if we are given gridded data points along with values that are monotone-consistent, and if we take  to be the type-1 triangulation of the data points, then the spline s ∈ S10 () that interpolates at the data points will be monotone. But what if we have scattered data points? We might expect that if the data is monotone-consistent, then there is at least one triangulation  of the data points such that the interpolant in S10 () is monotone. However, this is not the case, as the following example shows.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

264

Chapter 8. Shape Control

1

1

0.5

0 1

1

0.5 0 0

0.5

1

0.5 0 0

Figure 8.11. A triangulation  of the five data points in Example 8.24 and the spline s in S10 () interpolating the data given in the example.

Example 8.24. Let {(ξi , ηi )}5i=1 be the five points (0, 0), (0, 1), (.5, 1), (1, 0), and (1, 1). Let {u i }5i=1 := (0, 0, 0, 1, 1). Then no matter how we triangulate the data points, the corresponding spline s ∈ S10 () interpolating this data is not monotone. Discussion: We use the script Bmon01dat, and read the five points and the triangulation from the file mon5.dat. This gives the triangulation shown on the left in Figure 8.11. It is easy to check that this data set is monotone-consistent, and indeed, the values {u i }5i=1 can be gotten, for example, by sampling the monotone function 2(x − .5)2+ at the data points. The corresponding interpolating spline s ∈ S10 () is shown on the right. It is easy to see from the figure that this spline is not monotone in the sense of Definition 8.10, as can also be seen by plotting the x- and y-derivatives. There are two other triangulations of these points. They can be read from the files mon5b.dat and mon5c.dat, but they don’t lead to a monotone spline either. 8.3.2.2 Monotone interpolation of scattered data with C 1 cubic splines

In this section we extend the method of section 8.3.1.2 to the case of scattered data. Here is an outline. We begin by choosing the smallest rectangle R that contains all of the data points {(ξi , ηi )}ni=1 We then draw vertical and horizontal lines through each of these points to create a grid G on R. Next, we estimate values at all of these grid points, and adjust them to be consistent with monotonicity. Finally, we apply the method of the previous section to the gridded data using the spline space (8.7) defined on the type-2 triangulation obtained by drawing both diagonals in each subrectangle. We now discuss the steps in more detail. Step 1: To get the grid, we draw horizontal and vertical lines through each of the data sites {(ξi , ηi )}ni=1 . Suppose x := (x 1 , . . . , x n x ) and y := (y1 , . . . , yn y ) define the grid lines. Figure 8.12 (left) shows the resulting grid when we start with the 36 points shown in Figure 6.1. It is a 24 × 25 nonuniform grid. Step 2: Find an interpolating function based on the scattered data, and compute its value z i j at each grid point. We can use any of the scattered data interpolants of Chapn x ,n y ter 6. Next, we modify these values to get {˜z i j }i=1, j =1 which are consistent with monotonicity. First we number the grid points, starting with the point at (nx, ny) in the upper-right corner, and then traversing the southeast diagonals starting at

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

265

1

1

0.75

0.75

0.5

0.5

0.25

0.25

0 0

0.25

0.5

0.75

0 0

1

0.25

0.5

0.75

1

Figure 8.12. The grid associated with the 36 data points shown in Figure 6.1, and the corresponding type-2 triangulation of it.

7

4

(xi , yj ) 8

+ Rij

2

1

5

3

9

6

− Rij

10

Figure 8.13. The sets Ri+j and Ri−j involved in the adjustment process of Step 2.

(nx − i , ny) for i = 1, . . ., nx − 1; see Figure 8.13. Let I be the set of indices of grid points where the original data sites are located. Next we go through the list / I . Suppose that for some and adjust the z i j values for each grid point with (i , j ) ∈ (i , j ) ∈ / I , we want to adjust the value of z i j corresponding to (x i , y j ), having done all the previous points on our list. Let Ii+j = {(l, k) : l ≥ i , k ≥ j }, Ii−j = {(l, k) ∈ I : l ≤ i , k ≤ j }, − m− i j = max{z lk : (l, k) ∈ Ii j }, + m+ i j = min{z lk : (l, k) ∈ Ii j }.

The sets of points Ri+j = {(xl , yk ) : (l, k) ∈ Ii+j } and Ri−j = {(xl , yk ) : (l, k) ∈ Ii−j } are contained in the rectangles with dark outlines shown in Figure 8.13. Note that Ri+j and Ri−j are defined differently: Ii+j includes all points to the right and above (i , j ), while Ii−j only includes points to the left and below (i , j ) which lie in I . Since the original data is monotone, and the adjustment process maintains monotonicity, at

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

266

Chapter 8. Shape Control + every step of the process, m − i j ≤ m i j . Now we define

⎧ + ⎪ ⎨m i j , z˜ i j = m − ij , ⎪ ⎩ zi j ,

if z i j > m + ij , if z i j < m − ij , otherwise.

Note that this adjustment process does not change values of z i j for points (i , j ) ∈ I , which ensures that in the end our spline will interpolate as in (8.13). y

Step 3: Compute gradient values z ixj , z i j at each grid point. They can be generated from the n x ,n y gridded data {˜z i j }i=1, j =1

using the function gradgrid discussed in section 8.3.1.2. y Then use the function hsadj to create adjusted gradient values z˜ ixj , z˜ i j that satisfy the sufficient conditions for monotonicity in Theorem 8.16. y n ,n

x y Step 4: Interpolate the data {˜z i j , z˜ ixj , z˜ i j }i=1, j =1 using cubsib to get the coefficients of a 1 monotone C cubic spline that satisfies (8.13).

The following function carries out the adjustment process in Step 2: zw = monzadj(x,y,xi,eta,u,z) Here x and y are the vectors defining the grid, while xi,eta,u contain the scattered data points and values. The matrix z contains the values of the first stage fit at the grid points, and the output matrix zw are the desired adjusted grid values. Example 8.25. Construct a monotone C 1 cubic spline interpolating the sigmoidal function (8.6) at the 36 data points shown in Figure 6.1 (left). Discussion: We use the script Bmonscat, and read the scattered data points from the file pts36.dat. The data values at the scattered points are computed using our function sigmoid. The script creates a 24 × 25 grid containing the 36 points in Figure 6.1, and then calls on type2nu, which is a nonuniform version of the function type2 discussed in section 3.10. It creates the triangulation shown in Figure 8.12 (right). To get initial grid values, we compute the minimal energy C 1 Powell–Sabin spline interpolating the scattered data, and then evaluate it to get values for z i j for every grid point. These values are then adjusted to be monotone-consistent with a call on monzadj. Next, we call on gradgrid y to find z ixj and z i j for every grid point. These are then adjusted using hsadj. Finally, we compute the coefficients of our monotone interpolating spline with a call on cubsib. The monotone interpolating spline and its y-derivative are shown in Figure 8.14. The max and RMS errors for this spline interpolant are 1.29(−1) and 2.69(−2), respectively. The corresponding errors for the x-derivative are 2.07 and 3.95(−1) and for the y-derivative are 1.85 and 3.26(−1). In Step 3, instead of using gradgrid to estimate the gradients, we could have gotten them by evaluating the derivatives of the Powell–Sabin spline, and there is very little change in the spline or the error values. It should be emphasized that the approach of this section generally leads to splines defined on rather large triangulations as compared to the number of original sample points. In this case we had only 36 sample points, but ended up with the triangulation in Figure 8.12

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.3. Monotone interpolation

267

5 1

0 0 1

1 1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 8.14. Left: The monotone spline of Example 8.25 interpolating the values of (8.6) at the 36 data points shown in Figure 6.1. Right: its y-derivative.

which has 1152 vertices, 3359 edges, and 2208 triangles. The number of coefficients in the interpolating spline in this case is 10,078. Thus, it is clear that this method is not well suited for larger sets of scattered data. However, it seems to be the only available method for constructing monotone interpolating splines in the scattered case. In the following section we describe a method to replace this very complicated spline by a much simpler one which will be close enough that it almost interpolates the scattered data. 8.3.2.3 Almost interpolating monotone splines

If we are willing to give up the condition that the spline interpolate exactly at the scattered data points, we can replace the method of the previous section with a simpler method that produces a monotone spline that will generally come close to interpolating the scattered data. Here is an outline of the method: Step 1: Find a function s0 (for example, a radial basis function or a spline) that interpolates the values {u i }ni=1 at the scattered data points {(ξi , ηi )}ni=1 . Step 2: Let R be the smallest rectangle containing all of the data points, and choose a grid n x ,n y G covering R. Compute the values {z i j }i=1, j =1 of s0 at the grid points, and adjust them for monotone consistency using monzadj. Step 3: Use gradgrid to estimate gradients at the grid points, and use hsadj to adjust them to satisfy the sufficient conditions for monotonicity in Theorem 8.16. Step 4: Let  be the type-2 triangulation obtained from the grid G by drawing both diagonals in each subrectangle. Use cubsib of the previous section to construct the monotone C 1 cubic spline that interpolates this grid data. The key difference between this method and the one in the previous section is that here we choose a much simpler grid which may not contain all (or even any) of the interpolation nodes. As a result, the final spline does not necessarily interpolate at any of the interpolation nodes, but if the interpolant used in the first stage is a good approximation, the final monotone spline will almost interpolate.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

268

Chapter 8. Shape Control

1

1

0 1

1

0.5

0.5 0 0

0 1

1

0.5

0.5 0 0

Figure 8.15. Left: The minimal energy C 1 quadratic Powell–Sabin interpolant of the sigmoidal function (8.6) based on values at the 36 data points in Figure 6.1. Right: The corresponding almost interpolating monotone C 1 cubic spline; see Example 8.26.

Example 8.26. Construct a monotone C 1 cubic spline on a type-2 triangulation of a 9 × 9 grid that almost interpolates the sigmoidal function (8.6) at the 36 data points shown in Figure 6.1. Discussion: We use script Bmonscatai, and read the data points from file pts36.dat. The first stage computes a minimal energy C 1 Powell–Sabin interpolant at the 36 data points. The resulting surface is shown in Figure 8.15 (left). For this fit of the sigmoid function, the max and RMS errors on a 51 × 51 grid are 1.30(−1) and 3.45(−2), respectively. Next, we input nx = ny = 9 to get a 9 × 9 grid covering the smallest rectangle containing the 36 scattered data points. Figure 8.15 (right) shows a plot of the monotone C 1 cubic spline on the corresponding type-2 mesh. For this spline, the max and RMS errors are 1.25(−1) and 2.61(−2), respectively. This cubic spline does not interpolate exactly, but the maximum difference at the scattered data points is 2.56(−2) while the RMS difference is 6.82(−3). The underlying type-2 triangulation for this spline has only 256 triangles and 1201 coefficients, as compared with the 2208 triangles and 10,078 coefficients used in Example 8.25, and the errors are almost the same.

8.4 Monotone least-squares Suppose we are given noisy values {u ν }nν=1 at scattered data points {(ξν , ην )}nν=1 in some domain . We do not require that this data set be monotone-consistent, but we are thinking of the u i as samples of an underlying monotone function f . We now use the ideas of Section 8.3.2.3 to construct an approximation to f with a monotone C 1 cubic spline s defined on the smallest rectangle R containing . But here we don’t try to make s almost interpolate the data values, especially if they are subject to noise. Instead, we would like a method that smooths out some of the noise. To accomplish this, we follow the algorithm outlined in the previous section, but now in Step 1 we construct the first stage approximation s0 to be a least-squares spline defined on some triangulation of the domain. Here is an example, where in the first stage we choose  to be a type-2 triangulation covering the smallest rectangle R enclosing , and then take s0 to be least-squares fit of the data values from the corresponding C 1 Powell–Sabin spline space S21 ( P S ). Example 8.27. Construct a monotone C 1 cubic spline on a type-2 triangulation of a 15 × 15 grid based on samples of the sigmoid function (8.6) at 2000 randomly scattered points in the unit square.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.4. Monotone least-squares

269

1

1

0

0 1

1

1

0.5

0.5

1

0.5

0 0

0.5 0 0

Figure 8.16. Left: The C 1 quadratic Powell–Sabin spline on a type-2 triangulation of a 9 × 9 grid on the unit square obtained by least-squares based on 2000 randomly scattered data points. This is the first-stage spline in Example 8.27, and is not quite monotone. Right: The monotone C 1 cubic spline obtained in the second stage.

Discussion: We use the script Bmonlsq, adjusted to read random points using randxy. The triangulation is read from the file type2.25. Then we use mdsps and lsqbiv to construct the least-squares C 1 Powell–Sabin fit, which is shown in Figure 8.16 (left). It is not quite monotone since the minimum values of the x- and y-derivatives on a 51 × 51 grid are approximately −8.54(−21) and −8.25(−1), respectively. For this spline the max and RMS errors are 3.87(−2) and 7.51(−3), also measured on a 51 × 51 grid. We now choose n x = n y = 15, and construct the type-2 triangulation with 225 vertices for the second stage. The corresponding monotone C 1 cubic spline is shown in Figure 8.16 (right). It has max and RMS errors of 3.37(−2) and 6.48(−3), which are slightly better than what we got with the nonmonotone spline. Here is a similar example, but this time with noise. Example 8.28. Repeat Example 8.27 using noisy values at 2000 randomly scattered data points. Discussion: We again use the script Bmonlsq, and read the triangulation for the first stage from the file type2.25. We use the same data as in Example 8.27, but now add random noise read from the file noise.dat. Here we scaled this noise by ε = .1. The first stage C 1 Powell–Sabin least-squares spline is shown on the left in Figure 8.17. It is clearly not monotone, and has max and RMS errors of 7.81(−2) and 1.63(−2), respectively, as measured on a 51 × 51 grid. The monotone C 1 cubic spline with n x = n y = 15, which gives a type-2 triangulation with 225 vertices, is shown on the right in the figure. It has max and RMS errors of 6.76(−2) and 2.40(−2), respectively. The monotonicity of the spline can be checked visually by looking at the plots of the x- and y-derivatives, which are both nonnegative. The script also checks the monotonicity numerically by computing the minimum of these derivatives on a 51 × 51 mesh. These are both of order 10−15 for this spline. If we have noisy data, we can also use a penalized least-squares spline in the first stage to remove the noise.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

270

Chapter 8. Shape Control

1

1

0

0

1

1

0.5

0.5 0 0

1

1

0.5

0.5 0 0

Figure 8.17. Left: The C 1 least-squares Powell–Sabin spline constructed in the first stage of Example 8.28 based on noisy data at 2000 random data points in the unit square. Right: The monotone C 1 cubic spline obtained in the second stage.

8.5 Convex interpolation In this section we discuss methods to interpolate given data with a convex spline. Throughout the section we assume that we are working on a convex domain . Before starting, we should explain what we mean by a convex bivariate function. Definition 8.29. Suppose f is a continuous function defined on a convex domain , and let u be a unit vector. Then we say that f is convex in the direction u on , provided that if  is a line cutting through  and pointing in the direction of u, then the univariate function f | is convex at all points in . We say that f is convex on , provided that it is convex in all directions. If f is a C 2 function, convexity of f is equivalent to the condition that the second directional derivative Du2 ≥ 0 for all directions u and all points in  ∩ . The following result is well known. Lemma 8.30. Suppose f is a C 2 function on a convex domain . Then f is convex on  if and only if the matrix & % 2 Dx f Dx y f (8.15) K := Dx y f D 2y f is nonnegative definite. Using the fact that a matrix is nonnegative definite if and only if its principle minors are all nonnegative, we get the following result. Lemma 8.31. Suppose f is a C 2 function defined on convex domain . Then f is convex on  if and only if Dx2 f (x, y) ≥ 0, D 2y f (x, y) ≥ 0, and )

Dx2 (x, y) f

*)

* D 2y f (x, y) − (Dx y f (x, y))2 ≥ 0

for all points (x, y) ∈ . This lemma does not apply to splines that are not C 2 globally. However, the following result shows that for C 1 splines, it is enough to check the conditions for each triangle.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.5. Convex interpolation

271

Lemma 8.32. Let s be a C 1 spline defined on a triangulation  of a convex domain . Then s is convex on  if and only if for every triangle T ∈ , s|T is convex on T . Proof. Let s be such a spline. Then the property that s is convex in the direction u is the same as saying that for any line  containing u, the directional derivative Du s is nondecreasing as we move along the line in the direction of u. The result follows. Conditions on the B-coefficients of a spline that suffice for the spline to be convex on each triangle of  are given in section 8.5.2 below. Since the second derivatives of a C 1 quadratic spline are piecewise constant, for such splines the conditions of Lemma 8.31 can be easily checked. However, for splines of degree d > 2, we will have to be satisfied with checking them for a finite subset of . Here is a function for doing this test. It embeds  in a surrounding rectangle R, defines an ng × ng grid on R, and checks the conditions at all grid points lying in . [dxmin,dymin,dermin] = conck(d,x,y,v1,v2,v3,... e1,e2,e3,ie1,c,ng) Here c is the vector of B-coefficients of the spline. If all three values are nonnegative, the spline is likely to be convex. Otherwise, it is definitely nonconvex. We close this section by defining what we mean by convex data. Definition 8.33. Let {z i }ni=1 be a set of data values associated with scattered data points {vi := (x i , yi )}ni=1 . We say that this is a convex data set, provided that for every triple i , j , k of nonnegative integers such that the triangle Ti j k := vi , v j , vk  is nondegenerate, z l ≤ αi z i + α j z j + αk z k

(8.16)

for every l such that vl lies inside Ti j k . Here (αi , α j , αk ) are the barycentric coordinates of vl with respect to the triangle Ti j k . It is clear that if evaluate a convex function at the vertices of a triangulation  of a convex domain , we get a convex data set.

8.5.1 Convex interpolation with S10 () Let {(x i , yi , z i )}ni=1 be a convex data set. Let  be the convex hull of these sample points, and suppose  is a triangulation of  with vertices at the points {(x i , yi )}ni=1 . Then as we know, there is a unique spline s ∈ S10 () such that s(x i , yi ) = z i ,

i = 1, . . ., n.

(8.17)

In general, this spline will not be convex, even though we start with convex data; see Example 8.37 below. In this section we show that there is a triangulation with the same vertices such that the corresponding interpolating C 0 linear spline is convex. We begin by giving necessary and sufficient conditions for a spline s ∈ S10 () to be convex on . The following result is established in [SchumSp14].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

272

Chapter 8. Shape Control

Theorem 8.34. Suppose {(x i , yi , z i )}ni=1 is a convex data set, and let  be a triangulation of a convex domain  with vertices {vi }ni=1 . Given a spline s ∈ S10 (), let ci = z i , i = 1, . . . , n, be its set of B-coefficients. Then s is convex on  if and only if for every interior edge e := vi , vk , cl ≥ β1e ci + β2e c j + β3e ck , (8.18) where T1 := vi , v j , vk  and T2 := vi , vk , vl  are the two triangles in  sharing the edge e, and (β1e , β2e , β3e ) are the barycentric coordinates of vl relative to T1 . We have written the following function for checking whether the conditions of this theorem are satisfied: ckmin = conck01(x,y,v1,v2,v3,ie1,ie2,tril,trir,c) The input to this function is the usual information about the triangulation, together with a vector c containing the B-coefficients of the splines. The output is the minimum of the differences between the quantities on the left in (8.18) and the ones on the right. The spline is convex if and only if ckmin is nonnegative. Now suppose we are given a set of values {z i }ni=1 associated with the scattered data points {vi := (x i , yi )}ni=1 , and suppose these form a convex data set. The characterization of convexity of a spline s ∈ S10 () given in Theorem 8.34 leads to the following algorithm for constructing a convex spline interpolating the data, i.e., s(vi ) = z i , i = 1, . . . , n. Algorithm 8.35. Suppose {(x i , yi , z i )}ni=1 is a convex data set. Let 0 be an arbitrary triangulation of the convex hull  of the data points {vi = (x i , yi )}ni=1 with its vertices at the data points. Let s0 be the spline in S10 (0 ) that interpolates the values {z i }ni=1 at the vertices of 0 . Set i = 0. Then continue as long as possible: 1) Find an interior edge such that the two adjoining triangles form a strictly convex quadrilateral Q. 2) Swap the diagonal of Q if si is not convex on Q. 3) Let i+1 be the resulting triangulation, and let si+1 be the interpolating spline in S10 (i+1 ). This algorithm was introduced and analyzed in [Sco84, CarF96], where it was shown that it always terminates after a finite number of steps. Our next result shows that it produces a convex spline in S10 (); see Theorem 3.6 in [SchumSp14]. Theorem 8.36. Let {vi , z i }ni=1 be a convex data set associated with the scattered data points {vi }ni=1 . Let  be the triangulation obtained by Algorithm 8.35 applied to an arbitrary initial triangulation 0 with vertices at the data points. Then the corresponding interpolating spline s ∈ S10 () is convex. We have implemented this swapping algorithm in the function TRI = conswap(ne,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,x,y,z) The input includes the usual triangulation information for the initial triangulation 0 , along with the vector z of data values. The output is an n × 3 matrix TRI containing the indices of the new triangulation.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.5. Convex interpolation

273

0.7

0 1

1

0.5

0.5 0 0

0.7

0 1

1

0.5

0.5 0 0

Figure 8.18. Top: A triangulation with nine vertices and the C 0 linear spline interpolating the function (8.19) at its vertices. Bottom: The triangulation obtained by Algorithm 8.35, and the corresponding convex interpolating spline.

We now give several examples to illustrate convex interpolation with the space S10 (). Example 8.37. Let  3 [r (x, y) − .25]2, f (x, y) = 0,

if r (x, y) > .25, otherwise,

(8.19)

where r (x, y) := (x − .5)2 + (y − .5)2. Find a convex C 0 linear spline on the domain  := [0, 1] × [0, 1] that interpolates f at the nine vertices of the type-1 triangulation 0 shown on the top left in Figure 8.18. Discussion: We use the script Bcon01, and read an initial triangulation 0 from the data file type1.9. The function (8.19) is implemented in conf.m. It is convex on , and so its values at the nine vertices of the triangulation form a convex data set. We show the interpolating spline in S10 (0 ) on the top right in Figure 8.18. It is clearly not convex. For this spline, the function conck01 returns the value −2.52(−1). The maximum and RMS errors are 2.87(−1) and 1.51(−1), respectively. After applying Algorithm 8.35, we get the triangulation  shown on the bottom left in the figure. The associated C 0 linear interpolating spline is shown on the bottom right. Now the value produced by conck01 is 2.52(−1), showing that this spline is convex. The errors are now 1.87(−1) and 1.26(−1), which are actually slightly better than for the nonconvex spline interpolant. We now repeat this example using a larger set of data.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

274

Chapter 8. Shape Control

0.7

0.7

0 1

0 1

1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 8.19. Top: the triangulation tri36 and the triangulation produced by conswap. Bottom: the corresponding C 0 linear splines interpolating the function (8.19) at the 36 vertices of the triangulations. The surface on the right is convex, while the one on the left is not.

Example 8.38. Find a convex spline in S10 () that interpolates the function (8.19) at the 36 vertices of the triangulation shown in Figure 8.19. Discussion: We use the script Bcon01, and now read the initial triangulation from the file tri36.dat. The initial triangulation 0 and the spline in S10 (0 ) that interpolates at its vertices are shown on the left in Figure 8.19. For this spline, the value returned by conck01 is approximately −6.65(−2), and the max and RMS errors are 8.10(−2) and 3.38(−2), respectively. Next we apply conswap which resulted in a total of 12 swaps and led to the triangulation shown on the top right in the figure. The associated convex C 0 linear interpolating spline is shown on the bottom right. Now the value produced by conck01 is zero, showing that the spline is convex. The max and RMS errors are now 7.80(−2) and 3.20(−2), respectively, which are actually slightly better than for the original nonconvex spline. Example 8.39. Repeat Example 8.38 for the triangulation type1.81. Discussion: We again use the script Bcon01, this time with the data file type1.81. We show the initial triangulation and the swapped triangulation in Figure 8.20. Thirty swaps were required. We do not show plots of the splines since they are both quite accurate approximations of the function (8.19), and it is hard to see any difference. The value produced by conck01 for the initial triangulation was approximately −2.80(−2), indicating that the corresponding interpolating C 0 linear spline is nearly convex. The max and RMS

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.5. Convex interpolation

275

Figure 8.20. The triangulation type1.81 and the triangulation produced by conswap; see Example 8.39.

errors are 2.25(−2) and 1.01(−2) for this spline. The value produced by conck01 for the swapped triangulation was zero, indicating that the corresponding interpolating C 0 linear spline is now convex. The max and RMS errors for the convex spline are 1.50(−2) and 8.41(−3). Thus, as in the previous example, we not only get a convex surface with the swapped triangulation, but we also get better errors.

8.5.2 Convex interpolation with Sd0 () Given a convex data set {(x i , yi , z i )}ni=1 , in the previous section we considered the problem of constructing a convex C 0 linear spline that interpolates the values z i at the given data points (x i , yi ), i = 1, . . . , n. In this section we try to solve the same problem with a spline in Sd0 () with d > 1. The situation is now more complicated. First we need conditions that ensure that a polynomial p of degree d > 1 is convex on a given triangle T . Let {ci j k }i+ j +k=d be the B-coefficients of p relative to T . Let νμ be the difference operator along the edge direction vν − vμ . Thus, for example, 21 ci j k = ci, j +1,k − ci+1, j ,k for i + j + k = d − 1, and 221 ci j k = ci, j +2,k − 2ci+1, j +1,k + ci+2, j ,k , 21 31 ci j k = ci, j +1,k+1 − ci+1, j +1,k − ci+1, j ,k+1 + ci+2, j ,k for i + j + k = d − 2. It is known (see, e.g., Theorem 3.15 in [[LaiS07]]) that a sufficient condition for the convexity of the polynomial p on a triangle T is that the matrix %

Ai j k

221 ci j k = 21 31 ci j k

21 31 ci j k 231 ci j k

& (8.20)

formed from the B-coefficients of p with respect to T be nonnegative definite for each i + j + k = d − 2. This condition is also necessary for d = 2 and d = 3. The conditions (8.20) for convexity of a polynomial on a triangle T are nonlinear. Considerable effort has gone into finding practical linear conditions for convexity of a polynomial patch. The most general results were obtained recently in [SchumS12]. Fix

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

276

Chapter 8. Shape Control

i + j + k = d − 2, and let ri1j k (t1 , t2 ) := t1 t2 221 ci j k + (t1 (1 − t2) + t2(1 − t1))2131 ci j k + (1 − t1)(1 − t2)231 ci j k , ri2j k (t1 , t2 ) := t1 t2 232 ci j k + (t1 (1 − t2) + t2(1 − t1))3212 ci j k + (1 − t1)(1 − t2)212 ci j k , ri3j k (t1 , t2 ) := t1 t2 213 ci j k + (t1 (1 − t2) + t2(1 − t1))1323 ci j k + (1 − t1)(1 − t2)223 ci j k . In [SchumSp11] it was shown that requiring the nonnegativity of the functions rimj k (t1 , t2 ) at particular sets of points ensures that the matrix Ai j k in (8.20) is nonnegative definite, which in turn implies the convexity of p on T . We can summarize this convexity result as follows. n1

ijk Theorem 8.40. Given any positive integers n 1i j k , n 2i j k , and n 3i j k , let Xi j k := {x il j k }l=0 ,

n3

n2

ijk ijk , and Zi j k := {z li j k }l=0 , where Yi j k := {yil j k }l=0

n1

0 = x i0j k < x i1j k < · · · < x i jikj k = 1, n2

0 = yi0j k < yi1j k < · · · < yi jikj k = 1,

(8.21)

n3

0 = z i0j k < z i1j k < · · · < z i jikj k = 1 for i + j + k = d − 2. Suppose p is a polynomial of degree d whose B-coefficients relative to T satisfy the conditions l ri1j k (x il−1 j k , x i j k ) ≥ 0,

l = 1, . . ., n 1i j k ,

l ri2j k (yil−1 j k , yi j k ) ≥ 0,

l = 1, . . ., n 2i j k ,

l ri3j k (z il−1 j k , z i j k ) ≥ 0,

= 1, . . ., n 3i j k ,

l

(8.22)

for all i + j + k = d − 2. Then the corresponding surface patch is convex on T .

) * The conditions (8.22) can be expressed in the form Rc ≥ 0, where c is the N := d+2 ) *2  vector of B-coefficients of p, and R is a matrix of size ( i j k=d−2 (n 1i j k + n 2i j k + n 3i j k )) d2 × N. In practice we usually choose n 1i j k = n 2i j k = n 3i j k =: m, and take equally spaced points in (8.21). The simplest set of linear conditions is obtained by choosing m = 1 with the sets Xi j k = Yi j k = Zi j k = {0, 1} for every i + j + k = d − 2. This leads to the following simple conditions for convexity of p. Corollary 8.41. Suppose p is a polynomial in B-form with coefficients satisfying 21 31 ci j k ≥ 0,

32 12 ci j k ≥ 0,

13 23 ci j k ≥ 0

for all i + j + k = d − 2. Then the corresponding surface patch is convex on T .

(8.23)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.5. Convex interpolation

277

The conditions (8.23) can be interpreted as requiring the convexity of the control surface associated with p. All other sets of linear convexity conditions obtained by Theorem 8.40 are weaker these. We now give conditions for the convexity of a spline s ∈ Sd0 (). For simplicity, we assume that Xi j k = Yi j k = Zi j k = {0, 1/m, 2/m, . . ., 1} for some positive integer m. Then writing down the conditions (8.22) for every triangle T in , we are led to a set of inequalities that can be written in the form C p c ≥ 0, where now c is the vector of B-coefficients of ) * the spline, and C p is a matrix of size 3n t m d2 × N, where N is the dimension of the spline space and n t is the number of triangles in . Here is a function for computing the matrix C p for spline spaces of degree d. Cp = conpatch(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,m) The following result can be found in [SchumS12]. Theorem 8.42. Fix d > 1 and m ≥ 1, and let Sd0 () be the space of C 0 splines of degree d on a triangulation  of a convex domain . Let s be a spline in Sd0 () whose B-coefficient vector c satisfies C p c ≥ 0, where C p is the matrix described above. In addition, suppose that for every interior edge e := vκ , vμ  of , cˆi, j ,1 ≥ β1e ci+1,0, j + β2e ci,1, j + β3e ci,0, j +1 ,

i + j = d − 1,

(8.24)

where {ci j k }i+ j +k=d and {cˆi j k }i+ j +k=d are the B-coefficients of s relative to the two triangles T1 := vκ , vλ , vμ  and T2 := vκ , vμ , vν  in  sharing the edge e, and (β1e , β2e , β3e ) are the barycentric coordinates of vν with respect to T1 . Then the corresponding surface is convex over . This theorem gives sufficient conditions for the convexity of a spline in Sd0 (). It is shown in [SchumSp14] that the conditions are also necessary for d = 1, 2, but not for d ≥ 3. It is useful to have a function for checking whether the coefficients of a given spline satisfy the conditions (8.24). ckmin = conck0d(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,c) The input for this function is the usual information about the triangulation , along with a vector c containing the B-coefficients. The output is the minimum of the differences between the left- and right-hand sides of (8.24) for all i + j = d − 1 and all interior edges of . A spline in Sd0 () with coefficient vector c satisfies the conditions (8.24) if and only if the value of ckmin is nonnegative. The conditions (8.24) can be written in the form Ce c ≥ 0, where Ce is a matrix of size (d − 1)n e × N, and n e is the number of edges in . Here is a function for computing this matrix. Ce = conedge(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy) To solve the convex scattered data interpolation problem with C 0 splines of arbitrary degree d, we first triangulate the data and then apply the swapping algorithm (Algorithm 8.35)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

278

Chapter 8. Shape Control

to get the special triangulation that was used in the previous section to define a C 0 linear interpolating spline. We now look for an interpolant in a particular subspace of Sd0 (). Given m, let C p and Ce be the matrices described above, and let % & C C= p . Ce Let B := [I O], where I is the n × n identity matrix, and O is an n × (N − n) matrix of zeros. Set (8.25) S˜d0 () := {s ∈ Sd0 () : Cc ≥ 0 and Bc = z}. It is not clear a priori whether this set of splines is nonempty, but in this connection we have the following result from [SchumSp14]. Lemma 8.43. Let {(x i , yi , z i )}ni=1 be a convex data set, and suppose  is the triangulation obtained by applying Algorithm 8.35 to any initial triangulation 0 with vertices at the data points. Then the set S˜d0 () is nonempty. Proof. By Theorem 8.36, there exists a convex spline s ∈ S10 () that interpolates the data values at the vertices of . By Theorem 8.34 it must satisfy the conditions (8.18). Now we can use the function degraise described in section 4.15 to get a spline in Sd0 () that satisfies the conditions (8.24). We are ready to formulate a two-stage algorithm for solving the convex interpolation problem with Sd0 (). Algorithm 8.44. Suppose {(x i , yi , z i )}ni=1 is a convex data set. Let  be the triangulation obtained by applying Algorithm 8.35 to some initial triangulation with vertices at the data points. Step 1: Find a spline s˜ ∈ Sd0 () that either interpolates or approximates the data. Let c˜ be its set of coefficients. Step 2: Find a vector c with Cc ≥ 0 and Bc = z that minimizes the quadratic functional J1 (c) :=

1  (cξ − c˜ξ )2 . 2

(8.26)

ξ ∈Dd,

Step 1 can be done with any of the interpolation or approximation methods of Chapters 6 and 7. Note that in this step we do not require s˜ to interpolate. Step 2 is just a standard quadratic programming problem. By Lemma 8.43 we know that there is a feasible starting vector c for solving this problem, i.e., a coefficient vector c satisfying the constraints. To find a solution of this quadratic programming problem, we can use a standard built-in MATLAB function such as fmincon. We are ready to give an example to show how this method works. Example 8.45. Find a convex C 0 cubic spline that interpolates the function (8.19) at the 36 vertices of the triangulation shown in Figure 8.19. Discussion: We use the script Bcon03 together with the data file tri36.dat. It applies conswap to create the triangulation  shown on the top right in the figure. It then calls

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.5. Convex interpolation

279

0.7

0.7

0

0

1

1

1

0.5

1

0.5

0.5 0 0

0.5 0 0

Figure 8.21. The splines in Example 8.45. Left: The spline in S30 () produced by scat03 that interpolates the function (8.19) at the vertices of the triangulation in Figure 8.19 (right). Right: The corresponding convex spline interpolant in S30 () produced by Algorithm 8.44 using convexity conditions of order m = 5.

on scat03 to find an interpolating spline s˜ ∈ S30 (). It is shown in Figure 8.21 (left), and is clearly not convex. For this spline, conck0d produces the value −4.2(−2), while conck gives values of dx ≈ −1.93(1), dy ≈ −1.13(1), and dermin ≈ −3.79(1) for the minima of the quantities appearing in Lemma 8.31. Thus the spline fails the convexity check. It has maximum and RMS errors of 2.05(−2) and 6.37(−3), respectively. The script then inputs an integer m, and calls on the functions conpatch and conedge described above to produce the matrix C needed to enforce convexity. The function conpatch requires a parameter m controlling which of the convexity conditions (8.22) are used. The vector c minimizing J1 (c) over all vectors satisfying Cc ≥ 0 and Bc = z is then found with a call on fmincon. This gives the set of B-coefficients of a convex interpolating spline s ∈ S30 (). We can run the script with different values of m. With m = 1 we get the conditions in Corollary 8.41. Here is a table of max and RMS errors, along with time required by fmincon to find the optimal coefficients. m 1 2 3 4 5 6

emax 5.62(−2) 4.59(−2) 2.90(−2) 1.59(−2) 1.18(−2) 1.14(−2)

rms 1.56(−2) 9.48(−3) 5.92(−3) 4.07(−3) 3.53(−3) 3.46(−3)

time 1 1.5 5.3 2.4 1.96 2.88

All of these values produce convex splines. The errors are decreasing as we increase m, but the computational times vary. We show a plot of the convex spline obtained with m = 5 in Figure 8.21 (right). The maximum and RMS errors in this case are 1.18(−2) and 3.53(−2), respectively. This spline is not only convex, but provides a better approximation than the nonconvex first-stage cubic interpolating spline s˜.

8.5.3 Convex interpolation with S21 ( P S ) The ideas of the previous section can be adapted to work with any of the macro-element spaces described in section 4.14 to create convex interpolants of convex data sets associated

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

280

Chapter 8. Shape Control

with scattered data points. Let  be the triangulation obtained by applying Algorithm 8.35 to an initial triangulation with vertices at the data points {vi := (x i , yi )}ni=1 . In this section we make use of the space S21 ( P S ) of section 4.14.1, where  P S is the Powell–Sabin refinement of . According to Theorem 4.29, its dimension is given by N = 3n. Following the ideas of the previous section, we pick an integer m, and let C p be the corresponding matrix produced by the function conpatch. Then the condition C p c ≥ 0 enforces convexity of a spline in S21 ( P S ) on every triangle T of . Since we are working with C 1 splines, we do not need any convexity conditions associated with the edges of . Now let B be the matrix defined just before (8.25). We are going to look for a spline in the set Sˆ 1 () := {s ∈ S 1 ( P S ) : C p c ≥ 0 and Bc = z}. (8.27) 2

2

As shown in Theorem 4.32, each spline s ∈ S21 ( P S ) is uniquely defined by the value of s and its gradient at each of the vertices. In particular, if we are given n-vectors z, z x , and z y , then there exists a unique s ∈ S21 ( P S ) such that s(x i , yi ) = z i , Dx s(x i , yi ) = z ix , D y s(x i , yi ) =

i = 1, . . . , n;

(8.28)

y zi ,

see also Theorem 5.1. Suppose z, z x , and z y are all column vectors, and let ⎡ ⎤ % & z z ⎣ ⎦ w := z x , g := x . zy zy Then the B-coefficients of s are given by c = Aw, where A is the transformation matrix produced by the function nmdsps described in section 4.14.1. Since we want to interpolate, we keep the values of z fixed, and consider the values of the gradient to be free variables. The convexity conditions C p c ≥ 0 can be written as C p A w ≥ 0. This condition can be rewritten as A2 g ≥ −A1 z, where A1 is the matrix consisting of the first n columns of C p A, and A2 is the matrix consisting of the last 2n columns of C p A. We can now formulate an analog of the two-stage method of the previous section. Algorithm 8.46. Suppose {(x i , yi , z i )}ni=1 is a convex data set. Let  be the triangulation obtained by applying Algorithm 8.35 to some initial triangulation with vertices at the data points {vi := (x i , yi )}ni=1 , and let  P S be its Powell–Sabin refinement. Let A be the transformation matrix for the corresponding spline space S21 ( P S ), and let A1 and A2 be the submatrices consisting of the first n and last 2n columns of A, respectively. y

Step 1: Estimate the x- and y-derivatives {z ix }ni=1 and {z i }ni=1 at the data points. Let g˜ := y y (z 1x , . . . , z nx , z 1 , . . . , z n )T . Step 2: Find a vector g satisfying A2 g ≥ −A1 z that minimizes the quadratic functional 1 J2 (g) := (gi − g˜ i )2 . 2 2n

i=1

Step 3: Set c = A[z, g]T .

(8.29)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.5. Convex interpolation

281

1

1

0.5

0.5

0 0

0.5

1

0.7

0 0

0.5

1

0.7

0

0

1

1

1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 8.22. Top: The triangulation tri16 and the corresponding triangulation ∗ produced by Algorithm 8.35. Bottom: The minimal energy spline in S21 (∗P S ) interpolating the function (8.19) at the vertices, and the corresponding convex spline interpolant produced by Algorithm 8.46 with m = 3.

For Step 1 we can use the function derestlsq discussed in section 6.6.3. Step 2 is just a standard quadratic programming problem which can be solved with the built-in MATLAB function fmincon. Before illustrating the method, we should address the question of the existence of feasible solutions. Unlike in the case of C 0 splines discussed in section 8.5.2, we do not have a theorem guaranteeing the set (8.27) is nonempty, even if we take very large values of m. If this set is empty, then there will be no solution to the quadratic programming problem. Our first example illustrates this situation. Example 8.47. Find a convex C 1 quadratic spline that interpolates the function (8.19) at the 16 vertices of the triangulation on the top left in Figure 8.22. Discussion: We use the script Bconps together with the file tri16.dat. The script first evaluates the convex test function (8.19) at the vertices of the triangulation, and then applies conswap to create the triangulation ∗ shown on the top right in Figure 8.22. Next it computes the Powell–Sabin minimal energy interpolating spline s˜ shown on the bottom left in Figure 8.22. It is not convex, and conck gives values of approximately −1.58(0), −1.67(0), and −1.41(1) for the minimum values (over a 51 × 51 grid) of Dx2 s, D 2y s, and the determinant K defined in (8.15). The maximum and RMS errors for this spline are 1.12(−1) and 4.07(−2), respectively. The convexity constraints are set up using the function conpatch described in section 8.5.2, where the user must input an integer m controlling the strictness of the convexity constraints. The MATLAB function fmincon is then used to find estimates for the gradients at the vertices which approximate those of s˜ while subject to the convexity constraints.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

282

Chapter 8. Shape Control

With m = 1, 2, fmincon failed to find a feasible solution (as indicated by flag = 0). With m = 3, we get a convex spline with maximum and RMS errors of 8.18(−2) and 2.87(−2), respectively. This spline is not only convex, but provides a better approximation than s˜ . Larger values of m also lead to convex splines, but with slightly larger errors. Example 8.48. Find a convex C 1 quadratic spline that interpolates the function (8.19) at the 36 vertices of the triangulation tri36 shown in Figure 8.19 (left). Discussion: We again use the script Bconps, but now read the initial triangulation from the file tri36. The result of applying Algorithm 8.35 is the triangulation ∗ shown in Figure 8.19 (right). The corresponding Powell–Sabin minimal energy interpolating spline s˜ on this triangulation is not convex. This is a little hard to see from the plot, but the values returned by condk are −1.83(0), −1.68(0), and −6.38(0). The max and RMS errors are 2.32(−2) and 5.82(−3). In this case we were not able to find an interpolating spline in the space (8.27), despite trying the sequence of ever weaker patch convexity conditions corresponding to values of m = 1, . . ., 20. The function fmincon did not flag the problem as infeasible, but stopped due to limits on function evaluations and/or iterations. With m = 10 and the default limits, it stopped after 3.4 seconds, giving a spline whose convexity values are −3.25(−1), −4.23(−1), and −4.52(−1). This spline is not convex, but is closer to being convex than our initial fit. The errors are 2.55(−2) and 6.61(−3), which are only a little worse. Better results may be possible by adjusting the default functional evaluation and iteration limits for fmincon.

8.5.4 Convex near-interpolation with S21 ( P S ) The fact that the set (8.27) can be empty even for very large values of m severely limits the usefulness of the method described in the previous section. This problem can be nicely overcome if we are willing to accept a spline that almost interpolates. We proceed along the lines of Algorithm 8.46. First, we estimate the x- and y-derivatives at all data points and store them in vectors z x and z y . Set ⎡ ⎤ z w˜ := ⎣z x ⎦ . zy We are going to approximate w˜ by a vector w ∈ R3n that satisfies the convexity conditions. In particular, we choose w to minimize 1 (wi − w˜ i )2 2 3n

J3 (w) :=

(8.30)

i=1

over all w ∈ R3n such that C p A w ≥ 0, where A is the transformation matrix for S21 ( P S ) and C p is the matrix in (8.27). Then c = Aw gives the B-coefficients of our desired convex spline s. Since w1 , . . . , wn give the values of s at the data points, and are free variables in this minimization problem, the resulting spline s does not necessarily interpolate the data values z. However, since the nature of J3 forces the wi to be close to z i for i = 1, . . . , n, the spline s should come close to interpolating at the data points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.6. Convex least-squares

283

Example 8.49. Find a convex C 1 quadratic spline that nearly interpolates the function (8.19) at the 36 vertices of the triangulation tri36 of Figure 6.1 (left). Discussion: We use the script Bconpsni, and read the triangulation from the data file tri36.dat. Applying Algorithm 8.35 to the triangulation tri36 produces the triangulation ∗ shown on the top right in Figure 8.19. First we compute the corresponding minimal energy Powell–Sabin spline interpolant. It is not convex, and the minimum values (over a 51 × 51 grid) of Dx2 s, D 2y s, and the determinant K defined in (8.15) as computed by conck are approximately −1.83(0), −1.68(0), and −6.38(0). The max and RMS errors are 2.32(−2) and 5.82(−3), respectively. We can now choose an arbitrary value for the parameter m controlling the convexity conditions. Larger values give slightly better results. For m = 4, we get a convex spline with max and RMS errors of 3.70(−2) and 1.63(−2). These are somewhat larger than what we got for the first-stage nonconvex spline. This spline almost interpolates in the sense that the max and RMS discrepancy between the spline values at the data points and the values to be interpolated are 3.13(−2) and 2.27(−3), respectively. We do not plot either of these splines, although a close inspection of the figures shows the difference.

8.6 Convex least-squares n

n

d d Suppose we are given samples {z ν }ν=1 of a bivariate function f at n d points {(ξν , ην )}ν=1 in a domain . Let  be a triangulation of  with vertices at the points {(x i , yi )}ni=1 , and suppose S() is a subspace of Sd0 (). Our aim is to approximate f by a convex spline in S() which fits f in the least-squares sense, i.e., minimizes

F(s) :=

nd 

wν [s(ξν , ην ) − z ν ]2 .

(8.31)

ν=1

In this section we show how to solve this problem using two-stage methods similar to those used in the previous section. First we pick a triangulation and a spline space S(). Then we find a spline s˜ in S() that fits the data in the least-squares sense. Finally, we solve a quadratic programming problem to find a convex spline in S() that best fits the coefficients or degrees of freedom of s˜ . Of course s will not provide a minimum of (8.31), but it should come close to doing so. We now illustrate this method using the spaces Sd0 () and S21 ( P S ).

8.6.1 Convex least-squares with Sd0 () In this section we explore convex least-squares fitting using the space Sd0 (). Here we follow Algorithm 8.44, where in the first step we find a least-squares fit of the data from Sd0 (). This can be done using the function lsq0d described in section 7.2. Example 8.50. Let  be the type-1 triangulation of the unit square  with 25 vertices. Find a convex least-squares spline in S20 () that provides a least-squares fit of the convex function (8.19) based on data at 1000 points scattered randomly in . Discussion: We use the script Bconlsq0d together with the triangulation file type1.25. The 1000 random data points are read from the file randxy.dat. The

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

284

Chapter 8. Shape Control

1 0.8 0.6 0.4 0.2 0 0

0.5

1

Figure 8.23. The type-1 triangulation type1.25 with 25 vertices in the unit square , and a set of 1000 randomly scattered points in . 0.7

0.7

0

0

1

1

1

0.5

0.5 0 0

1

0.5

0.5 0 0

Figure 8.24. The C 0 quadratic splines of Example 8.50 fitting noisy measurements of the function (8.19) at 1000 randomly scattered points in the unit square. The one on the left is the least-squares fit, while the one on the right is the corresponding convex spline.

triangulation and set of data points are shown in Figure 8.23. Noise values are read from the file noise.dat, and are scaled to size ε = .1. First the least-squares fit from S20 () is computed using the function lsq0d described in section 7.2. The original least-squares fit is shown in the left in Figure 8.24, while the convex spline in S20 () as computed by Algorithm 8.44 is shown on the right. The function con0d is used to set up the matrix C for the convexity constraints, and the quadratic programming problem is solved with fmincon. The max and RMS errors for the nonconvex least-squares fit are 1.13(−1) and 2.13(−2), respectively. The errors for the second-stage convex spline are 1.40(−1) and 3.14(−2).

8.6.2 Convex least-squares with S21 ( P S ) In this section we explore convex least-squares fitting using the C 1 Powell–Sabin space S21 ( P S ). As in the previous section, we take a two-stage approach, where now in the first step we pick a triangulation and construct a least-squares fit of the data from S21 ( P S ). This can be done using the function nmdsps of section 4.14.1 to create the Powell–Sabin refinement and find the associated transformation matrix A, followed by a call on the function lsqbiv described in section 7.1.2 to find the B-coefficients of the least-squares

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.7. Remarks

285

0.7 0.7

0

0 1

1

0.5

0.5 0 0

1

1

0.5

0.5 0 0

Figure 8.25. Left: The C 1 quadratic least-squares Powell–Sabin spline of Example 8.51 fitting noisy measurements of the function (8.19) at 1000 randomly scattered points in the unit square. Right: The corresponding convex spline.

spline s˜ . Then taking w˜ = (s(v1 ), . . ., s(vn ), sx (v1 ), . . . , sx (vn ), s y (v1 ), . . . , s y (vn ))T to be the vector containing the degrees of freedom of s˜ , we minimize the expression in (8.30) over all w ∈ R3n such that C p A w ≥ 0, where A is the transformation matrix for S21 ( P S ) and C p is the matrix in (8.27). Then c = Aw gives the B-coefficients of our desired convex spline s. Example 8.51. Repeat Example 8.50 using the space S21 ( P S ) instead of Sd0 (). Discussion: We use the script Bconlsqps together with the triangulation file type1.25. The 1000 random data points are read using randxy. We read the noise values from the file noise.dat, and scale them to size ε = .1. The least-squares spline s˜ ∈ S21 ( P S ) is shown on the left in Figure 8.25. It is not convex, and conck produced values of approximately −2.06(1), −1.95(1), and −1.79(2). The max and RMS errors of this spline are 9.33(−2) and 1.91(−2). To get the nodal data vector w˜ needed in (8.30), we make use of the function gradps described in section 8.2.2. The convexity conditions are set up with conpatch, which requires the user to input an integer m that controls the strictness of the conditions. Here we use m = 3. Figure 8.25 (right) shows the convex spline approximant in S21 ( P S ). The max and RMS errors of this spline are 2.16(−1) and 6.36(−2).

8.7 Remarks Remark 8.1. The results of section 8.1 deal with constructing nonnegative splines. The same ideas apply if we want splines that are actually positive. Remark 8.2. In section 8.2.2 we examined nonnegative least-squares using the C 1 Powell– Sabin space S21 ( P S ). The method works equally well with any other convenient spline space, since all it involves is to replace negative B-coefficients by zero. If a spline is doing a good job of fitting a nonnegative function, then it will be almost nonnegative, and only a few coefficients will change. Moreover, the change will be small, and so the nonnegative spline will also provide a good fit. This is what we saw happening in Example 8.9, where we fit a hill function with a nonnegative C 1 Powell–Sabin spline. Remark 8.3. The method of section 8.2.2 can also be applied to splines produced by penalized least-squares.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

286

Chapter 8. Shape Control

Remark 8.4. Although the examples in this chapter focus on the square as a domain, we can work on more general polygonal domains. For constructing nonnegative splines, these may even have holes. For monotonicity and convexity, we should stick with convex domains. Remark 8.5. In section 8.3 we have defined monotonicity of functions to mean monotonicity along all lines pointing into the first quadrant. This can be generalized as follows. Let u 1 and u 2 be two unit vectors forming an angle less than 180 degrees, and let K := {a1 u 1 + a2 u 2 : a1 , a2 ≥ 0}. Then we say that f is monotone with respect to the cone K , provided that it is monotone along all lines pointing to the cone, i.e., f (x 1 , y1 ) ≤ f (x 2 , y2 ) for any pair of points (x 1, y1 ) and (x 2 , y2 ) lying in  such that the vector (x 2 − x 1 , y2 − y1 ) ∈ K . Lemma 8.11 also holds in this case. Remark 8.6. Throughout this chapter, we use the word monotone to mean monotone nondecreasing. It seems to be the property required most in practice. However, it is not hard to adjust the methods of section 8.3 to get splines that are strictly monotone increasing instead. The cases of monotone nonincreasing and strictly monotone decreasing can also be dealt with in a similar way. Remark 8.7. Monotone interpolation on a grid can also be done using C 1 bicubic splines; see [FriC83, CarF85, CarF89, CarF91]. Such splines are defined in terms of four values at y xy each grid point: z i j , z ixj , z i j , and z i j giving the gradient and so-called twist. In practice, these derivative values are generally not known, but can be estimated by the methods described in section 6.6.3. These then have to be adjusted in order to ensure monotonicity of the spline surface. Remark 8.8. In some applications, it may be enough to construct a spline that is monotone in just one direction. This problem was treated in [CarLF91]. Remark 8.9. We mention two other methods for dealing with monotonicity in the case of gridded data. Instead of using C 1 cubic splines on a type-2 triangulation as we did in section 8.3.1.2, it is possible to use C 1 biquadratic splines based on a rectangular partition obtained by inserting one extra knot line between each of the original grid lines. For details, see [AsaU89]. Alternatively, one can go one step further, and insert the diagonals in each subrectangle of this supergrid to get a type-2 partition, and then use C 1 quadratic splines; see [BeaZ85]. Both of these methods work with estimated derivatives at certain grid points, which then have to be adjusted to ensure monotonicity. Remark 8.10. The reason that we have plotted various x- and y-derivatives in many of the examples in section 8.3 on constructing monotone splines is to provide visual evidence that the constructed spline is indeed monotone. This can be hard to see from a plot of the spline. As we know from Lemma 8.11, if both of these derivatives are nonnegative on the domain , then the spline is monotone on that domain. Remark 8.11. The following definition of convexity of a bivariate function is equivalent to the one in Definition 8.29. Suppose f is a continuous function on a domain . Then f is convex on , provided that for every point v in , there is a plane L passing through the point (v, f (v)) such that f (x, y) > L(x, y) for all (x, y) ∈ .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

8.8. Historical notes

287

Remark 8.12. The built-in MATLAB command fmincon allows the user to specify certain options, including tolerances and number of iterations allowed. In some cases the user may have to adjust these to get good results. For an example, see our script Bcon03. Remark 8.13. The approach to finding convex splines in a least-squares setting discussed in section 8.6 does not produce a spline that minimizes the least-squares error among all convex splines in a given spline space. Instead, it produces a spline that is convex, and is close to the least-squares fit in the spline space. The problem of finding a least-squares spline in a restricted space can be formulated as a quadratic programming problem; see [WillD94b], where C 1 Powell–Sabin splines were used. The main problem with this approach is that it is generally not possible to prove that there is a feasible solution, in which case the optimization software may spend a lot of time looking for one with no result.

8.8 Historical notes The method described in section 8.1.2 for constructing a nonnegative polynomial spline in the space S21 ( P S ) which interpolates given scattered data comes from [SchumSp10]. For alternative methods based on the same space, see [MulS94]. For a similar method based on the space S31 (C T ), see [SchumSp10]. There is also a global method using S31 (C T ); see [Schm99]. For other work on interpolation with nonnegative splines on triangulations, see [ChaS94, MulS94b, HerMS96, KonOS04]. The algorithm in section 8.2.2 for finding a spline in S21 ( P S ) which fits scattered data (rather than interpolate it) is local. For a global method using the same space, see [WillD96]. It minimizes the least-squares fit subject to side conditions enforcing the nonnegativity. Several authors have developed methods for constructing C 1 splines interpolating data on a rectangular grid while satisfying the monotonicity conditions of Problem 8.12. Here we are following [HanS97], but for earlier work using C 1 cubic splines on appropriately refined triangulations, see [BeaZ85, CarlF85, FriC85, FriC85b, AsaU89, CarlF89, CarlF91], For other work on monotone interpolation and fitting, see [CostF90, CostM91, CostM96]. Some of these papers work with tensor-product splines or with parametric splines. The method for monotone least-squares fitting discussed in section 8.4 is a two-stage method. For a global method based on minimizing the least-squares fit subject to monotonicity constraints, see [WillD96]. As we saw in section 8.5.1, already for S10 (), the construction of a convex surface requires adjusting the triangulation. For this section we have followed [Sco84, CarnF96, SchumSp12]. The situation for Sd0 () with d > 1 is more complicated since we have to ensure convexity on each triangle. The results in section 8.5.2 come from [SchumSp12]. A lot of work has gone into finding conditions for the convexity of a Bernstein–Bézier polynomial patch — see the discussion in section 3.5 of [[LaiS07]], and the associated historical notes and references. Using the space S21 ( P S ) for convex interpolation basically reduces to finding choices of the gradients at the vertices of an appropriately swapped triangulation to guarantee convexity. The standard approach to doing this is to minimize some measure of energy while enforcing side conditions to ensure convexity. We can think of these as convex minimal energy splines. Finding them requires solving a quadratic programming problem; see [SchumSp11]. An alternate approach is also described in that paper. It is a two-stage

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

288

Chapter 8. Shape Control

method, where in the second stage we look for a convex interpolating spline that is close to a stage one (nonconvex) interpolant. We have followed this approach in section 8.5.3. Convex least-squares fitting with Powell–Sabin splines was studied in [WillD94b]. Their approach involved minimizing the least-squares functional subject to convexity constraints. Here we have elected to use a two-stage approach.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 9

Boundary-Value Problems

In this chapter we discuss the use of splines for finding approximate solutions to boundaryvalue problems involving elliptic PDE’s.

9.1 Examples of boundary-value problems In this section we give examples of the types of boundary-value problems to be treated here. Throughout the chapter we assume  is a domain in R2 . We begin with a simple model problem involving a second order elliptic PDE. Suppose f and κ are given functions defined on , and suppose g is a function defined on the boundary δ of . Problem 9.1. Find a function u defined on  such that Lu := −∇ · (κ∇u) = f u=g

on , on δ.

(9.1) (9.2)

Here ∇ denotes the vector-valued differential operator [Dx , D y ]T , and the dot in (9.1) denotes the vector inner product. Thus, for example, with κ = 1, the PDE in (9.1) becomes the Poisson equation − u := −(u x x + u yy ) = f .

(9.3)

When f = 0, (9.3) is called the Laplace equation. The boundary condition (9.2) is called a Dirichlet boundary condition. If g = 0, it is called a homogeneous boundary condition. The following is a more general version of Problem 9.1. Suppose ∂ = ∂ D ∪ ∂ N , and suppose g and h are given functions defined on ∂ D and ∂ N , respectively. For each point p on ∂, we write Dn := ∂u ∂n for the directional derivative of u corresponding to a unit vector n normal to ∂ at p, and pointing out of the domain.

289

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

290

Chapter 9. Boundary-Value Problems

Problem 9.2. Find a function u defined on  such that Lu := −∇ · (κ∇u) = f u=g ∂u =h κ ∂n

on , on ∂ D ,

(9.4) (9.5)

on ∂ N .

(9.6)

The boundary condition (9.6) is called a Neumann boundary condition. Together, (9.5) and (9.6) are called mixed boundary conditions. If we take ∂ D to be the empty set, then we call this the pure Neumann problem. For a solution to exist in this case, there must be a special relationship between f and h; see section 9.2.3. The differential equation in (9.1) is called second order since it involves partial derivatives up to order two. The methods of this chapter also apply to higher order boundary-value problems. Here is an example of a classical fourth order problem. Suppose f is a function defined on , and that g, h are functions defined on ∂. Problem 9.3. Find a function u defined on  such that 2 u = f u=g ∂u =h ∂n

on , on ∂,

(9.7) (9.8)

on ∂.

(9.9)

Here 2 u = u x x x x + 2u x x yy + u yyyy , and ∂u ∂n is the normal derivative operator described above. The PDE (9.7) is called the biharmonic equation.

9.2 The Ritz–Galerkin method In this section we describe the basic idea of the Ritz–Galerkin method for finding approximate solutions to the problems of the previous section. In the literature it is often referred to as the finite-element method; see any of the classical books such as [[Goc06]]. In this chapter we shall work only on domains  with polygonal boundaries. This is not a major restriction since a domain with curved boundaries can always be approximated with one that has polygonal boundaries; see, e.g., Example 9.14 below. We do not require  to be convex, and also allow it to have one or more holes. The approximations to be constructed in this chapter are going to be splines defined t on a triangulation  := {Ti }ni=1 of . A spline defined on a triangulation  is infinitely differentiable at all points of  except for those points that lie on the edges of , where it will have derivatives only up to some order r . Thus, at such points, it may happen that Ls is not even defined. But, we are not looking for a spline that satisfies (9.1) at all points of , or even at any of those points. What we are looking for is a spline that is close to the true solution.

9.2.1 The second order problem with Dirichlet boundary conditions In this section we focus on Problem 9.1. Let S() be an N-dimensional bivariate spline space defined on a triangulation  of . We assume S() is a subset of Sd0 () for some

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.2. The Ritz–Galerkin method

291

convenient value of d. To approximate the solution of Problem 9.1, we introduce the subspace of all splines in S() that vanish at all points on the boundary, i.e., U0 := {s ∈ S() : s(x, y) = 0, all (x, y) ∈ ∂}.

(9.10)

Now suppose {φ1 , . . . , φn0 } is a basis for U0 . Then we look for an approximate solution of Problem 9.1 in the form n0  s= ci φi + sb , (9.11) i=1

where sb is a spline in S() such that sb is approximately equal to g on the boundary ∂. Definition 9.4. Suppose the spline s in (9.11) is such that  [Ls(x, y) − f (x, y)] φi (x, y) d x d y = 0, 

i = 1, . . ., n 0 .

(9.12)

Then s is called the Ritz–Galerkin approximation to the solution u of Problem 9.1. In practice, it is common to use spline spaces that are only C 0 or C 1 . In this case, the expression Ls in (9.12) is not defined at points on the edges of the triangles in . Nevertheless, the integral in (9.12) is well defined if we think of it as the sum of the integrals over the triangles of . We now show that the coefficients of the Ritz–Galerkin spline (9.11) can be computed by solving a linear system of equations. First, we need some notation. For each triangle T ∈ , let  φ, ψ2,T := φ ψ d x d y, (9.13) T

and

 φ, ψG,T := κ(x, y) ∇φ(x, y) · ∇ψ(x, y) d x d y T = κ(x, y) [φx (x, y) ψx (x, y) + φ y (x, y) ψ y (x, y)] d x d y.

(9.14)

T

Let

φ, ψ2 :=



φ, ψ2,T ,

φ, ψG :=

T ∈



φ, ψG,T .

(9.15)

T ∈

Theorem 9.5. Suppose the basis for U0 is such that the matrix $n # M = φi , φ j G i,0j =1

(9.16)

is nonsingular. Then the spline (9.11) is the Ritz–Galerkin approximation to the solution u of Problem 9.1 if and only if the coefficient vector c = (c1 , . . . , cn0 )T is the solution of the linear system Mc = r , (9.17) with ri =  f , φi 2 − sb , φi G ,

i = 1, . . . , n 0 .

(9.18)

Proof. Substituting (9.11) in (9.12) and using standard Green’s identities, we see that (9.12) is equivalent to the system (9.16).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

292

Chapter 9. Boundary-Value Problems

The matrix M in (9.16) is called the stiffness matrix. It is clearly symmetric, and for the spline spaces we intend to use below, will usually be quite sparse. The nonsingularity of M depends on the spline space, and also requires appropriate conditions on κ; see Remark 9.3. In applications it will typically be positive definite. We should emphasize that the Ritz– Galerkin approximating spline s will not generally satisfy either the differential equation or the boundary condition exactly. However, it can be shown that if the mesh is sufficiently fine, then s does approximate the true solution well; see Remark 9.4.

9.2.2 The second order problem with mixed boundary conditions The Ritz–Galerkin method of the previous section can be easily adapted to approximately solve the boundary-value problem with mixed boundary conditions; see Problem 9.2. From now on, we assume that both of the sets ∂ D and ∂ N are unions of edges of the polygonal boundary ∂ of . Let U˜ 0 := {s ∈ S() : s(x, y) = 0, all (x, y) ∈ ∂ D }.x

(9.19)

If the set ∂ N is empty (so there are no Neumann boundary conditions), then U˜ 0 is the same as the subspace of splines U0 introduced in (9.10). Otherwise, it is a larger space with more free parameters. Suppose {φ1 , . . . , φn˜ 0 } is a basis for U˜ 0 . We now look for an approximate solution of Problem 9.1 in the form n˜ 0  s= ci φi + sb , (9.20) i=1

where sb is a spline in S() satisfying the Dirichlet boundary conditions on ∂ D . Definition 9.6. Suppose the spline s in (9.20) is such that  [Ls(x, y) − f (x, y)] φi (x, y) d x d y = 0, 

i = 1, . . ., n˜ 0 .

(9.21)

Then s is called the Ritz–Galerkin approximation to the solution u of Problem 9.2. 

Let h, φi 2,∂ N :=

∂ N

h φi ,

i = 1, . . . , n˜ 0 .

By our assumption that ∂ N is a union of edge segments of ∂, these integrals reduce to a sum of integrals over the line segments making up ∂ N . The following result follows from Green’s identities in the same way as the proof of Theorem 9.5. n˜ Theorem 9.7. Suppose ∂ D is nonempty, and that M˜ := [φi , φ j G ]i,0j =1 is nonsingular. Let sb be a spline in S() approximating g on ∂ D , and suppose c := (c1 , . . . , cn˜ 0 )T is the solution of the linear system ˜ = r˜ , Mc (9.22)

where r˜i :=  f , φi 2 + h, φi 2,∂ N − sb , φi G ,

i = 1, . . ., n˜ 0 .

Then the spline s given in (9.20) is the Ritz–Galerkin approximation of Problem 9.2.

(9.23)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.2. The Ritz–Galerkin method

293

9.2.3 The second order problem with pure Neumann boundary conditions We now consider Problem 9.2 in the case where there are only Neumann boundary conditions, i.e., ∂ D is the empty set and ∂ N = ∂. These boundary conditions are referred to as pure Neumann boundary conditions, and using the Ritz–Galerkin method now requires some extra care. In particular (see, e.g., [[Goc06]], page 17), it is known that the problem will not have a solution unless the following compatibility condition is satisfied:   f = h. (9.24) 

∂

Throughout this chapter, whenever we deal with a pure Neumann boundary-value problem, we assume that this compatibility condition is satisfied. This will automatically be the case if the function h in (9.6) describing the Neumann conditions is computed from a function u satisfying the differential equation (9.4). We should also point out that when it exists, a solution of the pure Neumann boundaryvalue problem is only unique up to a constant. This follows from the fact that any constant always satisfies both Lu = 0 and the Neumann boundary conditions. Suppose we are given a spline space S() with a basis {φ1 , . . . , φn }. Now we try to define the Ritz–Galerkin approximation s from S() by the conditions  [Ls(x, y) − f (x, y)] φi (x, y) d x d y = 0, i = 1, . . ., n. (9.25) 

After applying Green’s identities, we get    κ∇s · ∇φi = f φi + 



∂

hφi ,

i = 1, . . . , n.

(9.26)

Writing s in the form s=

n 

ci φ,

i=1

this reduces to the linear system of equations ˆ = rˆ , Mc

(9.27)

where Mˆ = [φi , φ j G ]ni, j =1 , and rˆi :=  f , φi 2 + h, φi 2,∂ ,

i = 1, . . . , n.

(9.28)

But in this case, the matrix Mˆ turns out to be singular; see [Goc06]. For a discussion of ways to treat this problem, see section 11.5 of that book. The simplest way to avoid the singularity of Mˆ is to convert the problem to one with mixed boundary conditions by enforcing a Dirichlet boundary condition at one point on the boundary, although mathematically this is not a well-posed problem; see [Goc06]. We illustrate this in Example 9.16 below.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

294

Chapter 9. Boundary-Value Problems

9.2.4 The fourth order problem In this section we discuss the Ritz–Galerkin method for finding a spline that approximately solves the fourth order boundary-value problem described in Problem 9.3. Suppose S() ⊆ Sd1 (). Note that here we are using C 1 splines in order to get conforming finite elements as required by the classical Ritz–Galerkin theory; see Remark 9.9. We now define Uˆ 0 := {s ∈ S() : s = Dn s = 0 on ∂}.

(9.29)

This is the space of all splines that satisfy the boundary conditions (9.8) and (9.9) with 0 g = h = 0. Let {φi }ni=1 be a basis for this space. Suppose now that sb ∈ S() is a spline that approximately satisfies the boundary conditions (9.8)–(9.9). Then we define the Ritz–Galerkin approximation of the solution u of Problem 9.3 to be the spline s ∈ S() such that  [2 s(x, y) − f (x, y)] φi (x, y) d x d y = 0, i = 1, . . . , n 0 . (9.30) 

For any two functions φ and ψ that are twice differentiable in the interior of each triangle T of , let nt   φ, ψ B := φ(x, y) ψ(x, y) d x d y. (9.31) ν=1 Tν

Using Green’s identities, we immediately get the following theorem, which shows how to compute the coefficients c = (c1 , . . . , cn0 )T of s by solving a linear system of equations. Theorem 9.8. Let M be the matrix with entries Mi j := φi , φ j  B ,

i , j = 1, . . . , n 0 ,

(9.32)

and let r be the vector with entries ri :=  f , φi 2 − sb , φi  B ,

i = 1, . . . , n 0 ,

(9.33)

where sb is a spline in S() that satisfies the boundary conditions (9.8) and (9.9). Suppose M is nonsingular, and let c := (c1 , . . . , cn0 ) be the solution of the system Mc = r .

(9.34)

Then the corresponding spline s defined as in (9.11) is the Ritz–Galerkin approximation to the solution of Problem 9.3.

9.3 Solving second order boundary-value problems with Sd0 () In this section we discuss how to implement the Ritz–Galerkin method for solving Problems 9.1–9.2 using the space Sd0 (). We recall from section 4.9 that the dimension of Sd0 () is   d −1 n c = n + (d − 1)n e + nt , 2 where n, n e , and n t are the numbers of vertices, edges, and triangles in . It was also shown there that the set of domain points M = Dd, is a minimal determining set for

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.3. Solving second order boundary-value problems with Sd0 ()

295

Figure 9.1. A minimal determining set M for S20 () for the triangulation shown. Domain points in Mb are marked with black dots, while those in M0 are marked with open circles.

Sd0 (). Let {φξ }ξ ∈M be the corresponding M-basis introduced in section 4.9.2. As shown in Lemma 4.10, all of these basis functions are nonnegative and have local supports which are either single triangles, pairs of triangles, or the triangles in the star of a vertex. For any triangle T contained in the support of φξ , the restriction φξ |T is just the Bernstein basis function BξT associated with the domain point ξ . This local support property of the basis ensures that the associated stiffness matrices are sparse.

9.3.1 Using Sd0 () with Dirichlet boundary conditions Let Mb be the set of domain points that lie on the boundary ∂, and let M0 be the set of those that do not. Figure 9.1 shows the sets Mb and M0 for d = 2 on a typical triangulation, where the points in Mb are marked with black dots, while those in M0 are marked with open circles. We can now summarize the Ritz–Galerkin method for solving Problem 9.1 using the space Sd0 (): 1) Find coefficients {cξ }ξ ∈Mb such that on the boundary ∂, sb = ξ ∈Mb cξ φξ is a good approximation of g.

the spline

2) Assemble the stiffness matrix M := [φξ , φη G ]ξ ,η∈M0 . 3) Compute the vector r with entries rξ =  f , φξ 2 − sb , φξ G for ξ ∈ M0 . 4) Solve Mc0 = r for the vector c0 := (cξ )ξ ∈M0 . 5) Store the coefficients {cξ }ξ ∈Mb and {cξ }ξ ∈M0 according to the storage convention of section 4.9.1. The following algorithm can be used to carry out Step 1. Algorithm 9.9 (Approximating g  on ∂). Choose the coefficients {cξ }ξ ∈Mb so that for each edge e of ∂, the spline sb = ξ ∈Mb cξ φξ interpolates the function g in (9.2) at the d + 1 domain points lying on e. This algorithm requires solving a (d + 1) × (d + 1) linear system for each edge e of . Although sb is constructed by interpolation on ∂, it is in fact defined on all of . However, due to the local support properties of the basis functions, sb will have nonzero

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

296

Chapter 9. Boundary-Value Problems

values only in triangles touching the boundary, i.e., it will be zero throughout most of ; see, e.g., Figures 9.2 and 9.3 below. We now give an algorithm for Steps 2 and 3, i.e., to assemble the stiffness matrix and right-hand side vector r . By definition of the inner products, we can compute the integrals in (9.15) one triangle at a time. Suppose T is a triangle in . If ξ is not in T , then φξ is identically zero on T , and any inner product on T involving φξ will be zero. If ξ ∈ T , then φξ |T = BξT , where BξT is the Bernstein polynomial relative to T associated with the domain point ξ . Thus, the problem of assembling the stiffness matrix reduces to computing the values of  T T Bξ , Bη G,T := κ(x, y)∇ BξT (x, y) · ∇ BηT (x, y) d x d y T (9.35) = κ [Dx BξT Dx BηT + D y BξT D y BηT ] d x d y T

for all triangles T in . These inner products will generally have to be computed with a quadrature rule such as the one described in section 4.6, or by the more efficient ones developed recently in [AinAD11]; see Remark 9.5. These require values of x- and y-derivatives of the Bernstein basis polynomials BξT at certain specified points in each triangle. These can be efficiently computed using the function mix described in section 4.4. Algorithm 9.10 (Assemble M and r). For all T ∈ , 1) For all ξ , η ∈ Dd,T , 2) For all ξ ∈ Dd,T ,

φξ , φη G ← φξ , φη G + BξT , BηT G,T rξ ← rξ +  f , BξT 2 − sb , BξT G,T

This algorithm works by looping through the triangles of  to compute the entries in M := [φξ , φη ]ξ ,η∈M0 and r by an accumulation process. Thus, for example, if ξ is at a vertex of , then the entry φξ , φξ G will get contributions from all triangles with a vertex at ξ . Similarly, if ξ lies on an edge of , then the entry φξ , φξ G will get contributions from all triangles that share that edge. We should emphasize that this algorithm operates only with Bernstein basis polynomials. We do not need explicit descriptions of any particular basis for Sd0 (). We have implemented the Ritz–Galerkin method for solving Problem 9.1 using the spline space Sd0 () in the function [c,M,t1,t2] = fem0d(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,area,bdy,kappa,f,g) The input includes the usual information about the triangulation , and also the names of the functions kappa, f, and g defining the boundary-value problem. The main output is the vector c of B-coefficients of the approximating spline, but for diagnostic purposes, we also output the stiffness matrix M and the times t1 and t2 to assemble and solve the corresponding sparse linear system. Note that t1 will generally be larger than t2. This is due to the fact that the assembly of the stiffness matrix requires the use of a quadrature

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.3. Solving second order boundary-value problems with Sd0 ()

297

rule. We have also written a simplified version of this function for the case d = 1 which runs faster. [c,M,t1,t2] = fem01(x,y,v1,v2,v3,e1,e2,e3,ie1,... area,bdy,kappa,f,g) Example 9.11. Let  be the unit square. Find a C 0 spline of degree d approximating the solution of Problem 9.1 with κ(x, y) := e x+y and f (x, y) = e x+y [4 cos(4x) + 4 cos(4y) − 16 sin(4x) − 16 sin(4y)],

(9.36)

with Dirichlet boundary condition (9.2) defined by g := u|∂ , with u(x, y) := − sin(4x) − sin(4y).

(9.37)

Discussion: The exact solution of this boundary-value problem is given by u. We make use of the script Bfem0d, and choose d = 1, 2, 3. In order to explore the rate of convergence as a function of mesh size, we perform the computations on the nested sequence of type-1 triangulations corresponding to the files type1.9, . . . , type1.4225. For each mesh, we tabulate the number n of vertices and the maximum and RMS errors on a 51 × 51 grid. We also list the size n 0 of the stiffness matrix M along with its condition number. d =1

emax 8.25(−1) 2.47(−1) 6.33(−2) 1.51(−2) 3.91(−3) 9.76(−4)

rms 3.68(−1) 9.98(−2) 2.53(−2) 6.35(−3) 1.59(−3) 3.98(−4)

cond 1.0(0) 7.7(0) 4.2(1) 2.1(2) 9.4(2) 4.1(3)

ratios 3.34 3.69 3.90 3.94 4.19 3.98 3.86 3.99 4.00 3.99

emax 1.25(−1) 1.54(−2) 2.04(−3) 2.45(−4) 3.08(−5)

rms 4.97(−2) 6.04(−3) 7.55(−4) 9.51(−5) 1.18(−5)

cond 6.6(0) 2.4(1) 1.1(2) 5.0(2) 2.2(3)

ratios 8.12 8.23 7.55 8.00 8.33 7.94 7.95 8.06

n n0 emax 9 25 1.35(−2) 25 121 8.63(−4) 81 529 5.07(−5) 289 2209 2.93(−6) 1089 9025 2.00(−7)

rms 4.41(−3) 2.96(−4) 1.86(−5) 1.14(−6) 7.25(−8)

cond 1.9(1) 4.6(1) 2.0(2) 8.8(2) 3.8(3)

ratios 15.64 14.90 17.02 15.91 17.30 16.32 14.65 15.72

n n0 9 1 25 9 81 49 289 225 1089 961 4225 3969

d =2

n n0 9 9 25 49 81 225 289 961 1089 3969

d =3

Figure 9.2 (left) shows the spline solution for d = 3 on the mesh with 25 vertices, while the corresponding spline sb satisfying the Dirichlet boundary condition is shown on the right.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

298

Chapter 9. Boundary-Value Problems

2

2

1

1

0 0

-1 -2 1

1

0.5

0.5

-1 1

1

0.5

0 0

0.5 0 0

Figure 9.2. The splines s and sb in S30 (), where  is a type-1 triangulation with 25 vertices; see Example 9.11.

The rates of convergence obtained are consistent with what we expect when using splines of degree d, i.e., we are getting order d + 1 convergence. The times required for these computations depend on d and the size of the triangulation. For d = 1 they range from thousandths of a second for n = 9, to about 3.5 seconds for n = 4225. For d = 2 it takes about 2 seconds for n = 1089, while for d = 3, the time to assemble and solve the system is about 3 seconds. Most of this time is used to assemble the stiffness matrix, and very little in solving the associated linear system. We should mention, however, that calculating the estimated condition numbers reported in the above tables can be quite slow for the larger matrices, even though they are sparse. As the table shows, the condition numbers grow slowly with n. This example shows the advantage of using higher degree splines. Using a cubic spline on the type-1 triangulation with 25 vertices gives better accuracy than using a linear spline on a type-1 triangulation with 4225 vertices, and the condition number of the linear system is better. Moreover, computing this cubic spline takes only .04 seconds as compared to over 3 seconds for the linear spline. With d = 3 we got RMS errors of 10−8 in only 3 seconds. To further explore the performance of the Ritz–Galerkin method with C 0 splines, we repeat this example for a problem with a more complicated solution. Example 9.12. Find a C 0 spline approximating the solution of the Poisson equation (9.3) on the unit square with right-hand side f (x, y) := −4 cos(x 2 + y 2 ) + 4(x 2 + y 2 ) sin(x 2 + y 2) − 10 cos(25(x 2 + y 2)) + 250(x 2 + y 2 ) sin(25(x 2 + y 2)),

(9.38)

and with the Dirichlet boundary condition (9.2) with g := u|∂ with u(x, y) := sin(x 2 + y 2 ) + .1 sin(25(x 2 + y 2 )).

(9.39)

Discussion: This corresponds to Problem 9.1 with κ = 1. The exact solution is given by the function in (9.39). It has quite a few oscillations; see, e.g., Figure 9.3 (left). We compare the Ritz–Galerkin method using Sd0 () for d = 1, 2, 3 using the script Bfem0d. As in the previous example, we perform the computations on the nested sequence of type-1 triangulations corresponding to the files type1.9, etc. For each mesh, we tabulate the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.3. Solving second order boundary-value problems with Sd0 ()

1.2

299

1.2

0 1

0 1

1

0.5

1

0.5

0.5 0 0

0.5 0 0

Figure 9.3. The splines s and sb in Sd0 () for d = 3 on a type-1 triangulation with 289 vertices; see Example 9.12.

number n of vertices and the maximum and RMS errors on a 51 × 51 grid. We also list the size of the n 0 × n 0 stiffness matrix M and its condition number. d =1

n n0 9 1 25 9 81 49 289 225 1089 961 4225 3969 16641 16129

d =2

n n0 25 49 81 225 289 961 1089 3969 4225 16129

d =3

emax 7.59(−1) 2.01(−1) 1.72(−1) 1.32(−1) 9.11(−2) 3.07(−2) 6.80(−3) emax 1.55(−1) 1.34(−1) 9.55(−2) 1.00(−2) 2.06(−3)

n n0 emax 25 121 1.96(−1) 81 529 1.17(−1) 289 2209 1.91(−2) 1089 9025 2.68(−3)

rms 2.56(−1) 9.62(−2) 7.06(−2) 4.87(−2) 2.04(−2) 5.99(−3) 1.56(−3) rms 6.65(−2) 4.89(−2) 1.34(−2) 1.75(−3) 2.30(−4)

rms 6.44(−2) 2.63(−2) 2.95(−3) 2.31(−4)

cond 1.0(0) 5.8(0) 2.5(1) 1.0(2) 4.1(2) 1.7(3) 6.8(3) cond 1.7(1) 6.1(1) 2.4(2) 9.5(2) 3.8(3)

cond 2.6(1) 9.7(1) 3.8(2) 1.5(3)

ratios 3.78 2.66 1.17 1.36 1.30 1.45 1.45 2.39 2.97 3.41 4.51 3.84

ratios 1.16 1.36 1.40 3.65 9.55 7.66 4.85 7.61

ratios 1.68 2.45 6.13 8.92 7.13 12.77

Figure 9.3 (left) shows the spline solution for d = 3 on the mesh with 289 vertices. The corresponding spline sb satisfying the Dirichlet boundary condition is shown on the right. The errors here are not as good as in the previous example, but this is to be expected due to the complicated nature of the true solution. The rates of convergence are also not as clear, but seem to be consistent with order d + 1 convergence for splines of degree d. As in the previous example, the times required for these computations depend on d and the size of the triangulation, and most of this time is used to assemble the stiffness matrix, and very little in solving the associated linear system. For d = 1, they range from thousandths of

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

300

Chapter 9. Boundary-Value Problems 0.8

0 0.5

0.5

0

0 -0.5 -0.5

Figure 9.4. A triangulation of an L-shaped domain, and the solution of Laplace’s equation with the Dirichlet boundary condition defined by (9.40).

a second for n = 9 to over 16 seconds for n = 16641. For d = 3, the times range from .04 to 3 seconds. As before, calculating the estimated condition numbers reported in the above tables can be quite slow for the larger matrices. As the table shows, they grow only modestly with n. The tables again show that using higher degree splines not only produces more accurate approximations, but is also much faster. For example, using a cubic spline on a grid with 289 vertices has comparable accuracy to the linear spline on a grid with 16641 vertices, and was computed in .6 seconds as compared to over 16 seconds for the linear spline. We now give a typical example on a nonrectangular domain. Example 9.13. Find a C 0 spline approximating the solution of the Laplace equation u = 0 on the L-shaped domain shown in Figure 9.4 (left) with Dirichlet boundary condition (9.2) with g := u|∂ with u(x, y) := r (x, y)2/3 sin(2θ (x, y)/3),

(9.40)

where (r (x, y), θ (x, y)) are the polar coordinates of (x, y). Discussion: With these boundary conditions, the true solution is just the function u defined in (9.40). To solve this problem, we can use the script Bfem0dL. We have written a function ureentrant to produce the value of u(x, y). It makes use of the MATLAB function cart2pol with a small adjustment since that function can return negative values of θ . This script is very similar to Bfem0d, and uses valspgrid to create values of the spline on a grid. These are then adjusted so that the errors are computed only for points in the L-shaped domain, and the corresponding plot is trimmed. As a first test, we read the triangulation from the file triL.11, which gives the triangulation shown in Figure 9.4 (left). With d = 1, we get the C 0 linear spline shown on the right in the figure. The max and RMS errors are 8.31(−2) and 2.48(−2), while the condition number of the system being solved is one. For this problem we have a continuous boundary condition, but the solution has unbounded derivatives as we approach the reentrant corner from the interior of the domain. To get a better approximation to the solution, we could refine the entire mesh, but since the problem is near the reentrant corner, instead we refine only locally to get the triangulations shown in Figure 9.5. To use the first refinement, we read the triangulation from

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.3. Solving second order boundary-value problems with Sd0 ()

301

Figure 9.5. Two local refinements of the triangulation in Figure 9.4.

the file triL.18. With this triangulation we get max and RMS errors of 5.38(−2) and 9.40(−3), a substantial improvement over what we got with the initial triangulation. Now the condition number is 5.3. The second refinement can be read from the file triL.25. It has 25 vertices, and gives max and RMS errors of 3.45(−2) and 4.84(−3) with a condition number of 10.8. To get even better errors we could refine further, but instead we now explore the effect of using higher degree splines. Here is a table of the errors for the three different triangulations for values of d = 1, . . ., 5. d 1 2 3 4 5

max 8.31(−2) 4.39(−2) 2.79(−2) 1.87(−2) 1.30(−2)

triL.11 rms 2.48(−2) 6.44(−3) 2.48(−3) 1.25(−3) 7.22(−4)

max 5.38(−2) 2.80(−2) 1.58(−2) 9.39(−3) 4.95(−3)

triL.18 rms 9.40(−3) 2.28(−3) 8.88(−4) 4.38(−4) 2.40(−4)

triL.25 max rms 3.45(−2) 4.84(−3) 1.57(−2) 9.46(−4) 7.07(−3) 3.13(−4) 2.24(−3) 1.35(−4) 1.06(−3) 7.56(−5)

To save space, we have not listed the condition numbers, but they grow very slowly with increasing refinements and with d, reaching a very modest max of 686 for triL.25 and d = 5. The times of computation also increase slowly with the numbers of vertices and the degree d, but the largest computational time for this table was only .07 seconds. As expected, the table shows improvements in the errors as we refine the meshes. We can’t really quantify this as the mesh sizes of the triangulations are computed globally, and are not going down at all. The errors also improve with increasing d. We do not bother to give plots of the splines on the finer triangulations with d > 1 as most of them are indistinguishable from the true solution. They do become smoother as we refine and/or increase the value of d. We conclude this section with an example where the domain is a polygonal approximation of a disk instead of a square. Example 9.14. Find a C 0 spline approximating the solution of the Poisson equation (9.3) on the unit disk with right-hand side f (x, y) = 20x 3 y 2 + 6(x y 4 − x y 2) + 12y 2 x 3 and with the Dirichlet boundary condition (9.2) taken from the exact solution u(x, y) := x 3 y 2 (1 − x 2 − y 2).

(9.41)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

302

Chapter 9. Boundary-Value Problems

Figure 9.6. The triangulations tridisk.25 and tridisk.81.

Discussion: This corresponds to Problem 9.1 with κ = 1. Here we use script Bfem0disk. It differs from Bfem0d only in the way it plots the spline. In particular, instead of ignoring grid points outside of the triangulation, it replaces them by zeros. To explore the rate of convergence, we work with a nested sequence of triangulations which can be read in from the files tridisk.25, tridisk.81, etc. The first two of these triangulations are shown in Figure 9.6. For each mesh, we tabulate the number n of vertices and the maximum and RMS errors. We also list the size n 0 of the stiffness matrix along with its condition number. d=1

emax 2.09(−2) 1.44(−2) 6.18(−3) 1.91(−3) 5.55(−4)

rms 7.30(−3) 4.19(−3) 1.37(−3) 3.67(−4) 8.99(−5)

cond 6.16(0) 2.47(1) 1.03(2) 4.38(2) 1.86(3)

ratios 1.45 1.74 2.33 3.06 3.24 3.73 3.44 4.08

emax 6.89(−3) 2.82(−3) 4.30(−4) 6.17(−5)

rms 2.38(−3) 6.64(−4) 9.79(−5) 1.28(−5)

cond 1.63(1) 5.99(1) 2.45(2) 1.06(3)

ratios 2.44 3.58 6.56 6.78 6.96 7.65

n n0 emax 25 121 1.65(−3) 81 529 2.93(−4) 289 2209 2.20(−5) 1089 9025 1.65(−6)

rms 5.05(−4) 6.60(−5) 4.62(−6) 3.05(−7)

cond 2.69(1) 1.03(2) 4.36(2) 1.75(3)

ratios 5.63 7.65 13.32 14.29 13.33 15.15

n n0 25 9 81 49 289 225 1089 961 4225 3969

d=2

n n0 25 49 81 225 289 961 1089 3969

d=3

Figure 9.7 shows the spline solutions for d = 1 and d = 3 on triangulation tridisk.81, plotted on [0, 1]2 for convenience. The rates of convergence are consistent with order d + 1 convergence for splines of degree d. This example again shows that using higher degree splines not only produces more accurate approximations, but is also more efficient. For example, using a cubic spline on a

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.3. Solving second order boundary-value problems with Sd0 ()

0.02

303

0.02

0

0 -0.02

-0.02 1

1

0

0 -1 -1

1

1

0

0 -1 -1

Figure 9.7. The C 0 linear and cubic splines defined on the triangulation tridisk.81 solving the boundary-value problem of Example 9.14.

grid with 81 vertices has better accuracy than the linear spline on a grid with 4225 vertices, and was computed in about .15 seconds as compared to 3.6 seconds.

9.3.2 Using Sd0 () with mixed boundary conditions Following the discussion in section 9.2.2, it is straightforward to modify our function fem0d to solve the second order boundary-value problem (Problem 9.2) with mixed boundary conditions using the spline space Sd0 (). We assume that both ∂ D and ∂ N are unions of edges of the polygonal boundary ∂ of . They need not be connected, but we do require that ∂ = ∂ D ∪ ∂ N . To find the B-coefficients of the spline approximation, we have to set up the stiffness matrix M˜ and the right-hand vector r˜ appearing in (9.22). The entries of M˜ are computed as before using a quadrature formula on each triangle to compute the quantities in (9.35). We use the quadrature rule described in section 4.6 with 25 sample points. For a reference to faster quadrature rules on triangles, see Remark 9.5. Note that here the stiffness matrix (9.22) is slightly larger than the one in (9.17) used in Example 9.11, since here the number n 0 of basis functions spanning the spline subspace U˜ 0 in (9.19) is larger than the number needed to span the subspace U0 in (9.10). To get the vector r˜ , we now have to compute integrals over the edges in the set ∂ N . For this we use a standard 5-point Gauss quadrature rule that samples at appropriate points in the interior of each such edge. Note that this means that we don’t make use of values of h at corners of the boundary set ∂ N . We have implemented the Ritz–Galerkin method for solving Problem 9.2 using the spline space Sd0 () in the function [c,M,t1,t2] = fem0dmix(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,area,kappa,eb,ebn,f,g,h) The input includes the usual information about the triangulation , and also the names of the functions kappa, f, g, and h defining the boundary-value problem. In addition, it requires a vector eb giving a list of the indices of the boundary edges of , and a second vector ebn whose i th component is zero if the associated edge has a Dirichlet boundary condition, and one if that edge has a Neumann boundary condition. The main output is the vector c of B-coefficients of the approximating spline, but for diagnostic purposes, we also output the stiffness matrix M and the times t1 and t2 to assemble and solve the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

304

Chapter 9. Boundary-Value Problems

Figure 9.8. Left: The spline sb ∈ S30 () in Example 9.15 which interpolates the Dirichlet boundary conditions on the left and top edges of the unit square. Right: The x-derivative of the spline s solving the boundary-value problem.

corresponding sparse linear system. Note that t1 will generally be much larger than t2. As noted before, this is due to the fact that the assembly of the stiffness matrix M˜ and right-hand-side vector r˜ require the use of a quadrature rule. Example 9.15. Let  be the unit square, and let ∂ D be the union of the top and left edges of , and let ∂ N be the union of the bottom and right edges. Let f and g be as in Example 9.11, and let κ = e x+y . Find a C 0 spline approximating the solution u of Problem 9.2, where g(x, y) := and

 − sin(4x) − sin(4), (x, y) on the top edge of , − sin(4y), 

h(x, y) :=

−4e x ,

(x, y) on the left edge of , (x, y) on the bottom edge of ,

−4e y+1 cos(4), (x, y) on the right edge of .

Discussion: We make use of the script Bfem0dmix, and read type-1 triangulations from the files type1.25, etc. It is easy to check that the exact solution of this boundary-value problem is the same as in Example 9.11, namely, u(x, y) := − sin(4x) − sin(4y). Figure 9.8 (left) shows the spline sb ∈ S20 () defined on the type-1 triangulation with 25 vertices that interpolates the Dirichlet boundary conditions on the left and top edges of . The spline s solving this mixed boundary-value problem is visually indistinguishable from the one obtained in Example 9.11 with Dirichlet boundary conditions on all four edges of ; see Figure 9.2 (left). So instead of plotting the spline itself, in Figure 9.8 (right) we plot its x-derivative. This figure shows that the spline does a good job of approximating the Neu∂s mann boundary condition on the right edge of the square. There ∂n = sx (1, y) has a nearly constant value close to the x-derivative of the true solution, which is −4 cos(4) ≈ 2.6145. In the following tables we give the max and RMS errors for a sequence of nested type-1 triangulations. The tables also show the size n 0 of the stiffness matrix M, along with its estimated condition number.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.3. Solving second order boundary-value problems with Sd0 ()

d =1

n n0 emax 9 4 8.56(−1) 25 16 2.51(−1) 81 64 6.55(−2) 289 256 1.56(−2) 1089 1024 4.05(−3) 4225 4096 1.01(−3)

d =2

emax n n0 25 64 1.81(−2) 81 256 2.39(−3) 289 1024 2.49(−4) 1089 4096 3.05(−5)

d =3

n n0 emax 25 144 8.45(−4) 81 576 5.06(−5) 289 2304 2.85(−6) 1089 9216 1.94(−7)

305

rms 4.21(−1) 1.10(−2) 2.79(−2) 7.00(−3) 1.75(−3) 4.38(−4)

cond 1.7(1) 8.6(1) 3.5(2) 1.5(3) 6.0(3) 2.4(4)

ratios 3.41 3.83 3.83 3.94 4.20 3.99 3.85 4.00 4.01 3.99

rms 6.09(−3) 7.55(−4) 9.51(−5) 1.18(−5)

cond 2.4(2) 1.1(3) 4.6(3) 1.9(4)

ratios 7.57 8.07 9.60 7.94 8.16 8.06

rms 2.89(−4) 1.82(−5) 1.12(−6) 7.14(−8)

cond 5.0(2) 2.3(3) 9.9(3) 4.1(4)

ratios 16.70 15.88 17.75 16.25 14.69 15.69

The errors obtained here with mixed boundary conditions are almost the same as those obtained in Example 9.11 with Dirichlet boundary conditions. The tables show that using splines of degree d, we are getting the expected rate of convergence d + 1. The stiffness matrices are slightly larger than those in Example 9.11. The condition numbers are also slightly larger, and increase slowly with n 0 . This example again shows the advantage of using higher degree splines. Using a cubic spline on type-1 triangulation with 25 vertices gives better accuracy than using a linear spline with 4225 vertices, and the condition number of the stiffness matrix is much smaller. Moreover, computing this cubic spline takes only .04 seconds as compared to 7.8 seconds for the linear spline. This does not count the time for computing the estimated condition numbers. As remarked before, this can be quite slow for the larger matrices, even though they are sparse.

9.3.3 Using Sd0 () with pure Neumann boundary conditions The code developed in the previous section cannot be used for solving Problem 9.2 in the case where only Neumann boundary conditions are specified. But following the discussion in section 9.2.3, there is a simple way to modify it to deal with pure Neumann conditions, assuming that the compatibility condition (9.24) is satisfied. Suppose  is a triangulation of a polygonal domain , and let n be the dimension of Sd0 (). By the results of section 4.9, we know that the set of all domain points Dd, associated with  forms a minimal determining set for Sd0 (). So in this case all B-coefficients are degrees of freedom. But as observed in section 9.2.3, it turns out that the associated stiffness matrix Mˆ is singular. Although there are several approaches to dealing with this

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

306

Chapter 9. Boundary-Value Problems

problem (see [Goc06]), we take the simplest one, namely, we drop the first row and column ˆ This corresponds to setting the B-coefficient associated with the domain point at the of M. first vertex of  to be zero. Here is our code. [c,M,t1,t2] = fem0dneu(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,area,kappa,f,h) The input includes the usual information about the triangulation , and also the names of the functions kappa, f, and h defining the boundary-value problem. In this case we know that all boundary edges carry Neumann boundary conditions, so there is no need for the vectors eb and ebn used in fem0dmix. The main output is the vector c of B-coefficients of the approximating spline, but for diagnostic purposes, we also output the stiffness matrix M and the times t1 and t2 to assemble and solve the corresponding sparse linear system. Example 9.16. Redo Example 9.11 with the Dirichlet boundary conditions replaced by the pure Neumann boundary conditions defined by the true solution u. Discussion: We make use of the script Bfem0dneu. As in Examples 9.11 and 9.15, we give tables of max and RMS errors using splines in the space Sd0 () with d = 1, 2, 3, based on type-1 triangulations. As before, we also give the size n 0 of the stiffness matrices, along with their estimated condition numbers. d =1

n n0 emax 25 24 4.40(−1) 81 80 1.22(−1) 289 288 3.00(−2) 1089 1088 7.68(−3) 4225 4224 1.95(−3)

d =2

emax n n0 25 80 2.68(−2) 81 288 3.67(−3) 289 1088 5.00(−4) 1089 4224 6.18(−5)

d =3

n n0 emax 25 168 1.40(−3) 81 624 6.39(−5) 289 2400 3.57(−6) 1089 9408 2.19(−7)

rms 3.00(−1) 8.08(−2) 2.06(−2) 5.18(−3) 1.30(−3)

cond 1.0(3) 6.0(3) 3.1(4) 1.5(5) 7.2(5)

ratios 3.61 3.71 4.07 3.92 3.91 3.98 3.94 3.98

rms 1.40(−2) 2.03(−3) 2.65(−4) 3.38(−5)

cond 4.6(3) 2.6(4) 1.3(5) 6.3(5)

ratios 7.30 6.90 7.34 7.66 8.09 7.84

rms 6.92(−4) 2.65(−5) 1.26(−6) 7.25(−8)

cond 1.2(4) 6.4(4) 3.2(5) 1.5(6)

ratios 21.91 26.11 17.90 21.03 16.30 17.38

The errors obtained here with pure Neumann boundary conditions are slightly larger than those obtained in Examples 9.11 and 9.15 using Dirichlet or mixed boundary conditions. The stiffness matrices here are a little larger, and their condition numbers are somewhat bigger. The tables show that using splines of degree d, we are getting the expected rate of convergence d + 1.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.4 Solving boundary-value problems using macro-element spaces

307

9.4 Solving second order boundary-value problems using macro-element spaces In this section we examine the use of macro-element spaces for solving the second order boundary-value problems discussed in section 9.1 with the Ritz–Galerkin methods described in section 9.2. Due to their local structure and excellent approximation properties, macro-element spaces are very convenient spaces to employ in the method. We illustrate this with the space S51,2 () in the following section. Throughout this section we assume that  is a polygonal domain. In particular, we suppose that ∂ is the union of a finite number of nonoverlapping line segments ∂i . This means that some of the ∂i will be open or half open. Now suppose that S() is a macroelement space defined on a triangulation  of , and let N be its dimension. Our aim is to find a spline s ∈ S() giving the Ritz–Galerkin approximation to the solution of Problem 9.1. Let c = (c1 , . . . , cnc ) be the vector of B-coefficients of s, numbered according to the convention of section 4.9.1. To describe an algorithm for computing these B-coefficients, we need some additional notation. Let  D be the part of the boundary of  where we want to enforce Dirichlet boundary conditions, and let  N be the part where we want to enforce Neumann boundary conditions. Then we begin by writing S() as a direct sum of the form S() = Ub ⊕ U0 ,

(9.42)

U0 := {s ∈ S() : s ≡ 0 on ∂ D }.

(9.43)

where Both Ub and U0 are finite dimensional spaces of splines. Let n b and n 0 be their dimensions, and suppose we are given minimal determining sets Mb and M0 for them. Then M = Mb ∪ M0 is a minimal determining set for S(), and N := n 0 + n b is its size. Let {ψξ }ξ ∈Mb and {φξ }ξ ∈M0 be the M-bases for Ub and U0 , In terms of these basis functions, we can write s in the form   cξ ψξ + c ξ φξ . (9.44) s := sb + s0 := ξ ∈ Mb

ξ ∈ M0

Suppose J = ( j1, . . . , j N ) is an index array such that c˜ := (c j1 , . . . , c j N ) are the Bcoefficients of s associated with the minimal determining set M for S(), and let A be the n c × N transformation matrix associated with the space S() and the minimal determining set M. Then the full vector c of B-coefficients can be computed from the vector c˜ by c = Ac. ˜ We can now formulate the following algorithm for determining the vector c of B-coefficients of the Ritz–Galerkin spline s. Algorithm 9.17. 1) Find coefficients {cξ }ξ ∈Mb to make sb be an approximation of the function g on the set  D . Store these in c˜ according to the index set J . 2) Solve the system M0 a = r , where M0 := [φξ , φη G ]ξ ,η∈M0 and rξ =  f , φξ 2 + h, φξ 2,∂ N − sb , φξ G for all ξ ∈ M0 . Store the components of a in the vector c˜ according to the index set J . 3) Let c = Ac. ˜

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

308

Chapter 9. Boundary-Value Problems

Step 1 can be accomplished by choosing the coefficient {cξ }ξ ∈Mb to make sb interpolate at n b points on the edges of ∂ D . Exactly where to place these points depends on the nature of Mb . We now describe an algorithm for setting up the matrix M0 appearing in Step 2. It is similar to Algorithm 9.10. Let K := (k1 , . . . , kn0 ) be an index set such that (ck1 , . . . , ckn0 ) are the B-coefficients) associated with M0 . Suppose that d is the degree of the spline space d+2* S(), and let n d := 2 . Algorithm 9.18 (Assemble M0 ). 1) Let M be a n 0 × N matrix of zeros. 2) For all T ∈ , a) Find index vector IT := (i 1 , . . . ,i nd ) so that (ci1 , . . . , cind ) are the B-coefficients associated with the domain points of T . Let B := A(IT , :) be the matrix obtained from A by selecting only the rows with indices in IT , and let B˜ := B(:, K ) be the matrix obtained from B by selecting only the columns with indices in K . b) Compute the matrix G T := BξT , BηT G,T , where BξT are the Bernstein basis polynomials associated with T . c) Let M ← M + B˜ T G T B. 3) Let M0 := M(:, K ) be the matrix obtained from M by selecting only the columns in the index set K . The final result of this algorithm is the n 0 × n 0 matrix M0 needed in Step 2 of Algorithm 9.17. It is computed by an accumulation process based on looping through the triangles of . The inner products needed to find G T require a quadrature rule. The right-hand side of the system arising in Step 2 of Algorithm 9.17 can be computed by an analogous accumulation process, which also involves numerical quadrature. We close this section with an important comment. Note that in computing the Bcoefficients of the Ritz–Galerkin spline, we never have to explicitly construct the basis functions appearing in (9.44). In Step 1 we need to find the values of the ψξ at points on the boundary edges ∂, where they reduce to univariate Bernstein polynomials. The assembly of the matrix M0 in Algorithm 9.18 only works with Bernstein basis polynomials on triangles. This is possible since the structure of the basis functions φξ is fully encoded in the transformation matrix A; see Lemma 4.23.

9.5 Solving second order boundary-value problems using the space S51,2 () In this section we illustrate the use of macro-element spaces to solve boundary-value problems. Here we focus on the space S51,2 () discussed in detail in earlier chapters. First we decompose it into a direct sum of the form S51,2 () = U0 ⊕ Ub , where

(9.45)

U0 := {s ∈ S51,2 () : s ≡ 0 on ∂}. (9.46) As discussed in the previous section, we now need to find minimal determining sets for Ub and U0 . The construction is similar to what we used in section 4.14.2, where we

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.5 Solving second order boundary-value problems using the space S51,2 ()

309

first introduced S51,2 (). The approach is based on a study of two-disks of domain points surrounding boundary vertices. First we need a definition. Definition 9.19. Let v be a boundary vertex of . If the two boundary edges attached to v are collinear, then we say that v is a degenerate boundary vertex. Otherwise, we call v a nondegenerate boundary vertex. We now show how to choose sets that determine the coefficients of a spline in S51,2 () for domain points in the two-disk surrounding a boundary vertex v. Let Tv be the first triangle attached to v, counting in counterclockwise order. If v is a nondegenerate boundary vertex, let Mbv := the five points in D2 (v) ∩ ∂, M0v := a point on R2 (v) not on ∂, and if v is a degenerate boundary vertex, let Mbv := the three points in D2Tv (v) ∩ ∂, M0v := the three points in D2Tv (v) not on ∂. Lemma 9.20. Let v be a boundary vertex of , and let Mv := M0v ∪ Mbv . Then all Bcoefficients of s ∈ S51,2 () associated with domain points in D2 (v) are uniquely determined by those associated with Mv . Proof. We first consider the case that v is nondegenerate. Suppose we set the coefficients of s ∈ S51,2 () associated with Mv to arbitrary values, and suppose there are l interior edges attached to v. Then there are l domain points on the ring R1 (v) that are not in M, and there are l C 1 smoothness conditions connecting the associated coefficients to each other. The matrix of this system can be manipulated into upper-triangular form with positive diagonal elements, and hence is nonsingular. Similarly, there are 2l undetermined coefficients associated with domain points on R2 (v), and 2l smoothness conditions connecting them. After performing some Gauss elimination steps, we see that the matrix of this system is also nonsingular. The case where v is degenerate is simpler. In this case we use C 1 conditions across each interior edge attached to v to uniquely compute the unset coefficients associated with domain points on the ring R1 (v). Then we use C 1 and C 2 smoothness conditions across each interior edge in order to find the unset coefficients associated with domain points on R2 (v). Let Vb and V I be the sets of boundary and interior vertices of , respectively. Let E be the set of all edges of . For each v ∈ V I , let Mv = D2Tv (v), where Tv is some triangle with vertex at v, and for each e ∈ E, let Me be as in Theorem 4.34. We now define 1 Mb := Mbv , v∈Vb

M := 0

1

v∈Vb

M0v ∪

1 v∈V I

Mv ∪

1 e∈E

Me .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

310

Chapter 9. Boundary-Value Problems

Theorem 9.21. The sets Mb and M0 are minimal determining sets for the spline spaces Ub and U0 , respectively, and M := Mb ∪ M0 is a minimal determining set for S51,2 (). Proof. The proof is similar to the proof of Theorem 4.34. For the first statement, we show that if we set the B-coefficients of a spline s ∈ S51,2 () corresponding to domain points in Mb , then all of the B-coefficients of s associated with domain points on ∂ are uniquely determined using Lemma 9.20. Then all other coefficients are uniquely determined once those corresponding to domain points in M0 are set. This can be seen by first considering the two-disks around the vertices. It follows immediately from this theorem that dim U0 = 6n I + 3n˜ b + nˆ b + n e , dimUb = 3n˜ b + 5nˆ b ,

(9.47)

where n I := number of interior vertices, n˜ b := number of degenerate boundary vertices, nˆ b := number of nondegenerate boundary vertices, n e := number of edges. We give two examples to illustrate this theorem. In the first example all boundary vertices are nondegenerate. Example 9.22. Consider the spline space S51,2 () on the triangulation shown in Figure 9.9. Discussion: This triangulation has two interior vertices and seven nondegenerate boundary vertices, along with 17 edges. The dimension of this space is 71, while the dimensions of Ub and U0 are 35 and 36, respectively. We mark the points in the set Mb with black dots in Figure 9.9 (left). Similarly, we mark the points in M0 with black dots or triangles in Figure 9.9 (right), where triangles are used for points in the sets Me . Note that in this example, Mb contains all domain points lying on ∂. This will always be the case for any triangulation whose boundary vertices are all nondegenerate. In our .. ......................................................... ............ .......................... .................... ............ ... ... ............ ...... ... .... ......... ... ... ... ... . ... ... ..... ... . ... .... . . . ... ... ... ..... .. ... . . . . . ... . ... . . ... ... ... ... ... ... ... . . . . ... . . . ... ... ... ... ... ... ... . . . ... . . . . ... ... ... ... ... ... ... . ... . . . . . . ... ... ... ... ... ... ... . . . . . . . . . ... ... ... .. .. . . ... .... . . . . . . . . . ... ... ... .. ... . ... ..... ... . . . . . ... ... ... ... ... ... . ... . . . . . . . . ..... ... ... .. . ... . ... . . . . . . . . . . . . . . . . . . . . . . . . .............. .. ... ... .............. ............ .... ... ................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .............. .... ... ... .. .............. ........ ..................... . . ............ ... . . . . . . . . . . . . . . . . . . . . .... . . . . . . . . . . . . . . . . . . ....................... ... .. ........... .... ..... . . . . ... ................. . . .. ..... .... .. ... ... ..... ..... ..... ... ..... ... ..... ... ..... ... ... ..... ... ..... ... .... ... ..... ... .... ..... ... ..... ... .... ..... . . ..... . . . . . . ... ... ..... .. .... ... ..... ... ... ..... ..... ... ... ... .... ..... .... ... ..... ... ..... .... ... ..... ... ... ... ..... ..... ... .. .... ..... ..... . . . . . . . . . . ..... ... .. ..... .... ........ ... ...... ..... .. ..... . .. ..... ... .... .......................................................................................................

.. ......................................................... ............ .......................... .................... ............ ... ... ............ ...... ... .... ......... ... ... ... ... . ... ... ..... ... . ... .... . . . ... ... ... ..... .. ... . . . . . ... . ... . . ... ... ... ... ... ... ... . . . . ... . . . ... ... ... ... ... ... ... . . . ... . . . . ... ... ... ... ... ... ... . ... . . . . . . ... ... ... ... ... ... ... . . . . . . . . . ... ... ... .. .. . . ... .... . . . . . . . . . ... ... ... .. ... . ... ..... ... . . . . . ... ... ... ... ... ... . ... . . . . . . . . ..... ... ... .. . ... . ... . . . . . . . . . . . . . . . . . . . . . . . . .............. .. ... ... .............. ............ .... ... ................... . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .............. .... ... ... .. .............. ........ ..................... . . ............ ... . . . . . . . . . . . . . . . . . . . . .... . . . . . . . . . . . . . . . . . . ....................... ... .. ........... .... ..... . . . . ... ................. . . .. ..... .... .. ... ... ..... ..... ..... ... ..... ... ..... ... ..... ... ... ..... ... ..... ... .... ... ..... ... .... ..... ... ..... ... .... ..... . . ..... . . . . . . ... ... ..... .. .... ... ..... ... ... ..... ..... ... ... ... .... ..... .... ... ..... ... ..... .... ... ..... ... ... ... ..... ..... ... .. .... ..... ..... . . . . . . . . . . ..... ... .. ..... .... ........ ... ...... ..... .. ..... . .. ..... ... .... .......................................................................................................

Figure 9.9. The sets Mb and M0 for S51,2 () on a triangulation with nine vertices.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.5 Solving second order boundary-value problems using the space S51,2 () ............................................................................................................................................................................................... .. .. . .. . .... . ..... .. .... ..... ... ..... .... ..... .... ..... ... .... ..... .... . . ..... ..... . . . . . . .... . . . .... . . . ..... ..... .... .... .... .... .... ..... ..... .... .... .... .... .... . ..... ..... . . . . . . . . .... .... . .. ..... . ..... . . . . . . . .... .... . . .. ..... ..... . . . . . . . .... .... . . . .. ..... . ..... . . . . . . . .... .... . . . .. ..... ..... . . . . . . .... .... . . . .... .... .... ........ .... ......... .... . .... ........ .... .... ........ ............................................................................................................................................................................................................ ... ... ... ... . . . . . . .... . . ..... .... ..... .... . . . . .... . . . . . . ..... ..... .... .... .... .... .... ..... ..... .... .... .... .... .... ..... ..... .. .... .... .... .... .. . ..... ..... . . . . . . . .... . .... . .. ..... ..... . . . . . . .... .... . . . . . .. ..... ..... . . . . . . . .... .... . . .. ..... ..... . . . . . . .... . .... . . . . .. ..... ..... . . . . . .... .... . . . . . .. ..... ..... . . . . . .... .... . . . . .... .... .... ......... .... .... ......... ................................................................................................................................................................................................................

311

............................................................................................................................................................................................... .. .. . .. . .... . ..... .. .... ..... ... ..... .... ..... .... ..... ... .... ..... .... . . ..... ..... . . . . . . .... . . . .... . . . ..... ..... .... .... .... .... .... ..... ..... .... .... .... .... .... . ..... ..... . . . . . . . . .... .... . .. ..... . ..... . . . . . . . .... .... . . .. ..... ..... . . . . . . . .... .... . . . .. ..... . ..... . . . . . . . .... .... . . . .. ..... ..... . . . . . . .... .... . . . .... .... .... ........ .... ......... .... . .... ........ .... .... ........ ............................................................................................................................................................................................................. ... ... ... ... . . . . . . .... . . ..... .... ..... .... . . . . .... . . . . . . ..... ..... .... .... .... .... .... ..... ..... .... .... .... .... .... ..... ..... .. .... .... .... .... .. . ..... ..... . . . . . . . .... . .... . .. ..... ..... . . . . . . .... .... . . . . . .. ..... ..... . . . . . . . .... .... . . .. ..... ..... . . . . . . .... . .... . . . . .. ..... ..... . . . . . .... .... . . . . .. ..... ..... . . . . . . .... .... . . . . .... .... .... ......... .... .... ......... .................................................................................................................................................................................................................

Figure 9.10. The sets Mb and M0 for S51,2 () on a type-1 triangulation with nine vertices.

next example we work with a triangulation that has several degenerate boundary vertices, in which case not all domain points on ∂ are included in Mb . Example 9.23. Consider the spline space S51,2 () on the triangulation shown in Figure 9.10. Discussion: This triangulation has one interior vertex, four nondegenerate boundary vertices, and four degenerate boundary vertices. The number of edges is 16. In this case, the dimension is 70, while the dimensions of Ub and U0 are 32 and 38, respectively. We mark the points in Mb with black dots in Figure 9.10 (left). Similarly, we mark the points in M0 with black dots and triangles in Figure 9.10 (right), where as before triangles are used for points in the sets Me . In section 4.14.2 we introduced a function mds15 for choosing a minimal determining set for S51,2 () and computing the corresponding transformation matrix A. Here we need a modification of that function to construct the minimal determining set described in Theorem 9.21 along with the corresponding transformation matrix. [A,dof,bdof,dofb] = mds15f(x,y,v1,v2,v3,e1,e2,e3,... ie1,ie2,tril,trir,adjstart,vadj,eadj,tstart,tadj,bdy) This function has the same input as mds15, namely information about the triangulation . The first output of this function is)the *transformation matrix A. It is a matrix of size n c × N, where n c := n + (d − 1)n e + d−1 2 n t is the number of B-coefficients of a spline 1,2 in S5 (), and N := 6n v + n e is the dimension of S51,2 (). The other three outputs are vectors describing the minimal determining set. The vector dof of length N gives the indices of the domain points chosen for the minimal determining set. The vector bdof marks the entries in dof that make up Mb . Finally, the vector dofb is of length n c , and identifies whether a given domain point is a degree of freedom or not. More precisely, if the i th domain point, numbered in the same way as the B-coefficients (see section 4.9.1), is a degree of freedom, then dofb(i) gives its position in the list dof. These lists are used in our code for solving boundary-value problems with S51,2 (); see our function fem15 below.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

312

Chapter 9. Boundary-Value Problems

9.5.1 Using S51,2 () with Dirichlet boundary conditions In this section we use the space S51,2 () to solve Problem 9.1 with Dirichlet boundary conditions. A call on mds15f produces the transformation matrix A and all index sets needed to carry out Algorithm 9.17. Here is our implementation: [c,cb,M,t1,t2] = fem15(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,area,bdy,A,dof,bdof,dofb,kappa,f,g) The input includes the usual information about the triangulation . It also includes the transformation matrix A and the lists dof, bdof, and dofb produced by mds15f. Finally, we must also input the names of the functions kappa, f, and g defining the boundary-value problem. The main outputs are the vectors c and cb containing the B-coefficients of the approximating spline, and the spline sb interpolating the boundary data. For diagnostic purposes, we also output the stiffness matrix M, and the times t1 and t2 needed to assemble it and solve the associated system of equations. Example 9.24. Repeat Example 9.11 using the space S51,2 () on type-1 triangulations with vertices at grid points. Discussion: For this example we are enforcing Dirichlet boundary conditions on all four edges of the unit square. We use the script Bfem15, and read in the triangulations from the files type1.9, etc. The following table contains the same information as contained in the tables of Example 9.11: n n0 9 38 25 150 81 590 289 2334

emax 1.56(−3) 2.50(−5) 3.49(−7) 5.24(−9)

rms 3.49(−4) 6.06(−6) 9.77(−8) 1.56(−9)

cond 2.7(3) 7.1(3) 1.1(4) 4.1(4)

ratios 62.40 57.59 71.63 62.03 66.60 62.63

Here we again see a modest growth in the condition number of the stiffness matrix as its size grows. The table exhibits the sixth order of convergence that we expect when using quintic splines. It is instructive to compare the results of this example with those obtained in Example 9.11 with C 0 splines. For example, here we got an RMS error of 9.77(−8) in about .75 seconds using the spline space S51,2 () on a type-1 grid with 81 vertices, whereas using S30 () on a type-1 grid with 1089 vertices gave a comparable RMS error of 7.25(−8), but took 3 seconds to compute. We also emphasize that our spline is now C 1 , instead of just C 0. Example 9.25. Repeat Example 9.12 using the space S51,2 () on a nested sequence of type-1 triangulations. Discussion: In this example we are again enforcing Dirichlet boundary conditions defined by the true solution on all four edges of the unit square. We make use of the script Bfem15, and read in the triangulations from the files type1.9, etc. The following table contains

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.5 Solving second order boundary-value problems using the space S51,2 ()

313

the same information as contained in the tables of Example 9.12: emax n n0 25 150 1.13(0) 81 590 1.09(−1) 289 2334 3.65(−3) 1089 9278 2.34(−4)

rms 1.41(−1) 1.82(−2) 6.04(−4) 2.13(−5)

cond 2.9(3) 5.1(3) 1.8(4) 6.8(4)

ratios 10.37 7.75 29.86 30.13 15.60 28.36

Here we again see a modest growth in the condition number of the stiffness matrix as its size grows. The rate of convergence is less than expected. The results here should be compared with those in Example 9.12. Using S51,2 () on a type-1 grid with 289 vertices, we got an RMS error of 6.04(−4) in about one second, whereas using S30 () on a type-1 grid with 1089 vertices required around three seconds to get an RMS accuracy of 2.31(−4). Of course, the spline here is also smoother since it is C 1 instead of only C 0 . Here is an example on an L-shaped domain. Example 9.26. Repeat Example 9.13 using S51,2 (). Discussion: We now use the script Bfem15L. This script is very similar to Bfem15, except that after using valspgrid to create values of the spline on a rectangle, it then manipulates them so that the errors are computed only for points in the L-shaped domain, and the corresponding plot is trimmed. As a first test, we read the triangulation from the file triL.11, which gives the triangulation shown in Figure 9.4 (left). The max and RMS errors are 1.65(−1) and 3.92(−2), while the condition number of the system being solved is 2048. These errors are worse than what we got with any of the spaces Sd0 () in Example 9.13. We show a plot of the resulting spline in Figure 9.11 (left). It does not correctly model the shape of the true function at this corner since the solution of this problem has singular derivatives at the reentrant corner, while the spline is C 2 at this vertex. With the refined triangulation shown in Figure 9.5 (left) with 18 vertices, we get max and RMS errors of 1.10(−1) and 1.76(−2), which are only slightly better than with the original triangulation. With the further refined triangulation shown in Figure 9.5 (right)

0.8

0.8

0.5 0 -0.5

0 0

0.5

-0.5

0 -0.5

0.5 0

0 0.5

-0.5

Figure 9.11. Left: The spline in S51,2 () on the triangulation shown in Figure 9.5 (left) solving Laplace’s equation on an L-shaped domain with the Dirichlet boundary condition given by the function (9.40). Right: The analogous spline for the refined triangulation shown in Figure 9.5 (right).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

314

Chapter 9. Boundary-Value Problems

with 25 vertices, we get max and RMS errors of 6.82(−2) and 7.24(−3). We show this spline in Figure 9.11 (right). This example shows that in some cases, using spaces of splines with higher smoothness is not advised. We need to pay some attention to the smoothness properties of the solution that we are seeking, if they can be identified. We conclude this section with one example where the domain is a disk. Example 9.27. Repeat Example 9.14 using the space S51,2 () on the triangulations approximating the unit disk used there. Discussion: We make use of the script Bfem15disk. It differs from Bfem0d only in the way it plots the spline. In particular, instead of ignoring grid points outside of the triangulation, it replaces them by zeros. We read the triangulations from the files tridisk.25, tridisk.81, etc. The following table contains the same information as contained in the tables of Example 9.14: n n0 emax 25 126 1.11(−4) 81 534 4.14(−6) 289 2214 6.28(−8) 1089 9030 1.50(−9)

rms 3.55(−5) 9.41(−7) 1.35(−8) 2.26(−10)

cond 2.36(3) 6.89(3) 3.48(4) 1.59(5)

ratios 26.81 37.73 65.92 69.70 41.87 59.73

The rates of convergence are consistent with the expected order 6 associated with quintic splines. As in earlier experiments, we see a modest growth in the condition number of the stiffness matrix as its size grows. Once again we see the advantages of using a higher degree spline space. Using S51,2 () on the triangulation tridisk.25 produced better errors that S30 () on the triangulation tridisk.81; see Example 9.14. In addition, the computational time is now .05 seconds as compared to .15 seconds for the cubic spline, and our spline is now C 1 instead of just C 0.

9.5.2 Using S51,2 () with mixed boundary conditions Following the discussion in section 9.4, it is straightforward to modify the function fem15 of the previous section to solve the second order boundary-value problem given in Problem 9.2 with mixed boundary conditions using the spline space S51,2 (). We assume that both ∂ D and ∂ N are unions of edges of the polygonal boundary ∂ of . They need not be connected, but we do require that ∂ = ∂ D ∪ ∂ N . To find the B-coefficients of the spline approximation, we have to set up the stiffness matrix M˜ and the right-hand vector r˜ appearing in (9.22). The entries of M˜ are computed as before using a quadrature formula on each triangle to compute the quantities in (9.35). We use the quadrature rule described in section 4.6 with 25 sample points. Note that the stiffness matrix in (9.22) here is slightly larger than the one in (9.17), since here the number n 0 of basis functions spanning the spline subspace U˜ 0 in (9.19) is larger than the number needed to span the subspace U0 in (9.10). To get the vector r˜ , we now have to compute integrals over the edges in the set ∂ N . For this we use a standard 5-point Gauss quadrature rule that samples at appropriate points

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.5 Solving second order boundary-value problems using the space S51,2 ()

315

in the interior of each such edge. Note that this means that we don’t make use of values of h at corners of the boundary ∂ N . We have implemented the Ritz–Galerkin method for solving Problem 9.2 using the spline space S51,2 () in the function [c,Mi,t1,t2] = fem15mix(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,area,bdy,kappa,A,dof,bdof,dofb,eb,ebn,f,g,h) The input and output of this function are the same as for the function fem0dmix, except that here we must also input the transformation matrix A and the lists dof, bdof, and dofb produced by mds15f. Example 9.28. Repeat Example 9.15 using the space S51,2 () on a sequence of nested type-1 triangulations. Discussion: In this example we enforce Dirichlet boundary conditions on the left and top edges of the unit square, and Neumann boundary conditions on the bottom and right edges. We make use of the script Bfem15mix, and read in the triangulations from the files type1.9, etc. The following table contains the same information as contained in the tables of Example 9.15: n n0 9 53 25 177 81 641 289 2433

emax 1.56(−3) 2.40(−5) 3.49(−7) 5.24(−9)

rms 5.01(−4) 7.52(−6) 9.86(−8) 1.37(−9)

cond 4.6(3) 1.2(4) 4.3(4) 1.6(5)

ratios 65.00 66.62 68.77 76.27 66.60 71.97

The errors obtained here are almost identical to those obtained with only Dirichlet boundary conditions in Example 9.24. The table shows the sixth order of convergence that we expect when using quintic splines. As before, we see a modest growth in the condition number of the stiffness matrix as its size grows. We can compare the results here with those in Example 9.15. On a type-1 grid with 81 vertices, here we got an RMS error of 9.86(−8) in about .2 seconds, whereas using S30 () on a type-1 grid with 1089 vertices required 3 seconds to get essentially the same accuracy. Using C 0 linear splines was even worse, where on a type-1 grid with 4225 vertices it required 7 seconds to get an RMS accuracy of only 4.38(−4).

9.5.3 Using S51,2 () with Neumann boundary conditions The function fem15mix in the previous section cannot be used for solving Problem 9.2 in the case where only Neumann boundary conditions are specified. But following the discussion in section 9.2.3, we can modify it to deal with pure Neumann conditions. First, we recall from section 9.2.3 that for a solution of Problem 9.2 to exist where  D is empty, the compatibility condition (9.24) must be satisfied. The key is to observe that without Dirichlet boundary conditions, all of the domain points in the set M := Mb ∪ M0 of Theorem 9.21 are associated with degrees of freedom. Thus, the matrix Mˆ appearing in (9.27) is of size N × N, where N = 6n + n e is the dimension of S51,2 (). But as observed

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

316

Chapter 9. Boundary-Value Problems

in section 9.2.3, it turns out that Mˆ is singular. As in section 9.3.3, we can overcome this ˆ This corresponds to setting the Bproblem by dropping the first row and column of M. coefficient associated with the domain point at the first vertex of  to be zero. Here is the resulting code. [c,M,t1,t2] = fem15neu(d,x,y,v1,v2,v3,e1,e2,e3,ie1,ie2,... tril,trir,area,bdy,kappa,f,h,A); The input includes information on the triangulation, along with the functions f and h describing the right-hand side of the differential equation and the Neumann boundary conditions, respectively. We also need to input the transformation matrix A. As before, the main output is the vector c of B-coefficients of the approximating spline, but for diagnostic purposes, we also output the stiffness matrix M and the times t1 and t2 to assemble and solve the corresponding sparse linear system. Example 9.29. Redo Example 9.24, where now the Dirichlet boundary conditions are replaced by pure Neumann boundary conditions defined by the true solution. Discussion: We make use of the script Bfem15neu, and read in the triangulations from the files type1.9, etc. This script uses the function mds15 of section 4.14.2 to choose degrees of freedom and construct the transformation matrix A. The following table contains the same information as contained in the tables of Example 9.24: n nc 9 69 25 205 81 693 289 2533

emax 1.56(−4) 5.34(−6) 5.93(−8) 7.46(−10)

rms 4.98(−5) 1.45(−6) 1.82(−8) 2.57(−10)

cond 4.8(4) 2.5(5) 1.1(6) 5.4(6)

ratios 29.21 34.34 90.05 79.67 79.50 70.82

The errors obtained here are actually slightly better than those obtained with Dirichlet boundary conditions in Example 9.24. Here we again see a modest growth in the condition number of the stiffness matrix as its size grows. The table show the sixth order of convergence that we expect when using quintic splines. On a type-1 grid with 81 vertices, here we got an RMS error of 1.82(−8) in about .23 seconds, whereas using S30 () on a type-1 grid with 1089 vertices required around 3 seconds to get an RMS accuracy of 7.25(−8); see Example 9.16. As an additional bonus, we now have a C 1 spline rather than one that is just C 0 .

9.6 Solving the biharmonic equation with C 1 quintic splines To use the Ritz–Galerkin method to solve Problem 9.3 using splines, we need to work with a space which is C 1 , and which is big enough to allow us to satisfy the boundary conditions (9.8) and (9.9). Given any triangulation , let Sˆ51,2 () := {s ∈ S51 () : s ∈ C 2 (v) for all v ∈ V I },

(9.48)

where V I is the set of interior vertices of . This space is bigger than S51,2 (), since here we have enforced supersmoothness at interior vertices only. To use it for the biharmonic

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.6. Solving the biharmonic equation with C 1 quintic splines

317

Figure 9.12. The minimal determining sets Mv for Sˆ51,2 () on two-disks around boundary vertices. Top: The case of nondegenerate vertices. Bottom: The case of degenerate vertices. The points in Mbv are marked with black dots, while those in Mov are marked with squares. Domain points not in Mv are marked with open dots.

equation, we decompose it into the direct sum Sˆ51,2 () = U0 ⊕ Ub ,

(9.49)

U0 := {s ∈ S() : s(x, y) = Dn (x, y) = 0, all (x, y) ∈ ∂},

(9.50)

where and Dn denotes the outward normal derivative for points on ∂. We now need to construct stable local minimal determining sets Mb and M0 for Ub and Uh . We first examine two-disks associated with boundary vertices of . Given such a v, let T1 , . . . , Tm v be the triangles attached to v, listed in counterclockwise order, and let T˜1 , . . . , T˜m v be their interiors. If v is a nondegenerate boundary vertex, let Mbv := all domain points in (D2 (v) ∩ ∂) ∪ (R2 (v) ∩ (T˜1 ∪ T˜m v )), Mov := all domain points in R2 (v) ∩ (T˜2 , . . . , T˜m v −1 ). If v is a degenerate boundary vertex, we modify these sets by removing the last point on R1 (v) (in counterclockwise order) from Mbv , and inserting the second point on R1 (v) in M0v . We illustrate these sets in Figure 9.12, where points in Mbv are marked with black dots, those in Mov are marked with squares, and domain points not in Mv are marked with open dots. Lemma 9.30. Suppose v is a boundary vertex of , and let Mv := M0v ∪ Mbv . Then all Bcoefficients of s ∈ Sˆ51,2 () associated with domain points in D2 (v) are uniquely determined by those associated with Mv . Proof. We first consider the case that v is nondegenerate. Suppose we set the coefficients of s ∈ Sˆ51,2 () associated with Mv to arbitrary values. This determines the x- and yderivatives of s at v, and thus all domain points in D1 (v). Then for each interior edge

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

318

Chapter 9. Boundary-Value Problems

e attached to v, the coefficient associated with the domain point in e ∩ R2 (v) is uniquely determined by a C 1 condition across that edge; see Figure 9.12, top right. The case where v is degenerate is simpler. In this case we proceed in a counterclockwise direction around v and use C 1 conditions across the interior edges attached to v to uniquely compute the unset coefficients associated with domain points on the ring R1 (v). The undetermined coefficients on R2 (v) are then determined by C 1 smoothness conditions as before. This lemma deals with two-disks around boundary vertices. If v is an interior vertex, we can choose Mv in the same way as we did in section 4.14.2 for S51,2 (), i.e., we pick a triangle Tv attached to v and choose the six domain points in D2 (v) ∩ Tv . Now let Vb and V I be the sets of boundary and interior vertices of , respectively, and let E be the set of all edges of . For each e ∈ E, let Me be as in Theorem 4.34, and set Mb :=

1 v∈Vb

M0 :=

1

v∈Vb

Mbv , M0v ∪

1 v∈V I

Mv ∪

1

Me .

e∈E

Theorem 9.31. The sets Mb and M0 are minimal determining sets for the spline spaces Ub and U0 in (9.49), and M := Mb ∪ M0 is a minimal determining set for Sˆ51,2 (). Moreover, N := dim Sˆ1,2 () = 6n + n e + n b , (9.51) 5

i

where n, n e are the numbers of vertices and edges of , and n bi is the number of interior edges attached to boundary vertices. Proof. The proof is similar to the proof of Theorem 6.1 in [[LaiS07]]. First, if we set to zero all of the coefficients corresponding to M of a spline s ∈ Sˆ51,2 (), then using the C 1 smoothness conditions, it is easy to see using Lemma 9.30 that s ≡ 0. This means that M is a determining set. On the other hand, we can set each of these coefficients to an arbitrary value, and then choose all remaining coefficients by the C 1 smoothness conditions. Since this does not lead to any inconsistencies, we conclude that M is actually a minimal determining set for Sˆ51,2 (). It follows that the dimension of S() is the cardinality of M, which is given by the formula (9.51). In Figure 9.13 we show the sets Mb and M0 for a triangulation with nine vertices. In this example all seven boundary vertices are nondegenerate. For this triangulation, there are 56 points in Mb and 24 points in M0 for a total of 80 degrees of freedom. Points in the sets Me associated with edges are marked with triangles. In Figure 9.14 we show the analogous sets for a type-1 triangulation with nine vertices, four of which are degenerate boundary vertices. In this case, there are 62 points in Mb and 18 points in M0 for a total of 80 degrees of freedom. To use Sˆ51,2 () in practice, we need a function that will compute the minimal determining sets Mb and M0 , and the transformation matrix A associated with M := Mb ∪ M0 .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.6. Solving the biharmonic equation with C 1 quintic splines ....................................................... ............ . ......................... ...................... ............ ... ... ............ ...... ... .... ......... ... ... ... ... ... .... ... ... . ....... . ... ... ... ... ... . ... . . . . ... ...... . . ... ... ... ... ... ... ... . . . . . . . ... ... ... ... ... ... ... . . . . . . . . . ... ... ... .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... . . . ... . . . . . ... ... ... ... ... ... ... . . . . .... . . . ... ... ... ... ... ... ... . . . ... . . . . ... ... ... ... ... ... . . . . ... . . . . ..... ... ... .. . . ... . . . . ... . . . . . . . . . . . . ... ..... ... ... ... ............ .... ........................... ........ . . . . . . . . . . . . . . . . . . . . . . . . . . .............. ... ..... ............. .. .............. ......... ...................... ... . ............ . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... . . . . . . ................................... ... .. ............ .... ..... . . ... . . ................... . . .. .... .. ... ..... ... ..... ..... .... ... .... ..... .... ... .. ... ..... ..... ... ... ..... .... ... ... ..... ... ..... .... ..... ... ..... ... .... . . . ..... . . . . ... ... .. ..... ..... ... ..... ... ... ..... ..... ... .... .... ... ..... ... ... ..... ... ..... ... .... ... ..... ... .... ..... ..... ... .. .... ..... ..... . . . . . . . . . ... ..... . . ..... ..... ........ ... ...... ..... .. .... .. ... ..... .. ..... ...........................................................................................................

319

....................................................... ............ . ......................... ...................... ............ ... ... ............ ...... ... .... ......... ... ... ... ... ... .... ... ... . ....... . ... ... ... ... ... . ... . . . . ... ...... . . ... ... ... ... ... ... ... . . . . . . . ... ... ... ... ... ... ... . . . . . . . . . ... ... ... .. .. .. ... ... ... ... ... ... ... ... ... ... ... ... ... . . . ... . . . . . ... ... ... ... ... ... ... . . . . .... . . . ... ... ... ... ... ... ... . . . ... . . . . ... ... ... ... ... ... . . . . ... . . . . ..... ... ... .. . . ... . . . . ... . . . . . . . . . . . . ... ..... ... ... ... ............ .... ........................... ........ . . . . . . . . . . . . . . . . . . . . . . . . . . .............. ... ..... ............. .. ... ... .............. ...................... ... . ............ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ... . . . . . . . ................................... ... .. ............ .... ..... . . ... . . ................... . . .. .... .. ... ..... ... ..... ..... .... ... .... ..... .... ... .. ... ..... ..... ... ... ..... .... ... ... ..... ... ..... .... ..... ... ..... ... .... . . . ..... . . . . ... ... .. ..... ..... ... ..... ... ... ..... ..... ... .... .... ... ..... ... ... ..... ... ..... ... .... ... ..... ... .... ..... ..... ... .. .... ..... ..... . . . . . . . . . ... ..... . . ..... ..... ........ ... ...... ..... .. .... .. ... ..... .. ..... ...........................................................................................................

Figure 9.13. The sets Mb and M0 for Sˆ51,2 () on a triangulation with nine vertices. Points in M are marked in black, with triangles reserved for points in the sets Me associated with edges. .......................................................................................................................................................................................................... .. .. ..... ..... ... ..... ... .... .... .... ... .. ..... ..... .. ..... .... .... . ..... ..... .... ..... ..... .... .... .. ..... ..... . . . . . . . . ..... .... .. .. . ... ..... ..... . . . . . . . . . . .... . .. .. ... ..... . ..... . . . . . . . ..... . . . .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ......... ..... ..... ........ . .. .... ......... .... .... ........ .......................................................................................................................................................................................................... . .... .... . ..... .... . . . . . . .... .. . .. . ..... .... ..... .... . . . . ..... . . .. .. .... ..... ..... ..... ..... ..... ..... .... .... ..... ..... ..... ..... ..... .... .... ..... ..... ..... ..... ..... .... ..... . ..... ..... . . . . . . . ..... ..... . .. .. ... ..... ..... . . .... . . . . . ..... . .. .. . ... ..... ..... . . . . . . . .... .... . .. .. ... ..... ..... . . . . ..... ..... . . . .. .. ... ..... ..... . . . . . ..... ..... . . . .. ..... ..... ..... ........ ..... ..... ........ .. .. ...................................................................................................................................................................................................

.............................................................................................................................................................................................. .. ..... .. ..... .. ..... ..... ... ..... ... .... .... .... ... .. ..... ..... ... ..... .... .... . ..... ..... ..... ..... ..... .... .... . ..... ..... . . . . . . . . ..... .... .. .. . ... ..... ..... . . . . . . . . . . .... . .. .. ... ..... . ..... . . . . . . . ..... . . . .. .. .. ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ..... ......... ..... ..... ........ . .. .... ......... .... .... ........ .......................................................................................................................................................................................................... . .... .... . ..... .... . . . . ..... . . .. . .. . ..... .... ..... .... . . . . ..... . . .. .. .... ..... ..... ..... ..... ..... ..... .... .... ..... ..... ..... ..... ..... .... .... ..... ..... ..... ..... ..... .... ..... . ..... ..... . . . . . . . ..... ..... . .. .. ... ..... ..... . . .. . . . . . ..... . . .. .. ... ... ..... ..... . . . . . . . . .... . . .. .. .. .. ..... ..... . . . . . . ..... . . . . .. .. ... ... ..... ..... . . . . . . ..... . . . . .. .. ..... ..... ..... ........ ..... ..... ........ .. .. ...................................................................................................................................................................................................

Figure 9.14. The sets Mb and M0 for Sˆ51,2 () on a type-1 triangulation with nine vertices. Points in the sets Me associated with edges are marked with triangles.

Here is such a function: [A,dof,dofb] = mds15bh(x,y,v1,v2,v3,e1,e2,e3, ie1,ie2,tril,trir,adjstart,vadj,eadj,tstart,tadj,bdy) The input consists of the usual lists describing the triangulation as produced by trilists. The main outputs are the transformation matrix A and the vector dof listing the domain points in the minimal determining set M. We also output a vector dofb which marks which domain points are in M. In particular, dofb(i) is zero if the domain point with index i is not in M. If it is in M, dofb(i) gives its location in the vector dof. For each ξ ∈ M0 , let φξ be its corresponding dual-basis spline as defined in section 4.13.4. By the support properties of φξ , it is clear that the values and first derivative in any direction all vanish on ∂. These splines form a basis for the set U0 defined in (9.49). Similarly, for each ξ ∈ Mb , let ψξ be its corresponding dual-basis spline. These splines form a basis for Ub . All of these basis splines have small supports, which means that the associated stiffness matrix arising in the Ritz–Galerkin method will be sparse. To solve Problem 9.3, we now look for a spline s ∈ Sˆ51,2 () in the form   cξ ψξ + c ξ φξ . (9.52) s = sb + s0 := ξ ∈ Mb

ξ ∈ M0

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

320

Chapter 9. Boundary-Value Problems

where sb takes care of the boundary conditions (9.8) and (9.9), and s0 satisfies homogeneous boundary conditions. Here is an outline of an algorithm for computing the coefficients of these splines, where we write n c for the number of B-coefficients of a spline in Sˆ51,2 (), and N for the dimension of Sˆ51,2 (). 1) For each boundary edge e := v2 , v3  of , let T := v1 , v2 , v3  be the triangle in  that contains e. Let P be the set of domain points in M that lie on e. Find coefficients of aξ so that ξ ∈P aξ BξT interpolates the values of the function g in (9.8) at the points of P. Store them in a vector c˜ of length n c according to the storage convention in section 4.9.1. 2) Let e and T be as in 1), and let u e be the unit vector describing the normal derivative along the edge e, i.e., a vector that is orthogonal to e and points out of the domain . Let P be the set of domain points in M that lie in T in the first row parallel to e, but not  on the boundary of . Let m be the cardinality of P. Find coefficients aξ so that ξ ∈P aξ BξT interpolates the values of the function h in (9.9) at m equally spaced points in the interior of e. Store them in a vector of c˜ of length n c according to the storage convention in section 4.9.1. 3) Let cˆ be a vector of length N whose components are cˆi = c(do ˜ f i ) for i = 1, . . . , N, where dof is the list of B-coefficients that form a determining set for Sˆ51,2 () as produced by mds15b. Compute cb := Ac. ˆ These will be the B-coefficients of the spline sb in (9.52). 4) Set up and solve the system (9.34) for the coefficients {cξ }ξ ∈M0 . Insert these in the vector c, ˜ and let cˆ be the vector whose components are cˆi = c(do ˜ f i ) for i = 1, . . ., N. Compute c := A5 c. These will be the B-coefficients of the Ritz–Galerkin spline approximation s to the solution of Problem 9.3. Here is our implementation of this algorithm: [c,cb,M,t1,t2] = fem15bh(d,x,y,v1,v2,v3,e1,e2,e3,... ie1,ie2,tril,trir,area,bdy,A,dof,dofb,f,g,ux,uy) The input includes the usual information about the triangulation  along with the transformation matrix A and vectors dof and dofb produced by mds15bh. It also inputs the name of the functions f and g appearing on the right-hand side of the differential equation (9.7) and in (9.8), respectively. For convenience, instead of passing the function h describing the normal derivative in the boundary condition (9.9), here we instead give functions ux and uy describing the x- and y-derivatives of u. For polygonal domains, these functions are typically easier to describe than h. The main output of this function is a vector c containing the B-coefficients of the approximating spline. For diagnostic purposes, we also output the stiffness matrix M used in Step 4 above, and the times t1 and t2 needed to assemble M and solve the associated system of equations. It should be noted that for a typical triangulation , the number of degrees of freedom (the length of dof) is much smaller than the total number of B-coefficients of our spline s. Moreover, the size of the linear system (9.34) is even smaller, since only the coefficients in {cξ }ξ ∈M0 are being computed from this system.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.6. Solving the biharmonic equation with C 1 quintic splines

8

8

1 1

1

321

1 1

0.5

1

0.5

0.5 0 0

0.5 0 0

Figure 9.15. The spline s ∈ Sˆ51,2 () on the type-1 triangulation with 25 vertices solving the boundary-value problem of Example 9.32, and the corresponding spline sb interpolating the boundary data.

We now give an example to illustrate the Ritz–Galerkin method for solving the biharmonic equation using Sˆ51,2 (). Example 9.32. Find an approximate solution u ∈ Sˆ51,2 () of the biharmonic equation 2 u(x, y) = 4e x+y on the unit square with the boundary conditions (9.8) and (9.9) with g(x, y) := h(x, y) := e x+y . Discussion: It is easy to check that exact solution of this problem is u(x, y) = e x+y . We make use of the script Bfem15biharm and the sequence of nested triangulations type1.9, . . . , type1.289. Here is a table of the max and RMS error bounds. For each run, we list the number n of vertices, the number n c of B-coefficients, and the size n 0 of the linear system being solved. We also give the condition numbers of the matrix M for each case. Finally, in order to get an idea of the order of convergence, we tabulate the ratios of both max and RMS errors. n nc n0 9 121 18 25 441 106 81 1681 498 289 6561 2146

emax 3.09(−5) 6.00(−7) 9.81(−9) 1.49(−10)

rms 1.02(−5) 1.27(−7) 1.49(−9) 4.17(−11)

cond 9.3(+2) 1.6(+4) 2.5(+5) 3.9(+6)

ratios 51.50 80.31 61.16 85.23 65.84 35.73

Since we are dealing with quintic splines, we expect a convergence rate of order 6. In Figure 9.15 (left) we show the final Ritz–Galerkin spline based on the type-1 triangulation with 25 vertices, while in Figure 9.15 (right) we show the corresponding spline sb interpolating the boundary data. We now give an example where the domain is the unit disk. Example 9.33. Find an approximate solution u ∈ Sˆ51,2 () of the biharmonic equation 2 u = f on the unit disk with f and boundary conditions determined from u(x, y) = x 3 y 2 (1 − x 2 − y 2).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

322

Chapter 9. Boundary-Value Problems

Discussion: We make use of the script Bfem15bhdisk. It differs from Bfembiharm only in the way it plots the spline. In particular, instead of ignoring grid points outside of the triangulation, it replaces them by zeros. We look at the sequence of nested triangulations corresponding to the files tridisk.9,. . ., tridisk.1089. The first two of these triangulations are shown in Figure 9.6. Here is a table of the max and RMS error bounds. For each triangulation, we also list the number n of vertices, the number n c of B-coefficients, the size n 0 of the linear system being solved, and the condition number of the stiffness matrix M. n nc n0 emax 9 121 14 9.42(−3) 25 441 102 3.55(−4) 81 1681 494 1.34(−5) 289 6561 2142 2.28(−7) 1089 25921 8894 2.07(−8)

rms 3.79(−3) 1.01(−4) 2.09(−6) 7.79(−8) 6.06(−9)

cond 5.56(+2) 2.16(+4) 4.72(+5) 1.28(+7) 2.63(+8)

ratios 26.53 37.25 26.49 48.33 58.77 26.83 11.01 12.85

Since we are dealing with quintic splines, we expect a convergence rate of order 6, but the ratios are a little too erratic to say exactly what the rate is. The solution here is the same as that in Example 9.14. The splines here look exactly like the one in Figure 9.7 (right), so we do not bother to plot any of them.

9.7 Remarks Remark 9.1. The approach used in this chapter is quite different from the standard FEM approach, which although based on piecewise polynomials on triangulations, usually involves finding mappings from a standard reference triangle to each of the triangles in the triangulation. This approach becomes complicated when we want to work with splines that have smoothness C r with r > 0. Our approach here is to work directly with the B-form of the splines, thus eliminating the need for a reference triangle and the associated maps. So far this approach has been used by only a few spline practitioners (see, e.g., [LaiW96, LaiW98, LaiW99, LaiW00, LaiLW03, LaiW04, AwaLW06, SpeDV06, Schum08, AinAD11]), but we hope that it will become more widely used. Remark 9.2. The Bernstein–Bézier approach has particular advantages when working with spaces of splines with smoothness C 1 or greater. As shown in several examples in the chapter, smoother spaces of splines tend to give better results than their C 0 analogs. Moreover, for higher order problems such as the biharmonic equation, they are in fact required for conformality (see Remark 9.9), although in practice, conformality is often ignored. Remark 9.3. We have not addressed the questions of existence of solutions of the boundary-value problems considered in this chapter. Both existence and uniqueness results can be found in the standard PDE literature, along with regularity results describing the smoothness of solutions. For an accessible discussion, see [[Goc06]]. Remark 9.4. We have not given error bounds for the Ritz–Galerkin method here. Such results can be found in the standard finite-element literature; see, e.g., [[BreS94, Goc06]]. Such bounds are usually given in terms of the L 2 norm or in terms of certain energy norms involving the L 2 norm of derivatives, but are also available for L ∞ norms. Note that here our tables of errors are all based on the maximum norm.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

9.7. Remarks

323

Remark 9.5. As we have seen, in general we have to resort to numerical quadrature to compute the integrals arising in the Ritz–Galerkin method. Clearly, the accuracy of such methods will affect the accuracy of the overall algorithms. The programs discussed in this chapter use standard Gaussian quadrature formulae based on 25 sample points. This gives exact integrals for polynomials of degree up to degree 10. More accurate formulae are available in the literature, and indeed, the function quadset described in section 4.6 has the option of using 79 sample points to exactly integrate polynomials up to degree 23. This will slow down our programs by a factor of about three, and for the spaces of splines used here will not lead to much improvement in accuracy. Remark 9.6. There has been recent research on alternative quadrature formulae that are especially useful for computing integrals of polynomials in Bernstein–Bézier form; see [AinAD11]. Remark 9.7. In this chapter we have illustrated the use of the Ritz–Galerkin method with only a few typical spline spaces. The method works equally well with all of the other macro-element spaces discussed in earlier chapters, and the many more available in the literature; see [[LaiS07]]. As we saw in section 9.5, the key is to be able to construct convenient stable local minimal determining sets for the decomposed space. Remark 9.8. The astute reader will have noticed that there is a minor problem in specifying Neumann boundary conditions at a corner v of a domain since there is no well-defined outward normal at such a point. We deal with this problem by using only one of the two possible normals associated with the two edges that share v. Remark 9.9. In choosing a spline space S() to use for a specific boundary-value problem, we want S() to have enough smoothness to ensure that the integrals appearing in the Ritz– Galerkin formulation are well defined. For example, for second order problems, we want splines which are a subspace of the Sobolev space H 1. Thus, it is enough to work with C 0 splines. However, for fourth order problems, we need splines that lie in H 2, which means that we will have to work with C 1 splines. When these conditions hold, we say that the spline space is conforming. Remark 9.10. Domains with curved boundaries are frequently encountered in practice. Here we have simply approximated such boundary curves by polygons. However, as an alternative, one could allow triangulations which contain triangles with one or more curved edges. The Bernstein–Bézier representation of a polynomial p relative to a triangle T can be used to evaluate p and its derivatives not only at points in the triangle, but everywhere. In particular, we can work on a polygonal domain, and simply extend our spline to the larger domain with curved boundary. This eliminates the need to create parametric mappings to curved triangles, but raises interesting questions about how to handle boundary conditions and what happens to error bounds. Remark 9.11. The methods of this chapter work for arbitrarily shaped polygonal domains, even with holes. However, as we saw in Example 9.13, if the domain has a reentrant corner, we have to be careful in selecting an appropriate spline space. Remark 9.12. As we saw in Example 9.13, when the behavior of the solution we are seeking varies greatly in different parts of the domain, it may be better to use a triangulation that is graded in the sense that we use smaller triangles in areas where we need improved

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

324

Chapter 9. Boundary-Value Problems

approximation power. This is often achieved by local adaptive refinement of a given mesh. To do this in practice in the case where we don’t know the solution, we need some kind of a posteriori error indicator to tell us where to refine. This idea has been heavily studied in the FEM literature. Remark 9.13. We have reduced problems involving nonhomogeneous boundary conditions to ones with homogeneous boundary conditions by first constructing a spline sb in the approximating space that (approximately) satisfies the boundary conditions. But the approach works just as well if sb is taken from a different spline space, as long as the needed inner products can be computed. Thus, it may be desirable to work on two different meshes, one of which has been locally refined only near the boundary to allow for better approximation of the boundary conditions. Remark 9.14. In this chapter we have focused on the use of splines defined over triangulations for solving boundary-value problems. But as observed in Remark 2.19, when  is a rectangle, tensor-product splines can also be used. In fact, they can also be used in the case when  is not a rectangle. For a full discussion, see [[Hol03]].

9.8 Historical notes The idea to use spaces of piecewise polynomials defined over triangulations for solving boundary-value problems has been around for a long time. For example, C 0 hat functions were used in [Cour43]. It is not our aim to trace the history of the FEM here, but see standard books such as [[BreS94, Goc06]]. Much of the work in the engineering literature is based on spline spaces with global smoothness C 0 . However, as shown in the examples of the chapter, there are several advantages to using smoother spline spaces. For some early work where smoother spline spaces defined over triangulations were used in the FEM, see [Zla68, Zla70, Cia74, CloT65, Zen73, Zen74, PowS77]. The standard approach to working with splines defined over triangulations in the FEM literature is to make use of parametric maps from a reference triangle to each of the triangles in the triangulation. One of the key aims of this chapter is to illustrate the convenience of working directly with Bernstein–Bézier representations of the splines, rather than with parametric maps. This approach is just starting to be explored in the FEM literature; see, e.g., [LaiW96, LaiW98, LaiW99, LaiW00, LaiW00b, LaiL03, LaiW04, AwaLW05, SpeDV06, Schum08, AinAD11].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 10

Spherical Splines

In this chapter we develop computational tools for working with splines defined on triangulations on the surface of a sphere. These are then used in the following chapter to describe various applications of spherical splines, including interpolation and data fitting on the sphere, and numerical solution of boundary-value problems on the sphere.

10.1 Spherical triangulations Throughout this chapter, whenever we talk about the sphere we mean the sphere in R3 of radius one centered at the origin. We denote it by S. However, most of what we do in this chapter would work just as well on a sphere of any radius. In this section we discuss various properties of triangulations lying on the surface of the sphere, along with MATLAB code for dealing with them.

10.1.1 Spherical triangles Let v1 , v2 be two points on the sphere which are not antipodal, i.e., they do not lie on a line through the center of the sphere. Then the points v1 , v2 divide the great circle passing through v1 , v2 into two circular arcs. We write v1 , v2  for the shortest of the arcs. Its length is just the geodesic distance between v1 and v2 . Suppose v1 , v2 , v3 are three points on the sphere S such that no pair of them is antipodal. Then we define the associated spherical triangle T := v1 , v2 , v3  to be the set of points on S that lie in the region bounded by the three circular arcs vi , vi+1 , i = 1, 2, 3, where we identify v4 = v1 . We say that T is nondegenerate, provided that T has nonzero area, where to compute the area of a spherical triangle, we can use the fact that area(T ) = a1 + a2 + a3 − π, where a1 , a2 , a3 are the angles at the vertices v1 , v2 , v3 . To compute the angle a1 , let u 12 be the unit vector that is tangent to the arc v1 , v2  at v1 , and let u 13 be the analogous unit vector tangent to the arc v1 , v3  at v1 . Then a1 is the arccos of the inner product of u 12 with u 13 . The computation of the other angles is similar. 325

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

326

Chapter 10. Spherical Splines

Figure 10.1. The spherical triangulations sptri1 and sptri2.

SplinePak contains the following function for computing the area of a triangle, where (x1,y1,z1), (x2,y2,z2), and (x3,y3,z3) are the Cartesian coordinates of the three vertices of T : area = sarea(x1,y1,z1,x2,y2,z2,x3,y3,z3) It can be tested on the spherical triangle with vertices at (1, 0, 0), (0, 1, 0), and (0, 0, 1); see the script SPtridemo below. This triangle corresponds to one-eighth of the sphere, and has an area equal to π/2.

10.1.2 Spherical triangulations We begin with a definition. Definition 10.1. A set of spherical triangles  := {Ti }1N is called a spherical triangulation, provided that the intersection of any two triangles in  is empty, or is a common vertex or -N Ti for the associated domain. We are mostly interested common edge. We write  := i=1 in the case  = S, in which case we say that  covers S. Figure 10.1 shows two examples of spherical triangulations that cover the sphere. We refer to the one on the left as sptri1. It has n = 6 vertices lying on the Cartesian axes, n e = 12 edges, and n t = 8 triangles. The triangulation on the right is the uniform refinement of the one on the left; see section 10.1.4. We call it sptri2. It has n = 18 vertices, n e = 48 edges, and n t = 32 triangles. These numbers can be checked using the following Euler relations for a spherical triangulation that covers the sphere: 1) n e = 3n t /2, 2) n t = 2n − 4, 3) n e = 3n − 6, where n, n e , n t denote the number of vertices, edges, and triangles in ; see Theorem 13.33 of [[LaiS07]]. Suppose  is a spherical triangulation that covers only part of S. Following [[LaiS07]], we say that  is regular, provided that for every vertex of , the union of the set of triangles with a vertex at v is connected. For regular spherical triangulations that cover only part of S, the same Euler relations as in the planar case hold; see section 3.13.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.1. Spherical triangulations

327

To facilitate working with spherical triangulations, we have written several functions for dealing with them. The first one reads a spherical triangulation from a file: [n,x,y,z,nt,TRI] = sreadtri This function asks for a file name, and returns the number n of data points and the number nt of triangles, along with vectors x,y,z containing the coordinates of the vertices, and an nt × 3 matrix containing the indices of the triangles. In working with splines on a spherical triangulation , we will need some additional information about how the triangles fit together. First we need to orient and number the edges. We store this information in two vectors ie1 and ie2 of length n e which contain the indices of the first and second endpoints of each edge. For each edge, we also need to know the indices of the triangles that lie to the left and to the right. We store these indices in the vectors tril and trir, which are also of length n e . Finally, it is also useful to be able to look up the numbers of the edges that make up a given triangle. We store these in the vectors e1,e2,e3 of length n t . These edges are listed in counterclockwise order, where for each 1 ≤ i ≤ n t , the edge e1(i) has endpoints v1(i) and v2(i). The following function computes these vectors for a triangulation TRI whose vertices have coordinates x,y,z. [v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir] = slists(x,y,z,TRI) The output of this function includes the list of vertices v1,v2,v3 of the triangles, possibly rearranged to ensure that all triangles have positive area. As with the lists associated with planar triangles, the edges are oriented so that i e1(i ) < i e2(i ) for all 1 ≤ i ≤ n e . We have also written the following function to render a spherical triangulation: srendtri(x,y,z,ie1,ie2) The following script can be used for testing these various functions. It calls sreadtri to input the spherical triangulation, and then calls slists to find the following lists: e1,e2,e3,ie1,ie2,tril,trir. Next, it calls srendtri to render . Then the script calls the function sarea described above to compute the area of each of the triangles in the triangulation. As we know, these should add up to the area of the entire sphere, which is 4π. % SPtridemo [n,x,y,z,nt,TRI] = sreadtri; [v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir] = slists(x,y,z,TRI); srendtri(x,y,z,ie1,ie2); for i = 1:nt v1i = v1(i); v2i = v2(i); v3i = v3(i); area(i) = sarea(x(v1i),y(v1i),z(v1i),... x(v2i),y(v2i),z(v2i),x(v3i),y(v3i),z(v3i)); end sumarea = sum(area)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

328

Chapter 10. Spherical Splines Table 10.1. Output of slists for the triangulation sptri1.

1 2 3 4 5 6 7 8 9 10 11 12

v1 1 1 1 1 6 6 6 6

v2 2 3 4 5 3 4 5 2

v3 3 4 5 2 2 3 4 5

e1 1 3 5 7 9 11 12 10

e2 2 4 6 8 2 4 6 8

e3 3 5 7 1 10 9 11 12

area 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708 1.5708

ie1 1 2 1 3 1 4 1 2 3 2 4 5

ie2 2 3 3 4 4 5 5 5 6 6 6 6

tril 1 1 2 2 3 3 4 8 6 5 7 8

trir 4 5 1 6 2 7 3 4 5 8 6 7

Figure 10.2. The spherical triangulation sptri42; see Example 10.2.

Example 10.2. Test the script SPtridemo with the data files sptri1, sptri2, and sptri42. Discussion: Table 10.1 shows a summary of the output of slists when run with the data file sptri1, which corresponds to the triangulation shown in Figure 10.1 (left). This triangulation has n = 6 vertices, ne = 12 edges, and nt = 8 triangles. Running SPtridemo with the file sptri2 renders the triangulation shown in Figure 10.1 (right). With the file sptri42, we get the spherical triangulation shown in Figure 10.2. It has n = 42 vertices, ne = 120 edges, and nt = 80 triangles. It is a spherical Delaunay triangulation; see the following section. We will use these spherical triangulations in several examples below.

10.1.3 Spherical Delaunay triangulations Suppose we want to construct a spherical triangulation  covering the sphere based on a given set of n points on the sphere which are to serve as the vertices of . For a given set of vertices, there are generally an extremely large number of different spherical triangulations

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.1. Spherical triangulations

329

that have the prescribed vertices. We need a way to somehow select the “best” of these possible triangulations. As in the planar case, this can be done by looking for a triangulation that has the property that the minimum angle appearing in the triangulation is as large as possible. It turns out that there is a triangulation achieving this property. It is called a spherical Delaunay triangulation. It is unique up to some “neutral cases”; see Remark 10.2. Although MATLAB does not seem to contain a specific function that can be used to construct the spherical Delaunay triangulation, we can easily create such a function by working with tetrahedral partitions. Suppose x, y, z are column vectors containing the coordinates of n distinct points on the sphere. Let x(n + 1) = y(n + 1) = z(n + 1) = 0 describe the coordinates of the origin. Then calling the built-in MATLAB function Tet = delaunay(x,y,z) produces a matrix Tet of size n t × 4 describing n t = 2n − 4 tetrahedra, each with a vertex at the origin. We can then extract vectors v1 , v2 , v3 of length n t describing the spherical triangles. This is accomplished by converting each four-tuple into a triple by dropping the index corresponding to the origin. For convenience, we have written the following function to produce a spherical Delaunay triangulation: [v1,v2,v3] = sdelaunay(x,y,z) This function can be tested with the following script: % SPdelaunay [n,x,y,z] = sreadpts; [v1,v2,v3] = sdelaunay(x,y,z); [v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir] = ... slists(x,y,z,[v1,v2,v3]); srendtri(x,y,z,ie1,ie2); This script calls on sreadpts to read n and the vectors x, y, z from a file. It also renders the resulting spherical triangulation. It can be tested with the files sptri1 and sptri2 which produce the spherical triangulations in Figure 10.1. If we run it with the file sptri42, it produces the spherical triangulation of Example 10.2; see Figure 10.2.

10.1.4 Refining a spherical triangulation Spherical triangulations can be refined in exactly the same way as planar triangulations, and all of the methods discussed in Chapter 3 carry over immediately. We give some code for creating the Powell–Sabin and Clough–Tocher refinements in sections 10.5.1 and 10.5.2. In this section we discuss only uniform refinement, where each triangle T is split into four subtriangles by inserting vertices at the midpoints of the edges of T and connecting them pairwise. The following function performs uniform refinement: [x,y,z,v1,v2,v3] = srefine(xo,yo,zo,v1o,v2o,v3o,... e1o,e2o,e3o,ie1o,ie2o)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

330

Chapter 10. Spherical Splines

Table 10.2. Numbers of vertices, edges, and triangles in the successive uniform refinements of the octahedral spherical triangulation.

n 6 18 66 258 1026 4098

sptri1 sptri2 sptri3 sptri4 sptri5 sptri6

ne 12 48 192 768 3072 12288

nt 8 32 128 512 2048 8192

The input includes the lists describing the initial triangulation. On output, the vectors x,y,z contain the Cartesian coordinates of the vertices of the refined triangulation. They are of length n = no + neo, where no,neo,nto are the numbers of vertices, edges, and triangles in the initial triangulation. The output vectors v1,v2,v3 contain the lists of indices of the spherical triangles in the refined triangulation. They are of length nt = 4*nto. Example 10.3. Use the script SPrefine to input a spherical triangulation, and create the uniform refinement of it. Discussion: We start by reading the file sptri1, which gives the triangulation shown in Figure 10.1 (left). It has n = 6 vertices, ne = 12 edges, and nt = 8 triangles. We call it the octahedral spherical triangulation since each triangle is an octant of the sphere. After applying srefine, we get the triangulation shown in Figure 10.1 (right). It has n = 18 vertices, ne = 48 edges, and nt = 32 triangles. For later use, this triangulation is stored in the data file sptri2. Repeating this process, we can refine sptri2 to get sptri3, etc. It is easy to see that the i th triangulation in this series has n = 22i +2 vertices, n e = 3 × 22i edges, and n t = 22i+1 triangles. We tabulate these values for i = 1, . . ., 6 in Table 10.2.

10.1.5 Integrals over a spherical triangulation t Suppose  := {Ti }ni=1 is a spherical triangulation of some domain  lying on the sphere. Then for any function f defined on , we have

 

f =

nt  

f.

i=1 Ti

Thus, to compute the integral of f over , it suffices to have a method for computing the integral of f over a single triangle. Suppose T is a spherical triangle whose diameter is not too large, where we define the diameter of T to be |T | := max d(u, v), (10.1) u,v∈T

where d(u, v) denotes the geodesic distance between u and v. Then any function f defined on the spherical triangle T := v1 , v2 , v3  can also be considered to be a function defined on the planar triangle T˜ passing through the vertices v1 , v2 , v3 . Indeed, if we define σ (v) :=

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.1. Spherical triangulations

331

v/v, then f˜(v) := f (σ (v)) is a function defined on T˜ . If the diameter of T is not too large, then the areas of T an T˜ are nearly equal, and we find that   f˜(v) dv. f (v) dv ≈ T˜

T

The integral over T˜ can be evaluated by Gauss quadrature as explained in section 4.6. To get more accurate results for larger triangles, we will have to divide them into smaller ones and sum the integrals over the small triangles. Given a triangle T and an integer m > 0, let Dm,T be the corresponding set of spherical domain points as defined in (10.11). Using these points as vertices, we can define an associated collection of m 2 triangles as in section 4.7. In particular, we choose these subtriangles to be Ti j k := ξi+1, j ,k , ξi, j +1,k , ξi, j ,k+1 , i + j + k = m − 1, T˜i j k := ξi, j +1,k+1 , ξi+1, j ,k+1 , ξi+1, j +1,k , i + j + k = m − 2.

(10.2)

Figure 4.3 shows these triangles in the planar case for m = 3. There they were congruent to each other, but here they do not all have the same exact shape. Now for each of these subtriangles t := v1 , v2 , v3 , we can use Gaussian quadrature with weights and sample points as described in section 4.6. In particular, let w,r , s, t be the output of the function quadset given there based on n q points. Then we have  f ≈ At t

nq 

wi f (αi , βi , γi ),

i=1

where At is the area of the spherical triangle t, and αi = ri x 1 + si y1 + ti z 1 , βi = ri x 2 + si y2 + ti z 2 , γi = ri x 3 + si y3 + ti z 3 . Here (x j , y j , z j ) are the Cartesian coordinates of v j for j = 1, 2, 3. We have written the following function to carry out this computation: int = sphintfT(m,w,r,s,t,x,y,z,f) Here m gives the level of refinement. The vectors w,r,s,t input the Gaussian quadrature data, and can be produced by a call on quadset. The vectors x,y,z give the Cartesian coordinates of the vertices of the triangle of interest. Finally, f is the name of the function to be integrated over T , and the output is the value of the integral. Example 10.4. Use Gaussian quadrature to integrate the function f (x, y, z) = x over the triangle T corresponding to the first octant of S. Discussion: We can make use of the script SPintfT. The quadrature weights and points are read using quadset with parameter nq = 25, which is the number of sample points to be used in each subtriangle. The exact value of the integral of f over the triangle T is π/4,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

332

Chapter 10. Spherical Splines

so we can compare the accuracy of the method with different values of m. Here is a table of the errors along with computation times for some selected values of m. m 1 2 4 8 16 32

error 2.84(−2) 4.16(−3) 2.81(−4) 1.85(−5) 1.17(−6) 7.33(−8)

time .0007 .0016 .003 .0124 .045 .174

The table shows how the accuracy improves as we increase m. As expected, the computational times increase by a factor of four every time we double m. For convenience, we now introduce a function for integrating a general function f defined over a spherical triangulation . int = sphintf(x,y,z,v1,v2,v3,e1,e2,e3,ie1,f,m,nq) Here x, . . . , ie1 describe the triangulation , and f is the name of the function to be integrated. The positive integer m gives the level of refinement, while nq gives the number of sample points to be used in each subtriangle for the Gaussian quadrature rule. These are read using quadset, which is set up to work only for values of n q in the set {1, 3, 4, 6, 12, 25, 79}. To illustrate the use of this function, we give one example. Let f (x, y, z) := x 4 + 1.1y 4 + 1.3z 4.

(10.3)

This function is used in many of the examples of Chapter 11. Example 10.5. Estimate the value of the integral of the function (10.3) over the entire sphere S. Discussion: We use the script SPintf, and read in an initial triangulation of S from the file sptri4. It has 258 vertices and 512 triangles. We choose n q = 25 in our call on quadset to input the weights and sample points for the quadrature formula. Here are the results for several values of m. m 1 2 3 4 8

integral time 8.54535171 .12 8.54514571 .38 8.54513472 .81 8.54513287 1.42 8.54513207 5.51

differences 2.06(−4) 1.10(−5) 1.85(−6) 8.00(−7)

Based on this table, we estimate the integral of f over the sphere to be 8.545132 to six digits of accuracy. More accurate estimates can be obtained with larger values of m.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.2. Spherical polynomials

333

10.2 Spherical polynomials In the following section we shall define spherical splines over a spherical triangulation  as a function defined piecewise in terms of certain spherical analogs of the bivariate polynomials. In this section we introduce these so-called spherical polynomials, discuss some of their properties, and explain how to compute with them.

10.2.1 Spherical barycentric coordinates To get started, we need to introduce some coordinates associated with a spherical triangle. Suppose T := v1 , v2 , v3  is such a triangle, and suppose v is any point on the sphere S. Then we define the real numbers b1 , b2 , b3 such that v = b1 v1 + b2v2 + b3v3

(10.4)

to be the spherical barycentric coordinates of v relative to T . To compute the spherical barycentric coordinates of a given point v = (x, y, z) on the sphere relative to the given spherical triangle T , suppose the vertices of T are vi := (x i , yi , z i ), i = 1, 2, 3. Then the b1 , b2 , b3 must satisfy ⎤⎡ ⎤ ⎡ ⎤ ⎡ x x 1 x 2 x 3 b1 ⎣ y1 y2 y3 ⎦⎣b2 ⎦ = ⎣ y ⎦ . (10.5) z 1 z 2 z 3 b3 z The determinant of the matrix in (10.5) is equal to six times the volume of the tetrahedron T := o, v1 , v2 , v3 , where o is the origin. Thus, if T is nondegenerate, then the spherical barycentric coordinates of any point v ∈ R3 are uniquely defined. By Cramer’s rule,   x x 2 x 3     y y2 y3     z z2 z3  , (10.6) b1 (x, y, z) =  x 1 x 2 x 3     y1 y2 y3    z1 z2 z3  with similar formulae for b2 and b3 . For some other properties of the spherical barycentric coordinates, see section 13.1.2 of [[LaiS07]]. The spherical barycentric coordinates are the natural analogs of the usual barycentric coordinates associated with a planar triangle, but they have one essential difference. Although they are nonnegative, their sum is strictly larger than one for all points in T \ {v1 , v2 , v3 }. For convenience, we have included the following function in SplinePak for computing the spherical barycentric coordinates of a point (x,y,z): [b1,b2,b3] = sbco(x1,y1,z1,x2,y2,z2,x3,y3,z3,x,y,z)

10.2.2 Spherical Bernstein basis polynomials Given a spherical triangle T := v1 , v2 , v3  and a point v on the sphere, let b1 (v), b2 (v), b3 (v) be the spherical barycentric coordinates of v relative to T . Now given an integer

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

334

Chapter 10. Spherical Splines

d > 0, let Bidj k :=

d! j bi b bk , i ! j ! k! 1 2 3

i + j + k = d,

(10.7)

where i , j , k are nonnegative integers. These are called the spherical Bernstein basis polynomials of degree d relative to T . It was shown in Corollary 13.19 in [[LaiS07]] that these polynomials are linearly independent on the triangle T . Definition 10.6. Given d > 0, let Bd be the span of the spherical Bernstein basis polynomials defined in (10.7). We call Bd the space of spherical polynomials of degree d . ) * Clearly, Bd is a linear space of dimension of d+2 2 , and the set of spherical Bernstein basis polynomials {Bidj k }i+ j +k=d form a basis for it. As in the planar case, the spherical Bernstein basis polynomials are nonnegative on T . However, in contrast to the planar case, they do not form a partition of unity. For later use, we point out one additional property: the d has value one at the vertex v , and is zero on the spherical Bernstein basis polynomial Bd00 1 opposite edge of T which includes both of the vertices v2 and v3 . The spherical Bernstein d d and B00d have analogous properties. basis polynomials B0d0 We close this section by pointing out that the space Bd of spherical polynomials is spanned by certain spherical harmonics. Definition 10.7. A trivariate polynomial p is called harmonic, provided that p ≡ 0, where  is the Laplace operator defined by  f := f x x + f yy + f zz . The polynomial p is said to be homogeneous of degree i , provided that p(r x,r y,r z) = r i p(x, y, z) for all r > 0 and all (x, y, z) ∈ R3 . The linear space Yi := { p| S : p ∈ Pi and p is harmonic and homogeneous of degree i } is called the space of spherical harmonics of exact degree i . For some properties of spherical harmonics, including explicit formulae in terms of Legendre polynomials, see section 13.1.9 of [[LaiS07]]. It is shown there that  d = 2k, Y0 ⊕ Y2 ⊕ · · · ⊕ Y2k , Bd = (10.8) Y1 ⊕ Y3 ⊕ · · · ⊕ Y2k+1 , d = 2k + 1, where for each i , Yi is the 2i + 1 dimensional space of spherical harmonics of exact degree i . Thus, when d is even, Bd is just the space of spherical harmonics of even degree at most d, while if d is odd, Bd is the space of spherical harmonics of odd degree at most d.

10.2.3 The spherical B-form Since the {Bidj k }i+ j +k=d form a basis for Bd , it follows that for every p ∈ Bd , there is a unique set of coefficients {ci j k }i+ j +k=d such that p=



ci j k Bidj k .

(10.9)

i+ j +k=d

This is called the Bernstein–Bézier representation of p, but we will usually refer to it simply as the spherical B-form of p. We refer to the {ci j k }i+ j +k=d as the B-coefficients of p.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.2. Spherical polynomials

335

It is clear that to store a spherical polynomial p in spherical B-form in a computer, it suffices to store the vertices of the spherical triangle T and a vector c containing the Bcoefficients of p relative to T . As in the planar case, we suggest storing the B-coefficients in lexicographical order; see section 4.1. Following the proof of Theorem 2.6 in [[LaiS07]], it is not hard to show that the spherical B-form is stable in the sense that K 1 c∞ ≤  pT ≤ K 2 c∞ ,

(10.10)

where  pT is the maximum norm on T , and the constants K 1 and K 2 depend only on d.

10.2.4 Domain points on a spherical triangle In working with polynomials in B-form, it is convenient to introduce an alternative indexing set for the Bernstein basis polynomials and the B-coefficients. Given an integer d > 0 and a spherical triangle T := v1 , v2 , v3 , we define " ! i v1 + j v2 + kv3 T Dd,T := ξi j k := . i v1 + j v2 + kv3  i+ j +k=d

(10.11)

These points lie on the face of the spherical triangle T . We refer to Dd,T as the set of spherical domain points associated with d and T . Figure 10.3 shows the set of domain points

D4,T for degree d = 4 associated with one triangle in a spherical triangulation covering the ) * unit sphere. Note that it contains d+2 2 = 15 points. Using the domain points Dd,T as an index set, we can now write a spherical polynomial in B-form as  cξ Bξd . (10.12) p= ξ ∈Dd,T

Each B-coefficient of p is uniquely associated with a domain point. The geometric location of these points turns out to be useful in understanding smoothness conditions between spherical polynomials defined on adjoining spherical triangles. In fact, the conditions for smooth joins are exactly the same as in the planar case in section 4.13.2, except that they now involve spherical barycentric coordinates; see Chapter 13 of [[LaiS07]].

Figure 10.3. The set D4,T for one of the spherical triangles T in the triangulation sptri2.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

336

Chapter 10. Spherical Splines

10.2.5 Evaluating spherical polynomials in B-form The de Casteljau algorithm discussed in section 4.3 is a very stable and efficient algorithm for evaluating a bivariate polynomial written in B-form. Because of the way in which the spherical Bernstein basis functions were defined in section 10.2.2, it follows that spherical polynomials written in the spherical B-form (10.9) can be evaluated with exactly the same algorithm, which for convenience we now repeat. Suppose (0)

ci j k := ci j k ,

i + j + k = d,

(10.13)

are the B-coefficients of a spherical polynomial p, and suppose we want to compute the value p(v) for some point v on the sphere with spherical barycentric coordinates (b1 , b2 , b3 ). Algorithm 10.8 (de Casteljau). For  = 1, . . ., d For i + j + k = d −  (−1) (−1) (−1) ci() j k := b1 ci+1, j ,k + b2 ci, j +1,k + b3 ci, j ,k+1 (d)

After completing this algorithm, the value of c000 is equal to p(v); see Theorem 13.12 of [[LaiS07]]. Note that the coefficients at step  are obtained from the coefficients at the previous step by taking combinations of three coefficients at a time, using the weights (b1 , b2 , b3 ). For points v ∈ T , the barycentric coordinates b1 , b2 , b3 are all nonnegative, and so the computation is numerically very stable. The steps are exactly the same as in the planar case, and are illustrated in Figure 4.1 for a polynomial of degree d = 2. Since the algorithm in the spherical case is identical to the one in the planar case, we can use the same function used there, namely val = decast (d,b1,b2,b3,c)

10.2.6 Derivatives of spherical polynomials in B-form Suppose f is a function defined on the sphere S, and suppose v is a point on S. With a slight abuse of notation, we will also write v for the vector in R3 whose tail is at the origin, and whose head is at the point v. Let πv be the plane that is tangent to S at the point v. Now suppose we are given a vector u in R3 such that its translate w := u + v lies in πv . Thus, w is tangent to S at v. We call u a direction vector. Given a positive number α, the homogeneous extension of f of degree α is defined to be Fα (v) = vα f (v/v)

for all v ∈ R3 \ {0}.

Definition 10.9. Given a smooth function f defined on S, let F be a homogeneous extension of f . Suppose u is a direction vector. Then we define the derivative of f at v in the direction u by d (10.14) Du f (v) := Du F(v) = F(v + tu) = u T ∇ F(v). dt At first glance, it may appear that the directional derivative will depend on which homogeneous extension of f we use, but it is shown in Lemma 13.25 of [[LaiS07]] that Du f (v) does not depend on the degree of the homogeneous extension. Higher order directional derivatives on the sphere can also be computed in terms of homogeneous extensions, but

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.2. Spherical polynomials

337

in this case the results do depend on the order of the extension; see [AlfNS96b] and section 13.2 of [[LaiS07]]. We now discuss derivatives of spherical polynomials. Fix a spherical triangle T := v1 , v2 , v3 , and let p be a spherical polynomial of degree d written in the B-form (10.9) using the spherical Bernstein basis functions Bidj k associated with T . Suppose {ci0j k }i+ j +k=d are the B-coefficients of p. Given v ∈ T , let u be a direction vector associated with the point v, i.e., a vector in R3 that is parallel to the tangent plane πv to S at v. Let (a1 , a2 , a3 ) be such that (10.15) u = a1 v1 + a2 v2 + a3v3 . We call (a1 , a2 , a3 ) the spherical directional coordinates of u relative to T . Note that unlike directional coordinates in the bivariate spline case, the sum of these coordinates is not necessarily zero. Given m > 0, let l−1 l−1 l−1 cil j k := a1 ci+1, j ,k + a2 ci, j +1,k + a3 ci, j ,k+1 a,

i + j + k = d − l,

for l = 1, . . . , m. The following result (cf. Theorem 13.28 of [[LaiS07]]) was first established in [AlfNS96]. Lemma 10.10. For any 0 ≤ m ≤ d, Dum p(v) =

d! (d − m)!



cimj k Bid−m j k (v).

(10.16)

i+ j +k=d−m

In view of this result, we can evaluate Dum p(v) by carrying out m steps of the de Casteljau algorithm using (a1 , a2 , a3 ), and then carrying out the remaining steps with the spherical barycentric coordinates (b1 , b2 , b3 ) of v. The analog of Lemma 10.10 holds for mixed directional derivatives; see Theorem 13.28 of [[LaiS07]]. The following special case of Lemma 10.10 is particularly useful as it gives a formula for the directional derivative at a vertex of a triangle that points along one edge of that triangle. Lemma 10.11. Let T := v1 , v2 , v3  be a spherical triangle. Suppose u is a direction vector parallel to the plane πv tangent to S at v, and that in addition u lies in the plane passing through v1 and v2 . Let (a1 , a2 , 0) be the corresponding directional coordinates of u, i.e., the spherical barycentric coordinates of u relative to T . Finally, suppose p is a spherical Bernstein–Bézier polynomial with B-coefficients as in (10.9). Then Du p(v1 ) = d[a2cd−1,1,0 − a1 cd00].

(10.17)

10.2.7 Integrating a spherical polynomial over a spherical triangle In the planar case we had explicit formulae for the integrals of the Bernstein basis polynomials over a triangle T lying in the plane. There do not seem to be such formulae for spherical Bernstein basis polynomials. Thus, to compute the integral of a spherical polynomial p over a spherical triangle T , we will resort to a quadrature formula. Following the ideas of section 10.1.5, we have the following code: int = sphintpol(d,m,w,r,s,t,x,y,z,co) Here d is the degree of the polynomial, and m is the level of refinement. The values w,r,s,t give the Gaussian quadrature data, and can be produced by a call on quadset. The vectors x,y,z give the Cartesian coordinates of the vertices of the triangle of inter-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

338

Chapter 10. Spherical Splines

est. Finally, co is a vector of length interest.

)d+1* 2

containing the coefficients of the polynomial of

Example 10.12. Use Gaussian quadrature to integrate a polynomial over the triangle T corresponding to the first octant of S. Discussion: We make use of the script SPintpol which uses a quadratic polynomial with random coefficients read from our file randpts2.dat. We don’t know the exact value of this integral, but we can compare the approximations of the integral obtained with several different levels of refinement. m 1 2 4 8 16 32

integral differences 1.995285108806062 2.104265785233139 1.09(−1) 2.122076318358746 1.78(−2) 2.123277098454560 1.20(−3) 2.123356298702392 7.92(−5) 2.123361327490082 5.03(−6)

The differences in this table suggest the level of accuracy for each choice of m. The computational times are almost the same as in Example 10.4. By integrating over one triangle at a time, the function sphintpol can be used to find the integral of a spline defined on a spherical triangulation; see section 10.3.4.

10.2.8 Plotting a spherical polynomial patch Suppose p is a spherical polynomial defined on a spherical triangle T . We can think of p(v) as giving the height of a surface above the spherical triangle T on a ray passing through v. Thus, there is a natural associated surface patch which we define as the set of points G := {(1 + p(v))v : v ∈ T }. In this section we explain how to render this surface patch. We follow the approach used in section 4.7 to render a surface patch associated with an ordinary polynomial defined on a planar triangle T . The idea is to create a set of small triangular facets in R3 with vertices lying on G, and then to render this collection of triangles with the MATLAB command trisurf. Given a positive integer m, we choose the vertices to be the points {(1 + p(ξ )ξ }ξ ∈Dm,T , where Dm,T is the set of spherical domain points associated with m and T as defined in (10.11). To get the planar facets, we connect neighboring points in Dm,T as was done in section 4.7 in the planar case. This is illustrated in Figure 4.3 for m = 3. The integer m controls the resolution of the plot. If it is too small, we will see all the planar facets of the surface. But if it is too large (say larger than 100), then the plot will have too many edges, and will appear as almost all black. The following function produces the lists needed by trisurf: [gx,gy,gz,G] = valsphpol(d,m,x,y,z,c) ) * vector of its BHere d is the degree of the spherical polynomial, and c is the d+2 2 coefficients, written in lexicographical form. The vectors x, y, and z contain the coordinates of the three vertices of T , and m is the positive integer controlling the num-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.2. Spherical polynomials

339

ber of facets to be displayed. The output includes three vectors gx,gy,gz of length n := (m + 1)(m + 2)/2, where (gx(i ), gy(i ), gz(i)) are the Cartesian coordinates of the i th vertex for 1 ≤ i ≤ n. The connectivity of this faceted surface is described by the matrix G of dimension m 2 × 3, where the i th row contains the indices of the i th triangular facet. After calling srendpatch, we can plot the patch with the call trisurf(G,gx,gy,gz); axis equal The following script can be used for testing valsphpol: % SPrendpatch [n,x,y,z,nt,TRI] = sreadtri; d = 3; nc = (d+1)*(d+2)/2; m = input(’input m ’); c = zeros(nc,1); c(8) = .5; [gx,gy,gz,G] = valsphpol(d,m,x,y,z,c); h2 = trisurf(G,gx,gy,gz); set(h2,’edgecolor’,[0 0 0],’facecolor’,[.8 .2 .2]); axis vis3d; axis equal tight off; hidden on; rotate3d on; hold on; c = zeros(nc,1); [gx,gy,gz,GT] = valsphpol(d,m,x,y,z,c); h = trisurf(GT,gx,gy,gz); set(h,’edgecolor’,[0 0 0],’facecolor’,[1 1 1]); This script uses valsphpol to get the values needed to render both the surface patch (shown in red) and the underlying domain triangle (shown in white). Example 10.13. Render a spherical Bernstein basis polynomial. Discussion: We make use of SPrendpatch, and read the domain triangle from the file stri1.dat, which corresponds to one of the triangles of the triangulation sptri2 shown in Figure 10.1 (right). We then set d = 3, and define all 10 coefficients of p to be zero except for c(8) = .5. With m = 15, we get the plot shown in Figure 10.4 of the

Figure 10.4. A spherical triangle (white) and the associated spherical Bernstein basis poly3 (red). nomial B021

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

340

Chapter 10. Spherical Splines

3 , scaled by a factor of one-half. It vanishes on spherical Bernstein basis polynomial B021 two of the edges of the domain triangle.

10.2.9 Domain points on a spherical triangulation In preparation for working with splines on a spherical triangulation, we need the notion t . Given a positive of domain points associated with a spherical triangulation  = {Ti }ni=1 integer d, we define the associated set of spherical domain points to be 1 Dd,T , (10.18) Dd, := T ∈

where Dd,T is the set of spherical domain points (10.11) associated with T . Domain points on edges shared by two spherical triangles are included just once in Dd, . Later in this chapter we will need to work with special subsets of the domain points which are located near the vertices of , namely so-called rings and disks. These can be defined exactly as in section 4.2 for planar triangulations, and we use the same notation, namely Rm (v) for the ring of radius m around v , and Dm (v) for the disk of radius m around v .

10.3 The space Sd0 () on a spherical triangulation t Suppose  = {Ti }ni=1 is a spherical triangulation lying on the unit sphere S, and let d be a positive integer. Then we define the space of C 0 spherical splines of degree d to be the linear space Sd0 () := {s ∈ C 0 () : s|Ti ∈ Bd , i = 1, . . ., n t }. (10.19)

Here Bd is the space of spherical polynomials of degree d; see Definition 10.6. Let s ∈ Sd0 (), and suppose T is a spherical triangle in . Then there exists a unique set of coefficients {cξ }ξ ∈Dd,T such that s|T =

 ξ ∈Dd,T

cξ Bξd,T ,

(10.20)

where Bξd,T are the spherical Bernstein basis polynomials of degree d associated with the triangle T . Since s is continuous, if ξ lies on an edge between two different triangles T and T˜ , then the coefficients cξ for s|T and s|T˜ are the same. This shows that for each spherical spline s ∈ Sd0 (), there is a unique associated set of coefficients {cξ }ξ ∈Dd, . We call these the B-coefficients of s. The converse also holds, i.e., given any {cξ }ξ ∈Dd, there is a unique spline s ∈ Sd0 () defined by (10.20). These arguments show that Sd0 () is in one-to-one correspondence with the set of domain points Dd, . This immediately implies that   d −1 (10.21) dim Sd0 () = #Dd, = n + (d − 1)n e + nt , 2 where n, n e , and n t are the numbers of vertices, edges, and triangles in .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.3. The space Sd0 () on a spherical triangulation

341

10.3.1 Storing splines in Sd0 () It follows from the discussion in the previous subsection that to store a spherical spline s ∈ S d0 () in the computer, it suffices to store its set of B-coefficients {cξ }ξ ∈Dd, . It is convenient to arrange these coefficients in a vector c in a specified order. We use the same storage convention as in the planar case, namely, Storage Convention: 1) the first n components of c contain the coefficients associated with the domain points at the vertices of ; 2) the next set of (d − 1)n e components of c contains the coefficients associated with the d − 1 points on each of the edges e1 , . . . , ene of ; ) * 3) the next set of d−1 2 n t components of c contains the coefficients associated with the )d−1* points in the interior of each of the triangles T1 , . . . , Tnt of . 2 Two comments are in order. To uniquely identify the coefficients associated with domain points on an edge, we have to assume the edge has an orientation, i.e., we need to know which end comes first. Similarly, to uniquely identify the coefficients associated with domain points in the interior of a triangle, we also have to assume the triangle has a specific orientation, i.e, we need to know that the vertices appear in counterclockwise order, and which is the first vertex.

10.3.2 A basis for Sd0 () In applications, we can generally work directly with the B-coefficients of a spherical spline in Sd0 (). However, to describe methods for some applications, we need to introduce a basis for Sd0 (). Bases can be constructed in various ways. We use the following approach. For each ξ ∈ Dd, , let φξ be the unique spline in Sd0 () such that  1, if η = ξ , cη = δξ η := (10.22) for all η ∈ Dd, . 0, otherwise, Theorem 10.14. The set of splines {φξ }ξ ∈Dd, form a basis for Sd0 (). Proof. In view of the duality relations (10.22), it is clear that the splines {φξ }ξ ∈Dd, are linearly independent. Since the cardinality of Dd, is equal to the dimension of Sd0 () given in (10.21), it follows that they form a basis for Sd0 (). These basis functions have some properties reminiscent of the B-splines that play such an important role in the univariate and tensor-product cases. First, using the same arguments as in the planar case, we see that for each ξ ∈ Dd, , 1) if ξ is a vertex of , then φξ has support on star(ξ ); 2) if ξ lies in the interior of an edge e of , then φξ has support on the spherical triangle or pair of spherical triangles containing e; 3) if ξ lies in the interior of a spherical triangle T of , then φξ has support on T .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

342

Chapter 10. Spherical Splines

Moreover, φξ is nonnegative at all points in its support. Here star(v) is the union of the triangles surrounding v. We plot some typical basis functions in Sd0 () in Example 10.15 below. Note that, in contrast to the planar case, the splines {φξ }ξ ∈Dd, do not form a partition of unity.

10.3.3 Evaluating spherical splines and their derivatives We now have the tools needed to evaluate a spherical spline s ∈ Sd0 () with coefficient vector c. Suppose v is a point on the sphere where we wish to evaluate s. Then we 1) find a spherical triangle T which contains v, 2) extract the B-coefficients of the spherical polynomial s|T , 3) evaluate this polynomial using the de Casteljau algorithm. For ordinary polynomial splines on planar triangulations, we searched for a triangle containing a given point using the function tsearchn; see section 3.7. Unfortunately, we can’t use it here, so instead we make use of the fact that if any one of the spherical barycentric coordinates of a point v relative to a spherical triangle T is negative, then v does not lie in T . This is the basis for the following function: [it,b1,b2,b3] = sfindtri(x,y,z,v1,v2,v3,xv,yv,zv) Here x, . . . , v3 are vectors describing the spherical triangulation , and xv,yv,zv give the Cartesian coordinates of the point v of interest. The values b1,b2,b3 give the spherical barycentric coordinates of v relative to that triangle. To extract the B-coefficients of s|T , we can use the function getco of section 4.2, since here we are using the same storage convention as in the planar case. For Step 3, we can use the same function decast as was used for bivariate splines. For computing errors of spherical splines, we will have to evaluate a given spherical spline at many points on the sphere. For this purpose we have written the following function, where the points are read from a file: [xp,yp,zp,g] = valsphsp(d,x,y,z,v1,v2,v3,... e1,e2,e3,ie1,c,fname) Here d gives the degree of the spline, and x, . . . , ie1 are vectors describing the triangulation. The input c is the vector of B-coefficients of the splines, and fname is a file name from which the evaluation points are to be read. For most of the examples of this chapter we will use the file sptri7, which contains 16386 almost equally spaced points on the sphere. The output vectors xp,yp,zp contain the Cartesian coordinates of the evaluation points. They are needed if we want to compare the spline values, which are contained in the vector g, with values of a test function at the same points.

10.3.4 Rendering a spherical spline surface Suppose s is a spherical spline defined on a spherical triangulation , and let c be the vector containing its B-coefficients. To render s, we evaluate it at the vertices of a triangulation

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.3. The space Sd0 () on a spherical triangulation

343

with a lot of vertices spread out over the sphere, for example the triangulation sptri6 which has 4098 vertices and 8192 triangles. This defines a collection of triangular facets in R3 that can be displayed using the MATLAB function trisurf as was done for a single patch in section 10.2.8. Here is a function to generate the Cartesian coordinates gx,gy,gz of the vertices of the triangular facets, and a list of triangles G. [G,gx,gy,gz] = rendsphsp(d,x,y,z,v1,v2,v3,... e1,e2,e3,ie1,c,fname) The parameter d is the degree of the spline s, and the vectors x, y, z, . . . , ie1 contain information about the triangulation on which it is defined. The vector c should contain the B-coefficients of s. The parameter fname gives the name of a spherical triangulation to be used for display purposes, for example sptri6. We use this triangulation for most of the plots in this chapter. Note that in all cases the underlying sphere is taken to be the unit sphere, and so the appearance of the plot will depend on the maximum cmax of the absolute values of the spline coefficients. These may have to be scaled before calling this function to get the best plots. The output of this function includes the matrix G giving the indices of the triangular facets to be displayed. The vectors gx,gy,gz contain the Cartesian coordinates of the points 1 + s(x pi , ypi , zpi ), where (x pi , ypi , zpi ) are the coordinates of the vertices of the triangulation corresponding to the file fname. This is all we need for rendering the spline with trisurf(G,gx,gy,gz). Example 10.15. Plot some basis splines in Sd0 () for d = 2 and d = 3. Discussion: We make use of the script SPrendsp, and read the triangulation from the file sptri3. We set all coefficients to be zero except for c(1) = .25. For this data file, the first vertex is located at v1 = (0, 0, 1), and so according to our storage convention for B-coefficients, this gives the basis spline that has a value .25 at v1 , and has local support on the set of triangles surrounding this vertex — see the list of properties of dual basis splines in section 10.3.2. Figure 10.5 shows the results for d = 2 and d = 3. Note that these figures have been rotated to show the basis functions more clearly. The figures show the local support of these basis splines, and they also show that the splines are continuous, but not C 1.

Figure 10.5. Left: Plot of the basis spline φξ in the space S20 () on the spherical triangulation sptri3, where ξ = (0, 0, 1). Right: The analogous basis spline in S30 ().

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

344

Chapter 10. Spherical Splines

10.3.5 Integrals of spherical splines Suppose  is a spherical triangulation that covers the sphere S, and suppose s ∈ S10 () is a spherical spline defined over . Then we can compute the integral of s over S by summing the integrals over the individual triangles in  using the function sphintpol discussed in section 10.2.7. To improve accuracy, for each triangle T in , this function works with the refinement m of T obtained by splitting T into m 2 subtriangles. It then uses a quadrature rule involving n q points on each such subtriangle. We have the following function for computing the integral of a spline: int = sphintsp(d,x,y,z,v1,v2,v3,e1,e2,e3,ie1,c,m,nq) The input d gives the degree of the spline, and x, . . . , ie1 are the lists describing . The vector c should contain the B-coefficients of the spline to be interpolated. The parameter m controls the level of refinement, and nq is the number of sample points to be used in the quadrature rule to be applied on each subtriangle. Since we read these points and weights from a file, we must choose nq from the set {1, 3, 4, 12, 25, 79}; see the function quadset in section 4.6. The function sphintsp can be tested with SPintsp.

10.4 Spaces of smooth spherical splines In practice we often want to use spline spaces which are not only continuous, but which also have one or more continuous derivatives. Definition 10.16. Given integers r and d with 0 ≤ r < d, we define the space of spherical splines of degree d and smoothness r as

Sdr () := C r () ∩ Sd0 ().

(10.23)

We will also make use of certain subspaces of Sdr () which have enhanced smoothness at some or all of the vertices of . Given a spline s ∈ Sd0 () and a vertex v of , we say that s ∈ C ρ (v), provided that all of the spherical polynomial pieces of s associated with spherical triangles surrounding the vertex v have common directional derivatives at v (in all directions) up to order ρ. Definition 10.17. Suppose r , ρ, d are integers such that 0 ≤ r ≤ ρ < d, and let Sd () := {s ∈ Sdr () : s ∈ C ρ (v) all v ∈ V}, r,ρ

(10.24)

r,ρ

where V is the set of all vertices of . We call Sd () a spherical superspline space. It is possible to define more general spaces of spherical splines by requiring varying degrees of smoothness across the edges of  and/or varying degrees of smoothness at the vertices of . For a discussion of these types of spline spaces in the planar case, see sections 5.5.2 and 5.5.3 in [[LaiS07]]. In the remainder of this section we present various tools for working with spaces of smooth spherical splines.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.4. Spaces of smooth spherical splines

345

10.4.1 Storing and evaluating smooth spherical splines Suppose S ⊆ Sd0 () is a space of smooth spherical splines of degree d defined on a spherical triangulation . Then any s ∈ S can be regarded as a spline in Sd0 () whose Bcoefficients happen to satisfy certain smoothness conditions. Thus, we can store and evaluate s just like any other spline in Sd0 (), and all of the methods discussed earlier in this chapter apply.

10.4.2 Minimal determining sets and the M-basis Suppose S is a subspace of Sd0 (), and let Dd, be the corresponding set of domain points. Then a subset M of Dd, is called a determining set for S , provided that if s is a spline in S whose B-coefficients cη are zero for all η ∈ M, then s ≡ 0. A determining set M is called a minimal determining set for S , provided that there is no smaller determining set. For more on minimal determining sets in the case of spherical splines, see section 13.4.3 of [[LaiS07]]. If M is a minimal determining set for a spherical spline space S, then the dimension of S is given by #M. Minimal determining sets can also be used to construct a basis for a spherical spline space in exactly the same way as was done in section 4.13.4 in the planar case. Theorem 10.18. For each ξ ∈ M, let ψξ be the unique spherical spline in S such that  1, if η = ξ , cη = δξ η := for all η ∈ M. (10.25) 0, otherwise, Then {ψξ }ξ ∈M are linearly independent and form a basis for S. We refer to this basis as the M-basis for S . These basis functions have some very nice properties reminiscent of the B-splines that play such an important role in the univariate and tensor-product cases. In particular, depending on how we choose M, we can often get basis functions with local support. For example, for the space Sd0 (), the minimal determining set is M = Dd, , and we get the locally supported basis functions discussed in section 10.3.2; see also Example 10.15. Minimal determining sets are also useful for computing with spaces of smooth spherical splines. They tell us which coefficients are free parameters, i.e., the degrees of freedom of the spline. Thus, to find a spline s ∈ S solving some interpolation or approximation problem, it suffices to compute the vector c˜ of coefficients {cξ }ξ ∈M . The remaining Bcoefficients of s can then be computed from the smoothness conditions appearing in Theorem 4.17, but with the planar Bernstein basis polynomials replaced by their spherical analogs introduced in section 10.2.2. We have the following analog of Lemma 4.20, where N and n c are the dimension and number of B-coefficients for the space S, respectively. Given any vector c, we write c for its max-norm, i.e., the maximum of the absolute values of its components. Lemma 10.19. Suppose M is a minimal determining set for a space of spherical splines S ⊆ Sd0 (). Then there exists an n c × N matrix A such that given any vector c˜ := {c˜ξ }ξ ∈M , the vector c = A c˜ (10.26)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

346

Chapter 10. Spherical Splines

contains the B-coefficients of a spline s ∈ S with cξ = c˜ξ for all ξ ∈ M. Moreover, c ≤ K c, ˜ where K := max

1≤i≤n c

N 

|ai j |.

(10.27)

(10.28)

j =1

We call the matrix A the transformation matrix. We give code for computing transformation matrices associated with some of the most useful spherical macro-element spline spaces in sections 10.5.1–10.5.3 below. They will be used in Chapter 11 for computing several global interpolation and approximation methods for fitting data on the sphere, including the minimal energy, least-squares, and penalized least-squares methods. The size of the constant K in (10.28) is an indicator of the stability of the computation of B-coefficients. We can use it to help in choosing the best minimal determining set for a given spline space S. It was observed in [Schum08] for the planar case that once we have the transformation matrix, it is easy to find the B-coefficients of any basis function in an M-basis. The same result holds in the spherical case. Lemma 10.20. For every 1 ≤ i ≤ N and every spherical triangle T ,  ψi |T = aν(η),i BηT ,

(10.29)

η∈DT

where aν(η),i is the entry in A corresponding to the row ν(η) associated with the B-coefficient cη and the column i . Although this lemma allows us to explicitly find the coefficients of each M basis function in a given spherical spline space, just as in the case of planar splines discussed in earlier chapters, for many applications we do not need to work explicitly with basis functions at all. Even when we do need basis functions to describe a method, as we do for minimal energy splines and for least-squares and penalized least-squares splines, for computations we will be able to use the transformation matrix to directly compute B-coefficients.

10.4.3 Nodal minimal determining sets Suppose v is a point on the sphere S, and let D1,u and D2,w be directional derivatives associated with two noncollinear unit vectors tangent to S at v. Given a set of real numbers {ανμ }ν+μ=m with m ≥ 0, let  μ ν λ := εv αν,μ D1,u D2,w , (10.30) ν+μ=m

where εv denotes point evaluation at the point v. By definition, λ is a linear functional defined on C m (S). We refer to the point v as the carrier of λ. Now suppose S is a subspace of Sd0 () for some triangulation  of a domain . SupN is a set of linear functionals of the form (10.30). We call N a nodal pose N = {λi }i=1

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.4. Spaces of smooth spherical splines

347

determining set for S , provided that if s ∈ S satisfies λi s = 0 for all 1 ≤ i ≤ N, then s ≡ 0. We say that a nodal determining set N is a nodal minimal determining set for S if there

is no nodal determining set with fewer elements. For more on nodal determining sets for spherical splines, see section 13.4.5 of [[LaiS07]]. As in the planar case, the cardinality of N is equal to the dimension of S. Given a spline s ∈ S, let c˜ = (λ1 s, . . . , λ N s)T , and let c = (c1 , . . . , cnc )T be the vector of the B-coefficients of s, indexed according to the convention in section 10.3.1. We have the following analog of Lemma 4.26. Lemma 10.21. Suppose N is a nodal determining set for a space of spherical splines S ⊆ Sd0 (). Then there exists an n c × N matrix A such that given the vector c˜ = (λ1 s, . . . , λ N s)T of nodal values of a spline s ∈ S, the vector c of all B-coefficients of s is given by c = A c. ˜

(10.31)

c ≤ K c, ˜

(10.32)

Moreover,

where K := max

1≤i≤n c

N 

|ai j |.

(10.33)

j =1

Nodal minimal determining sets can be used to construct bases for spaces of spherical splines in the same way as was done in Theorem 4.27 for the planar case. Theorem 10.22. For each 1 ≤ i ≤ N, there is a unique spline φi ∈ S such that λ j φi = δ i j ,

all 1 ≤ i , j ≤ N.

(10.34)

N is a basis for S. It is called the N -basis of S. Moreover, := {φi }i=1

The basis functions in Theorem 10.22 are not necessarily nonnegative in general. A given spline space will generally have many different nodal minimal determining sets. The choice of N will affect the nature of the basis functions. To be useful in practice, we need basis functions that are local and stable as defined in Definition 4.24 for planar splines. The following analog of Lemma 10.20 shows how to find the B-coefficients of the basis functions (10.34) once we have the transformation matrix A for S. Lemma 10.23. For every 1 ≤ i ≤ N and every spherical triangle T , φi | T =

 η∈DT

aν(η),i BηT ,

(10.35)

where aν(η),i is the entry in A corresponding to the row ν(η) associated with the B-coefficient cη and the column i .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

348

Chapter 10. Spherical Splines

10.5 Spherical macro-element spaces In this section we discuss some useful C 1 macro-element spaces defined on the sphere. Given a spherical triangle T := v1 , v2 , v3 , we define the barycenter of T to be the point vT :=

v1 + v2 + v3 . v1 + v2 + v3 

(10.36)

In analogy with the planar case, we define the incenter of T to be the point u T in T where the arcs bisecting each of the angles of T meet. It can be shown that this point is the center of the largest spherical cap {v : d(v, u T ) ≤ r } contained in T . Here d(v, u T ) denotes the geodesic distance from v to u T .

10.5.1 The Powell–Sabin space S21 ( P S ) Let  be a spherical triangulation. Then the Powell–Sabin refinement  P S of  is defined as in the planar case as follows: 1) find the incenter u T of each spherical triangle T in ; 2) for each T , connect u T to each of its three vertices; 3) for each pair of neighboring spherical triangles T and T˜ , connect their incenters. Note that in forming the Powell–Sabin refinement of , each spherical triangle is divided into six subtriangles. We refer to the original spherical triangles in  as macro triangles. Figure 10.6 shows the Powell–Sabin refinements corresponding to the spherical triangulations shown in Figure 10.1. We now explicitly describe a minimal determining set for S21 ( P S ). Let V be the set of vertices of . For each v ∈ V, let Tv be some spherical triangle in  with a vertex at v, and let Mv be the set of three domain points in Tv that lie in the disk D1 (v). The proof of the following result is similar to the proof of Theorem 6.9 of [[LaiS07]] which deals with splines on planar triangulations.

Figure 10.6. The Powell–Sabin refinements of the spherical triangulations in Figure 10.1.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.5. Spherical macro-element spaces

349

Theorem 10.24. The dimension of the space S21 ( P S ) is N := 3n, where n is the number of vertices of . Moreover, the set 1 Mv (10.37) M := v∈V

is a minimal determining set for S21 ( P S ). Note that there is some freedom in the above construction of M. In particular, for each vertex v, the triangle Tv can be any of the spherical triangles with a vertex at v. We have implemented this algorithm in the following function, which produces the Powell– Sabin refinement, creates a list dof of the indices of the B-coefficients that have been selected as degrees of freedom, and constructs the associated transformation matrix A of Lemma 10.19. [x,y,z,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,A,dof]... = smdsps(xo,yo,zo,v1o,v2o,v3o,e1o,e2o,e3o,... ie1o,ie2o,trilo,triro) The input is the usual information about the initial spherical triangulation . The output includes the corresponding information for the refined triangulation  P S . The length of the vector dof is the dimension N of S21 ( P S ). It contains the indices of the B-coefficients that were selected as the degrees of freedom, assuming the B-coefficients are in the canonical order described in section 10.3.1. The associated transformation matrix A is a sparse matrix of size n c × N, where n c is the number of B-coefficients of a spline in S21 ( P S ). Example 10.25. Examine some basis functions in the space S21 ( P S ) on the triangulation sptri2. Discussion: We use the script SPmdsps, and read the triangulation from the file sptri2. This corresponds to the triangulation  shown in Figure 10.1 (right). It has n = 18 vertices, ne = 48 edges, and nt = 32 spherical triangles. A call on smdsps finds the corresponding Powell–Sabin refinement  P S . It has n = 98 vertices, ne = 288 edges, and nt = 192 spherical triangles; see Figure 10.6 (right). The dimension of S21 ( P S ) on this spherical triangulation is 54, and the number of B-coefficients is 386. Thus, the transformation matrix A is of size 386 × 54. This script is set up to explore the shape of individual basis functions in S21 ( P S ). To plot the basis function corresponding to a given degree of freedom, we set all degrees of freedom to zero except for the one of interest, which we set to one. The corresponding vector c of B-coefficients is then computed using the transformation matrix A. This script also calls on our function sc1ck to check that all of the C 1 smoothness conditions are satisfied. We first plot the basis function corresponding to the first degree of freedom in the list dof. It corresponds to the domain point at the first vertex of the initial triangulation sptri2, which is located at v1 := (0, 0, 1). The corresponding basis function is shown in Figure 10.7 (left), where we can see that it is C 1 smooth. It has support on star(v1 ), i.e., the set of spherical triangles sharing the vertex v1 . Next, we plot the basis function corresponding to the 19th degree of freedom, which corresponds to the B-coefficient c99 . It is associated with the domain point lying on the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

350

Chapter 10. Spherical Splines

Figure 10.7. Plot of the basis splines φ1 and φ19 in the space S21 ( P S ) on the Powell–Sabin refinement of the spherical triangulation sptri2.

Figure 10.8. The Clough–Tocher refinements of the spherical triangulations sptri1 and sptri2.

first edge of  P S , which has endpoints at v1 = (0, 0, 1) and v51 = (0, .2515, .9678). A plot of this basis function is shown in Figure 10.7 (right). It has support on the set of spherical triangles sharing vertex v1 . Note that both figures have been rotated to better show the basis functions, and that neither one is nonnegative throughout its support.

10.5.2 The Clough–Tocher space S31 (CT ) Let  be a spherical triangulation. Then the Clough–Tocher refinement (C T ) of  is defined in the same way as in the planar case as follows: 1) find the barycenter u T of each spherical triangle T in ; 2) for each T , connect u T to each of its three vertices. Note that in forming the Clough–Tocher refinement of , each spherical triangle is divided into three subtriangles. We refer to the original spherical triangles in  as macro triangles. Figure 10.8 shows the Clough–Tocher refinements corresponding to the spherical triangulations shown in Figure 10.1. We now give an explicit minimal determining set for S31 (C T ). Let V be the set of vertices of , and let E be its set of edges. For each v ∈ V, let Tv be some triangle in 

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.5. Spherical macro-element spaces

351

with a vertex at v, and let Mv be the set of three domain points in D3,Tv that lie in the disk D1 (v). For each e := v2 , v3  ∈ E, let Te : v1 , v2 , v3  be a spherical triangle in (C T ) that Te contains e, and set Me := {ξ111 }. The following result can be established in the same way as Theorem 6.5 in [[LaiS07]], which deals with the planar case. Theorem 10.26. The dimension of the space S31 (C T ) is N := 3n + n e , where n is the number of vertices of  and n e is the number of edges. Moreover, the set 1 1 M := Mv ∪ Me (10.38) v∈V

e∈E

is a minimal determining set for S31 (C T ).

SplinePak contains the following function for creating the Clough–Tocher refinement (C T ) of a given spherical triangulation . It also chooses a minimal determining set, and computes the transformation matrix A needed for working with the spherical spline space S31 (C T ). [x,y,z,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,A,dof] = ... smdsct(xo,yo,zo,v1o,v2o,v3o,e1o,e2o,e3o,... ie1o,ie2o,trilo,triro) The input is the usual information about the initial spherical triangulation . The output includes the corresponding information for the refined triangulation (C T ), along with a vector dof of length N := dim S31 (C T ) which gives the indices of the B-coefficients that were chosen as the degrees of freedom, assuming we list the coefficients in the canonical order described in section 10.3.1. The function also returns the associated transformation matrix A. It is given as a sparse matrix of size n c × N, where n c is the number of Bcoefficients of a spline in S31 (C T ). Using A, we can compute the vector c of all B-coefficients of s from the vector c˜ containing the coefficients corresponding to the domain points in M as in (10.26). This function can be used to explore the nature of the M basis described in Theorem 10.18. Indeed, suppose ξ ∈ M. Then if we set all entries in the vector c˜ of Lemma 10.19 to be zero except for the one corresponding to ξ , which we set to one, then c = Ac˜ gives us the B-coefficients of ψξ . Example 10.27. Examine some basis functions in S31 (C T ). Discussion: We use the script SPmdsct, and read the spherical triangulation  from the file sptri2. This gives the triangulation shown in Figure 10.1 (right). It has n = 18 vertices, ne = 48 edges, and nt = 32 spherical triangles. The corresponding Clough– Tocher refinement (C T ) is shown in Figure 10.8 (right), where now n = 50, ne = 144, and nt = 96. The number of B-coefficients for S31 (C T ) on this refined triangulation is 434, and the dimension of S31 (C T ) is 102. Thus, the transformation matrix A is of size 434 × 102. The first 18 degrees of freedom correspond to domain points at the vertices of . Each of these basis functions has support on the star of the corresponding vertex, and is a nonnegative function there. Their plots look very similar to the basis function for S21 ( P S ) shown in Figure 10.7 (left). The next 36 degrees of freedom correspond to domain points

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

352

Chapter 10. Spherical Splines

that lie on the first ring around a vertex of . Each of these basis functions has support on the star of that vertex, but is no longer nonnegative. The last 48 degrees of freedom correspond to domain points in the set Me in (10.38). These basis functions have support on the two triangles of  that share the edge e, and are also not nonnegative. Their plots are similar to the plot of the basis function for S21 ( P S ) shown in Figure 10.7 (right).

10.5.3 The space S51,2 () In this section we work with the spherical superspline space defined in (10.24) with r = 1, ρ = 2, and d = 5. Let V and E be the sets of vertices and edges of , and let n := #V and n e := #E. For each v ∈ V, let Tv be some spherical triangle with a vertex at v, and let Mv be the set of domain points that lie in Tv ∩ D2 (v), where D2 (v) is the disk of radius two around v. For each edge e := v2 , v3  of , let Te := v1 , v2 , v3  be some spherical triangle Te containing e, and let Me := {ξ122 }. The proof of the following result is similar to the proof of Theorem 6.1 in [[LaiS07]]. Theorem 10.28. The space S51,2 () has dimension N := 6n + n e . Moreover, the set M :=

1 v∈V

Mv ∪

1

Me

(10.39)

e∈E

is a minimal determining set for S51,2 (). Note that there is some freedom in the above construction of M. In particular, for each vertex v, Tv can be any of the spherical triangles with a vertex at v. To get the most stable basis, we recommend choosing Tv to be the one with the largest angle at v. For interior edges, we also have two choices for the spherical triangle Te used to get Me . We also choose it to reduce the constant of stability. We have implemented this algorithm in the following function: [A,dof] = smds15(x,y,z,v1,v2,v3,e1,e2,e3,ie1) This function produces a vector dof containing a list of the indices of the domain points forming the minimal determining set, where we assume the domain points are numbered according to the storage convention of section 10.3.1. The function also computes the transformation matrix A, which is a sparse matrix of size n c × N, where n c is the number of B-coefficients of splines in S51,2 (), and N is its dimension. The matrix A can be used to compute the vector c of B-coefficients from the vector c˜ containing the coefficients corresponding to the domain points in M; see (10.26). Example 10.29. Examine the basis functions in the space S51,2 () defined on the spherical triangulation shown in Figure 10.1 (right). Discussion: We make use of the script SPmds15, and read the spherical triangulation from the file sptri2. This gives the triangulation shown in Figure 10.1 (right). It has n = 18 vertices, ne = 48 edges, and nt = 32 spherical triangles. The associated spline space S51,2 () has dimension 156. For this space we have 402 B-coefficients, so the matrix A is a 402 × 156 sparse matrix. The vector dof has 156 entries. Each of the first 18 corresponds

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.6. Remarks

353

to the domain point at a vertex v of . The associated basis function is nonnegative and has support on the star of v. The next 90 indices in dof correspond to domain points in the disks D2 (v) around the vertices of . Each of these basis functions has support on the star of a vertex, but is no longer nonnegative. The last 48 degrees of freedom correspond to domain points in the set Me in (10.39). These basis functions have support on the two triangles of  that share the edge e, and are also not nonnegative. The plots of these basis functions are similar to those shown in Figure 10.7 for the space S21 ( P S ).

10.6 Remarks Remark 10.1. The word spherical spline has been used in various ways in the literature. For example, in much of the literature it refers to a spherical analog of the bivariate thin plate spline, i.e., it is a combination of spherical radial basis functions; see, e.g., [Wah81,Wah82]. Related spherical splines were defined in terms of reproducing kernel Hilbert spaces on the sphere in a long series of papers going back to the early 1980’s by Freeden and colleagues; see the book [[FreeGS98]]. Certain curves on the sphere were also called spherical splines in [[HosS92]]. The type of spherical splines discussed here (piecewise functions defined on a spherical triangulation) were introduced in [AlfNS96]. Remark 10.2. Just as in the planar case, the spherical Delaunay triangulation is only unique up to so-called neutral cases. Indeed, suppose we choose four points lying on a spherical cap. Then there are two ways to form a spherical triangulation with these points as vertices. But it is easy to show that the minimal angle is the same for both triangulations, and thus they are both Delaunay triangulations. Here is an example:

Figure 10.9. Two spherical triangulations of four points on a spherical cap. Both are spherical Delaunay triangulations.

Remark 10.3. In section 10.1.4 we have discussed uniform refinement of a spherical triangulation, while in sections 10.5.1 and 10.5.2 we use Powell–Sabin and Clough–Tocher refinements. Just as in the planar case, there are many other ways to refine spherical triangulations, and in fact in practice it is often useful to do local refinement where only some of the triangles are split. Any method that works in the planar case can be extended to spherical triangulations. Remark 10.4. One of the most important domains for applications is the surface of the earth, which of course is not a sphere. However, for most applications we can map it onto the unit sphere by projecting points radially. Remark 10.5. The situation is more complicated when the domain of interest is a general smooth closed manifold in R3 . One could define triangulations with geodesic edges, but

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

354

Chapter 10. Spherical Splines

it is not clear how to extend the Bernstein–Bézier theory we have for spherical splines to such domains. However, some adhoc methods have been developed for interpolation and approximation on manifolds; see, e.g., [DavS08]. Remark 10.6. There are only three spherical triangulations such that all triangles have the same size and shape. The smallest has 4 vertices which are vertices of a tetrahedron. This triangulation has 6 edges and 4 triangles. The second example has 6 vertices which are the vertices of an octahedron. This triangulation has 8 triangles, and corresponds to our file sptri1. The third example is obtained by taking the vertices from an icosahedron. This gives a triangulation with 12 vertices, 30 edges, and 20 congruent spherical triangles. To see a plot of it, call SPrefine with the file icos.dat. Remark 10.7. For each of the three triangulations of the previous remark, all of the edges have the same length. In this sense, the points are equally spaced on the sphere. No other spherical triangulation has this property, which raises an interesting question: how to choose “almost equally spaced” points on the sphere. There is quite a bit of recent work on this question. Remark 10.8. Most of the plots in this chapter have been created with valsphsp using the triangulation sptri6, which has 4098 vertices and 8192 triangles. Plots with finer grids can be produced by using sptri7, which has 16386 vertices and 32768 triangles. They don’t look as good on the screen, however. Remark 10.9. In the plots produced by valsphsp we see the outlines of some triangles on the surface of the sphere. These edges appear because we are rendering a collection of 8192 triangular facets. They appear to coincide with the edges of the triangulation sptri2. These spherical arcs appear in all the triangulations in the nested sequence sptri3, . . . , sptri6 obtained by uniform refinement. These edges are not the edges of the triangulation underlying the spline being rendered. Remark 10.10. Our function srendtri works equally well with spherical triangulations that do not cover the sphere. However, the function valsphsp for evaluating a spherical spline on a given set of points does not work for such spherical triangulations. For this we have the function valsphsp2. It can be substituted for valsphsp in all of the scripts where such splines are being plotted. Remark 10.11. The function quadset is designed to read in the weights and sample point locations (in barycentric coordinates) for performing Gauss quadrature on a planar triangle. The parameter n q controls the number of sample points. Tables of these weights and locations for various values of n q can be found in the literature. Our function only works with n q chosen from the set {1, 3, 4, 12, 25, 79}. The corresponding formulae are exact for bivariate polynomials of degrees 1, 2, 3, 6, 10, and 23. When used to integrate spherical polynomials as described in section 10.2.7, we can expect them to get quite accurate results, particularly if we choose the refinement parameter in sphintpol sufficiently large. Remark 10.12. Examples 10.4 and 10.12 illustrating the use of Gauss quadrature to compute integrals over spherical triangles were run with n q = 25. For those tests, we get very similar values for n q = 12, 79. This is not surprising as the functions being integrated there were spherical polynomials of degrees four and two, respectively.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

10.7. Historical notes

355

Remark 10.13. In the planar case, the constant K 2 in the analog of (10.10) is one; see (4.6). Since the spherical Bernstein basis functions defined in (10.7) are not bounded by one, here we need a larger constant. For some explicit constants that work in (10.10), see [BarL05]. Remark 10.14. In section 10.5 we have discussed three useful macro-element spaces of C 1 spherical splines. However, all of the macro-element spaces discussed in Chapters 6–8 of [[LaiS07]] have spherical analogs, including, for example, those treated in sections 4.14.3 and 4.14.4 in the planar case. Remark 10.15. The space of spherical polynomials Bd reduces to the space of spherical harmonics of even order if d is even, and to the space of spherical harmonics of odd order if d is odd. Thus, for example, the constant function is contained in Bd for d even, but not for d odd. To remedy this problem, one can work with the direct sum of Bd and Bd−1, although it is not clear how much is to be gained by doing so; see [GomS98].

10.7 Historical notes The idea of a spherical triangulation is a natural generalization of a planar triangulation, and no doubt has been around in the mathematics literature for a long time. For some early papers where piecewise functions defined on spherical triangulations were used to interpolate or approximate data on the sphere, see [Law84, Ren84, Renk84b]. The first paper contains a method for building a spherical triangulation, and then optimizing it to maximize the minimum angles. This amounts to constructing the spherical Delaunay triangulations; see also [Ren97] for a Fortran program. In Chapter 3 we saw that the key to computing with polynomials defined on a planar triangulation was to work with barycentric coordinates. Until publication of the paper [AlfNS96], it was thought that there was no analog for spherical triangulations; see, e.g., [BroW92]. It was later discovered that in fact Möbius had introduced them in 1886; see the discussion in section 5.1 of the survey [FasS98] and references therein. The paper [AlfNS96] was the paper that initiated the study of splines on spherical triangulations, and much of the theory of this chapter is based on it. For more details on spherical harmonics, see [FasS98]. Applications of spherical splines to interpolation and data fitting on the sphere were first studied in [AlfNS96b]. The approach to rendering used here is taken from that paper, where the nested sequence of spherical triangulations sptri1, . . . , sptri6 were also introduced. The spherical macro-element spaces of section 10.5 can also be found there. The approximation power of spherical splines was first investigated in [NeaS04], although there had been considerable work on how well smooth functions defined on the sphere could be approximated (locally) by spherical harmonics; see the survey [FasS98] for some references.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Chapter 11

Applications of Spherical Splines

In this chapter we show how the methods of Chapters 5, 6, and 7 for interpolating and fitting data in the bivariate setting can be carried over to the sphere. We also discuss solving PDE’s on the sphere with spherical splines.

11.1 Interpolation with S10 () We begin by explaining how to use the spherical spline space S10 () introduced in section 10.3 to interpolate scattered data on the sphere. Suppose  is a spherical triangulation with vertices at the points {vi }ni=1 , and suppose we are given associated values {wi }ni=1 . Then by the properties of S10 (), it is easy to see that there is a unique spline in S10 () that interpolates these data values in the sense that s(vi ) = wi ,

i = 1, . . ., n.

Indeed, on each triangle T , the function s|T is a spherical polynomial in the space B1 spanned by {Bi1j k }i+ j +k=1 ; see section 10.2.2. It is uniquely determined by its values at the three vertices of T . Thus, the corresponding vector of B-coefficients defining s is just c = (w1 , . . . , wn ). To explore interpolation with S10 (), we look at some examples where the values {wi }ni=1 are sampled from a known test function. In this section, and throughout the chapter, we use the following test function: [w,grad] = sfun(nf,x,y,z) Here x,y,z are n-vectors giving the Cartesian coordinates of the points {vi }ni=1 , and nf is an integer input which determines which of the following functions to evaluate: f 1 := x + y + z, f 2 := x 2 + y 2 + z 2 , f 3 := 2 + x 3 + y 3 + z 3, f 4 := x 4 + 1.1y 4 + 1.3z 4,

(11.1) (11.2) (11.3) (11.4) 3

2

f 5 := 1 + x 8 + 10x yz + e2y + e2z , f 6 := 2x 3 + y 3 + z 3 − x − y − z. 357

(11.5) (11.6)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

358

Chapter 11. Applications of Spherical Splines

The output of this function is an n-vector w that gives the function values at the points {(x i , yi , z i )}ni=1 , and an n × 3 matrix grad containing the values of the 3D gradients at the same points. In this section we do not use the gradients, but they will be needed later in the chapter. Using this function, it is easy to create a script to test interpolation with S10 (): % SP01 d = 1; [n,x,y,z,nt,TRI] = sreadtri; [v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir] = slists(x,y,z,TRI); nf = input(’input nf ’); c = sfun(nf,x,y,z); [G,gx,gy,gz] = rendsphsp(d,x,y,z,v1,v2,v3,e1,e2,e3,... ie1,c,’sptri6’); figure; h = trisurf(G,gx,gy,gz); axis vis3d; axis equal tight off; rotate3d on; set(h,’edgecolor’,[0 0 0],’facecolor’,[1 .8 .65]); [xp,yp,zp,g] = valsphsp(d,x,y,z,v1,v2,v3,e1,e2,e3,... ie1,c,’sptri7’); err = g - sfun(nf,xp,yp,zp); fprintf(’emax = %5.2e RMS = %5.2e\n’,norm(err,inf),... erms(err)); This script first reads a triangulation from a file and computes the corresponding triangulation lists; see section 10.1.2. It then computes the values to be interpolated by evaluating the test function sfun. Next it calls on the function rendsphsp introduced in section 10.3.4 to evaluate the spline at the vertices of the triangulation sptri6, which has 4098 vertices and 8192 triangles. Here G is a matrix of size 8192 × 3 giving the vertex lists of the triangulation sptri6. A call on trisurf then produces a plot of the surface. To compute the max and RMS errors of the spline, we use valsphsp with the file sptri7. This evaluates the spline on a set of 16386 points spread almost uniformly across the sphere. Example 11.1. Find the spherical splines in S10 () that interpolate the values produced by the functions (11.1)–(11.6) at the 42 vertices of the spherical triangulation sptri42 shown in Figure 11.1. Discussion: We use the script SP01, and read the triangulation from the file sptri42. It has 42 vertices, 120 edges, and 80 triangles. Here is a table of the max and RMS errors, measured at the 16386 vertices of the spherical triangulation sptri7. f1 f2 f3 f4 f5

emax 1.55(−15) 1.76(−1) 6.85(−1) 3.18(−1) 2.27(0)

rms 1.92(−16) 7.26(−2) 1.89(−1) 8.55(−2) 6.05(−1)

When restricted to the sphere, the test function f 1 belongs to S10 (), which explains why for this function we get an error of essentially zero. We give plots of the other splines in

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.1. Interpolation with S10 ()

359

Figure 11.1. The spherical triangulation corresponding to the file sptri42. It has 42 vertices, 120 edges, and 80 triangles.

Figure 11.2. The splines in S10 () interpolating the functions f 2 , f 3 , f 4 , and f 5 at the 42 vertices of the triangulation sptri42.

Figure 11.2. They are not very good fits — much better fits of these functions are shown in other plots later in this chapter. We now give an example to explore the order of approximation of the space S10 () when interpolating the function f4 on a nested sequence of spherical triangulations.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

360

Chapter 11. Applications of Spherical Splines

Figure 11.3. The splines in S10 () interpolating the function f4 at the vertices of the triangulations sptri2 and sptri4.

Example 11.2. Find the spline in S10 () that interpolate values of the test function f 4 at the vertices of the spherical triangulation sptri1 in Figure 10.1 (left). Repeat for its successive uniform refinements. Discussion: We again make use of the script SP01, but now read the triangulations from the files sptri1, . . . , sptri5. These correspond to a sequence of uniform refinements of the initial triangulation sptri1. Figure 11.3 shows the interpolating splines corresponding to the spherical triangulations sptri2 and sptri4. They have 18 and 258 vertices, respectively. The plots show clearly that the splines are only C 0 , although with the larger point set sptri4, the surface looks almost C 1 . The maximum and RMS errors computed at the 16386 vertices of sptri7 are shown in the following table, along with the ratios as we repeatedly refine the triangulation: triang sptri1 sptri2 sptri3 sptri4 sptri5

emax 1.58(0) 3.17(−1) 2.23(−1) 5.79(−2) 1.52(−2)

rms 1.02(0) 1.09(−1) 6.88(−2) 1.73(−2) 4.32(−3)

ratios 4.98 9.36 1.42 1.58 3.85 3.98 3.81 4.00

Since we are dealing with spherical splines of degree d = 1, by Theorem 11.3, we expect the error to behave like O(||2 ), where || is the mesh size of the triangulation. The triangulations used here are nested with their mesh size going down by a factor of approximately two for each successive refinement, and so we expect the errors to go down by a factor of four each time, which is what the table shows. Interpolation using the spline space S10 () has several advantages. For example, it is very efficient — no computation is needed to find the B-coefficients. However, it has several drawbacks. Perhaps the main one is that a spline in this space is only continuous. In addition, since the order of convergence is only two, to get high accuracy will require a lot of (well-distributed) interpolation points. This suggests that we should look at other spaces of splines of higher degree and smoothness. We conclude this section with a result giving an error bound for interpolation with the space S10 (). To state it, we need some additional notation. Given a spherical triangulation

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.2. Hermite interpolation with macro-element spaces

361

, we define its mesh size || to be the arc-length of the longest edge appearing in . Given a function f defined on S, and an integer k > 0, we define its spherical semi-norm of order k as  | f |k := D α f k−1 ∞ , |α|=k

where f k−1 is the homogeneous extension of order k − 1 of f ; see section 10.2.6. Here the norms of the derivatives are measured in the maximum norm taken over the sphere. Theorem 11.3. For every f ∈ C m+1 (S) with 0 ≤ m ≤ 1, the spline s ∈ S10 () that interpolates f at the vertices of  satisfies  f − s ≤ K ||m+1 | f |m+1 .

(11.7)

11.2 Hermite interpolation with macro-element spaces In this section we discuss spherical analogs of several of the Hermite interpolation methods discussed in Chapter 5 for the bivariate case. It will be clear from the discussion that the other methods considered there also extend easily to spherical splines.

11.2.1 Frame vectors Given a point v on the surface of the unit sphere S, let πv be the plane tangent to S at v. It will be convenient to establish a coordinate system on πv . Definition 11.4. Given a point v on S, let u and u˜ be two unit vectors in R3 that are orthogonal to each other and to the vector pointing from the origin to v. We call u and u˜ the frame vectors associated with v. The frame vectors u and u˜ can be used to define a coordinate system for πv . Let U be the vector obtained by translating u without changing its direction so that its tail is at v. Similarly, let U˜ be the translation of u˜ to the plane πv . Then U and U˜ form the desired coordinate system. Suppose now that g is a vector in R3 whose translation to v lies in the plane πv . Then there exist α and β such that g = αu + β u, ˜ and it follows from the definition of directional derivatives that Dg f (v) = α Du f (v) + β Du˜ f (v). Thus, if we are given the two directional derivatives Du f (v) and Du˜ f (v) at a point v on the sphere, we can calculate all other directional derivatives at v. Clearly, for a given v, the vectors u and u˜ in Definition 11.4 are not uniquely defined. In particular, we can take u to be any unit vector orthogonal to the vector pointing from the origin to the point v, and then take u˜ to be a unit vector that is orthogonal to both v and u. Here is a code for computing frame vectors u and w associated with a set of points on the sphere. [u,uw] = sframe(x,y,z) The inputs x,y,z are n-vectors giving the Cartesian coordinates of the points of interest. The output consists of two n × 3 matrices u and uw giving the Cartesian coordinates of the pair of frame vectors associated with these points.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

362

Chapter 11. Applications of Spherical Splines

11.2.2 Interpolation with S21 ( P S ) Given a spherical triangulation  with n vertices {vi }ni=1 , let  P S be the Powell–Sabin refinement of  described in section 10.5.1. In this section we show how to use the corresponding Powell–Sabin space S21 ( P S ) to solve a certain Hermite interpolation problem on the sphere involving values and derivatives at the vertices of . To describe the problem, we need to choose coordinate frames for each vertex of . For each vertex vi , let u i and u˜ i be associated frame vectors in R3 , and let Du i and Du˜ i be the corresponding directional derivatives. The following result was proved in Theorem 5.6 of [[AlfNS96b]]. Theorem 11.5. Given real numbers {(wi , wi1 , wi2 )}ni=1 , there exists a unique spline s ∈ S21 ( P S ) such that s(vi ) = wi , Du i s(vi ) = wi1 , Du˜ i s(vi ) =

i = 1, . . . , n.

(11.8)

wi2 ,

As in the bivariate case, the B-coefficients of the spline s can be computed directly from the data without solving any linear systems of equations. Suppose T := v1 , v2 , v3  is one of the triangles in  which has been split into six subtriangles in forming  P S . Let u T be the incenter of T , and let v12 , v13 , v23 be the vertices inserted on the edges of T in forming its Powell–Sabin refinement. Now consider the restriction s|T to the macro triangle T . It is a spline defined on the Powell–Sabin refinement of T , and consists of six spherical polynomial pieces of degree two, joined together with C 1 smoothness. This subspline is determined by 19 B-coefficients which we can numbered as in Figure 5.2, where c1 , c2 , c3 are associated with the vertices v1 , v2 , v3 , respectively. Then, c1 = w1 ,

c2 = w2 ,

c3 = w3 .

We now show how to compute c4 . Let u 1 and u˜ 1 be the frame vectors associated with the point v1 , and let πv1 be the tangent plane to S at v1 . Let u be a unit vector that is orthogonal to the vector from the origin to v1 , and which lies in the plane determined by the origin and the two points v1 and v2 . If we translate its tail to v, we get a vector that lies in the plane πv1 and points along the edge v1 , v2  of T . Writing u as a linear combination of the frame vectors as u = αu 1 + β u˜ 1 , it follows that if s satisfies (11.8), we have Du s(v1 ) = αw11 + βw12 . Now suppose (a1 , a2 , 0) are the spherical directional coordinates of u relative to the triangle v1 , v12 , u T . Using the formula (10.16) for the directional derivative of a spherical Bpolynomial, we then get c4 = [Du s(v1 )/2 − a1w1 ]/a2 . The coefficients c5 , . . . , c12 can be computed from similar formulae. The remaining coefficients c13 , . . . , c19 can be computed by the C 1 smoothness conditions across the interior edges of the Powell–Sabin split of T . Indeed, we can use the same formulae as in (5.5), except that now we use spherical barycentric coordinates in place of the planar ones. Here is our function to carry out interpolation on the sphere with S21 ( P S ). [x,y,z,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,bdy,c] = ... sphps(x,y,z,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o, ... trilo,triro,u,uw,w,w1,w2)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.2. Hermite interpolation with macro-element spaces

363

The input includes vectors describing the initial spherical triangulation  of the data points, along with frame vectors u,uw associated with the vertices of . It also includes vectors w,w1,w2 giving the data to be interpolated. The output includes triangulation information for the spherical Powell–Sabin refinement, along with a vector c containing the Bcoefficients of the interpolating spline in S21 ( P S ), stored in the canonical order described in section 10.3.1. Due to the fact that the spline s is C 1 , for each vertex v of , it will match the directional derivatives of f at v in all directions. Example 11.6. Interpolate the functions f 1 , . . . , f5 at the vertices of the spherical triangulation sptri42 using the C 1 quadratic Powell–Sabin macro element. Discussion: We make use of the script SPps, and read in the triangulation from the file sptri42. Here is a table of the max and RMS errors, measured at the 16386 vertices of the spherical triangulation sptri7. f1 f2 f3 f4 f5

emax 5.75(−2) 1.18(−14) 7.39(−2) 1.33(−1) 4.81(−1)

rms 1.12(−2) 3.86(−15) 1.45(−2) 3.15(−2) 9.21(−2)

When restricted to the sphere, the test function f 2 belongs to S21 ( P S ), which explains why its interpolant is almost exact. We give plots of the other splines in Figure 11.4. They are clearly much better than what we got in Figure 11.2 with the space S10 (). In addition to being C 1 instead of C 0 , the splines here are also more accurate as we can see by comparing the tables. But of course here we are interpolating gradients as well as values at the 42 vertices. We now explore the order of approximation of the spherical spline spaces S21 ( P S ) by computing interpolation errors on a nested sequence of spherical triangulations. Example 11.7. Interpolate the function f 4 using the spaces S21 ( P S ) based on Hermite data at the vertices of the nested sequence of spherical triangulations used in Example 11.2. Discussion: We again make use of the script SPps, but now read the triangulations from the files sptri1, . . . , sptri5. We give plots of the splines interpolating f 4 corresponding to sptri2 and sptri4 in Figure 11.5. Here is a table of the maximum and RMS errors computed at the 16386 vertices of sptri7. The table also shows the ratios of errors for successive data sets. triang sptri1 sptri2 sptri3 sptri4 sptri5

emax 7.57(−1) 1.89(−1) 2.19(−2) 3.76(−3) 3.96(−4)

rms 4.64(−1) 6.64(−2) 6.98(−3) 7.37(−4) 8.52(−5)

ratios 4.01 6.99 8.63 9.51 5.82 9.47 9.49 8.65

By Theorem 11.9 below, we expect a rate of convergence of O(||3 ). The ratios here are consistent with that rate.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

364

Chapter 11. Applications of Spherical Splines

Figure 11.4. The splines in S21 ( P S ) interpolating the functions f 1 , f 3 , f 4 , and f 5 at the 42 vertices of the triangulation sptri42.

Figure 11.5. The splines in S21 ( P S ) interpolating the function f 4 at the vertices of the triangulations sptri2 and sptri4.

Since splines are known to simultaneously approximate derivatives, it is of interest to explore the accuracy of the derivatives of the Powell–Sabin interpolating splines constructed in the previous example.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.2. Hermite interpolation with macro-element spaces

365

Example 11.8. Construct the Powell–Sabin splines interpolating the function f 4 at the vertices of the nested sequence sptri1, . . . , sptri5 of spherical triangulations, and check how well they fit directional derivatives of f 4 at the vertices of sptri7. Discussion: We make use of the script SPpsder, and read the triangulations from the data files sptri1, . . . , sptri5. For each of the vertices of the triangulation sptri7 (which are the points used above in computing the error of our interpolating splines), we compute a directional derivative in a random direction, and compare it to the true directional derivative at that point. If u := (u 1 , u 2 , u 3 ) is the direction vector, we can compute the true directional derivative of f 4 at a point v on the sphere as Du f 4 (v) = u 1 Dx f 4 (v) + u 2 D y f 4 (v) + u 3 Dz f 4 (v), where (Dx f 4 (v), D y f4 (v), Dz f 4 ) is the gradient of a homogeneous extension of f 4 . It can be computed with a call on sfun with nf = 4. To compute the directional derivative of the spline at v, we first find a triangle T ∈  P S that contains v. Then we extract the Bcoefficients of s|T , and use the function decastder described in section 4.4 to compute the directional derivative. The results of our test are shown in the following table, which gives the maximum and RMS errors and the corresponding ratios: triang sptri1 sptri2 sptri3 sptri4 sptri5

emax 1.30(0) 1.07(0) 2.13(−1) 8.26(−2) 2.36(−2)

rms 6.43(−1) 3.18(−1) 6.37(−2) 1.64(−2) 4.77(−3)

ratios 1.21 2.02 5.02 4.99 2.58 3.88 3.50 3.44

According to Theorem 11.9, the first derivatives of the Powell–Sabin splines should have an approximation order of O(||2 ) for a C ∞ function. This is approximately what we are getting. Note that if we run this example with nf = 2, which corresponds to the constant function, all the errors are zero as they should be. Following the arguments for getting error bounds for Hermite interpolation with macroelement spline spaces in the bivariate case (see Theorem 5.26 in [[LaiS07]]), and combining with results in [NeaS04] for approximation on the sphere, we get the following result. Theorem 11.9. For every f ∈ C m+1 (S) with 0 ≤ m ≤ 2, its C 1 Powell–Sabin interpolant s satisfies  f − s ≤ K ||m+1 | f |m+1 . Moreover, for every point v and any vector u tangent to S at v, |Du ( f − s)| ≤ K ||m | f |m+1 .

(11.9)

Here the constant K depends only on the smallest angle in the triangulation. This result shows that if we interpolate data sampled from a function f in C 3 (), then we can expect the error to behave like O(||3 ) as we let || go to zero. This is the optimal order of convergence for quadratic splines. Assuming f is smoother will not lead to higher order convergence, as we saw in Example 11.7 where the data came from a C ∞ function.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

366

Chapter 11. Applications of Spherical Splines

On the other hand, if the smoothness of f is less than C 3 , we may get a lower rate of convergence; see section 5.8 for some examples in the bivariate case.

11.2.3 Hermite interpolation on the sphere with S31 (CT ) In this section we discuss Hermite interpolation on the sphere using the space S31 (C T ) discussed in section 10.5.2, where C T is the Clough–Tocher refinement of a given triangulation  with n vertices and n e edges. For each vertex v of , let Du 1 and Du˜ 1 be the directional derivatives appearing in Theorem 11.5. For each edge e := u, v of , let ηe := (u + v)/2 be the midpoint of e, and let Du e be the directional derivative associated with the unit vector u e tangent to the sphere at ηe , and perpendicular to the plane through u, v and the origin. We take u e so that it points into the triangle. The following theorem follows from results in [AlfNS96b]. Theorem 11.10. Suppose {(wi , wi1 , wi2 )}ni=1 and {we }e∈E are given real numbers, where E is the set of edges of . Then there exists a unique spline s ∈ S31 (C T ) such that s interpolates the Hermite data at vertices as in (11.8), and in addition Du e s(ηe ) = we ,

e ∈ E.

(11.10)

The space S31 (C T ) is a macro-element space in the sense of Definition 5.27 of [[LaiS07]]. This means that the interpolant can be computed one macro triangle at a time. Suppose T := v1 , v2 , v3  is one of the triangles in  which has been split into three subtriangles in forming C T . Now consider the restriction s|T to the macro triangle T . It is a spherical spline on the Clough–Tocher refinement of T , and consists of three spherical polynomial pieces of degree three, joined together with C 1 smoothness. This subspline is determined by 19 B-coefficients which we number as in Figure 5.6, where c1 , c2 , c3 are associated with the vertices v1 , v2 , v3 , respectively. As shown in [AlfNS96b], there are simple formulae for computing the vector of B-coefficients of the spline s ∈ S31 (C T ) solving this Hermite interpolation problem. First we have c1 = w1 ,

c2 = w2 ,

c3 = w3 .

We now show how to compute c4 . Let u := (u 1 , u 2 , u 3 ) be a unit tangent vector to the sphere at v1 in the plane containing the origin and the edge v1 , v2 . Suppose (a1, a2 , a3 ) are the spherical directional coordinates of u relative to the triangle v1 , v2 , u T . Then using the formula (10.16) for the directional derivative of a spherical B-polynomial, we get c4 = [Du s(v1 )/3 − a1w1 ]/a2 . The coefficients c5 , . . . , c12 can be computed from similar formulae. Next we give a formula for c13 . Suppose u is a unit vector tangent to the sphere at the midpoint v12 of the edge e := v1 , v2  and perpendicular to the plane through the vertices v1 , v2 and the origin. We suppose u points into the triangle T , and let (a1 , a2 , a3 ) be its spherical directional coordinates relative to the triangle v1 , v2 , u T . Let (a˜ 1 , a˜ 2 , a˜ 3 ) be the spherical barycentric coordinates of v12 relative to the triangle v1 , v2 , u T . Then we have c13 = [we /3 − a˜ 12(a1 w1 + a2c4 + a3c5 ) − 2a˜ 1a˜ 2 (a1c4 + a2c9 ) − a˜ 22(a1 c9 + a2w2 + a3c8 )]/(2a˜ 1a˜ 2 a3 ).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.2. Hermite interpolation with macro-element spaces

367

The coefficients c14 and c15 can be computed with similar formulae. The remaining coefficients c16 , . . . , c19 can be computed by the C 1 smoothness conditions across the interior edges of the Clough–Tocher split of T . Indeed, we can use the same formulae as in (5.9), except that now we use spherical barycentric coordinates in place of the planar ones. To perform interpolation with the spherical Clough–Tocher interpolant, we have written the script SPct. It calls sreadtri and slists to read a triangulation  and compute the edge lists. The code uses the test function sfun to compute the values and derivatives to be interpolated. Then it calls on the following function: [x,y,z,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,c] = ... sphct(x,y,z,v1o,v2o,v3o,e1o,e2o,e3o,ie1o,ie2o,... trilo,triro,w,u,uw,w1,w2,ue,we) The input is the usual information about the initial spherical triangulation , along with the frame vectors u,uw associated with the vertices of the initial triangulation. The corresponding directional derivative values are contained in w1,w2. The input ue lists the cross vectors associated with each edge, and we contains the corresponding data values. The output includes the lists for the Clough–Tocher refinement, along with the vector c of B-coefficients of the interpolating spline in S31 (C T ). Example 11.11. Interpolate the functions f 1 , . . . , f6 at the vertices of the spherical triangulation sptri42 using the corresponding spherical spline space S31 (C T ). Discussion: We make use of SPct, and read the triangulation from the file sptri42. Here is a table of the max and RMS errors, measured at the 16386 vertices of sptri7. f1 f2 f3 f4 f5 f6

emax 2.58(−10) 3.62(−2) 7.24(−2) 6.09(−2) 2.54(−1) 2.58(−10)

rms 6.09(−11) 8.91(−3) 1.78(−2) 8.39(−3) 4.86(−2) 6.09(−11)

When restricted to the sphere, the test functions f 1 and f 6 both belong to S31 (C T ), which explains why their interpolants are essentially exact. Note that f3 is also a cubic polynomial, but it contains a constant. Since spaces of cubic splines do not contain constants (see (10.8)), this explains why the interpolant of f 3 is not exact. The errors here are generally somewhat smaller than in Example 11.6 which used Powell–Sabin splines. We do not bother to show plots of these splines since they look almost identical to those shown in Figure 11.4. We now explore the order of approximation of the spherical spline spaces S31 (C T ) by computing interpolation errors on a nested sequence of spherical triangulations. Example 11.12. Interpolate the function f 4 using the space S31 (C T ) for a sequence of nested spherical triangulations. Discussion: We again make use of SPct, but now read the triangulations from the files sptri1, . . . , sptri5. The data comes from the test function sfun with nf = 4. We

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

368

Chapter 11. Applications of Spherical Splines

do not bother to give plots of these splines as they look very similar to those obtained with S21 ( P S ); see Figure 11.5. Here is a table of the maximum and RMS errors measured at the 16386 vertices of sptri7. triang sptri1 sptri2 sptri3 sptri4 sptri5

emax 2.78(−1) 2.27(−2) 5.39(−3) 4.57(−4) 3.10(−5)

rms 1.76(−1) 1.36(−2) 2.05(−3) 1.25(−4) 7.82(−6)

ratios 12.25 12.94 4.21 6.63 11.79 16.40 14.74 15.98

By Theorem 11.14 below, we expect the rate of convergence to be O(||4 ), which is approximately what we are getting. Example 11.13. Explore the accuracy of the derivatives of the Clough–Tocher interpolating splines constructed in the previous example. Discussion: We make use of the script SPctder and the triangulations in the nested sequence sptri1, . . . , sptri5. For each triangulation, we construct the C 1 Clough– Tocher spline interpolating the function f 4 . To test the accuracy of the derivatives, for each vertex of sptri7, we choose random direction vectors as explained in Example 11.8. The corresponding directional derivatives are compared with the true values on sptri7, and we report the max and RMS errors. triang sptri1 sptri2 sptri3 sptri4 sptri5

emax 5.16(−1) 7.64(−2) 3.58(−2) 6.10(−3) 8.24(−4)

rms 2.52(−1) 3.40(−2) 1.17(−2) 1.47(−3) 1.76(−4)

ratios 6.75 7.41 2.13 2.91 5.87 7.96 7.40 8.35

These errors are consistent with Theorem 11.14, which says that the first derivatives of the Clough–Tocher splines should have an approximation order of O(||3 ) for a C ∞ function. Following the arguments for getting error bounds for Hermite interpolation with macroelement spline spaces in the planar case (see Theorem 5.26 in [[LaiS07]]), and combining with results in [NeaS04] for approximation on the sphere, we get the following result. Theorem 11.14. For every f ∈ C m+1 (S) with 0 ≤ m ≤ 3, its C 1 Clough–Tocher interpolant s satisfies (11.11)  f − s ≤ K ||m+1 | f |m+1 . Moreover, for every point v and any vector u tangent to S at v, |Du ( f − s)| ≤ K ||m | f |m+1 .

(11.12)

This result shows that if we interpolate data sampled from a function f in C 4 (S), then we can expect the error to behave like O(||4 ) as we let || go to zero. This is the optimal

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

369

order of convergence for cubic splines. Assuming f is smoother will not lead to higher order convergence, as we saw in Example 11.12 where the data came from a C ∞ function. On the other hand, if the smoothness of f is less than C 4 , we may get a lower rate of convergence.

11.3 Scattered data interpolation on the sphere The macro-element-based methods of the previous section require Hermite data. In practice, we are often given only values at the sample points, and no derivative information. In this section we discuss spherical analogs of several of the methods of Chapter 6 for interpolating scattered data. Here is our basic problem. Given points {(x i , yi , z i )}ni=1 on the sphere and associated data values {wi }ni=1 , find a spherical spline s defined on an appropriate spherical triangulation such that s(x i , yi , z i ) = wi ,

i = 1, . . ., n.

(11.13)

11.3.1 Interpolation on the sphere with minimal energy splines In section 6.3 we discussed minimal energy splines as a tool for solving the bivariate scattered data interpolation problem. We now show how the method can be carried over to the sphere. Suppose S() ⊂ Sd0 () is a space of spherical splines over a triangulation t Ti , and let  := ∪ni=1 U := {s ∈ S() : s(x i , yi , z i ) = wi , i = 1, . . . , n}.

(11.14)

This is the subspace of splines in S() that interpolate the data. For the spaces to be used below, it is easy to see that it is nonempty. As in the bivariate case, the idea is to choose the spline in U that minimizes some measure of the energy of the spline. Following [AlfNS96b], given s ∈ U , let E(s) :=

nt  

(∗ s)2 ,

(11.15)

i=1 Ti

where

∗ s := sx x + s yy + szz − d(d + 1)s.

(11.16)

This is the Laplace–Beltrami operator applied to the spline; see Remark 11.17. Problem 11.15. Find a spline s which minimizes E(s) over U . We call s a spherical minimal energy interpolating spline.

Using the same argument as in section 6.3.1, it is not hard to see that as long as U is not empty, there exists a unique minimal energy interpolating spline. To compute it, suppose N is a basis for the spline space S() such that {φi }i=1 φi (x j , y j , z j ) = δi j , and

φi+n (x j , y j , z j ) = 0,

i , j = 1, . . . , n,

j = 1, . . ., n,

i = 1, . . ., N − n.

(11.17) (11.18)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

370

Chapter 11. Applications of Spherical Splines

We seek a solution of Problem 11.15 in the form s=

n 

wi φi +

i=1

N−n 

ai φi+n .

(11.19)

i=1

Clearly, s automatically satisfies (11.13) in view of properties (11.17) and (11.18) of our basis functions. We need some additional notation. For any two splines φ and ψ in S(), let  φ, ψ E := ∗ φ ∗ ψ. (11.20) S

Now let M := [φi , φ j  E ]i,Nj =1 . It will be convenient to rewrite M in the block form % & M11 M12 M= , M21 M22

(11.21)

(11.22)

where M11 is of size n × n, M12 is of size n × (N − n), M21 is of size (N − n) × n, and M22 is of size (N − n) × (N − n). Note that both M11 and M22 are symmetric, and M22 is positive definite. Let w := (w1 , . . . , wn )T . Then arguing as in the proof of Theorem 6.6, we can show the following result. Theorem 11.16. The coefficients a := (a1 , . . . , a N−n ) of the spherical minimal energy interpolating spline are the solution of M22 a = −M21 w. To implement these ideas, suppose 0 is a spherical triangulation with vertices at the data points {(x i , yi , z i )}ni=1 . Suppose S() is one of the macro-element spaces discussed in section 10.5, based on an appropriate refinement  of 0 . Creating this refinement may require introducing new vertices, so that a spline in S() may have more than n vertices, but the spline s that we are computing will interpolate only at the first n of these, i.e., at the vertices of 0 . Let A be a transformation matrix for S(). Then the matrix M in (11.36) can be assembled following the suggestions of section 6.3.2. We have the following function for computing the coefficients of a minimal energy interpolating spline: c = smen(d,x,y,z,v1,v2,v3,e1,e2,e3,ie1,w,A) Here d is the degree of the spline space. The vectors x,y,z give the Cartesian coordinates of the vertices of , while the vectors v1, . . . , ie1 come from slists for the triangulation . The input w contains the given data values, and A is the transformation matrix. Example 11.17. Find the spherical Powell–Sabin minimal energy splines interpolating the functions f 1 , . . . , f 5 in section 11.1 at the 42 vertices of spherical triangulation sptri42. Discussion: We make use of the script SPmenps, where we read in the triangulation from the file sptri42. This script calls on smdsps to create the Powell–Sabin split and the transformation matrix of the space S21 ( P S ). The data values are computed by evaluating

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

371

Figure 11.6. The spherical Powell–Sabin minimal energy splines interpolating the functions f 3 and f 4 at the vertices of the spherical triangulation sptri42.

the function sfun. Here is a table of the max and RMS errors, measured at the 16386 vertices of sptri7. emax rms f 1 2.95(−2) 7.86(−3) f 2 8.19(−3) 1.74(−3) f 3 1.26(−1) 2.77(−2) f 4 1.86(−1) 3.81(−2) f 5 7.73(−1) 1.57(−1) We give plots of the splines interpolating f 3 and f 4 in Figure 11.6. The errors obtained here are better than what we got with the space S10 (), and a comparison of Figure 11.6 with Figure 11.2 shows that the plots are much smoother. We now explore the rates of convergence for these minimal energy Powell–Sabin interpolants. Example 11.18. Find the spherical Powell–Sabin minimal energy spline interpolants of the function f 4 based on data at the vertices of the nested sequence of spherical triangulations sptri1, . . . , sptri4. Discussion: We again make use of the script SPmenps, but now read the triangulations from the files sptri1, . . . , sptri4. Here is a table of the maximum and RMS errors computed at the vertices of sptri7, along with the ratios of errors for successive data sets. For each triangulation, we also list the number of interpolation points, which is the number of vertices of that triangulation. triang n 0 sptri1 6 sptri2 18 sptri3 66 sptri4 258

emax 7.57(0) 1.89(−1) 1.91(−2) 4.28(−3)

rms time 4.64(−1) .03 6.65(−2) .06 5.94(−3) .14 7.04(−4) 4.65

ratios 4.01 6.98 9.90 11.95 4.46 8.44

The error ratios do not clearly indicate what rate of convergence we are getting, but it seems to be at least order two. Order two convergence has been established for minimal energy splines whose degree d is at least 3r + 2, where r is the smoothness; see Remark 11.8.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

372

Chapter 11. Applications of Spherical Splines

That result does not apply to the spline space S21 ( P S ) since d < 3r + 2. We note that the condition numbers for computing the minimal energy splines remain small for all four triangulations, starting at 3.4 and rising to only 25.8. We now repeat this example using the spherical spline space S31 (C T ) introduced in section 10.5.2. Example 11.19. Find the Clough–Tocher minimal energy interpolants for the functions f 1 , . . . , f5 based on samples at the 42 vertices of the triangulation sptri42. Discussion: We make use of the script SPmenct, where we read in the triangulation from the file sptri42. This script calls on smdsct to refine the initial triangulation and compute the associated transformation matrix. It calls on sfun to create the data values. Here is a table of the max and RMS errors, measured at the 16386 vertices of sptri7. f1 f2 f3 f4 f5

emax 2.44(−2) 3.07(−2) 1.36(−1) 8.90(−2) 5.11(−1)

rms 5.89(−3) 7.82(−3) 3.34(−2) 2.29(−2) 1.26(−1)

The plots of the interpolating splines are virtually identical to those for the Powell–Sabin minimal energy spline; cf. Figure 11.6. The errors here are also very similar to those we got in Example 11.17 with Powell–Sabin splines. They are a little better in some cases, but a little worse in others. The condition number of the matrix M22 in (11.22) is 8.03(+3) for this triangulation. We now explore the rates of convergence for Clough–Tocher minimal energy interpolants. Example 11.20. Find the Clough–Tocher minimal energy splines interpolating the function f4 at the vertices of the nested sequence of spherical triangulations sptri1, . . . , sptri4. Discussion: We again make use of the script SPmenct, but now read the triangulations from the files sptri1, . . . , sptri4. Here is a table of the maximum and RMS errors computed at the vertices of sptri7, along with the ratios of errors for successive data sets. We also give the number n 0 of interpolation points, and the computational times. n0 sptri1 6 sptri2 18 sptri3 66 sptri4 258

emax 2.78(−1) 2.79(−2) 4.33(−2) 1.06(−3)

rms time 1.76(−1) .01 1.36(−2) .06 1.10(−2) .17 2.94(−4) 15.34

ratios 9.96 12.94 .64 1.24 40.85 37.41

The errors here are generally somewhat better than we got with Powell–Sabin minimal energy splines in Example 11.18. There is no clear indication from the table concerning the rate of convergence. The space S31 (C T ) is also not covered by the error bound described in Remark 11.8. The condition numbers of the matrix M22 in (11.22) remain quite small, ranging from 4.44(+1) to only 4.57(+2).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

373

In SplinePak we have included a script for carrying out minimal energy interpolation of scattered data on the sphere using the macro-element space S51,2 () described in section 10.5.3 — it is called SPmen15. However, since the errors are similar (but slightly larger) than what we got with S21 ( P S ) or S31 (C T ), we do not report them here.

11.3.2 A local C 0 cubic spline method In this section we develop the spherical analog of the method described in section 6.4. We begin by constructing a spherical triangulation with vertices at the interpolation points {(x i , yi , z i )}ni=1 . Then to find a spline s ∈ S30 () satisfying (11.13), we suggest the following analog of Algorithm 6.14. Pick an integer m > 10. Algorithm 11.21. For each triangle T in : 1) Find the set PT := { pi }m i=1 of vertices of  \ T that are closest to the barycenter of T. 2) Compute the B-coefficients of a cubic spherical polynomial that interpolates the data at the three vertices of T , and fits the data at the points of PT in the least-squares sense. Store these as coefficients of a spline in S30 (). Discussion: In Algorithm 6.14 we used stars of the vertices of T to select the set PT , and we could do the same here. However, it is a little faster to work with the m closest points. To find them, we can use knnsearch; see section 6.6.3. Step 2 can be carried out in the same way as in the bivariate case, except that now we use sbco and sbasis to construct the analogous observation matrix O; cf. Lemma 6.15. We have implemented this algorithm in the following function: c = sloc03(x,y,z,w,v1,v2,v3,e1,e2,e3,ie1,ie2,m) Here the vectors x,y,z,w describe the scattered data, m controls the number of sample points to be used, and the rest of the input describes the triangulation. The output is the vector of B-coefficients of the interpolating spline s ∈ S30 (). For small sets of scattered data, this method does not perform as well as the minimal energy spline methods of section 11.3.1, and hence we do not bother to illustrate the method with small data sets. We now explore the performance and rate of convergence for larger data sets. Example 11.22. Interpolate the function f4 defined in (11.4) using the above local C 0 spherical cubic spline method based on data at the vertices of a nested sequence of spherical triangulations. Discussion: We make use of the script SPscat03 and read the triangulations from the files sptri3, . . . , sptri6. These triangulations are nested, with the smallest containing 66 vertices, and the largest containing 4098 vertices. The following table gives the maximum and RMS errors for the various triangulations as computed with the function serr described in Remark 11.3. The table also shows the value produced by the function sc1ck

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

374

Chapter 11. Applications of Spherical Splines

which checks how close the spline is to being C 1 , along with the computational time for sloc03. triang sptri3 sptri4 sptri5 sptri6

emax 9.11(−2) 4.95(−3) 3.92(−4) 3.02(−5)

rms 3.83(−2) 1.62(−3) 9.93(−5) 6.62(−6)

c1ck time 6.50(−2) .02 3.63(−3) .06 2.47(−4) .21 1.67(−5) .87

ratios 18.40 23.64 12.63 16.31 12.98 15.00

For this test function, the convergence seems to be O(||4 ), which is what we expect for a cubic spline. The computational time is approximately linear in the number of data points. Note that as n increases, the splines become smoother and smoother, and are eventually essentially C 1 . This is to be expected since for larger n, they become very close to the test function, which is C ∞ .

11.3.3 A local C 1 Clough–Tocher method In this section we carry over the method of section 6.5 to the sphere. Let  be a triangulation of the data points, and let C T be the corresponding Clough–Tocher refinement. Here is an algorithm for computing a spherical spline in S31 (C T ) solving the scattered data fitting problem (11.13). It is based on the local C 0 cubic spline method of the previous section. Algorithm 11.23. Let s0 ∈ S30 () be a cubic spline interpolating given values at the vertices of a triangulation . 1) Use subdivision to rewrite s0 as a spline s˜ ∈ S30 ((C T )). 2) Adjust the coefficients of s˜ to get a C 1 spline s ∈ S31 (C T ). The subdivision process of Step 1 can be accomplished using the function ctsubdiv described in section 4.16. The adjustment process of Step 2 can be accomplished locally following the ideas of Algorithm 6.17, except that here we have to use spherical barycentric coordinates. We now present some details. Let c˜ be the vector of coefficients of s˜ , and let c be the coefficients of the desired spline s ∈ S31 (C T ). We first adjust the coefficients of s associated with domain points lying on the two-rings around the vertices of . Let v = (x, y, z) be a vertex of , and let ei := v, vi , i = 1, . . ., m, be the set of edges attached to v. For each i , let u i be the unit vector orthogonal to the vector v at the point v and lying in the intersection of the tangent plane to the sphere at v with the plane through the origin and containing ei . Let Du 1 , . . . , Du m be the associated directional derivatives. For each i = 1, . . ., m, let cei be the coefficient of s associated with the domain point located at ei ∩ R1 (v), and let wv be the value of s˜ at v. Then by formula (10.16), Du i s = 3(ai wv + bi cei ),

(11.23)

where ai and bi are such that u i = ai v + bi vi . The analogous formulae hold for the di-

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

375

rectional derivatives of s˜. Using (11.23) for s˜ , we can use its coefficients on R2 (v) to compute Du i s˜ for i = 1, . . ., m. To define the corresponding coefficients of s, we select Du 1 s, . . . , Du m s to ensure C 1 smoothness at v while providing a best least-squares fit to Du 1 s˜ , . . . , Du m s˜ . To complete Step 2, we need to adjust the coefficients of s˜ to get C 1 continuity across each interior edge e of . For each such edge e, there are three C 1 conditions, but only the one in the middle needs to be enforced as the other two are covered by the C 1 continuity around the vertices of . This smoothness condition involves four coefficients, two of which lie on the edge e and are already known. We choose the other two to be as close to the corresponding coefficients of s˜ as possible in the least-squares sense while satisfying the smoothness condition. We have now determined the coefficients of s associated with domain points in the disks of radius one around the vertices of , as well as those within a distance one of each edge of . These determine all remaining B-coefficients of s by C 1 smoothness conditions across the interior edges of each macro triangle. We have implemented this adjustment algorithm in the function c = sctadj(x,y,z,v1,v2,v3,e1,e2,e3,ie1,ie2,tril,trir,... xo,v1o,v2o,v3o,ie1o,ie2o,trilo,triro,c) Here xo, . . . , triro are lists associated with the initial triangulation , while x, . . . , trir are associated with the Clough–Tocher refinement C T of . For small sets of scattered data, this method does not perform as well as the minimal energy spline methods of section 11.3.1, and hence we do not bother to illustrate the method with small data sets. Here is the analog of Example 11.22 where we explore the performance and rate of convergence for larger data sets. Example 11.24. Interpolate the function f4 defined in (11.4) using the above local C 1 spherical cubic spline method based on data at the vertices of a nested sequence of spherical triangulations. Discussion: We use the script SPscatlocct, and read the triangulations from the files sptri3, . . . , sptri6. The following table gives the maximum and RMS errors computed using the function serr introduced in Remark 11.3. We also give the computational time in seconds for the computation of the B-coefficients of the spline. triang sptri3 sptri4 sptri5 sptri6

emax 6.48(−2) 2.94(−3) 2.05(−4) 1.39(−5)

rms time 2.14(−2) .16 6.51(−4) .31 3.27(−5) 1.22 1.91(−6) 4.86

ratios 22.04 32.87 14.34 19.91 14.74 17.12

For this test function, the convergence seems to be order four, which is what we expect for a cubic spline. The table suggests that the computational time is linear in the number of interpolation points n. The results of this example show that computing the C 1 Clough–Tocher spline is only slightly slower than the C 0 cubic spline method of the previous section, but is much

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

376

Chapter 11. Applications of Spherical Splines

more accurate. The accuracy here is only slightly worse than for the minimal energy Clough–Tocher splines of Example 11.20, but the computational times are significantly smaller. Here we were able to interpolate with 4098 and 16386 data points in a reasonable amount of time. The computation of minimal energy splines is very slow for these larger problems. In section 11.3.1 we showed that minimal energy Powell–Sabin and Clough–Tocher splines are a good choice for interpolating scattered data on the sphere with up to about 250 points, but are too slow for larger data sets. The local C 1 cubic Clough–Tocher method in this section seems to be a good choice for problems involving larger numbers of data points. The method is a multi-stage method that first constructs a C 0 cubic spline interpolant, which is then subdivided and adjusted to get the final C 1 spline interpolant.

11.3.4 A two-stage method using S21 ( P S ) As in the bivariate case, we can construct local two-stage methods for scattered data interpolation on the sphere by using the Hermite interpolation methods described in section 11.2, coupled with an algorithm for estimating the needed derivatives from the scattered data. We now illustrate this approach with the Powell–Sabin Hermite interpolant. Suppose  is a spherical triangulation with vertices {vi }ni=1 , and suppose  P S is its Powell– Sabin refinement. Given any set of real numbers {wi }ni=1 , we want to compute a spline s ∈ S21 ( P S ) such that s(vi ) = wi ,

i = 1, . . ., n.

(11.24)

We can do this in two stages. In the first stage we estimate the derivatives needed for Powell–Sabin Hermite interpolation, and then in the second stage we construct an associated interpolating Powell–Sabin spline using the function sphps introduced in section 11.2.2. We now briefly discuss the first stage. Let v be a vertex of . To get derivatives at v, we choose a triangle T with one vertex at v. Fix de > 0, and let p(x, y, z) :=

N 

ci φi (x, y, z),

i=1

where φ1 , . . . , φ N are ) the * spherical Bernstein basis polynomials of degree de associated with T , and N = de2+2 . Following our experience with the bivariate case, we suggest using de = 3, which gives N = 10. Now pick a set Vv := {ξi }m i=1 of m > N vertices of  that lie near v. For convenience, we shall use the 3D analog of the function knnsearch mentioned in section 6.6.3. If the vectors x,y,z contain the Cartesian coordinates of the vertices of a spherical triangulation , and xv,yv,zv give the Cartesian coordinates of v, then for any given m, the command k = knnsearch([x,y,z],[xv,yv,zv],’K’,m) will produce a list of the indices of the m vertices of  that lie closest to v. Here the

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

377

distances are distances in three dimensions, not geodesic distances on the sphere, but if the points are relatively near v, their selection will not depend on which distance we use. Here we take de = 3 and m = 20. We now compute the coefficients of p to make it fit the values w(k1 ), . . . , w(km ) at the points ξi := (x(ki ), y(ki ), z(ki )), i = 1, . . . , m. This can be done by solving the overdetermined system Oc = r , where O = [φ j (ξi )]m,N i=1, j =1 is the observation matrix, and r = T [w(k1 ), . . . , w(km )] . Assuming O has full rank m, the MATLAB command O \ r will give the desired coefficients. Now we compute the needed derivatives at v from p. Combining these ideas, we have the following function for estimating the directional derivatives corresponding to a set of frame vectors associated with the vertices of a spherical triangulation , based on samples of an unknown function at these vertices: [w1,w2] = sderest(x,y,z,w,v1,v2,v3,ie1,ie2,u,uw,de,m) Here x,y,z,w are vectors giving the scattered data, and v1, . . . , ie2 describe a triangulation  with vertices at the data points. The input de controls the degree of the polynomials to be used in the local least-squares fits, while m controls the number of sample points to be used. The output consists of the two vectors w1,w2 giving the estimated directional derivatives in the frame directions. Example 11.25. Use the two-stage Powell–Sabin method to interpolate the test functions f 1 , . . . , f5 based on data at the vertices of the spherical triangulation sptri42. Discussion: We make use of the script SPscatps, and read the triangulation from the file sptri42. This script uses the function sderest described above to estimate the needed directional derivatives at the vertices of the triangulation, and then calls sphps to create the Powell–Sabin refinement and compute the B-coefficients of the interpolating spline. Here is a table of the max and RMS errors computed using serr.

f1 f2 f3 f4 f5

emax 5.76(−2) 1.73(−2) 4.05(−1) 2.48(−1) 1.02(0)

rms 7.65(−3) 3.61(−2) 7.29(−2) 4.89(−2) 2.19(−1)

Comparing with the results of Example 11.17, we see that the errors here are about twice as large as what we got with the minimal energy spline in the same space. The surfaces produced with the minimal energy method are also much smoother looking. This example shows that the two-stage Powell–Sabin method does not perform as well as the minimal energy Powell–Sabin method of section 11.3.1 for this data set. This will generally be true for data sets with less than a few hundred points. However, as we observed in section 11.3.1, the minimal energy methods are too slow to use for larger data sets,

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

378

Chapter 11. Applications of Spherical Splines

whereas the two-stage method here, being local, can be used for much larger scattered data interpolation problems. Here is an example testing it on some larger sets of sample points. It also serves to explore the rate of convergence of the method. Example 11.26. Use the two-stage Powell–Sabin method to interpolate values of the test function f 4 at vertices of the nested sequence of spherical triangulations sptri3, . . . , sptri6. Discussion: We again make use of the script SPscatps, but now read the triangulations from sptri3, . . . , sptri6. Here is a table of the max and RMS errors for each triangulation as computed with the function serr described in Remark 11.3. We also give the computational times for finding the B-coefficients of the splines. triang sptri3 sptri4 sptri5 sptri6

emax 6.61(−2) 3.74(−3) 3.99(−4) 5.18(−5)

rms time 1.99(−2) .07 8.44(−4) .29 8.74(−5) 1.17 1.06(−5) 4.78

ratios 17.67 23.58 9.37 9.66 7.70 8.25

The errors here for sptri4 are very close to what we got with the minimal energy Powell– Sabin spline, but the computational time is about 10 times smaller. We seem to be getting the expected order three rate of convergence.

11.3.5 A two-stage method using S31 (CT ) As a second example of a two-stage method based on a macro-element space, in this section we describe a method based on S31 (C T ). Suppose  is a spherical triangulation with vertices at the data points {(x i , yi , z i )}ni=1 , and let C T be the Clough–Tocher refinement of . Given any real numbers {wi }ni=1 , we want to compute a spline s ∈ S31 (C T ) satisfying (11.24). As in the previous section, we can do this in two stages. In this case we need cross derivatives at the midpoints of the edges of  along with the first derivatives at the vertices of . To get estimates for the latter, we can use the same function sderest described in the previous section, based on local least-squares with spherical polynomials. Given an edge e of , the first step is to select data points to use to compute the least-squares fit. We suggest using knnsearch to find the m data points closest to the midpoint of e. This gives the following function: we = sderestmid(x,y,z,w,v1,v2,v3,ie1,ie2,tril,trir,... xm,ym,zm,ue,de,m) Here x,y,z,w are vectors giving the scattered data, and v1, . . . , trir describe a triangulation  with vertices at the data points. The inputs xm,ym,zm give the coordinates of the midpoints of the edges of the triangulation, and ue should contain the associated unit vector perpendicular to the edge (pointing to the left of the oriented edge). The input de controls the degree of the polynomials to be used in the local least-squares fits, and m controls the number of sample points to be used. The output is the vector we giving the estimated values of the derivatives at the midpoints of the edges of  in the directions defined by ue.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

379

Example 11.27. Use the two-stage method based on S31 (C T ) to interpolate the test functions f 1 , . . . , f 5 at the vertices of the spherical triangulation sptri42. Discussion: We make use of script SPscatct, which uses sderest and sderestmid to compute the estimated derivatives at the vertices and midpoints of the edges of the given triangulation , based on data at the vertices of . It then calls on sphct to construct the Clough–Tocher refinement of , and compute the B-coefficients of the interpolating spline. We read the triangulation from the file sptri42. Here is a table of the max and RMS errors computed using serr.

f1 f2 f3 f4 f5

emax 1.89(−14) 1.49(−1) 2.98(−1) 1.45(−1) 1.00(0)

rms 3.52(−15) 3.80(−2) 7.61(−2) 4.07(−2) 2.28(−1)

The error for f 1 is essentially zero since the method is exact for linear and cubic polynomials. The errors for the other functions are very close to what we got with the two-stage Powell–Sabin method in Example 11.25, and are about twice as large as what we got with the minimal energy method based on S31 (C T ); see Example 11.19. The plots here are not as smooth as those of the minimal energy interpolants. This example shows that the two-stage Clough–Tocher method does not perform as well as the minimal energy Clough–Tocher method of section 11.3.1 for this data set. This will generally be true for data sets with less than a few hundred points. However, as we observed in section 11.3.1, the minimal energy methods are too slow to use for larger data sets, whereas the two-stage method here, being local, can be used for much larger scattered data interpolation problems. Here is an example testing it on some larger sets of sample points. It also serves to explore the rate of convergence of the method. Example 11.28. Use the two-stage method based on S31 (C T ) to interpolate the test function f 4 , based on data at the vertices of a nested sequence of spherical triangulations. Discussion: We again make use of the script SPscatct, but now read the triangulations from the files sptri3, . . . , sptri6. Here is a table of the max and RMS errors for each triangulation as computed by serr. We also give the computational times. triang sptri3 sptri4 sptri5 sptri6

emax 5.97(−2) 1.37(−3) 1.06(−4) 1.05(−5)

rms time 1.69(−2) .09 4.31(−4) .38 2.47(−5) 1.52 1.44(−6) 6.16

ratios 43.58 39.21 12.93 17.45 10.10 17.15

The errors here are somewhat better than what we got with Powell–Sabin splines in Example 11.26, but the computational times are a little larger since we had to estimate cross derivatives at the midpoints of each of the edges of the initial triangulation. It appears we are getting the expected order 4 convergence.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

380

Chapter 11. Applications of Spherical Splines

11.3.6 Interpolation with radial basis functions on the sphere In section 6.14 we showed that radial basis functions provide an alternative to splines for interpolating scattered data in the plane. In this section we show that they can also be used for scattered data on the sphere, but with the same caveats as in the planar case. As in the previous two sections, suppose {vi := (x i , yi , z i )}ni=1 are scattered points on the sphere, and suppose we are given corresponding data values {wi }ni=1 . We are looking for a smooth function interpolating this data, i.e., satisfying the equations (11.24). For each data point (x i , yi , z i ) and each (x, y, z) on the sphere, let di (x, y, z) := arccos(x x i + yyi + zz i ) be the arc-length distance between the two points. Given a radial basic function φ defined on [0, ∞), let (11.25) φi (x, y, z) = φ(di (x, y, z)). We call φi a spherical radial basis function with center at (xi , yi , z i ). We now look for an interpolant of the form n  g(x, y, z) = ci φi (x, y, z) (11.26) i=1

satisfying the interpolation conditions (11.24). To find the coefficients of g, we need only solve the linear system Mc = w, where M = [φi (x j , y j , z j )]ni, j =1 , and w is the vector whose components are w1 , . . . , wn . It can be shown that for certain radial basic functions, including the Gaussian (6.33), the matrix M will be nonsingular for all choices of centers; see, e.g., [[Fass07]]. We have written the following function to carry out RBF interpolation at scattered points on the sphere: c = srbfinterp(dsites,w,eps,rbf) Here dsites is an n × 3 matrix containing the Cartesian coordinates of the sample points, and w is an n-vector containing the data values. For the sake of generality, this function also inputs the name of the radial basic function to be used, and a parameter eps to control its shape. Example 11.29. Interpolate the functions f 1 , . . . , f 5 at the 42 vertices of the spherical triangulation sptri42 using the radial basis functions based on the Gaussian basic function (6.33). Discussion: We make use of the script SPrbf, and read the centers as the vertices of the triangulation associated with sptri42. We compute the sample values by calling on the test function sfun. To see the role of eps, consider the function f 2 , which reduces to the constant 1 on the sphere S. With eps = 3, we get the surface shown in Figure 11.7 (left). The plot of this function should be a sphere of radius two, so as we can see, we got a very poor fit. On the other hand, if we repeat the experiment with eps = 1, we get the surface shown in Figure 11.7 (right). This is a far better fit of the sphere. The following table gives the max and RMS errors measured at the 4098 vertices of the spherical triangulation

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

381

Figure 11.7. The spherical radial basis interpolant of the constant function f 2 based on 42 scattered data points on the sphere. The surface on the left corresponds to the interpolant using the Gaussian with parameter ε = 3, while the one on the right was computed with ε = 1.

Figure 11.8. The RBF interpolants of the functions f 1 , f 3 , f 4 , f 5 on the sphere based on 42 scattered data points, all computed using the Gaussian with parameter ε = 1.

sptri6 for each of the functions, using eps = 1: f1 f2 f3 f4 f5

emax 9.83(−4) 8.53(−4) 6.89(−3) 5.03(−3) 2.50(0)

rms 2.29(−4) 2.23(−4) 1.84(−3) 1.39(−3) 5.90(−1)

We show plots of the radial basis interpolants to the functions f1 , f 3 , f 4 , f 5 in Figure 11.8.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

382

Chapter 11. Applications of Spherical Splines

Note that the errors obtained in this experiment are much better than those obtained with the various spherical spline interpolation methods, except in the cases when the spline interpolants were exact. In addition, these RBF interpolants are generally very smooth, being infinitely differentiable. But as we saw above, to get good results, we have to select an appropriate value for the parameter ε.

11.3.7 A comparison of the interpolation methods In this section we compare the performance of the above methods for solving the scattered data interpolation problem on the sphere. We first examine the case where we have a relatively small number of sample points. Example 11.30. Interpolate the function f 4 using data at the vertices of the spherical triangulation sptri42. Discussion: This triangulation corresponds to the data file sptri42 and has 42 vertices, 120 edges, and 80 triangles; see Figure 11.1. For the radial basis interpolant, we report two values: one for eps = 3 and one for eps = 1. The following table gives max and RMS errors at the 16386 vertices of sptri7, and also lists the computation times, along with the dimension and number of coefficients for each space. Method SP01 SPmenps SPmenct SPmen15 SPscat03 SPscatlocct SPscatps SPscatct SPrbf(3) SPrbf(1)

emax 3.18(−1) 1.86(−1) 8.90(−2) 7.66(−2) 4.60(−1) 2.63(−1) 2.48(−1) 1.45(−1) 5.77(−1) 5.03(−3)

rms time 8.55(−2) 0 3.81(−2) .19 2.29(−2) .18 2.26(−2) .41 1.33(−1) .07 4.07(−2) .14 4.89(−2) .07 4.07(−2) .05 2.11(−1) .01 1.39(−3) .01

dim 42 126 246 372 362 246 126 246 42 42

nc 42 962 1082 1002 362 1082 962 1082 42 42

As we can see from the table, the best results using splines were obtained with the minimal energy splines. They also give the best looking plots among the spline methods. The other spline methods all gave similar errors, with some difference in the plots. The two RBF methods produce quite different results, depending on the choice of eps. With eps = 3, the errors are worse than any of the spline methods, but with eps = 1, they are substantially better. The RBF surfaces are extremely smooth looking since the Gaussian radial basic function is infinitely differentiable. As a second example, we compare the same collection of methods for a case where we have a larger number of well-distributed points. Example 11.31. Interpolate the function f 4 using data at the vertices of the spherical triangulation sptri4. Discussion: This triangulation corresponds to the data file sptri4 and has 258 vertices, 768 edges, and 512 triangles. As in the previous example, we report results for the radial basis interpolants with both eps = 3 and eps = 1. The following table gives max

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.3. Scattered data interpolation on the sphere

383

and RMS errors, measured at the 16386 vertices of sptri7, and also lists computation times and evaluation times, along with the dimensions and number of coefficients being computed. Method SP01 SPmenps SPmenct SPmen15 SPscat03 SPscatlocct SPscatps SPscatct SPrbf(3) SPrbf(1)

emax 5.79(−2) 4.28(−3) 1.06(−3) 3.12(−3) 4.95(−3) 2.94(−3) 3.74(−3) 1.37(−3) 7.73(−5) 2.05(−5)

rms compute dim nc 1.73(−2) 0 258 258 7.04(−4) 4.74 774 6164 2.94(−4) 15.21 1542 6914 7.32(−4) 15.01 2316 6402 1.62(−3) .06 2306 2306 6.51(−4) .30 1542 6914 8.44(−4) .14 774 6146 4.31(−4) .22 1542 6914 1.72(−5) .005 258 258 6.80(−6) .005 258 258

As we can see from the table, except for SP01, the spherical spline methods all gave similar errors, but the computational times for the minimal energy methods were substantially higher. For this example, the effect of using an incorrect values for eps in the RBF method was not as drastic as in Example 11.30. However, having to choose a parameter for the Gaussian is still a disadvantage for the RBF method. The fastest method is RBF interpolation, followed by interpolation with S10 () and the two-stage macro-element methods. All of these are fast enough to run on larger data sets such as sptri5 with 1026 points and sptri6 with 4098 points. However, the minimal energy spline codes already run very slowly for sptri5. This is to be expected since they are global methods where all coefficients are computed in one linear system. This problem can be partially overcome by using certain domain decomposition methods; see Remark 11.16. In conclusion, for scattered data interpolation problems on the sphere with up to about 200 data points, we can recommend the minimal energy spline methods, or RBF interpolation if the user is willing to experiment to find a good value for eps. We close with a few additional remarks concerning scattered data interpolation on the sphere. • When the number of data points is more than a few hundred, one has to ask whether interpolation is even appropriate. If the underlying function generating the data is reasonably smooth, it should not take a spline with a huge number of coefficients to fit it well. In such cases, it may be more appropriate to construct a least-squares fit from a smaller spline space, rather than try to interpolate. We discuss such methods in the following section. • When the data is subject to noise, it is generally not appropriate to interpolate. In such cases we should compute either a least-squares fit or a penalized least-squares fit; see the following section. • For large interpolation problems, it is possible to divide the sphere into (overlapping) pieces. Then one interpolates on each piece and somehow puts the pieces together smoothly. Such methods have been called domain decomposition methods; see [LaiS09] and Remark 11.16.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

384

Chapter 11. Applications of Spherical Splines

• While the RBF methods perform very well for a modest number of data (provided we choose the correct shape parameter for the radial basic function), they are less suitable when we have a large number of data points. First, they are global methods which involve solving a large system of equations with a matrix which is often dense and often ill-conditioned. Second, evaluation can also become expensive since for every evaluation point, unless we use a locally supported basic function, we have to sum over all the basis functions. For more on RBF interpolation on the sphere, see [JetSW98, PotE90].

11.4 Least-squares fitting with spherical splines As in the bivariate case, there are two situations where it is advisable to fit data rather than interpolate it: 1) when there are a large number of data points, 2) when the measurements are subject to noise. To solve these kinds of fitting problems, in this section we develop the spherical analogs of the least-squares methods of section 7.1. d Suppose that we are given samples {wν }nν=1 of a function f at n d points {(ξν , ην , nd ζν )}ν=1 on the sphere. Given a spherical triangulation  of , fix d ≥ 1, and let S() be an N-dimensional subspace of Sd0 () with N ≤ n d . The vertices of  need not be chosen from among the sample points. Our aim is to approximate f by a spline in S() which fits f in the following weighted least-squares sense. n

d Problem 11.32. Let {αν }ν=1 be a set of positive weights. Find a spline s in S() which minimizes nd  αν [s(ξν , ην , ζν ) − wν ]2 . (11.27) F(s) :=

ν=1 N is a basis for the space S(). Then To compute a least-squares spline, suppose {φi }i=1 writing N  c i φi , (11.28) s= i=1

our problem is to find the coefficients. Let ⎡ φ1 (ξ1 , η1 , ζ1 ) ⎢ .. O := ⎣ .

φ1 (ξnd , ηnd , ζnd )

... .. .

...

⎤ φ N (ξ1 , η1 , ζ1 ) ⎥ .. ⎦. . φ N (ξnd , ηnd , ζnd )

(11.29)

This is called the observation matrix. Now define G := O T DO, where D is the n d × n d matrix with α1 , . . . , αnd on its diagonal. The matrix G is called the Gram matrix. Following the proof of Theorem 7.2, we get the following result.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.4. Least-squares fitting with spherical splines

385

Theorem 11.33. Suppose the data in Problem 11.32 is sufficiently well distributed so that the observation matrix (11.29) has full rank N. Then there exists a unique spline s ∈ S() minimizing (11.27). Moreover, its coefficient vector c in the expansion (11.28) is the solution of the linear system of equations Gc = r ,

(11.30)

where r = O T Dw. To create a function for computing the B-coefficients of a spline in Sd0 () solving the least-squares fitting problem on the sphere, we need to set up the Gram matrix G and the vector r in (11.30). The matrix G can be assembled by an accumulation process. As a first step, we can use sfindtri to find the triangles containing the data points, along with their spherical barycentric coordinates. The entries of G and r are then be computed with a call on basis. We have the following function based on this approach. [c,G] = slsq0d(d,x,y,z,v1,v2,v3,e1,e2,e3,ie1,xd,yd,zd,wd,wt) Here d is the degree of the spline to be computed, and the vectors x, . . . , ie1 contain the triangle information, while xd,yd,zd,wd contain the coordinates of the data points and the data values. The input wt contains the nonnegative weights. In addition to the vector c of B-coefficients, we also output the Gram matrix G for diagnostic purposes. Example 11.34. Let  be the triangulation sptri42. Find the least-squares fits of the function f 4 from Sd0 () with d = 1, 2, 3 based on measurements at the vertices of the triangulations sptri3, . . . , sptri6. Discussion: We make use of SPlsq0d. We read the triangulation  from file sptri42, and the data from the files sptri3, . . . , sptri6. Here we take all of the weights to be 1, and experiment with different choices of d. Here are the max and RMS errors, measured as usual at the 16386 vertices of sptri7. d =1 sptri3 sptri4 sptri5 sptri6

emax 4.55(−1) 2.19(−1) 2.18(−1) 2.16(−1)

rms 8.34(−2) 5.69(−2) 5.52(−2) 5.51(−2)

d =2

emax rms sptri5 7.31(−2) 1.44(−2) sptri6 7.24(−2) 1.42(−2)

d =3

emax rms sptri5 1.40(−2) 1.25(−3) sptri6 1.17(−2) 1.11(−3)

For d = 2, 3, there are no results for sptri3 and sptri4 since the Gram matrices were essentially singular in those cases. The table shows that there is not much improvement in the errors when we use the larger data sets. However, we are clearly getting better

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

386

Chapter 11. Applications of Spherical Splines

Figure 11.9. The least-squares splines in S10 () and S20 () fitting the function f 4 using the triangulation sptri42, and based on sample points at the vertices of the triangulation sptri5.

fits with higher degree splines. In Figure 11.9 we show a plot of the splines with d = 1, 2, based on the data set sptri5. We now explore the rates of convergence for least-squares spline fitting using Sd0 (). Example 11.35. Find the least-squares fits from Sd0 () of the function f4 using the nested sequence of triangulations sptri2, . . . , sptri5, and based on measurements at the vertices of the triangulation sptri7. Discussion: We again make use of SPlsq0d, where we read the triangulations from the files sptri2, . . . , sptri5, and the sample points from the file sptri7. We again take all of the weights to be 1, and experiment with different choices of d. The following table gives the max and RMS errors measured as usual at the 16386 vertices of sptri7. d=1 sptri2 sptri3 sptri4 sptri5 d=2 sptri2 sptri3 sptri4 sptri5

emax 1.74(−1) 1.29(−1) 4.05(−2) 1.11(−2)

rms 5.07(−2) 4.08(−2) 8.50(−3) 2.25(−3)

ratios 1.35 1.24 3.19 4.80 3.65 3.78

emax 9.90(−2) 1.25(−2) 2.82(−3) 3.72(−4)

rms 3.60(−2) 4.41(−3) 6.74(−4) 8.76(−5)

ratios 7.92 8.16 4.43 6.54 7.58 7.69

For splines of degree one, we expect the order of approximation to be O(||)2 ), which is about what we are getting. For d = 2, we expect third order convergence, which we are also getting. As expected, the errors are smaller with d = 2. We now look at an example where S() is a macro-element space for which we can compute the transformation matrix A. The discussion in section 7.1.2 of how to assemble

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.4. Least-squares fitting with spherical splines

387

Figure 11.10. Left: The least-squares spline fitting the function f 4 with S21 ( P S ) on the triangulation sptri42 based on data at the vertices of the triangulation sptri5. Right: The least-squares spline for the triangulation sptri3 based on data at the vertices of the triangulation sptri6.

the normal equations in the bivariate case carries over directly to (11.30) in the spherical case. Here is our function for computing the coefficients. c = slsq(d,x,y,z,v1,v2,v3,e1,e2,e3,ie1,xd,yd,zd,wd,wt,A) The input includes information on the triangulation, vectors xd,yd,zd,wd,wt giving the data and weights, and the transformation matrix A. The output is the vector of Bcoefficients of the least-squares spline fit. We now give several examples based on the macro-element spaces S21 ( P S ), S31 (C T ), and S51,2 (). Example 11.36. Let  be the triangulation sptri42, and let  P S be its Powell–Sabin refinement. Find the least-squares fits from S21 ( P S ) of the function f4 based on measurements at the sets sptri4, . . . , sptri6. Discussion: We make use of SPlsqps, where we read the triangulation  from the file sptri42, and the data from the files sptri4, . . . , sptri6. Here we take all of the weights to be 1. The following table gives the max and RMS errors, measured as usual at the 16386 vertices of sptri7. We do not have any results for sptri3 since the Gram matrix is singular in this case. triang emax rms sptri4 1.29(−1) 2.10(−2) sptri5 9.07(−2) 1.94(−2) sptri6 9.09(−2) 1.94(−2) This table shows little improvement in the errors for the larger data sets. For a plot of the spline based on data at the vertices of sptri5, see Figure 11.10 (left). We now explore the rates of convergence for least-squares fitting with the space S21 ( P S ). Example 11.37. Find the least-squares fits from S21 ( P S ) of the function f 4 based on measurements at the vertices of the triangulation sptri7 and using the nested sequence of triangulations sptri2, . . . , sptri5.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

388

Chapter 11. Applications of Spherical Splines

Discussion: We again make use of SPlsqps, where we now read the triangulations from the files sptri2, . . . , sptri5 and the data from the file sptri7. We again take all of the weights to be 1. The following table gives the max and RMS errors, measured as usual at the 16386 vertices of sptri7. triang sptri2 sptri3 sptri4 sptri5

emax 1.87(−1) 1.49(−2) 2.99(−3) 3.31(−4)

rms 6.10(−2) 5.18(−3) 6.28(−4) 7.48(−5)

ratios 12.55 11.78 4.98 8.25 9.03 8.40

We note that the assembly times increase significantly with larger triangulations, due to the time spent searching for the triangles that contain the data points. For sptri4 it was 1.2 secs, and for sptri5 it was 7.6 seconds. Since we are using splines of degree two, we expect the order of approximation to be O(||)3 ), which is about what we are getting. For a plot of the spline on the triangulation sptri3, see Figure 11.10 (right). For the purposes of comparison, we now perform least-squares fitting with the Clough– Tocher space S31 (C T ). Example 11.38. Let  be the triangulation sptri42, and let C T be its Clough–Tocher refinement. Find the least-squares fits from S31 (C T ) of the function f 4 based on measurements at the vertices of the triangulations sptri5 and sptri6. Discussion: We make use of SPlsqct, where we read the triangulation  from the file sptri42, and the data from the files sptri5 and sptri6. Here we take all of the weights to be 1. The following table gives the max and RMS errors, measured as usual at the 16386 vertices of sptri7. The computation failed with sptri3 and sptri4 as they did not contain enough points to get a nonsingular matrix. emax rms sptri5 1.98(−2) 3.11(−3) sptri6 2.01(−2) 3.07(−3) The errors are better than what we got in Example 11.36 with the space S21 ( P S ). As before, there is no reduction in the error as we go from sptri5 to sptri6. We now explore the rates of convergence for least-squares fitting with the space S31 (C T ). Example 11.39. Find the least-squares fits from S31 (C T ) of the function f4 based on measurements at the vertices of the triangulation sptri7 and using a nested sequence of spherical triangulations. Discussion: We again make use of SPlsqct, where we now read the triangulations from the files sptri2, . . . , sptri5 and the data from the file sptri7. We again take all of the weights to be 1. The following table gives the max and RMS errors, measured as usual

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.4. Least-squares fitting with spherical splines

389

at the 16386 vertices of sptri7: triang sptri2 sptri3 sptri4 sptri5

emax 1.39(−2) 1.73(−3) 1.41(−4) 1.29(−5)

rms 5.82(−3) 5.10(−4) 4.67(−5) 3.75(−6)

ratios 8.03 11.41 12.27 10.92 10.93 12.45

Since we are using splines of degree three, we expect the order of approximation to be O(||)4 ). We seem to be getting a little less. To conclude this section, we now explore least-squares fitting with the space S51,2 (). Example 11.40. Let  be the triangulation sptri42. Find the least-squares fits from S51,2 () of the function f 4 based on measurements at the sets sptri5 and sptri6. Discussion: We make use of SPlsq15, where we read the triangulation  from the file sptri42, and the data from the files sptri5 and sptri6. Here we take all of the weights to be 1. The following table gives the max and RMS errors, measured as usual at the 16386 vertices of sptri7. The computation failed for the set sptri4 as it did not contain enough points to get a nonsingular matrix. triang emax rms sptri5 2.06(−3) 1.52(−4) sptri6 9.13(−4) 1.24(−4) This table shows that there is some small improvement when using sptri6 instead of sptri5. In the next example we examine the rates of convergence for least-squares fitting with the space S51,2 (). Example 11.41. Find the least-squares fits from S51,2 () of the function f 4 based on measurements at the vertices of the triangulation sptri7 using a nested sequence of triangulations. Discussion: We again make use of SPlsq15, where we now read the triangulations from the files sptri2, . . . , sptri5, and the data from the file sptri7. We again take all of the weights to be 1. The following table gives the max and RMS errors, measured as usual at the 16386 vertices of sptri7: triang sptri2 sptri3 sptri4 sptri5

emax 6.36(−4) 1.94(−5) 3.31(−7) 4.45(−9)

rms 1.50(−4) 4.39(−6) 6.44(−8) 1.10(−9)

ratios 32.78 34.17 58.61 68.17 74.38 58.55

Since we are using splines of degree five, we expect the order of approximation to be O(||)6 ), which is about what we are getting.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

390

Chapter 11. Applications of Spherical Splines

11.4.1 A comparison of the least-squares methods In this section we compare the performance of the above methods for constructing leastsquares splines fitting scattered data on the sphere. We first examine the case where we have a relatively small number of sample points. Example 11.42. Let  be the triangulation sptri42. Compare least-squares methods for fitting the function f 4 based on measurements at the vertices of the spherical triangulation sptri5. Discussion: This triangulation corresponds to the data file sptri42 and has 42 vertices, 120 edges, and 80 triangles; see Figure 11.1. The following table gives max and RMS errors measured at the 16386 vertices of sptri7, along with the dimension and number of B-coefficients of each spline. We also give total computational times, including times to compute minimal determining sets and transformation matrices. We give results for using SPlsq0d for values of d = 1, 2, 3. Method SPlsq0d(1) SPlsq0d(2) SPlsq0d(3) SPlsqps SPlsqct SPlsq15

emax 2.18(−1) 7.31(−2) 1.40(−2) 9.07(−2) 1.98(−2) 2.06(−3)

rms time 5.52(−2) .07 1.44(−2) .08 1.25(−3) .08 1.94(−2) .09 3.11(−3) .08 1.52(−4) .07

dim nc 42 42 162 162 362 362 126 962 246 1082 372 1002

As we can see from the table, the higher degree splines give better accuracy with almost the same computational times. The fastest and most accurate of the C 1 methods is SPlsq15. As a second example, we compare the same collection of methods for a case where we have a larger well-behaved triangulation. Example 11.43. Let  be the triangulation sptri4. Compare the least-squares methods for fitting the function f 4 based on measurements at the vertices of the spherical triangulation sptri7. Discussion: This triangulation corresponds to the data file sptri4 and has 258 vertices, 768 edges, and 512 triangles. The following table gives max and RMS errors measured on the 16683 vertices of sptri7, also lists the total computational, the dimension of the spline space, and the number of B-coefficients of the spline. We give results using SPlsq0d for values of d = 1, 2, 3. Method SPlsq0d(1) SPlsq0d(2) SPlsq0d(3) SPlsqps SPlsqct SPlsq15

emax 4.05(−2) 2.82(−3) 8.93(−5) 2.99(−3) 1.41(−4) 3.31(−7)

rms compute dim nc 8.50(−3) 1.06 258 258 6.74(−4) 1.17 1026 1026 1.83(−5) 1.35 2306 2306 6.28(−4) 1.27 774 6146 4.67(−5) 1.44 1542 6914 6.44(−8) 4.29 2316 6402

As we can see from the table, the errors are much smaller with higher degree splines. Taking account of speed and accuracy, SPlsq15 seems to be the best choice.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.5. The effect of noise

391

Figure 11.11. The splines in S10 () and S21 ( P S ) interpolating the function f 4 using the triangulation sptri42, based on noisy data with ε = .2.

11.5 The effect of noise In the previous sections we have discussed ways to construct a spline approximation to a function f based on measurements of the function f at certain points. In practice, these measurements are rarely exact, i.e., we have noisy data. This typically causes both a loss of accuracy and a deterioration in the shape of the spline. Here are some examples based on interpolation from S10 () and S21 ( P S ). We begin with two examples involving scattered data interpolation. Example 11.44. Interpolate the function f 4 based on noisy data at the vertices of the triangulation sptri42 using S10 () and S21 ( P S ). Discussion: To see what happens with S10 (), we use the script SP01noise, and read the triangulation from sptri42. We introduce noise by taking the sample values to be wi = f (x i , yi , z i ) + εri ,

(11.31)

where r is a vector of 42 random numbers in the interval [−1, 1]. For reproducibility reasons, we read these numbers from our file noise.dat. Here we choose ε = .2. The max and RMS errors are 4.85(−1) and 1.30(−1), which can be compared to the values 3.18(−1) and 8.55(−2) obtained without noise. The resulting interpolant is shown in Figure 11.11 (left). It is clearly a somewhat distorted version of what we got without noise; see the bottom left surface in Figure 11.2. For our second experiment, let  P S be the Powell–Sabin refinement of the triangulation sptri42. We now use the script SPscatps, again with ε = .2. This produces a spline in S21 ( P S ). The max and RMS errors are 3.08(−1) and 1.16(−1), which can be compared to the values 2.48(−1) and 4.89(−2) obtained without noise. The resulting interpolant is shown in Figure 11.11 (right). It is a distorted version of what we get without noise. The following example shows that the effect of noise on scattered data interpolation can be even more dramatic for larger data sets. Example 11.45. Interpolate the function f4 using S10 () and S21 ( P S ) based on noisy sample values at the vertices of the triangulation sptri5. Discussion: We again use the script SP01noise, and set ε = .2. The max and RMS errors are 2.05(−1) and 8.51(−2), which can be compared to the values 1.52(−2) and 4.32(−3)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

392

Chapter 11. Applications of Spherical Splines

Figure 11.12. The splines in S10 () and S21 ( P S ) interpolating the function f4 at the vertices of the triangulation sptri5, based on noisy sample values with ε = .2.

obtained without noise. This is a very significant loss in accuracy. More importantly, the corresponding surface plot is a badly distorted version of what we get without noise as we can see by comparing the noisy interpolant in Figure 11.12 (left) with the interpolant in Figure 11.3 (right). To see what happens with the two-stage method based on S21 ( P S ), we use the script SPscatps, where we now set the noise level to ε = .2. The max and RMS errors are 2.41(−1) and 9.76(−2), which can be compared to the values 3.99(−4) and 8.74(−5), obtained without noise. This is a huge loss of accuracy. The resulting interpolant is shown in Figure 11.12 (right), and is a badly distorted version of what we get without noise. The above examples show that noise can lead to poor fits when using scattered data interpolation methods. In the next two examples we show that noise also has a deleterious effect on least-squares splines. Example 11.46. Let  to be the triangulation sptri42. Find the least-squares fits of the function f 4 from the spaces S20 () and S21 ( P S ) based on noisy data at the vertices of the triangulation sptri5. Discussion: First we use the script SPlsq0d with d = 2, and add noise as in Example 11.44 with ε = .2. The max and RMS errors with noise are 1.95(−1) and 4.48(−2), which can be compared to the values 7.31(−2) and 1.44(−2) obtained without noise. The surface with noise is shown in Figure 11.13 (left), which shows that the shape of the fit with noise is not good. For the second test, we use the script SPlsqps with ε = .2. The max and RMS errors are now 1.76(−1) and 4.41(−2), which can be compared to the values 9.07(−2) and 1.94(−2) obtained without noise. As shown in Figure 11.13 (right), there is again considerable distortion in the shape of the spline. The following example shows that the effect of noise on least-squares spline fits can also be very significant even when working on larger triangulations. Example 11.47. Let  be the triangulation sptri4. Find the least-squares fits of the function f 4 using the spline spaces S20 () and S21 ( P S ), based on noisy data at the vertices of the triangulation sptri6.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.6. Spherical penalized least-squares

393

Figure 11.13. The least-squares splines in S30 () and S21 ( P S ) fitting the function f 4 using the triangulation sptri42, based on noisy data at the vertices of sptri5 with ε = .2.

Figure 11.14. The least-squares splines in S20 () and S21 ( P S ) fitting the function f 4 using the triangulation sptri4, based on noisy data at the vertices of sptri5 with ε = .2.

Discussion: For the first experiment we use the script SPlsq0d with d = 2, and add noise as in Example 11.44 with ε = .2. The max and RMS errors with noise are 2.26(−1) and 5.09(−2), which can be compared with the values 2.95(−3) and 6.81(−4) obtained without noise. The resulting surface is shown in Figure 11.14 (left), which shows that least-squares has not succeeded in smoothing out the noise. For the space S21 ( P S ), we use the script SPlsqps, and again set ε = .2. The max and RMS errors are now 1.90(−1) and 4.67(−2), which can be compared to the values 3.00(−3) and 6.29(−4) obtained without noise. Figure 11.14 (right) shows the C 1 quadratic Powell– Sabin spline surface.

11.6 Spherical penalized least-squares As we saw in the bivariate case in section 7.9, an effective way to smooth out noise in scattered data fitting is to perform penalized least-squares instead of least-squares. As in nd nd at scattered points {(ξν , ην , ζν )}ν=1 on the section 11.5, suppose we are given data {wν }ν=1 nd sphere. Let {αν }ν=1 be given nonnegative weights, and let S() be a spline subspace of Sd0 () corresponding to a triangulation with vertices at {(x i , yi , z i )}ni=1 .

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

394

Chapter 11. Applications of Spherical Splines

Problem 11.48. Fix λ ≥ 0. Find a spline s in S() which minimizes

E λ (s) :=

nd 

αν [s(ξν , ην , ζν ) − wν ]2 + λE(s),

(11.32)

ν=1

where E(s) is the energy of s as defined in (11.15). We call such a spline a spherical penalized least-squares spline. N is a basis for S(). Writing s as a To solve this problem numerically, suppose {φi }i=1 linear combination of these functions as in (11.28), the following theorem tells us how to compute the coefficients. Its proof is essentially the same as the proof of Theorem 7.25.

Theorem 11.49. Fix λ > 0, and let S() be a space of C 1 splines. Suppose n d ≥ 3, and not all of the data points lie on one circular arc. Then there is a unique spline s ∈ S() solving Problem 11.48. Moreover, writing s as in (11.28), its coefficient vector c is the solution of the nonsingular linear system (G + λM)c = r , where G and r are as in Theorem 11.33, and M is the N × N matrix with entries Mi j := φi , φ j  E ,

i , j = 1, . . ., N,

(11.33)

where the energy inner product is defined in (11.20). Penalized least-squares can be implemented by combining the steps needed to compute the energy matrix M and the Gram matrix G. These were discussed in sections 11.3.1 and 11.4. Here is our function. c = spenlsq(d,x,y,z,nd,xd,yd,zd,wd,wt,v1,v2,v3,... e1,e2,e3,ie1,A,lam) The input includes information on the triangulation, vectors xd,yd,zd,wd,wt giving the data and weights, and the transformation matrix A. The output is the vector of Bcoefficients of the penalized least-squares spline fit. This is not the same as the coefficient vector appearing in (11.28) — to get the B-coefficients we need to multiply by the transformation matrix A. Example 11.50. Let  be the triangulation sptri4, and let  P S be its Powell–Sabin refinement. Find the penalized least-squares fit of the function f 4 using the space S21 ( P S ), based on noisy data at the vertices of the spherical triangulation sptri6. Discussion: We make use of the script SPpenlsq, and read the initial triangulation from the file sptri4. The data is read from the file sptri6, and we add noise of size ε = .2 as in the examples of the previous section. Here are the max and RMS errors for a range of

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.6. Spherical penalized least-squares

395

Figure 11.15. The splines in S21 ( P S )) fitting the function f 4 using the triangulation sptri4, based on noisy data at the vertices of sptri5 of size ε = .2. The spline on the left is with λ = .0075, and the one on the right is with λ = 100.

values of λ: λ 0 .01 .02 .03 .04 .05 .10 .50 100 1000

emax 1.90(−1) 8.06(−2) 6.80(−2) 6.39(−2) 6.30(−2) 6.35(−2) 7.39(−2) 1.76(−1) 5.70(−1) 5.85(−1)

rms 4.67(−2) 1.76(−2) 1.58(−2) 1.58(−2) 1.66(−2) 1.78(−2) 2.59(−2) 7.82(−2) 2.07(−1) 2.10(−1)

The table shows that the choice of λ which gives the minimum RMS error is about .03. The spline corresponding to this choice is shown in Figure 11.15 (left). Clearly, all the bad effects of noise in the least-squares spline fit (see Figure 11.14 (right)) are removed. In addition to getting rid of the ripples in the surface, we also got a significant reduction in error; cf. the errors in the above table for λ = 0 and λ = .03. For large values of λ, we get splines which are essentially constant. This is due to the fact that with large λ, the value of E λ depends primarily on energy, and constant functions have zero energy. This explains the shape of the penalized-least squares spline from S21 ( P S ) in Figure 11.15 (right). Example 11.51. Plot the RMS errors of the previous example as a function of their corresponding λ values. Discussion: Here we make use of the script SPpenlsqg which fits the error curve with a not-a-knot cubic spline. We use 25 equally spaced values of λ in the range [0, .1]. The corresponding plot is shown in Figure 11.16, and we can again see the value of λ giving a minimum of RMS error is around .03. The plot shows the typical behavior for penalized least squares, i.e., it looks like a parabola with a well defined minimal value.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

396

Chapter 11. Applications of Spherical Splines 0.05

0.03

0.015 0

0.02

0.04

0.06

0.08

0.1

Figure 11.16. A plot of the RMS errors versus the λ values in Example 11.50.

11.7 PDE’s on the sphere In this section we show how spherical splines can be used to solve PDE’s on the sphere S. We focus on the case where the domain is the entire sphere, and consider differential equations of the form Lu(x, y, z) = f (x, y, z),

all (x, y, z) ∈ S.

(11.34)

Here f is a given function, and we are looking for an approximation to u. Note that there are no boundary conditions since we are working on the entire sphere. Following the discussion in Chapter 9 for the bivariate case, we make the following definition. Definition 11.52. Let S() be a spherical spline space defined on a triangulation of the sphere, and suppose {φi }ni=1 is a basis for it. Then a spline s ∈ S() is called a Ritz– Galerkin approximation to u, provided that  [Lu(x, y, z) − f (x, y, z)]φi (x, y, z) d x d y dz = 0, i = 1, . . ., n. (11.35) S

For any two functions defined on the sphere, we write  f , g =

S

f g.

Theorem 11.53. Suppose the matrix

# $n M = Lφi , φ j  i, j =1

is nonsingular. Then the spline s=

n 

c i φi

(11.36)

(11.37)

i=1

is the Ritz–Galerkin approximation to the solution of the PDE (11.34) if and only if the coefficient vector c = (c1 , . . . , cn )T is the solution of the linear system Mc = r ,

(11.38)

with ri =  f , φi ,

i = 1, . . . , n.

Proof. Substituting (11.37) in (11.35), we immediately get the system (11.38).

(11.39)

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.7. PDE’s on the sphere

397

Whether the matrix M appearing in (11.36) is nonsingular or not will depend on the partial differential operator L and the nature of the spline space S(). To illustrate the method, we look at the second order equation Lu = (−∗ + ω2 )u = f ,

(11.40)

where ∗ is the Laplace–Beltrami operator defined for functions on the sphere, and ω is any real number. Assuming S() is macro-element space with a minimal determining set M and associated transformation matrix A, we can use the following function to determine the B-coefficients of the Ritz–Galerkin spline: [c,M] = sfem(d,x,y,z,v1,v2,v3,e1,e2,e3,ie1,A,os,f) Here d is the degree of the splines, and x, . . . , ie1 describe the triangulation. The input os is the value of ω2 , and the function f describes the differential equation. The main output is the vector c of B-coefficients of the Ritz–Galerkin spline. We also output the stiffness matrix M for diagnostic purposes. The integrals involved in (11.38) are computed by Gaussian quadrature; see section 10.1.5. In the following two sections we illustrate this method using the spherical macro-element spline spaces S31 (C T ) and S51,2 ().

11.7.1 Solving PDE’s on the sphere with S31 (CT ) In this section we examine two examples where we approximate the solution of the PDE −∗ u + ω2u = f using the spherical spline space S31 (C T ). Our first example shows that if the true solution is a spherical polynomial in B1 ⊕ B3 , we will get exact results. Example 11.54. Given ω ≥ 0, let f (x, y, z) = (12 + ω2 )(y 3 + z 3 ) − 6(y + z). Then the Ritz–Galerkin approximation to the solution of (11.40) from the space S31 (C T ) is exactly equal to the true solution u(x, y, z) = y 3 + z 3. Discussion: The fact that u is the true solution corresponding to this f can be verified by computing Lu using the formula given in Remark 11.17 for the Laplace–Beltrami operator applied to a spherical polynomial. We now make use of the script SPfemct, and read the triangulation from the file sptri42. This script computes the transformation matrix A using smdsct. It is a sparse matrix of size 1082 × 246. Thus, the dimension of S31 (C T ) on this triangulation is 246, while the number of B-coefficients is 1082. Since we know the true solution in this case, we can compute the maximum and RMS errors for any set of points on S. The following table uses 16386 vertices of the spherical triangulation sptri7. We give the errors for various choices of ω to illustrate its role in the problem, and also list the estimated condition numbers of the stiffness matrices M. ω2 0 .1 1 100

emax 5.47(−12) 4.93(−14) 8.44(−15) 4.66(−15)

rms cond(M) 5.39(−12) 4.12(6) 1.79(−14) 3.60(4) 1.62(−15) 4.40(3) 5.81(−16) 6.71(2)

The table shows that the condition numbers and accuracy depend on the value of ω, but that in all cases we are getting essentially the exact solution. For a plot of it, see Figure 11.17 (left).

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

398

Chapter 11. Applications of Spherical Splines

Figure 11.17. Left: The Ritz–Galerkin spline in S31 (CT ) for Example 11.54, based on the triangulation sptri42. Right: The Ritz–Galerkin spline in S51,2 () for Example 11.54, based on the triangulation sptri3.

We now give an example to illustrate the rate of convergence of the method. Example 11.55. Let f (x, y, z = (ω2 + x 2 + 2x − 1)e x . Compute the Ritz–Galerkin approximations to the solution of the PDE (11.40) using the space S31 (C T ) with a nested sequence of spherical triangulations. Discussion: We claim that the true solution of Lu = f is the function e x . To verify this, we can convert f and u to spherical coordinates, and then apply the definition of the Laplace– Beltrami operator in spherical coordinates. We again make use of the script SPfemct, but now read the triangulations from the files sptri2, . . . , sptri5. For a plot of the spline based on the triangulation sptri3, see Figure 11.17 (right). Since we know the true solution in this case, we can compute the maximum and RMS errors for any set of points on S. The following table uses 16386 vertices of the spherical triangulation sptri7. The table is based on ω = 1, and also gives the estimated condition numbers of the stiffness matrices, and the time to assemble and solve the Ritz–Galerkin system.  sptri2 sptri3 sptri4 sptri5

emax 2.69(−2) 1.91(−3) 1.35(−4) 8.55(−6)

rms cond(M) time 1.27(−2) 5.8(2) 1.58 5.82(−4) 1.5(3) 1.84 3.68(−5) 5.1(3) 2.11 3.04(−6) 3.0(4) 7.76

ratios 14.08 21.82 14.15 15.81 15.79 12.10

The times listed here do not include the time for finding the triangulation lists and computing the minimal determining set. These grow rather rapidly with the number of vertices of the triangulation, and are over 50 seconds for sptri5. The table is consistent with a fourth order rate of convergence.

11.7.2 Solving PDE’s on the sphere with S51,2 () In this section we examine two examples where we approximate the solution of the PDE (11.40) using the spherical spline space S51,2 (). Our first example shows that if the true solution belongs to B1 ⊕ B3 ⊕ B5 , we will get exact results.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.8. Remarks

399

Example 11.56. Given ω2 ≥ 0, let f (x, y, z) = (30 + ω2 )x 2 z 3 − 2z 3 − 6x 2 z. Then for the PDE (11.40), the Ritz–Galerkin approximation from the space S31 (C T ) is exactly equal to the true solution u(x, y, z) = x 2 z 3 . Discussion: The fact that u is the true solution for this f can be verified using the formula for the Laplace–Beltrami operator applied to a spherical polynomial given in Remark 11.17. We make use of the script SPfem15, and read the triangulation from the file sptri42. This script computes the transformation matrix A using smds15. For this triangulation, it is of size 1002 × 372, which means that the dimension of the space is 372, and the number of B-coefficients is equal to 1002. Since we know the true solution in this case, we can compute the maximum and RMS errors for any set of points on S. The following table uses 16386 vertices of the spherical triangulation sptri7. We give the errors for various choices of ω to illustrate its role in the problem, and also give the condition numbers for the stiffness matrix. ω2 0 .1 1 100

emax 4.25(−10) 9.46(−15) 5.63(−15) 1.46(−15)

rms 4.25(−10) 6.01(−15) 1.03(−15) 1.56(−16)

cond(M) 1.59(10) 6.61(5) 8.89(4) 5.46(4)

The table shows that the condition numbers and accuracy both depend on the value of ω2 . However, even for ω2 = 0, the spline is very close to the exact solution. We now give an example to illustrate the rate of convergence of the method. Example 11.57. Repeat Example 11.55 using the space S51,2 () for a nested sequence of spherical triangulations. Discussion: We again make use of the script SPfem15, but now read the triangulations from the files sptri2, . . . , sptri5. Here we take ω2 = 1. The following table shows the maximum and RMS errors computed at the 16386 vertices of the spherical triangulation sptri7. The table also gives the condition number of the stiffness matrix M, and the times to assemble and solve the Ritz–Galerkin system.  sptri2 sptri3 sptri4 sptri5

emax 2.00(−3) 3.44(−5) 6.28(−7) 1.01(−8)

rms 3.72(−4) 1.04(−5) 1.40(−7) 4.87(−9)

cond 2.6(3) 1.2(4) 3.6(4) 2.2(5)

time 2.23 2.12 2.72 9.54

ratios 58.14 35.77 54.78 74.29 62.18 28.75

The times listed here do not include the times for finding the triangulation lists and computing the transformation matrix. These grow rather rapidly with the size of the triangulation. It is not clear from the table whether we have sixth order convergence.

11.8 Remarks Remark 11.1. In this chapter we have shown how several of the methods in Chapters 5–7 for interpolating and fitting functions in the bivariate case can be carried over to the sphere.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

400

Chapter 11. Applications of Spherical Splines

The other methods in those chapters also have spherical analogs, and indeed, in general, any bivariate spline method will have a spherical analog. Remark 11.2. In this chapter we have focused on interpolation and approximation problems using splines defined on the entire sphere. It is straightforward to modify everything done here to work on some subdomain of the sphere. Remark 11.3. The error values given throughout this chapter have generally been computed at the 16386 vertices of the spherical triangulation sptri7 by calling on valsphsp. For very large triangulations, this may not give very accurate values for the errors. Thus, in some examples involving the triangulation sptri6, we have instead calculated the errors at the points of the domain points Dk, of degree k associated with the triangulation. The size of k is adaptively chosen depending on how many triangles there are in , with the aim of getting at least 100,000 points. Here is an implementation. For its use, see, e.g., the script SPps. err = serr(d,x,y,z,v1,v2,v3,e1,e2,e3,ie1,c,nf) This function computes errors for the test function sfun, where nf controls which of the test functions should be used. The output is a vector of error values at the chosen domain points. The density of the sample points used in this function can vary significantly. In very small triangles they are very close together, while in large ones, they are far apart. Remark 11.4. The plots shown in this chapter are all snapshots of the 3D surfaces corresponding to our splines. They can all be rotated on the screen, which often leads to a much better appreciation of the shape of the surface. Here we have elected to display wireframe representations of our surfaces, but of course it is easy in MATLAB to modify these to show smooth surfaces with lighting effects. Remark 11.5. Throughout this chapter we have used the test function f 4 defined in (11.4) in most of our examples. It is a polynomial containing only terms of degree four, and produces a surface with a nice symmetric shape which is good for comparison purposes. Remark 11.6. We recall that if d is even, then the spline space Sd0 () contains the spaces of spherical polynomials Bk of even degree k ≤ d. Similarly, if d is odd, then Sd0 () contains Bk of odd degree k ≤ d. As a consequence, some of our interpolation methods give exact results for certain spherical polynomials. The method SP01 is exact for constants, and the method Sps is exact for polynomials of degree k = 0, 2. The methods SPct, SPscat03, and SPscatlocct are exact for polynomials of degree k = 1, 3. Note that for nf = 3, the function produced by sfun includes a mix of a constant with a polynomial in B3 , so none of the methods is exact for it. The choice nf = 7 gives an element of B3 . The minimal energy methods are not exact for any polynomials. Remark 11.7. Some of the least-squares methods are also exact for certain spherical polynomials. In particular, if d is even, then SPlsq0d is exact for Bk for all even k ≤ d. Similarly, if d is odd, then it is exact for all odd k ≤ d. The method SPlsqps is exact for Bk with k = 0, 2. Similarly, SPlsqct is exact for Bk with k = 1, 3, and SPlsq15 is exact for Bk with k = 1, 3, 5. The penalized least-squares methods are not exact for any polynomials.

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

11.8. Remarks

401

Remark 11.8. An error bound for spherical minimal energy splines was established in [BarL05], assuming the degree d of the spline is at least 3r + 2, where r is the smoothness. Thus, the result does not apply to either of the spaces S21 ( P S ) or S31 (C T ) used in section 11.3.1. The bound requires the triangulation to be β-uniform. It shows that if f ∈ C 2 (S) and d is even, then  f − s ≤ K tan(||/2)2 | f |2 ,

(11.41)

where | · |2 is an appropriate semi-norm defined for functions on the sphere; see [NeaS04]. If f ∈ C 3 (S) and d is odd, then  f − s ≤ K 1 tan(||/2)2 | f |2 + K 2 tan(||/2)3 | f |3 .

(11.42)

Remark 11.9. As in the bivariate case, it is possible to construct minimal energy spherical splines that interpolate Hermite data; see [Bar12]. That paper also contains an error bound showing that with the space S31 (C T ) on a β-uniform spherical triangulation with || ≤ 1, one can get the error bound  f − s ≤ K 1 ||3 | f |3 + K 2 ||4 | f |4

(11.43)

4 (S). for all f in the spherical Sobolev space W∞

Remark 11.10. As in the bivariate case, it is possible to modify the radial basis interpolation method of section 11.3.6 to include a spherical polynomial term. Remark 11.11. In this chapter we have used local polynomial least-squares to estimate derivatives for our two-stage scattered data methods. This could also be done with local radial basis interpolation, or with some hybrid method using both. Remark 11.12. In some papers in the literature, the authors prefer to report relative errors; see, e.g., [AlfNS96b]. However, since most of our examples involve the function f 4 , which has a maximum value of approximately 1.3 on the sphere, there is little difference as compared to the actual errors. Remark 11.13. In this chapter all computations with radial basis functions are based on the Gaussian with an appropriately chosen value for the associated parameter ε. There are other radial basis functions that would work as well; see [[Wen05, Fas07]]. Remark 11.14. As pointed out several times throughout the chapter, a problem with using radial basis functions is that they require selecting a shape parameter ε. As we have seen in the examples of section 11.3.6, using the wrong ε can lead to very poor results. As in the bivariate case, one can try to construct an adaptive process for selecting ε. Remark 11.15. In section 11.3.1 we have worked with the energy expression (11.15) which is based on the Laplace–Beltrami operator applied to spherical polynomials of degree d, or more generally functions defined on the sphere with homogeneous extensions to R3 of degree d. For some other choices; see [BarL05]. Remark 11.16. One approach to handling very large sets of scattered data is to divide the sphere into (overlapping) pieces. Then one interpolates or approximates on each piece, and somehow puts the pieces together smoothly. Such methods have been called domain decomposition methods; see [LaiS09].

Downloaded 07/30/15 to 170.140.26.180. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

402

Chapter 11. Applications of Spherical Splines

Remark 11.17. The Laplace–Beltrami operator is a second order differential operator that applies to functions defined on the sphere. It is the natural analog of the usual Laplacian. To define it, we work in spherical coordinates, where x = sin(θ ) cos(φ), y = sin(θ ) sin(φ), and y = cos(θ ), with θ ∈ [−π/2, π/2] and φ ∈ [0, 2π]. Then for any function u(θ , φ) defined on S, we write 1 1 Dθ [sin(θ )Dθ u] + ∗ u := D 2 u. (11.44) sin(θ ) sin(θ )2 φ It is known that if p is a spherical polynomial of degree d defined in terms of Cartesian coordinates, then ∗ p := p x x + p yy + pzz − d(d + 1) p. (11.45) Remark 11.18. Spherical splines can also be used to solve PDE’s on the sphere using the collocation method instead of the Ritz–Galerkin method; see [LayCJ06, LayCJ06b]

11.9 Historical notes For a survey of methods for interpolating and fitting data on the sphere, see [FasS98], and the 206 references cited there, some of which go back to the early 1970’s, although spherical harmonic expansions were no doubt used much earlier. Besides the use of spherical splines in our sense, the survey also discusses alternative methods. Several of these were based on mapping the sphere to a rectangle and using tensor-product functions; see, e.g., [Die87, Tra87, SchumT91]. Others were based on thin plate splines or other radial functions; see, e.g., [Wah81, Wah82, Wah84], where a reproducing kernel approach was used. For more on reproducing kernel and RBF methods, see the book [[FreGS98]]. Most of the methods discussed in this chapter are based on the work done in [AlfNS96a, AlfNS96b]. Minimal energy splines on the sphere were introduced in [AhLNS96b]. For later work, see [BarL05, BarLS06, LaiSBW08].

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Bibliography [ArcCT04]

A RCANGÉLI , R., C RUZ L ÓPEZ DE S ILANES , M., AND T ORRENS , J. J., Multidimensional Minimizing Splines, Kluwer (Dordrecht), 2004.

[AveNZ14]

AVERBUCH , A., N EITAANMÄKI , P., AND Z HELUDEVE , V., Spline and Spline Wavelet Methods with Applications to Signal and Image Processing: Volume I: Periodic Splines, Springer (Berlin), 2014.

[Bag13]

BAGDASAROV, S., Chebyshev Splines and Kolmogorov Inequalities, Birkhäuser (Basel), 2013.

[Bar88]

BARSKY, B., Computer Graphics and Geometric Modeling Using Beta-splines, Springer (Berlin), 1988.

[BarBB87]

BARTELS , R., B EATTY, J., AND BARSKY, B., An Introduction to Splines for Use in Computer Graphics and Geometric Modeling, Morgan Kaufmann (Palo Alto), 1987.

[BezV01]

B EZHAEV, A. Y. AND VASILENKO , V. A., Variational Theory of Splines, Kluwer (Dordrecht), 2001.

[BieW13]

B IEBLER , K.-E. AND W ODNY, M., Splines and Compartment Models: An Introduction, World Scientific (Singapore), 2013.

[BisL08]

B ISWATH , S. AND L OVELL , B., Bézier and Splines in Image Processing and Machine Vision, Springer (Berlin), 2008.

[Boh74]

B ÖHMER , K., Spline-Funktionen, Teubner (Stuttgart), 1974.

[BojHS93]

B OJANOV, B. D., H AKOPIAN , H. A., AND S AKHAKIAN , A. A., Spline Functions and Multivariate Interpolations, Kluwer (Dordrecht), 1993.

[Boo78]

B OOR , C. DE , A Practical Guide to Splines, Springer (New York), 1978.

[Boo01]

B OOR , C. 2001.

[BooHR93]

B OOR , C. DE , H ÖLLIG , K., AND R IEMENSCHNEIDER , S. D., Box Splines, SpringerVerlag (New York), 1993.

[BreS94]

B RENNER , S. C. AND S COTT, L. R., The Mathematical Theory of Finite Element Methods, Springer (New York), 1994.

[Chu88]

C HUI , C. K., Multivariate Splines, CBMS-NSF Regional Conf. Ser. in Appl. Math. 54, SIAM (Philadelphia), 1988.

DE ,

A Practical Guide to Splines, (Revised Edition), Springer (New York),

403

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

404

Bibliography

[Chu92]

C HUI , C. K., An Introduction to Wavelets. Wavelet Analysis and its Applications, Academic Press (Boston), 1992.

[CohRE01]

C OHEN , E., R IESENFELD , R., AND E LBER , G., Geometric Modelling with Splines, A K Peters (Natick, MA), 2001.

[Die93]

D IERCKX , P., Curve and Surface Fitting with Splines, Monographs on Numerical Analysis, Oxford University Press (Oxford), 1993.

[Edel87]

E DELSBRUNNER , H., Algorithms in Computational Geometry, Springer (Berlin), 1987.

[Edel01]

E DELSBRUNNER , H., Geometry and Topology for Mesh Generation, Cambridge University Press (Cambridge), 2001.

[EgeM09]

E GERSTEDT, M. AND M ARTIN , C., Control Theoretic Splines: Optimal Control, Statistics, and Path Planning, Princeton University Press (Princeton), 2009.

[Eub88]

E UBANK , R. L., Spline Smoothing and Nonparametric Regression, Marcel Dekker (New York), 1988.

[Far88]

FARIN , G., Curves and Surfaces for Computer Aided Geometric Design, Academic Press (New York), 1988.

[FarHK02]

FARIN , G., H OSCHEK , J., AND K IM , M. S. ( EDS .), Handbook of CAGD, North– Holland (Amsterdam), 2002.

[Fas07]

FASSHAUER , G. E., Meshfree Approximation Methods with Matlab, World Scientific (Singapore), 2007.

[FisJ75]

F ISHER , S. D. AND J EROME , J. W., Minimum Extremals in Function Spaces, Lecture Notes in Math. 479, Springer (Heidelberg), 1975.

[FreeGS98]

F REEDEN , W., G ERVENS , T., AND S CHREINER , M., Constructive Approximation on the Sphere, Oxford University Press (Oxford), 1998.

[Gru82]

G RUSA , K.-U., Zweidimensionale, interpolierende Lg-Splines und ihre Anwendungen, Springer (Berlin), 1982.

[Goc06]

G OCKENBACH , M. S., Understanding and Implementing the Finite Element Method, SIAM (Philadelphia), 2006.

[GreeS94]

G REEN , P. J. AND S ILVERMAN , B. W., Nonparametric Regression and Generalized Linear Models: A Roughness Penalty Approach, Chapman and Hall (London), 1994.

[Gu02]

G U , C., Smoothing Spline ANOVA Models, Springer (Berlin), 2002.

[Hol03]

H ÖLLIG , K., Finite Element Methods with B-Splines, SIAM (Philadelphia), 2003.

[HolH13]

H ÖLLIG , K. AND H ÖRNER , J., Approximation and Modeling with B-Splines, SIAM (Philadelphia), 2013.

[HosL93]

H OSCHEK , J. AND L ASSER , D., Fundamentals of Computer Aided Geometric Design, A K Peters (Wellesley, MA), 1993.

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Bibliography

405

[Isk04]

I SKE , A., Multiresolution Methods an Scattered Data Modelling, Springer (Berlin), 2004.

[Jer98]

J ERRI , A., The Gibbs Phenomenon in Fourier Analysis, Splines and Wavelet Approximations, Springer (Berlin), 1998.

[KinC00]

K INCAID , D. AND C HENEY, W., Numerical Analysis, Mathematics of Scientific Computing (Third Edition), American Mathematics Society (Providence), 2000.

[Kir92]

K IROV, G., Approximation with Quasi-Splines, CRC Press (Boca Raton, FL), 1992.

[KorLB96]

KORNEICHUK , N., L IGU , A., AND BABENKO , V., Extremal Properties of Polynomials and Splines, Nova Science Publishers (Commack, NY), 1996.

[Kno99]

K NOTT, G., Interpolating Cubic Splines, Birkhäuser (Boston), 1999.

[Kva00]

K VASOV, B. I., Methods of Shape Preserving Spline Approximation, World Scientific (Singapore), 2000.

[LaiS07]

L AI , M. J. AND S CHUMAKER , L. L., Spline Functions on Triangulations, Cambridge University Press (Cambridge), 2007.

[LifC85]

L IGHT, W. A. AND C HENEY, E. W., Approximation Theory in Tensor Product Spaces, Lecture Notes in Math. 1169 (Springer-Verlag, New York), 1985.

[MarC01]

M ARSH , L. AND C ORNIER , D., Spline Regression Models (Quantitative Applications in the Social Sciences), Sage Publications (London), 2001.

[Mas10]

M ASSOPUST, P., Interpolation and Approximation with Splines and Fractals, Oxford University Press (Oxford), 2010.

[Mic13]

M ICHEL , V., Lectures on Constructive Approximation: Fourier, Spline, and Wavelet Methods on the Real Line, the Sphere, and the Ball, Birkhäuser (New York), 2013.

[Nur89]

N ÜRNBERGER , G., Approximation by Spline Functions, Springer (Berlin), 1989.

[Osw88]

O SWALD , P., Multilevel Finite Element Approximation: Theory and Applications, Teubner (Stuttgart), 1988.

[PraBP02]

P RAUTZSCH , H., B OEHM , W., AND PALUSZNY, M., Bézier and B-Spline Techniques, Springer (Berlin), 2002.

[Pre75]

P RENTER , P. M., Splines and Variational Methods, Wiley (New York), 1975.

[SarW71]

S ARD , A. AND W EINTRAUB , S., Book of Splines, Wiley (New York), 1971.

[Schul73]

S CHULTZ , M. H., Spline Analysis, Prentice–Hall (Englewood Cliffs, NJ), 1973.

[Schum81]

S CHUMAKER , L. L., Spline Functions: Basic Theory, Wiley Interscience (New York), 1981.

[Schum07]

S CHUMAKER , L. L., Spline Functions: Basic Theory 3rd Edition, Cambridge University Press (Cambridge), 2007.

[ShikP95]

S HIKIN , E. V. AND P LIS , A. I., Handbook on Splines for the User, CRC Press (Boca Raton, FL), 1995.

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

406

Bibliography

[Spa95a]

S PÄTH , H., One-Dimensional Spline Interpolation Algorithms, A K Peters (Wellesley, MA), 1995.

[Spa95b]

S PÄTH , H., Two-Dimensional Spline Interpolation Algorithms, A K Peters (Wellesley, MA), 1995.

[Wah90]

WAHBA , G., Spline Models for Observational Data, CBMS NSF Regional Conf. Ser. Appl. Math. 59, SIAM (Philadelphia), 1990.

[Wan01]

WANG , R. H., Multivariate Spline Functions and Their Applications, Translated from the 1994 Chinese original by Shao-Ming Wang, Kluwer (Dordrecht), 2001.

[WangY11]

WANG , Y., Smoothing Splines: Methods and Applications, CRC Press (Boca Raton, FL), 2011.

[Wei12]

W EINERT, H., Fast Compact Algorithms and Software for Spline Smoothing, Springer (New York), 2012.

[Wen05]

W ENDLAND , H., Scattered Data Interpolation, Cambridge University Press (Cambridge), 2005.

[ZavKM80] Z AVIALOV, Y U . S., K VASOV, B. I., AND M IROSHNICHENKO , V. L., Methods of Spline-Functions (Russian), Nauka (Moscow), 1980.

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Script Index

B01, 162–164, 196 B01dat, 199 B01disk, 196 B01r1, 203 B01swap, 204 B15, 148 Bcon01, 273, 274 Bcon03, 278 Bconlsq0d, 283 Bconlsqps, 285 Bconps, 281, 282 Bconpsni, 283 Bct, 145, 153 Bctsubdiv, 131 Bdegraise, 130 Bdelaunay, 87 Bdelaunayrand, 88 Bderest, 183 Bderestr, 184 Bderestv12, 179 Bderestv20, 180 Bderestv20r, 181 Bfem0d, 297, 298, 302 Bfem0disk, 302 Bfem0dL, 300 Bfem0dmix, 304 Bfem0dneu, 306 Bfem15, 312, 313 Bfem15bhdisk, 322 Bfem15biharm, 321 Bfem15disk, 314

Bfem15L, 313 Bfem15mix, 315 Bfem15neu, 316 Bfembiharm, 322 Bfindtri, 86 Bgaussquad, 103 Bgetco, 109, 110 Blsq0d, 223–225 Blsq0drand, 226 Blsq15, 229, 230, 236 Blsq15rand, 230 Blsq29, 233 Blsqct2, 232 Blsqps, 227, 228 Blsqwang, 231 Bmds15, 125 Bmds29, 127 Bmdsps, 121, 122 Bmdswang, 129 Bmen15, 172 Bmenps, 170 Bmenpsdisk, 197 Bmenpshole, 196 Bmenpsm, 213 Bmon01, 256 Bmon01dat, 264 Bmongridhs, 259–263 Bmonlsq, 269 Bmonscat, 266 Bmonscatai, 268 Bnmdsps, 124

407

Bpenlsq15, 239 Bpenlsq15g, 241 Bpenlsq29g, 242 Bpenslq29, 242 Bpos01, 248 Bposlsq01, 251 Bposlsqps, 253 Bposps, 250 Bps, 139, 140 Bps12, 142, 143 Bpsd, 154 Bpsf0, 152 Bpsf1, 151 Bpsr1, 157, 158 Bpsrand, 154 Brbf, 206, 207 Brefine, 90 Brendpol, 105 Brendsp, 112 Brendspgrid, 108, 112 Bscale01, 192, 202 Bscalelocct, 193 Bscalelsq0d, 234 Bscalemenps, 193 Bscalepenlsq15, 243 Bscaleps, 155, 194 Bscalerbf, 207 Bscat03, 174, 196 Bscat03dat, 200 Bscat15, 188, 196 Bscat15dat, 200

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

408

Bscatct, 187, 196 Bscatctdat, 200 Bscatlocct, 176, 177 Bscatlocctdat, 200 Bscatps, 185, 186 Bscatpsdat, 200 Bscatwang, 189, 190, 196 Bscatwangdat, 200 Btridemo, 82, 84 Btriplot, 80, 81 Btype1, 90 Btype2, 90 Bwang, 149 SP01, 358, 360 SP01noise, 391 SPct, 367 SPctder, 368 SPdelaunay, 329 SPfem15, 399 SPfemct, 397, 398 SPintf, 332 SPintfT, 331 SPintpol, 338 SPintsp, 344 SPlsq0d, 385, 386, 392, 393 SPlsq15, 389 SPlsqct, 388

Script Index

SPlsqps, 387, 392, 393 SPmds15, 352 SPmdsct, 351 SPmdsps, 349 SPmenct, 372 SPmenps, 370, 371 SPpenlsq, 394 SPpenlsqg, 395 SPps, 363 SPpsder, 365 SPrbf, 380 SPrefine, 330 SPrendpatch, 339 SPrendsp, 343 SPscat03, 373 SPscatct, 379 SPscatlocct, 375 SPscatps, 377, 378 SPtridemo, 327, 328 TP01, 58, 59 TPctdat, 212 TPcubclamp, 63 TPcubherm, 62 TPcubquasi, 66 TPdemo, 55, 57 TPlsq, 68 TPlsqnoise, 69 TPnotaknot, 60

TPnotaknotnoise, 68 TPpenlsq, 71 TPpenlsqg, 71 TPscatmenps, 209 TPscatps, 210 TPscatpsdat, 211 U01, 8 Ubvp, 38, 39 Ubvph, 36, 37 Ucubclamp, 13 Ucubclampest, 13 Ucubherm, 15 Ucubquasi, 22 Ucubshape, 18 Ugauss, 34 Uknotrem, 31 Ulsq, 24, 25 Ulsqopt, 30 Unotaknot, 10–12, 25 Unotaknotnoise, 25 Upenlsq, 27 Upenlsqg, 28 Uquadherm, 16 Uquadshape, 20 Ushape, 16 Usplinedemo, 6, 7

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Function Index

adjgradpspos, 250 arg15, 147 bcoord, 85 bilintp, 58 bspl, 7 bsplder, 8 bvp, 38 bvp1, 38 bvph, 35 c1ck, 115 cksmooth, 115 con0d, 284 conck, 271 conck01, 272 conck0d, 277 conedge, 277 conpatch, 277 conswap, 272 ct, 145 ctadj, 176 ctsubdiv, 131 cubclamp, 12 cubclamptp, 63 cubherm, 15 cubhermtp, 62 cubquasi, 22 cubquasitp, 66 cubshape, 18 cubsib, 258

decast, 99, 336 decastder, 101 decastdermix, 101 degraise, 130 delaunay, 329 derest15, 188 derestct, 186 derestlsq, 182 derestlsqk, 182 derestlsqv, 179 derestrbf, 182 derestrbfk, 182 derestrbfv, 181 derestwang, 189 derspl, 5 errg, 58, 136 fem01, 297 fem0d, 296 fem0dmix, 303 fem0dneu, 306 fem15, 312 fem15bh, 320 fem15mix, 315 fem15neu, 316 findinterval, 4 findtri, 86 franke2, 59 franke2d, 62, 63

getindex, 110 gradgrid, 261 gradps, 253 hill, 247 hsadj, 261 intcotp, 56 intspl, 6 intsplco, 6 intspltp, 56 knnsearch, 182, 376 knotrem, 31 lsq0d, 223 lsqbiv, 222 lsqopt, 30 lsqspl, 24 lsqtp, 67 mds15, 125 mds15bh, 319 mds15f, 311 mds29, 127 mdsps, 121 mdswang, 129 men15, 171 menps, 170 mix, 101 monzadj, 266 nmdsps, 123

getco, 109

409

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

410

notaknot, 10 notaknottp, 60 penlsq, 27 penlsqbiv, 239 penlsqtp, 70 ps, 139 ps12, 142 quadherm, 16 quadset, 103, 331 quadshape, 20 rbfinterp, 206 readnoise, 25 readtri, 80 readxy, 87 readxyz, 199 refine, 90, 131 rendpol, 105 rendsphsp, 343 sarea, 326, 327 sbco, 333 scat03, 174 scatlocct, 176 sctadj, 375 sdelaunay, 329 sderest, 377

Function Index

sderestmid, 378 serr, 400 sfem, 397 sfindtri, 342 sframe, 361 sfun, 357 sigmoid, 255 slists, 327 sloc03, 373 slsq, 387 slsq0d, 385 smds15, 352 smdsct, 351 smdsps, 349 smen, 370 sp2tp, 209 spenlsq, 394 sphct, 367 sphintf, 332 sphintfT, 331 sphintpol, 337, 354 sphintsp, 344 sphps, 362 srbfinterp, 380 sreadpts, 329 sreadtri, 327 srefine, 329

srendtri, 327 startri, 84 starv, 84 surfl, 111 sval, 5 sval2, 5 swap01, 204 trilists, 81, 82 trisurf, 104, 339 tsearchn, 85 type1, 90 type2, 90 valspdergrid, 113 valspDP, 112 valspgrid, 111, 196 valspgridh, 196 valspgridxy, 111 valsphpol, 338 valsphsp, 342 valsphsp2, 354 valtp, 53 valtpder, 54 valtpgrid, 54 wang, 149 writegv, 133

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Subject Index

almost interpolation, 208 anonymous function, 10 antiderivative, 55 antipodal, 325 area of a spherical triangle, 325 triangle, 85 Argyris space, 124, 352 B-coefficients, 98, 106, 334 B-form of a bivariate polynomial, 98 spherical polynomial, 334 univariate spline, 4 barycenter of a spherical triangle, 348 triangle, 143 barycentric coordinates of a spherical triangle, 333 triangle, 84 Bernstein –Bézier representation, 98, 334 basis polynomials, 97 beta-quasi-uniform, 169 bicubic Hermite interpolant, 62 biharmonic equation, 290 bilinear spline interpolant, 58 Black Forest data, 199, 211 bounded linear projector, 41 carrier, 118, 346 centers, 204, 380 circular arc, 325 domain, 196

clamped bicubic spline, 63 cubic spline, 12 Clough–Tocher refinement, 143, 350 space, 144, 350 coarser triangulation, 90 co-convex, 20 co-monotone, 20 comparison of Hermite interpolation methods, 150 least-squares methods, 234, 390 scattered data methods, 190 compatibility condition, 293 complete bicubic spline, 74 condensation, 159 conforming spline space, 323 convex bivariate function, 270 data set, 271 in a direction, 270 interpolation, 270, 275, 279 least-squares, 283, 284 near-interpolation, 282 convexity-consistent, 19 covering spherical triangulation, 326 cross derivative, 144 validation, 28, 72 cubic complete spline, 45 de Casteljau algorithm, 99, 336

411

degenerate boundary vertex, 309 degree raising, 130 degrees of freedom, 116, 345 Delaunay triangulation, 87, 329 determining set, 116, 345 diameter of a spherical triangle, 330 direction vector, 100, 336 directional coordinates, 100, 337 derivative, 100, 336 Dirichlet boundary condition, 289 discrete least-squares, 23, 66, 219, 384 disk of domain points, 99, 340 domain decomposition, 198, 383, 401 domain points for a bivariate polynomial, 98 bivariate spline, 105 spherical spline, 340 spherical triangle, 335 domains with holes, 153, 195 energy of a bivariate spline, 166 spherical spline, 369 tensor-product spline, 69 univariate spline, 26 equi-scale invariant, 156, 234 estimating cross derivatives, 184

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

412

derivatives at a vertex, 178, 182 Euler formula, 94 relations, 326 extended partition, 2 finer triangulation, 90 finite-element method, 290 four-direction mesh, 89, 95 frame vectors, 361 Franke’s function, 59 Gaussian function, 205 quadrature rule, 103 generalized cross validation, 28, 76 global mesh ratio, 41 graded triangulation, 89, 323 Gram matrix, 23, 220, 384 Greville points, 46, 75 grid generation, 89 gridded data, 256, 257 hanging vertex, 79 harmonic polynomial, 334 Hermite –Birkhoff interpolation, 46, 74 data, 159 interpolation, 12, 13, 60, 135 hill function, 247 holes, 153, 195 homogeneous boundary condition, 289 extension of a function, 336 of degree i, 334 trivariate polynomial, 334 incenter of a spherical triangle, 348 triangle, 169 indexing set, 98, 335 inner products of B-polynomials, 101 inradius of a triangle, 169 knot removal algorithm, 31

Subject Index

knots, 1, 52 -local, 118 -stable, 118 Lagrange data, 159 Laplace –Beltrami operator, 369, 402 equation, 289 operator, 334 lexicographical order, 98, 335 linear projector, 41 Lipschitz constant, 216 locally bounded linear operator, 40 M-basis, 118, 345 macro -element space, 142, 144 triangle, 120, 137, 348, 350 Markov inequality, 41 Marsden’s identity, 21 max-min angle triangulation, 87 mesh size, 11, 72, 136, 165, 361 minimal determining set, 116, 345 energy spherical spline, 369 energy spline, 166 mixed boundary condition, 290 modulus of continuity, 42, 165 monotone bivariate function, 254 consistent data, 19, 255, 263 least-squares, 268 scattered data, 264 with respect to a cone, 286 N -basis, 119, 347 natural bicubic spline, 74 cubic spline, 45 nested triangulations, 90 Neumann boundary condition, 290 nodal

determining set, 119 minimal determining set, 119 noise, 25, 68, 391 non-Delaunay triangulations, 203 nondegenerate boundary vertex, 309 spherical triangle, 325 nonnegative interpolation, 247 norm of an operator, 41 normal equations, 46, 178 normalized B-splines, 2 NURBS, 76 observation matrix, 23, 178, 220, 384 octahedral spherical triangulation, 330 optimal interpolation, 47 knots, 29 order of approximation, 40 recovery, 47 triangulation, 91 order of a polynomial, 1 oriented edge, 107, 341 partition of unity, 3, 52, 97, 108, 334 PDE’s of order four, 290, 294 of order two, 289 penalized least-squares, 26, 70, 236 periodic spline, 48 Poisson equation, 289 polynomial patch, 104 reproduction, 40 Powell–Sabin -12 refinement, 141 refinement, 121, 137, 348 space, 137, 348 pure Neumann problem, 290 quadrangulation, 94 quadrature rule, 34, 102

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

Subject Index

quasi-interpolation formula, 21 radial basic function, 204, 380 basis function, 204, 380 rectangular grid, 54 refinement of a triangulation, 90 regular spherical triangulation, 326 triangulation, 93, 94 rendering a bivariate spline, 111 directional derivative, 113 polynomial patch, 104 spherical spline, 342 ring of domain points, 99, 340 Ritz inequality, 33 Ritz–Galerkin approximation, 32, 291, 292, 294, 396 RMS error, 10, 59, 136 scale invariant, 155, 156, 192, 233, 234 scattered data interpolation, 161, 204, 369 Schoenberg–Whitney theorem, 9, 14 second order PDE, 290 semi-norm, 73, 165, 361 shape-preserving splines, 17 shellable triangulation, 93 sigmoid function, 255 simulated annealing, 92, 95 smoothing spline, 47, 75 smoothness across an edge, 114, 345 Sobolev space, 216, 323, 401 sphere, 325 spherical B-coefficients, 334, 340 B-form, 334 barycentric coordinates, 333 Bernstein basis polynomials, 334 Bernstein–Bézier representation, 334

413

cap, 348 Delaunay triangulation, 329 determining set, 345 directional coordinates, 337 domain points, 335, 340 harmonics, 334 M-basis, 345 macro-element space, 348 minimal determining set, 345 minimal energy spline, 369 N -basis, 347 nodal determining set, 347 nodal minimal determining set, 347 penalized least-squares, 394 polynomials, 334 radial basis functions, 380 semi-norm, 361 Sobolev space, 401 spline, 340, 344, 353 superpline, 344 triangle, 325 triangulation, 326 stability of the bivariate B-form, 98 spherical B-form, 335 star of a triangle, 84 of a vertex, 84 of order j , 84 stiffness matrix, 33, 292 storing a bivariate spline, 107 spherical polynomial, 335 spherical spline, 341 tensor-product spline, 53 triangulation, 80 univariate spline, 4 strictly convex quadrilateral, 92 strongly coercive, 45 subdivision, 131 supersplines, 114, 344 surface patch, 338 swap algorithm, 92

tensor-product B-form, 52 B-splines, 52 discrete least-squares, 66 Hermite interpolation, 60 NURBS, 76 penalized least-squares, 69 polynomials, 51 quasi-interpolation, 64 smoothing spline, 75 splines, 52 tensor-product interpolation, 60 thin plate spline, 216 three-direction mesh, 89, 95 transformation matrix, 116, 221, 346 triangulated quadrangulations, 94 triangulation constructing a, 86 Delaunay, 87 general, 79 graded, 89 max-min angle, 87 nested, 90 optimal, 91 regular, 93, 94, 326 shellable, 93 spherical, 326 type-1, 89 type-2, 89 with a hanging vertex, 79 twist, 63 two-stage method, 159, 376 type-1 triangulation, 89 type-2 triangulation, 89 uniform refinement, 90, 329 variational approach to splines, 217 Wang macro-element space, 128 refinement, 128 weighted discrete least-squares, 219

Downloaded 12/07/19 to 82.154.40.205. Redistribution subject to SIAM license or copyright; see http://www.siam.org/journals/ojsa.php

This book describes in detail the key algorithms needed for computing with spline functions, and illustrates their use in solving several basic problems in numerical analysis, including function approximation, numerical quadrature, data fitting, and the numerical solution of PDEs. The focus is on computational methods for bivariate splines on triangulations in the plane and on the sphere, although both univariate and tensor-product splines are also discussed. • The book contains numerous examples and figures to illustrate the methods and their performance. • All of the algorithms in the book have been coded in a separate MATLAB® package available for license. The package can be used to run all of the examples in the book and also provides readers with the essential tools needed to create software for their own applications. • In addition to the included bibliography, a list of over 100 pages of additional references can be found on the book’s website. This book is designed for mathematicians, engineers, scientists, and anyone else wanting to make use of spline functions for numerical computation. Larry L. Schumaker is currently the Stevenson Professor of Mathematics at Vanderbilt University, and earlier was on the faculties of both the University of Texas in Austin and Texas A & M University. He was a Humboldt fellow at the Free University of Berlin, and later spent a year at Ludwig Maximilian University in Munich as a Humboldt Prize winner. He is a SIAM Fellow and a member of the Norwegian Academy of Sciences. In addition to editing 40 conference proceedings and translating a number of books from German, he is the author of Spline Functions: Basic Theory, and a coauthor of Spline Functions on Triangulations. His research continues to focus on spline functions and their applications. For more information about SIAM books, journals, conferences, memberships, or activities, contact:

Society for Industrial and Applied Mathematics 3600 Market Street, 6th Floor Philadelphia, PA 19104-2688 USA +1-215-382-9800 • Fax +1-215-386-7999 [email protected] • www.siam.org OT142

ISBN 978-1-611973-89-1 90000

9781611973891

OT142