
Computation
Visualization
Programming
For Use with MATLAB
®
User’s Guide
Version 1
Curve Fitting
Toolbox

How to Contact The MathWorks:
www.mathworks.com Web
comp.soft-sys.matlab Newsgroup
support@mathworks.com Technical support
suggest@mathworks.com Product enhancement suggestions
bugs@mathworks.com Bug reports
doc@mathworks.com Documentation error reports
service@mathworks.com Order status, license renewals, passcodes
info@mathworks.com Sales, pricing, and general information
508-647-7000 Phone
508-647-7001 Fax
The MathWorks, Inc. Mail
3 Apple Hill Drive
Natick, MA 01760-2098
For contact information about worldwide offices, see the MathWorks Web site.
Curve Fitting Toolbox User’s Guide
COPYRIGHT 2001-2002 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used
or copied only under the terms of the license agreement. No part of this manual may be photocopied or repro-
duced in any form without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by
or for the federal government of the United States. By accepting delivery of the Program, the government
hereby agrees that this software qualifies as "commercial" computer software within the meaning of FAR
Part 12.212, DFARS Part 227.7202-1, DFARS Part 227.7202-3, DFARS Part 252.227-7013, and DFARS Part
252.227-7014. The terms and conditions of The MathWorks, Inc. Software License Agreement shall pertain
to the government’s use and disclosure of the Program and Documentation, and shall supersede any
conflicting contractual terms or conditions. If this license fails to meet the government’s minimum needs or
is inconsistent in any respect with federal procurement law, the government agrees to return the Program
and Documentation, unused, to MathWorks.
MATLAB, Simulink, Stateflow, Handle Graphics, and Real-Time Workshop are registered trademarks, and
TargetBox is a trademark of The MathWorks, Inc.
Other product or brand names are trademarks or registered trademarks of their respective holders.
Printing History: July 2001 First printing New for Version 1 (Release 12.1)
July 2002 Second printing Revised for Version 1.1 (Release 13)

i
Contents
Preface
What Is the Curve Fitting Toolbox? . . . . . . . . . . . . . . . . . . . . . . vi
Exploring the Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . vi
Related Products . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . viii
Using This Guide . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Expected Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
How This Guide Is Organized . . . . . . . . . . . . . . . . . . . . . . . . . . . . ix
Documentation Examples and Data Sets . . . . . . . . . . . . . . . . . . . . x
Installation Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xi
Typographical Conventions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xii
1
Getting Started with the Curve Fitting Toolbox
Opening the Curve Fitting Tool . . . . . . . . . . . . . . . . . . . . . . . . 1-2
Importing the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Fitting the Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
The Data Fitting Procedure . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-5
Determining the Best Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8
Saving the Fit Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-13
Analyzing the Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-15
Saving the Analysis Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-16

ii Contents
Saving Your Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-17
Saving the Session . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18
Generating an M-File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19
2
Importing, Viewing, and Preprocessing Data
Importing Data Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Example: Importing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4
Viewing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Viewing Data Graphically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Viewing Data Numerically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Smoothing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9
Moving Average Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12
Lowess and Loess: Local Regression Smoothing . . . . . . . . . . . 2-14
Savitzky-Golay Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19
Example: Smoothing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
Excluding and Sectioning Data . . . . . . . . . . . . . . . . . . . . . . . . 2-25
Marking Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-27
Sectioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Example: Excluding and Sectioning Data . . . . . . . . . . . . . . . . 2-32
Example: Sectioning Periodic Data . . . . . . . . . . . . . . . . . . . . . . 2-35
Additional Preprocessing Steps . . . . . . . . . . . . . . . . . . . . . . . 2-40
Transforming the Response Data . . . . . . . . . . . . . . . . . . . . . . . 2-40
Removing Infs, NaNs, and Outliers . . . . . . . . . . . . . . . . . . . . . 2-41
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-42

iii
3
Fitting Data
The Fitting Process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
Parametric Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Basic Assumptions About the Error . . . . . . . . . . . . . . . . . . . . . . 3-5
The Least Squares Fitting Method . . . . . . . . . . . . . . . . . . . . . . . 3-6
Library Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
Custom Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Specifying Fit Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-23
Evaluating the Goodness of Fit . . . . . . . . . . . . . . . . . . . . . . . . . 3-27
Example: Rational Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-41
Example: Fitting with Custom Equations . . . . . . . . . . . . . . . . 3-46
Example: Robust Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-61
Nonparametric Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-68
Interpolants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-68
Smoothing Spline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-70
Example: Nonparametric Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-72
Selected Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-75
4
Function Reference
Functions – By Category . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-78
Fitting Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-78
Getting Information and Help . . . . . . . . . . . . . . . . . . . . . . . . . . 4-78
Getting and Setting Properties . . . . . . . . . . . . . . . . . . . . . . . . . 4-78
Preprocessing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-78
Postprocessing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-79
General Purpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-79
Functions – Alphabetical List . . . . . . . . . . . . . . . . . . . . . . . . . 4-80