MATLAB Curve Fitting Toolbox™ Users Guide (The MathWorks, Inc.) (z-library.sk, 1lib.sk, z-lib.sk)
,
Matlab
No Description
7
Views
Registered users can read the full content for free
Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.
Page
1
Curve Fitting Toolbox™ User's Guide R2020a
Page
2
How to Contact MathWorks Latest news: www.mathworks.com Sales and services: www.mathworks.com/sales_and_services User community: www.mathworks.com/matlabcentral Technical support: www.mathworks.com/support/contact_us Phone: 508-647-7000 The MathWorks, Inc. 1 Apple Hill Drive Natick, MA 01760-2098 Curve Fitting Toolbox™ User's Guide © COPYRIGHT 2001–2020 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 reproduced 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, for, or through the federal government of the United States. By accepting delivery of the Program or Documentation, the government hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014. Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and Documentation by the federal government (or other entity acquiring for or through the federal government) and shall supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is inconsistent in any respect with federal procurement law, the government agrees to return the Program and Documentation, unused, to The MathWorks, Inc. Trademarks MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be trademarks or registered trademarks of their respective holders. Patents MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for more information.
Page
3
Revision History July 2001 First printing New for Version 1 (Release 12.1) July 2002 Second printing Revised for Version 1.1 (Release 13) June 2004 Online only Revised for Version 1.1.1 (Release 14) October 2004 Online only Revised for Version 1.1.2 (Release 14SP1) March 2005 Online only Revised for Version 1.1.3 (Release 14SP2) June 2005 Third printing Minor revision September 2005 Online only Revised for Version 1.1.4 (Release 14SP3) March 2006 Online only Revised for Version 1.1.5 (Release 2006a) September 2006 Online only Revised for Version 1.1.6 (Release 2006b) November 2006 Fourth printing Minor revision March 2007 Online only Revised for Version 1.1.7 (Release 2007a) September 2007 Online only Revised for Version 1.2 (Release 2007b) March 2008 Online only Revised for Version 1.2.1 (Release 2008a) October 2008 Online only Revised for Version 1.2.2 (Release 2008b) March 2009 Online only Revised for Version 2.0 (Release 2009a) September 2009 Online only Revised for Version 2.1 (Release 2009b) March 2010 Online only Revised for Version 2.2 (Release 2010a) September 2010 Online only Revised for Version 3.0 (Release 2010b) April 2011 Online only Revised for Version 3.1 (Release 2011a) September 2011 Online only Revised for Version 3.2 (Release 2011b) March 2012 Online only Revised for Version 3.2.1 (Release 2012a) September 2012 Online only Revised for Version 3.3 (Release 2012b) March 2013 Online only Revised for Version 3.3.1 (Release 2013a) September 2013 Online only Revised for Version 3.4 (Release 2013b) March 2014 Online only Revised for Version 3.4.1 (Release 2014a) October 2014 Online only Revised for Version 3.5 (Release 2014b) March 2015 Online only Revised for Version 3.5.1 (Release 2015a) September 2015 Online only Revised for Version 3.5.2 (Release 2015b) March 2016 Online only Revised for Version 3.5.3 (Release 2016a) September 2016 Online only Revised for Version 3.5.4 (Release 2016b) March 2017 Online only Revised for Version 3.5.5 (Release 2017a) September 2017 Online only Revised for Version 3.5.6 (Release 2017b) March 2018 Online only Revised for Version 3.5.7 (Release 2018a) September 2018 Online only Revised for Version 3.5.8 (Release 2018b) March 2019 Online only Revised for Version 3.5.9 (Release 2019a) September 2019 Online only Revised for Version 3.5.10 (Release 2019b) March 2020 Online only Revised for Version 3.5.11 (Release 2020a)
Page
4
(This page has no text content)
Page
5
Getting Started 1 Curve Fitting Toolbox Product Description . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2 Curve Fitting Tools . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3 Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Interactive Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Programmatic Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 Surface Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Interactive Surface Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Programmatic Surface Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-6 Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 About Splines in Curve Fitting Toolbox . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Interactive Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Programmatic Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-8 Interactive Fitting 2 Interactive Curve and Surface Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Introducing the Curve Fitting App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Fit a Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 Fit a Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3 Model Types for Curves and Surfaces . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4 Selecting Data to Fit in Curve Fitting App . . . . . . . . . . . . . . . . . . . . . . . . . 2-5 Save and Reload Sessions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6 Data Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Selecting Data to Fit in Curve Fitting App . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 Selecting Compatible Size Surface Data . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9 Troubleshooting Data Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10 Create Multiple Fits in Curve Fitting App . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Refining Your Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Creating Multiple Fits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Duplicating a Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 Deleting a Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Displaying Multiple Fits Simultaneously . . . . . . . . . . . . . . . . . . . . . . . . . 2-12 Using the Statistics in the Table of Fits . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13 v Contents
Page
6
Generating MATLAB Code and Exporting Fits . . . . . . . . . . . . . . . . . . . . . 2-15 Interactive Code Generation and Programmatic Fitting . . . . . . . . . . . . . 2-15 Compare Fits in Curve Fitting App . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Interactive Curve Fitting Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Loading Data and Creating Fits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-16 Determining the Best Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 Analyzing Your Best Fit in the Workspace . . . . . . . . . . . . . . . . . . . . . . . . 2-22 Saving Your Work . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-24 Surface Fitting to Franke Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26 Programmatic Curve and Surface Fitting 3 Curve and Surface Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Fitting a Curve . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Fitting a Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Model Types and Fit Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2 Workflow for Command Line Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 Curve and Surface Fitting Objects and Methods . . . . . . . . . . . . . . . . . . . . 3-6 Curve Fitting Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6 Curve Fitting Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7 Surface Fitting Objects and Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 Linear and Nonlinear Regression 4 Parametric Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Parametric Fitting with Library Models . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2 Selecting a Model Type Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 Selecting Model Type Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Using Normalize or Center and Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4 Specifying Fit Options and Optimized Starting Points . . . . . . . . . . . . . . . . 4-5 List of Library Models for Curve and Surface Fitting . . . . . . . . . . . . . . . . 4-10 Use Library Models to Fit Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Library Model Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 Model Names and Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 Polynomial Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 About Polynomial Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14 Fit Polynomial Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15 Fit Polynomials Using the Fit Function . . . . . . . . . . . . . . . . . . . . . . . . . . 4-16 Polynomial Model Fit Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25 Defining Polynomial Terms for Polynomial Surface Fits . . . . . . . . . . . . . . 4-26 vi Contents
Page
7
Exponential Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28 About Exponential Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28 Fit Exponential Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28 Fit Exponential Models Using the fit Function . . . . . . . . . . . . . . . . . . . . . 4-30 Fourier Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 About Fourier Series Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 Fit Fourier Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34 Fit Fourier Models Using the fit Function . . . . . . . . . . . . . . . . . . . . . . . . 4-35 Gaussian Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42 About Gaussian Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42 Fit Gaussian Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42 Fit Gaussian Models Using the fit Function . . . . . . . . . . . . . . . . . . . . . . . 4-43 Power Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45 About Power Series Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45 Fit Power Series Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45 Fit Power Series Models Using the fit Function . . . . . . . . . . . . . . . . . . . . 4-46 Rational Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-48 About Rational Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-48 Fit Rational Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-48 Selecting a Rational Fit at the Command Line . . . . . . . . . . . . . . . . . . . . . 4-49 Example: Rational Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-49 Sum of Sines Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-54 About Sum of Sines Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-54 Fit Sum of Sine Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-54 Selecting a Sum of Sine Fit at the Command Line . . . . . . . . . . . . . . . . . . 4-55 Weibull Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56 About Weibull Distribution Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56 Fit Weibull Models Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56 Selecting a Weibull Fit at the Command Line . . . . . . . . . . . . . . . . . . . . . 4-57 Least-Squares Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59 Error Distributions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59 Linear Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-60 Weighted Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-62 Robust Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-63 Nonlinear Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-65 Robust Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-66 Custom Linear and Nonlinear Regression 5 Custom Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Custom Models vs. Library Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 Selecting a Custom Equation Fit Interactively . . . . . . . . . . . . . . . . . . . . . . 5-2 Selecting a Custom Equation Fit at the Command Line . . . . . . . . . . . . . . . 5-4 vii
Page
8
Custom Linear Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 About Custom Linear Models . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 Selecting a Linear Fitting Custom Fit Interactively . . . . . . . . . . . . . . . . . . 5-6 Selecting Linear Fitting at the Command Line . . . . . . . . . . . . . . . . . . . . . 5-7 Fit Custom Linear Legendre Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . 5-8 Custom Nonlinear Census Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16 Custom Nonlinear ENSO Data Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-19 Load Data and Fit Library and Custom Fourier Models . . . . . . . . . . . . . . 5-19 Use Fit Options to Constrain a Coefficient . . . . . . . . . . . . . . . . . . . . . . . 5-21 Create Second Custom Fit with Additional Terms and Constraints . . . . . 5-23 Create a Third Custom Fit with Additional Terms and Constraints . . . . . . 5-24 Gaussian Fitting with an Exponential Background . . . . . . . . . . . . . . . . . 5-27 Surface Fitting to Biopharmaceutical Data . . . . . . . . . . . . . . . . . . . . . . . . 5-30 Interpolation and Smoothing 6 Nonparametric Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 Interpolation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 About Interpolation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3 Selecting an Interpolant Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Selecting an Interpolant Fit Interactively . . . . . . . . . . . . . . . . . . . . . . . . . 6-5 Fit Linear Interpolant Models Using the fit Function . . . . . . . . . . . . . . . . . 6-5 Smoothing Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 About Smoothing Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 Selecting a Smoothing Spline Fit Interactively . . . . . . . . . . . . . . . . . . . . . 6-9 Fit Smoothing Spline Models Using the fit Function . . . . . . . . . . . . . . . . 6-10 Example: Nonparametric Fitting with Cubic and Smoothing Splines . . . . 6-11 Lowess Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15 About Lowess Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15 Selecting a Lowess Fit Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-15 Fit Lowess Models Using the fit Function . . . . . . . . . . . . . . . . . . . . . . . . 6-16 Fit Smooth Surfaces To Investigate Fuel Efficiency . . . . . . . . . . . . . . . . . 6-18 Filtering and Smoothing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 About Data Smoothing and Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 Moving Average Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-26 Savitzky-Golay Filtering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-27 Local Regression Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-28 Example: Smoothing Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-32 Example: Smoothing Data Using Loess and Robust Loess . . . . . . . . . . . . 6-33 viii Contents
Page
9
Fit Postprocessing 7 Explore and Customize Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Displaying Fit and Residual Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 Viewing Surface Plots and Contour Plots . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3 Using Zoom, Pan, Data Cursor, and Outlier Exclusion . . . . . . . . . . . . . . . . 7-4 Customizing the Fit Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-5 Print to MATLAB Figures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-6 Remove Outliers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Remove Outliers Interactively . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Exclude Data Ranges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-8 Remove Outliers Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 Select Validation Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 Generate Code and Export Fits to the Workspace . . . . . . . . . . . . . . . . . . 7-13 Generating Code from the Curve Fitting App . . . . . . . . . . . . . . . . . . . . . 7-13 Exporting a Fit to the Workspace . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14 Evaluate a Curve Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 Evaluate a Surface Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-25 Compare Fits Programmatically . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-32 Evaluating Goodness of Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-44 How to Evaluate Goodness of Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-44 Goodness-of-Fit Statistics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-45 Residual Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-48 Plotting and Analysing Residuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-48 Example: Residual Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-49 Confidence and Prediction Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-52 About Confidence and Prediction Bounds . . . . . . . . . . . . . . . . . . . . . . . . 7-52 Confidence Bounds on Coefficients . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-52 Prediction Bounds on Fits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-53 Compute Prediction Intervals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-55 Differentiating and Integrating a Fit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-57 ix
Page
10
Spline Fitting About Splines 8 Introducing Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 About Splines in Curve Fitting Toolbox . . . . . . . . . . . . . . . . . . . . . . . 8-2 Spline Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2 Interactive Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3 Programmatic Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3 Curve Fitting Toolbox Splines and MATLAB Splines . . . . . . . . . . . . . 8-4 Curve Fitting Toolbox Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4 MATLAB Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Expected Background . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Vector Data Type Support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5 Spline Function Naming Conventions . . . . . . . . . . . . . . . . . . . . . . . . 8-6 Arguments for Curve Fitting Toolbox Spline Functions . . . . . . . . . . . 8-6 Acknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-7 Simple Spline Examples 9 Cubic Spline Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 Cubic Spline Interpolant of Smooth Data . . . . . . . . . . . . . . . . . . . . . 9-2 Periodic Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3 Other End Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 General Spline Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4 Knot Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5 Smoothing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6 Least Squares . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7 Vector-Valued Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-9 Fitting Values at N-D Grid with Tensor-Product Splines . . . . . . . . . 9-11 Fitting Values at Scattered 2-D Sites with Thin-Plate Smoothing Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12 Postprocessing Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13 x Contents
Page
11
Types of Splines 10 Types of Splines: ppform and B-form . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 Polynomials vs. Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 ppform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 B-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2 Knot Multiplicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3 B-Splines and Smoothing Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 B-Spline Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-4 Variational Approach and Smoothing Splines . . . . . . . . . . . . . . . . . 10-4 Multivariate and Rational Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-6 Multivariate Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-6 Rational Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-7 The ppform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8 Introduction to ppform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8 Definition of ppform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-8 Constructing and Working with ppform Splines . . . . . . . . . . . . . . . 10-10 Constructing a ppform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-10 Working With ppform Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-10 Example ppform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-11 The B-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13 Introduction to B-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13 Definition of B-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13 B-form and B-Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-13 B-Spline Knot Multiplicity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-14 Choice of Knots for B-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-15 Constructing and Working with B-form Splines . . . . . . . . . . . . . . . 10-17 Construction of B-form . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17 Working With B-form Splines . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17 Example: B-form Spline Approximation to a Circle . . . . . . . . . . . . 10-18 Multivariate Tensor Product Splines . . . . . . . . . . . . . . . . . . . . . . . . 10-21 Introduction to Multivariate Tensor Product Splines . . . . . . . . . . . 10-21 B-form of Tensor Product Splines . . . . . . . . . . . . . . . . . . . . . . . . . 10-21 Construction With Gridded Data . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21 ppform of Tensor Product Splines . . . . . . . . . . . . . . . . . . . . . . . . . 10-22 Example: The Mobius Band . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22 NURBS and Other Rational Splines . . . . . . . . . . . . . . . . . . . . . . . . . 10-23 Introduction to Rational Splines . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23 rsform: rpform, rBform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-23 Constructing and Working with Rational Splines . . . . . . . . . . . . . . 10-25 Rational Spline Example: Circle . . . . . . . . . . . . . . . . . . . . . . . . . . 10-25 Rational Spline Example: Sphere . . . . . . . . . . . . . . . . . . . . . . . . . 10-26 Functions for Working With Rational Splines . . . . . . . . . . . . . . . . 10-26 xi
Page
12
Constructing and Working with stform Splines . . . . . . . . . . . . . . . 10-28 Introduction to the stform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-28 Construction and Properties of the stform . . . . . . . . . . . . . . . . . . 10-28 Working with the stform . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-29 Advanced Spline Examples 11 Least-Squares Approximation by Natural Cubic Splines . . . . . . . . . 11-2 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 General Resolution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 Need for a Basis Map . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2 A Basis Map for “Natural” Cubic Splines . . . . . . . . . . . . . . . . . . . . . 11-3 The One-line Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3 The Need for Proper Extrapolation . . . . . . . . . . . . . . . . . . . . . . . . . 11-3 The Correct One-Line Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4 Least-Squares Approximation by Cubic Splines . . . . . . . . . . . . . . . . 11-5 Solving A Nonlinear ODE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6 Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6 Approximation Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6 Discretization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6 Numerical Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7 Linearization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7 Linear System to Be Solved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8 Construction of the Chebyshev Spline . . . . . . . . . . . . . . . . . . . . . . . 11-10 What Is a Chebyshev Spline? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10 Choice of Spline Space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10 Initial Guess . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10 Remez Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11 Approximation by Tensor Product Splines . . . . . . . . . . . . . . . . . . . 11-14 Choice of Sites and Knots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14 Least Squares Approximation as Function of y . . . . . . . . . . . . . . . 11-14 Approximation to Coefficients as Functions of x . . . . . . . . . . . . . . 11-15 The Bivariate Approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-16 Switch in Order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-17 Approximation to Coefficients as Functions of y . . . . . . . . . . . . . . 11-18 The Bivariate Approximation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-19 Comparison and Extension . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-20 Splines Glossary A List of Terms for Spline Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . A-2 xii Contents
Page
13
Functions 12 Bibliography B xiii
Page
14
(This page has no text content)
Page
15
Getting Started • “Curve Fitting Toolbox Product Description” on page 1-2 • “Curve Fitting Tools” on page 1-3 • “Curve Fitting” on page 1-4 • “Surface Fitting” on page 1-6 • “Spline Fitting” on page 1-8 1
Page
16
Curve Fitting Toolbox Product Description Fit curves and surfaces to data using regression, interpolation, and smoothing Curve Fitting Toolbox provides an app and functions for fitting curves and surfaces to data. The toolbox lets you perform exploratory data analysis, preprocess and post-process data, compare candidate models, and remove outliers. You can conduct regression analysis using the library of linear and nonlinear models provided or specify your own custom equations. The library provides optimized solver parameters and starting conditions to improve the quality of your fits. The toolbox also supports nonparametric modeling techniques, such as splines, interpolation, and smoothing. After creating a fit, you can apply a variety of post-processing methods for plotting, interpolation, and extrapolation; estimating confidence intervals; and calculating integrals and derivatives. Key Features • Curve Fitting app for curve and surface fitting • Linear and nonlinear regression with custom equations • Library of regression models with optimized starting points and solver parameters • Interpolation methods, including B-splines, thin plate splines, and tensor-product splines • Smoothing techniques, including smoothing splines, localized regression, Savitzky-Golay filters, and moving averages • Preprocessing routines, including outlier removal and sectioning, scaling, and weighting data • Post-processing routines, including interpolation, extrapolation, confidence intervals, integrals and derivatives 1 Getting Started 1-2
Page
17
Curve Fitting Tools Curve Fitting Toolbox software allows you to work in two different environments: • An interactive environment, with the Curve Fitting app and the Spline Tool • A programmatic environment that allows you to write object-oriented MATLAB® code using curve and surface fitting methods To open the Curve Fitting app or Spline Tool, enter one of the following: • cftool. See Curve Fitting. • splinetool To list the Curve Fitting Toolbox functions for use in MATLAB programming, type help curvefit The code for any function can be opened in the MATLAB Editor by typing edit function_name Brief, command line help for any function is available by typing help function_name Complete documentation for any function is available by typing doc function_name You can change the way any toolbox function works by copying and renaming its file, examining your copy in the editor, and then modifying it. You can also extend the toolbox by adding your own files, or by using your code in combination with functions from other toolboxes, such as Statistics and Machine Learning Toolbox or Optimization Toolbox software. Curve Fitting Tools 1-3
Page
18
Curve Fitting Interactive Curve Fitting To interactively fit a curve, follow the steps in this simple example: 1 Load some data at the MATLAB command line. load hahn1 2 Open the Curve Fitting app. Enter: cftool 3 In the Curve Fitting app, select X Data and Y Data. Curve Fitting app creates a default interpolation fit to the data. 4 Choose a different model type using the fit category drop-down list, e.g., select Polynomial. 5 Try different fit options for your chosen model type. 6 Select File > Generate Code. Curve Fitting app creates a file in the Editor containing MATLAB code to recreate all fits and plots in your interactive session. For more information about fitting curves in the Curve Fitting app, see “Interactive Curve and Surface Fitting” on page 2-2. For details and examples of specific model types and fit analysis, see the following sections: 1 “Linear and Nonlinear Regression” 2 “Interpolation” 3 “Smoothing” 4 “Fit Postprocessing” Programmatic Curve Fitting To programmatically fit a curve, follow the steps in this simple example: 1 Load some data. load hahn1 Create a fit using the fit function, specifying the variables and a model type (in this case rat23 is the model type). f = fit( temp, thermex, 'rat23' ) Plot your fit and the data. plot( f, temp, thermex ) f( 600 ) To learn what functions you can use to create and work with fits, see: “Curve and Surface Fitting” on page 3-2. 1 Getting Started 1-4
Page
19
For details and examples of specific model types and fit analysis, see the following sections: 1 “Linear and Nonlinear Regression” 2 “Interpolation” 3 “Smoothing” 4 “Fit Postprocessing” See Also fit Related Examples • “Interactive Curve and Surface Fitting” on page 2-2 Curve Fitting 1-5
Page
20
Surface Fitting Interactive Surface Fitting To interactively fit a surface, follow the steps in this simple example: 1 Load some data at the MATLAB command line. load franke 2 Open the Curve Fitting app. Enter: cftool 3 In the Curve Fitting app, select X Data, Y Data and Z Data. Curve Fitting app creates a default interpolation fit to the data. 4 Choose a different model type using the fit category drop-down list, e.g., select Polynomial. 5 Try different fit options for your chosen model type. 6 Select File > Generate Code. Curve Fitting app creates a file in the Editor containing MATLAB code to recreate all fits and plots in your interactive session. For more information about fitting surfaces in the Curve Fitting app, see “Interactive Curve and Surface Fitting” on page 2-2. For details and examples of specific model types and fit analysis, see the following sections: 1 “Linear and Nonlinear Regression” 2 “Interpolation” 3 “Smoothing” 4 “Fit Postprocessing” Programmatic Surface Fitting To programmatically fit a surface, follow the steps in this simple example: 1 Load some data. load franke 2 Create a fit using the fit function, specifying the variables and a model type (in this case poly23 is the model type). f = fit( [x, y], z, 'poly23' ) 3 Plot your fit and the data. plot(f, [x,y], z) To learn what functions you can use to create and work with fits, see: “Curve and Surface Fitting” on page 3-2. For details and examples of specific model types and fit analysis, see the following sections: 1 Getting Started 1-6
The above is a preview of the first 20 pages. Register to read the complete e-book.
AI Reading Assistant
Whole-book reading guide from stratified index samples; jump to passages in the text
AI guide
【One-Line Pitch】
A practical, example-driven manual for anyone who needs to fit curves and surfaces to data in MATLAB—from quick interactive exploration to production-grade programmatic fitting. Best suited to engineers, scientists, and analysts who already know basic MATLAB and want to turn noisy measurements into defensible models.
【Book Arc】
- **Opening (~0%–10%)**: Orients you to the toolbox's two entry points—the interactive Curve Fitting app (`cftool`) and the programmatic `fit`/`fittype` functions—and establishes the spline-fitting vocabulary used throughout.
- **Early (~10%–32%)**: Walks through interactive fitting workflow: creating, duplicating, and comparing multiple fits, refining settings, excluding outliers, and generating reusable code from a session. Then introduces the library of built-in models (polynomial, exponential, Gaussian, Fourier, power, rational, sin, distribution) and custom equations.
- **Middle (~32%–48%)**: Moves into interpolation and smoothing, robust least squares (LAR and bisquare) for outlier resistance, and fit postprocessing—confidence/prediction bounds, coefficient inspection, and diagnosing overfitting.
- **Late (~48%–end of sampled range)**: Extends to advanced spline work: tensor-product splines for gridded N-D data, least-squares approximation by cubic splines, Chebyshev splines, and solving nonlinear ODEs via spline approximation spaces.
- **Ending (beyond sampled range)**: Excerpts indicate a spline glossary and reference appendices; the excerpts do not cover the closing reference material in detail.
【Book Arc note】The progression is deliberate: get a fit working interactively, understand the model families, then learn to judge and refine fits statistically before tackling spline mathematics.
【Key Takeaways】
- **Two parallel workflows—GUI and code—are treated as one** (Early): the app lets you explore and compare fits visually, then "Generate Code" reproduces the whole session as a script, bridging exploration and reproducibility.
- **Model choice is a menu, not a mystery** (Early): the library spans polynomial (to degree 9), exponential, Gaussian peaks, Fourier, rational, and distribution models, each with named inputs to `fit`, `fitoptions`, and `fittype`.
- **Custom models are first-class** (Early): you can supply a MATLAB expression, `.m` file, anonymous function, or cell array of linear terms—enabling piecewise and physically motivated equations.
- **Goodness-of-fit must be read graphically and numerically** (Middle): residuals plots are the first check, but confidence bounds crossing zero and wide prediction intervals reveal overfitting that statistics alone can hide.
- **Outliers demand robust methods** (Middle): least squares squares residuals and amplifies extremes; LAR and bisquare weighting reduce that influence, and the app supports interactive outlier exclusion and range-based rules.
- **Extrapolation is a judgment call** (Middle): the toolbox will plot beyond the data range, but prediction bounds widen sharply where data is sparse—evidence you need more data, not a higher-degree model.
- **Splines scale to surfaces and N-D grids** (Late): tensor-product splines fit gridded multivariate data with the same construction commands, and vector-valued splines handle multiple outputs.
- **Advanced spline theory is included for the curious** (Late): least-squares cubic spline approximation, Chebyshev splines via Remez iteration, and ODE solving show the toolbox's mathematical depth.
【Reading Tips】
- **Skim the table of contents and glossary first** to map terminology (knots, basis maps, stform) before diving in; the manual is reference-structured, not narrative.
- **Deep-read Chapters 2, 4, and 7** (interactive fitting, model library, postprocessing)—these carry the practical payoff; treat the advanced spline chapter as optional unless you need N-D or theoretical work.
- **Work the examples in MATLAB as you read**; the manual teaches by runnable snippets, and the code-generation feature means you can capture your own experiments.
- **Watch the overfitting discussion closely**—the polynomial-degree and prediction-bound examples are the book's most transferable lesson for real data work.
- **Keep it as a lookup companion** rather than a cover-to-cover read; the model-name tables and coefficient-ordering functions are the parts you'll return to.
【Coverage Limits】
This guide is based on stratified excerpts covering roughly the first half of the manual plus the table of contents; later reference chapters, appendices, and the full spline glossary are only partially represented, so specifics there are not summarized.
Passage locations
Page 12
. . . . . . . . . 11-7 Linear System to Be Solved . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7 Iteration . . . . . . . . . . . . . . . ....
View in text
Excerpt 2
ne (with your original data or new data as input arguments). In this case, your original variables still appear in the workspace. 2-32 Curve and Surface Fitt...
View in text
Excerpt 3
Fitting app, select x and y in the X data and Y data lists. 4 Use your piecewiseLine function in the Curve Fitting app by selecting the Custom Equation fit t...
View in text
Excerpt 4
very method that you can use with the fit. methods(surffit) Methods for class sfit: argnames dependnames indepnames predint sfit category differentiate islin...
View in text
Recommended for You
{{#thumbnailUrl}}
{{/thumbnailUrl}}
{{^thumbnailUrl}}
{{/thumbnailUrl}}
Loading recommended books...
Failed to load, please try again later
Tip the Site
Scan the WeChat Pay or Alipay code to tip. No login required.
WeChat Pay
Alipay