100% found this document useful (5 votes)
2K views

Download ebooks file (Ebook) MATLAB Curve Fitting Toolbox™ User's Guide by The MathWorks, Inc. all chapters

The document is a user's guide for the MATLAB Curve Fitting Toolbox, published by The MathWorks, Inc. It provides detailed instructions on using various curve fitting tools, including interactive and programmatic fitting, surface fitting, and spline fitting. Additionally, it includes information on generating MATLAB code, exporting fits, and troubleshooting data problems.

Uploaded by

laynehotekyl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (5 votes)
2K views

Download ebooks file (Ebook) MATLAB Curve Fitting Toolbox™ User's Guide by The MathWorks, Inc. all chapters

The document is a user's guide for the MATLAB Curve Fitting Toolbox, published by The MathWorks, Inc. It provides detailed instructions on using various curve fitting tools, including interactive and programmatic fitting, surface fitting, and spline fitting. Additionally, it includes information on generating MATLAB code, exporting fits, and troubleshooting data problems.

Uploaded by

laynehotekyl
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 55

Download Full Version ebook - Visit ebooknice.

com

(Ebook) MATLAB Curve Fitting Toolbox™ User's Guide


by The MathWorks, Inc.

https://ebooknice.com/product/matlab-curve-fitting-
toolboxtm-user-s-guide-11236242

Click the button below to download

DOWLOAD EBOOK

Discover More Ebook - Explore Now at ebooknice.com


Instant digital products (PDF, ePub, MOBI) ready for you
Download now and discover formats that fit your needs...

Start reading on any device today!

(Ebook) MATLAB Econometrics Toolbox™ User's Guide by The


MathWorks, Inc.

https://ebooknice.com/product/matlab-econometrics-toolboxtm-user-s-
guide-11236174

ebooknice.com

(Ebook) MATLAB Bioinformatics Toolbox™ User's Guide by The


MathWorks, Inc.

https://ebooknice.com/product/matlab-bioinformatics-toolboxtm-user-s-
guide-11236232

ebooknice.com

(Ebook) MATLAB Mapping Toolbox™ User's Guide by The


MathWorks, Inc.

https://ebooknice.com/product/matlab-mapping-toolboxtm-user-s-
guide-11236250

ebooknice.com

(Ebook) MATLAB Optimization Toolbox™ User's Guide by The


MathWorks, Inc.

https://ebooknice.com/product/matlab-optimization-toolboxtm-user-s-
guide-11236252

ebooknice.com
(Ebook) Deep Learning Toolbox Getting Started Guide -
MATLAB by The MathWorks, Inc.

https://ebooknice.com/product/deep-learning-toolbox-getting-started-
guide-matlab-43710832

ebooknice.com

(Ebook) MATLAB Computer Vision Toolbox™ User's Guide by


The MathWorks, Inc.

https://ebooknice.com/product/matlab-computer-vision-toolboxtm-user-s-
guide-11236240

ebooknice.com

(Ebook) MATLAB Fuzzy Logic Toolbox™ User's Guide by The


MathWorks, Inc.

https://ebooknice.com/product/matlab-fuzzy-logic-toolboxtm-user-s-
guide-11236244

ebooknice.com

(Ebook) MATLAB Global Optimization Toolbox™ User's Guide


by The MathWorks, Inc.

https://ebooknice.com/product/matlab-global-optimization-toolboxtm-
user-s-guide-11236246

ebooknice.com

(Ebook) MATLAB Image Processing Toolbox™ User's Guide by


The MathWorks, Inc.

https://ebooknice.com/product/matlab-image-processing-toolboxtm-user-
s-guide-11236248

ebooknice.com
Curve Fitting Toolbox™
User's Guide

R2020a
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.
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)
Contents

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
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
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
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
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
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
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
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
Functions
12

Bibliography
B

xiii
1

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 Getting Started

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-2
Curve Fitting Tools

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.

1-3
1 Getting Started

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-4
Curve Fitting

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

1-5
1 Getting Started

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-6
Surface Fitting

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

1-7
1 Getting Started

Spline Fitting

In this section...
“About Splines in Curve Fitting Toolbox” on page 1-8
“Interactive Spline Fitting” on page 1-8
“Programmatic Spline Fitting” on page 1-8

About Splines in Curve Fitting Toolbox


You can work with splines in Curve Fitting Toolbox in several ways.

Using the Curve Fitting app or the fit function you can:

• Fit cubic spline interpolants to curves or surfaces


• Fit smoothing splines and shape-preserving cubic spline interpolants to curves (but not surfaces)
• Fit thin-plate splines to surfaces (but not curves)

The toolbox also contains specific splines functions to allow greater control over what you can create.
For example, you can use the csapi function for cubic spline interpolation. Why would you use
csapi instead of the fit function 'cubicinterp' option? You might require greater flexibility to
work with splines for the following reasons:

• You want to combine the results with other splines, e.g., by addition.
• You want vector-valued splines. You can use csapi with scalars, vectors, matrices, and ND-arrays.
The fit function only allows scalar-valued splines.
• You want other types of splines such as ppform, B-form, tensor-product, rational, and stform thin-
plate splines.
• You want to create splines without data.
• You want to specify breaks, optimize knot placement, and use specialized functions for spline
manipulation such as differentiation and integration.

If you require specialized spline functions, see the following sections for interactive and
programmatic spline fitting.

Interactive Spline Fitting


You can access all spline functions from the splinetool GUI.

See “Introducing Spline Fitting” on page 8-2.

Programmatic Spline Fitting


To programmatically fit splines, see “Spline Construction” for descriptions of types of splines and
numerous examples.

1-8
2

Interactive Fitting

• “Interactive Curve and Surface Fitting” on page 2-2


• “Data Selection” on page 2-8
• “Create Multiple Fits in Curve Fitting App” on page 2-11
• “Generating MATLAB Code and Exporting Fits” on page 2-15
• “Compare Fits in Curve Fitting App” on page 2-16
• “Surface Fitting to Franke Data” on page 2-26
2 Interactive Fitting

Interactive Curve and Surface Fitting


In this section...
“Introducing the Curve Fitting App” on page 2-2
“Fit a Curve” on page 2-2
“Fit a Surface” on page 2-3
“Model Types for Curves and Surfaces” on page 2-4
“Selecting Data to Fit in Curve Fitting App” on page 2-5
“Save and Reload Sessions” on page 2-6

Introducing the Curve Fitting App


You can fit curves and surfaces to data and view plots with the Curve Fitting app.

• Create, plot, and compare multiple fits.


• Use linear or nonlinear regression, interpolation, smoothing, and custom equations.
• View goodness-of-fit statistics, display confidence intervals and residuals, remove outliers, and
assess fits with validation data.
• Automatically generate code to fit and plot curves and surfaces, or export fits to the workspace for
further analysis.

Fit a Curve
1 Load some example data at the MATLAB command line:
load census
2 Open the Curve Fitting app by entering:
cftool

Alternatively, click Curve Fitting on the Apps tab.


3 Select X data and Y data. For details, see “Selecting Data to Fit in Curve Fitting App” on page 2-
5.

The Curve Fitting app creates a default polynomial fit to the data.
4 Try different fit options. For example, change the polynomial Degree to 3 to fit a cubic
polynomial.

2-2
Interactive Curve and Surface Fitting

5 Select a different model type from the fit category list, e.g., Smoothing Spline. For information
about models you can fit, see “Model Types for Curves and Surfaces” on page 2-4.

6 Select File > Generate Code.

The Curve Fitting app creates a file in the Editor containing MATLAB code to recreate all fits and
plots in your interactive session.

Tip For a detailed workflow example, see “Compare Fits in Curve Fitting App” on page 2-16.

To create multiple fits and compare them, see “Create Multiple Fits in Curve Fitting App” on page 2-
11.

Fit a Surface
1 Load some example data at the MATLAB command line:

load franke
2 Open the Curve Fitting app:

cftool
3 Select X data, Y data, and Z data. For more information, see “Selecting Data to Fit in Curve
Fitting App” on page 2-5.

2-3
2 Interactive Fitting

The Curve Fitting app creates a default interpolation fit to the data.
4 Select a different model type from the fit category list, e.g., Polynomial.

For information about models you can fit, see “Model Types for Curves and Surfaces” on page 2-
4.

5 Try different fit options for your chosen model type.


6 Select File > Generate Code.

The Curve Fitting app creates a file in the Editor containing MATLAB code to recreate all fits and
plots in your interactive session.

Tip For a detailed example, see “Surface Fitting to Franke Data” on page 2-26.

To create multiple fits and compare them, see “Create Multiple Fits in Curve Fitting App” on page 2-
11.

Model Types for Curves and Surfaces


Based on your selected data, the fit category list shows either curve or surface fit categories. The
following table describes the options for curves and surfaces.

Fit Category Curves Surfaces


Regression Models
Polynomial on page 4-14 Yes (up to degree 9) Yes (up to degree 5)
Exponential on page 4-28 Yes
Fourier on page 4-34 Yes
Gaussian on page 4-42 Yes
Power on page 4-45 Yes

2-4
Interactive Curve and Surface Fitting

Fit Category Curves Surfaces


Rational on page 4-48 Yes
Sum of Sine on page 4-54 Yes
Weibull on page 4-56 Yes
Interpolation
Interpolant on page 6-3 Yes Yes
Methods: Methods:
Nearest neighbor Nearest neighbor
Linear Linear
Cubic Cubic
Shape-preserving (PCHIP) Biharmonic (v4)
Thin-plate spline
Smoothing
Smoothing Spline on page 6-8 Yes
Lowess on page 6-15 Yes
Custom
Custom Equation on page 5-2 Yes Yes
Linear Fitting on page 5-6 Yes

For information about these fit types, see:

• “Linear and Nonlinear Regression”


• “Custom Models” on page 5-2
• “Interpolation”
• “Smoothing”

Selecting Data to Fit in Curve Fitting App


To select data to fit, use the drop-down lists in the Curve Fitting app to select variables in your
MATLAB workspace.

• To fit curves:

• Select X data and Y data.


• Select only Y data to plot Y against index (x=1:length( y )).
• To fit surfaces, select X data, Y data, and Z data.

You can use the Curve Fitting app drop-down lists to select any numeric variables (with more than
one element) in your MATLAB workspace.

Similarly, you can select any numeric data in your workspace to use as Weights.

2-5
2 Interactive Fitting

For curves, X, Y, and Weights must be matrices with the same number of elements.

For surfaces, X, Y, and Z must be either:

• Matrices with the same number of elements


• Data in the form of a table

For surfaces, weights must have the same number of elements as Z.

For more information see “Selecting Compatible Size Surface Data” on page 2-9.

When you select variables, the Curve Fitting app immediately creates a curve or surface fit with the
default settings. If you want to avoid time-consuming refitting for large data sets, you can turn off
Auto fit by clearing the check box.

Note The Curve Fitting app uses a snapshot of the data you select. Subsequent workspace changes
to the data have no effect on your fits. To update your fit data from the workspace, first change the
variable selection, and then reselect the variable with the drop-down controls.

If there are problems with the data you select, you see messages in the Results pane. For example,
the Curve Fitting app ignores Infs, NaNs, and imaginary components of complex numbers in the
data, and you see messages in the Results pane in these cases.

If you see warnings about reshaping your data or incompatible sizes, read “Selecting Compatible Size
Surface Data” on page 2-9 and “Troubleshooting Data Problems” on page 2-10 for information.

Save and Reload Sessions


• “Overview” on page 2-6
• “Saving Sessions” on page 2-7
• “Reloading Sessions” on page 2-7
• “Removing Sessions” on page 2-7

Overview

You can save and reload sessions for easy access to multiple fits. The session file contains all the fits
and variables in your session and remembers your layout.

2-6
Interactive Curve and Surface Fitting

Saving Sessions

To save your session, first select File > Save Session to open your file browser. Next, select a name
and location for your session file (with file extension .sfit).

After you save your session once, you can use File > Save Session to overwrite that session for
subsequent saves.

To save the current session under a different name, select File > Save Session As.

Reloading Sessions

Use File > Load Session to open a file browser where you can select a saved curve fitting session
file to load.

Removing Sessions

Use File > Clear Session to remove all fits from the current Curve Fitting app session.

See Also

Related Examples
• “Compare Fits in Curve Fitting App” on page 2-16
• “Create Multiple Fits in Curve Fitting App” on page 2-11

2-7
Exploring the Variety of Random
Documents with Different Content
Luego salió Damón, mozo
membrudo, aunque de poca
edad, gran amigo de Colín, pero
presto le hizo compañía y alguna
parte de consuelo.
Los dos vencidos pastores tenían
á Barcino más animoso y á los
circunstantes menos
determinados. Y assí de la
segunda lucha le dexaron algún
tanto de lugar para que
descansasse; pero Pradelio, que,
ardido en amores, los ojos en la
pastora Filena, con gran atención
veía mirar á los otros que
luchaban, pareciéndole que le
hurtaba á su corazón cualquier
vuelta que con sus ojos daba en
otra parte, á la hora, sin más
prevención de quitarse el gabán y
el cinto, se presentó con gentil
cuerpo y donaire al vitorioso
Barcino, que ya le esperaba.
Asiéronse por los brazos
igualmente, y aunque la fuerza de
Barcino era aventajada, la maña
de Pradelio no era menos, y
cuanto el uno de la fuerza del
uno, el otro de la maña del otro se
debían recelar. Y assí, andando
en torno gran espacio, sin dar el
uno lugar al otro para sus fuerzas
ni el otro al otro para sus mañas,
ya sus venas estaban tan gruesas
que parecían querer reventar, y el
sudor de sus frentes les quitaba la
vista; pisaban sobre la verde
hierba, inconveniente grande para
Barcino por no poder restribar en
ella como quisiera, pero no para
Pradelio, que tenía en esso la
confianza. Y assí, viendo á
Barcino que con gran furia venía
sobre él, hurtándole el cuerpo,
tuvo muy cerca la vitoria; mas el
fuerte pastor, proveyendo al daño,
tan fuertemente tuvo á Pradelio
por los brazos, que juntos
llegaron á tierra y juntos se
levantaron, juntos se tornaron á
apercibir y juntos gimieron como
dos bravos toros en pelea. Ya la
gente estaba admirada de la
terrible y peligrosa lucha, y
lastimosos los dos pastores; pero
ellos, más animosos que al
principio, iban buscando sus
presas, cuando Sileno, puesto en
medio, les atajó su porfía, con
aprobación de toda la compañía,
mayormente de las pastoras
Dinarda y Filena. Y á Barcino le
fué dado el cayado gentil, y á
Pradelio el galán arco, y á Colín y
á Damón licencia para tenerles
envidia.
Quedó Sileno nuevamente
deseoso de ver á los demás
ejercitarse en saltar ó correr ó
tirar á la barra. Gran turba de
pastores se levantó para estos
ejercicios, pero con diferentes
intentos: porque Uranio y Folco,
Frónimo y Tirseo, se apercibieron
para la carrera; Elpino, Bruno y
Silveo para la barra; Delio,
Lidonio y Florino para el salto.
Cupo la primera suerte de
ejercicio á los cuatro corredores,
que sin ningún detenimiento se
despojaron de sus vestidos, salvo
de las camisas y zarafuelles, sin
medias ni zapatos. Puso Sileno al
cabo de la carrera, que era en
una parte del valle, sin tropiezo ni
hierba, cuatro premios. El
primero, y menos bueno, un rabel
de tres cuerdas, de oloroso ciprés
de Candía; el segundo, y mejor,
un zurrón de seda y lana, labrado
con gran arte; el tercero, y mejor
que el segundo, un espejo de
acero, guarnecido en palo de
serval; el cuarto, y mejor que
todos, un puñal de monte, por la
una parte de corte vivo y por la
otra sierra muy fuerte, con vaina
verde y empuñadura de cuerno
de ciervo, trabado con correas
blancas de venado. En esta
forma: el rabel colgaba de un
olmo; y adelante ocho pasos, el
zurrón, de un salce; y otros ocho
adelante, el espejo, de un mirto; y
doce más el puñal, de un enebro.
Y hecha calle vistosíssima de
todos los pastores y pastoras, ya
que los cuatro corredores estaban
los pies izquierdos adelante y los
derechos casi en las puntas,
haciendo Arsindo señal, el son de
su bocina fué como el de la
cuerda de sacudido arco, y los
pastores no otra cosa parecieron
que ligeras saetas por el aire.
Fáltame por decir lo más gustoso:
como Sildeo, pastor de claro
entendimiento, aunque de pies
perezosos, vido el orden con que
los premios estaban, barruntó
luego lo que había de suceder, y
alzó al viento las luengas haldas
del sayo y púsose con los cuatro,
que en ligereza excedían al
viento, y juntamente con ellos
empezó á medir sus passos por la
carrera, y toda la gente que lo
miraba á reirse de su osadía; pero
como los cuatro passaron tan
adelante, y los ojos de todos iban
tras ellos, Sildeo pudo correr á
sus anchuras sin ser más mirado
ni reído. Que cosa fué ver á Folco
del primer vuelo tan aventajado,
que á la mitad de la carrera todos
juzgaron el puñal por suyo; pero
Fronimo, corrido, criando alas de
su afrenta, con dos cuerpos se le
puso delante. Uranio iba tras
Folco, y Tirseo tras Uranio,
cuando Fronimo, vanaglorioso de
su ventaja y codicioso de la
vitoria, ó tropezó en la tierra ó en
sus piernas, que súbito pareció
tendido en la carrera, y Folco
sobre él, que no pudo apartase
sin caer. Uranio y Tirseo se vieron
señores del campo, y la grita y
ruido de la gente, que les debiera
animar, parece que los desalentó,
de modo que los dos caídos,
levantándose, y ellos dos
entorpeciéndose, todos cuatro
llegaron casi juntos á los premios,
y todos cuatro, despreciándose
del rabel, passaron al zurrón, y
desde allí al espejo, y adelante al
puñal, que en un instante
alargaron los brazos á tomarle.
Bien se contentara Sildeo (que
tras ellos iba) con el rabel, pero
viéndolos que, asidos del puñal,
reciamente porfiaban, passó
hasta el espejo y tomóle, y baxó
al zurrón y púsosele al cuello y
desde allí al rabel, y pudo hacerlo
porque el concierto era que,
comenzando de premio mayor,
pudiessen de allí tomar los
menores que hallasen. Sildeo,
risueño y gritado de la gente,
enderezó los passos á Sileno, y
los cuatro pastores asidos de su
puñal, cuál por la vaina, cuál por
el puño y cuáles por los correas,
hicieron lo mismo. No pudo
Uranio (aunque quisiera)
desnudar el cuchillo, porque tenía
un secreto que le cerraba; pero
Sileno, presto en atajar su
contienda, tomó á su cargo el
puñal y dióle á Sildeo para que él
le diesse á quien le agradasse.
Discreto y gracioso era Sildeo, y
como se vió hecho juez de todo,
les dixo desta manera: Estos
premios se pusieron para el
corredor que primero los viesse
en su poder; yo los veo en el mío
sin que nadie me tocasse á los
tres en la carrera, y sin que
ninguno de vosotros haya tenido
el cuarto libremente como yo, y
assí, por derecho y condición son
todos los cuatro míos, y así lo
juzgo. No solos los amigos de
Sildeo rieron de la graciosa
sentencia, pero á los mismos
pretensores hizo mucho donaire,
y Sileno la confirmó como bien
dada, y mandó á Valleto, zagal
suyo, que diesse á los cuatro
pastores, el siguiente día, cada
dos gruesos carneros de los
mejores del rebaño, con que
quedaron los circunstantes muy
contentos y los pastores muy
pagados.
Y mientras muchos se estaban
culpando de no haber tenido el
aviso de Sildeo, Delio, Lidonio y
Florino pidieron lugar para los
saltos, y Elpino, Bruno y Silveo
para la barra, y aunque quisiera
Sileno dársele, viendo que del día
estaba gastada la mayor parte, y
aquellos ejercicios (aunque de
mucha estima) no eran de tanta
recreación, acordó que se
ingeniasen en pruebas de fuerza
y ligereza, cada cual como
supiesse ó bastasse, prometiendo
á todos dignos premios de su
exercicio. Prueba haré yo, dixo
Bruno, que no la hará otro pastor
de la ribera. Hazla, dixo Elpino;
veamos dónde llega tu soberbia.
Agora lo veréis, dixo Bruno, y
haciéndose atar por las muñecas
con dos cuerdas de torcido
cáñamo dió el un cabo á Elpino y
el otro á Silveo, y tomando en
cada mano una manzana, tirad,
les dixo, cada uno por su parte,
veréis si salgo con mi intención.
Con tanta fuerza tiraban los dos
pastores, que parecía quererle
abrir por los pechos; pero Bruno,
recogiendo sus fuerzas, haciendo
piernas, apretando los dientes, á
pesar de entrambos puso las
manzanas en la boca. No hubo
entre todos quien á otro tanto se
atreviesse. Pero Lidonio, que
deseaba mostrarse en algo aquel
día, viendo presente á la hermosa
Silvia (digo aquélla que á la ida
del valle toparon Alfeo y Finea
con la pastora Dinarda), alegre de
verla sin los dos competidores
Licio y Celio, le pidió licencia para
ejercitarse en su nombre, y ella,
que de nada tenia gusto, le dixo
que hiciese el suyo; esto tuvo
Lidonio por gran favor, y animado
con él, mientras que Delio y
Florino, haciendo vueltas galanas
y dificultosas por el suelo y por el
aire, entretenían la gente, envió
por perchas altas y delgadas á un
huerto suyo, que cerca del valle
estaba, y puesto en medio de la
gente, las afirmó en tierra
derechas sin hincarlas, y con
ambas manos, sin otra ayuda,
comenzó á subir por ellas con
grande facilidad, hasta poner los
brazos sobre lo alto, y
arrimándolas al cuerpo sin otra
ligadura, ni afirmar los pies en
nada, se comenzó á pasear por
entre los que le miraban, y
después de ser bien visto, se
dexó deslizar por ellas hasta el
suelo. Prueba fué que agradó y
admiró á todos en general.
Mas viendo que el luchador
Pradelio tomaba el puesto para
hacer nueva prueba, todos
volvieron á él atentamente, y el
mancebo gentil, tendiéndose en
tierra de espaldas, los brazos
abiertos, sobre la una mano se
puso un pastor de pies y sobre la
otra otro, asiéndose los dos de las
manos para afirmarse. Pradelio
levantó en alto los brazos con
ellos y estuvo assí un rato, y
luego se sentó en tierra con la
misma carga, tras lo cual se
levantó en pie, y trayendo á los
pastores tres ó cuatro vueltas en
el aire, se fué sentando y
tendiendo y baxando los brazos
hasta dexarlos donde los había
tomado. ¡Oh, cómo fué prueba
esta del esfuezo y maña de
Pradelio y cómo contentó á todos
los pastores y pastoras que la
vieron! El gusto de Filena para
después se quede, y aun las
pruebas por ahora, porque Sileno
bien siente que no es razón de
exercitarse tanto con tanta fatiga,
y así, premiando á todos con
mucha voluntad y franqueza,
mandó tornar á componer las
rústicas mesas con regaladas
viandas, de donde brevemente
todos se levantaron, y siguiendo á
Sileno, Galafrón y Barcino, Mireno
y Liardo y el rabadán Alfesibeo
enderezaron á la devota pirámide;
y allí Galafrón, tierno y verdadero
amante de la difunta Elisa, la una
rodilla en tierra, al son de la flauta
de Barcino, que de la misma arte
la tocaba, cantó estos versos
tristes y amorosos:

GALAFRÓN
Elisa, que un tiempo fuiste
descanso de los enojos
con sólo volver los ojos
á los que en llanto volviste,
la furia perpetua y triste
de nuestras continuas quexas
no es tanto porque nos dexas
como por ver que te fuiste.
Porque, Elisa, aunque
dexarnos
sea lo mismo que irte,
sintiendo el mal de partirte
no se entiende el de
quedarnos;
y sólo en representarnos
la memoria que te has ido,
no queda libre el sentido
para de otro mal quexarnos.
Mas, dime: ¿en prisión tan
grave
por qué nos dexas con ceño,
como cautivos sin dueño,
donde esperanza no cabe?
¿qué nueva vendrá suave
á nuestra prisión y pena,
si, cerrada la cadena,
el cielo rompe la llave?
Algún alivio tenemos
en ausencia tan amarga,
y es que no puede ser larga,
aunque ya larga la vemos;
otra rienda hallaremos
que más enfrene al tormento,
y es que vives en contento
ya que nosotros penemos.
Tengo aquí, pastora cara,
una canción que decías,
con cuyos versos cubrías
de mis lágrimas mi cara,
y aunque de dulzura avara
y más que la muerte fiera,
si yo agora te la oyera
bien piadosa la juzgara.
De suerte nos igualaste,
que contra el competidor
nuestra venganza mayor
era ver que le miraste:
bien seguros nos dexaste
de memorias de contento,
porque aun de darnos
tormento,
señora, no te preciaste.
Por nuestra afición abrojos
nos diste, en lugar de palma,
y nunca sintió tu alma
lo que hicieron tus ojos;
nuestros más ricos despojos
llevaste sin pretendellos,
y este es el mal, que, á
querellos,
gloria fueran los enojos.
Baxe ya tu luz preciosa
del alto cielo á la tierra,
y venga á hacernos guerra
si no quisiere piadosa,
por el mármol do reposa
tu ceniza sepultada,
que de mi diestra cuitada
fué pruebecilla amorosa.
Vaya lexos la alegría
de nuestro monte y ribera,
cuanto se teme y se espera
pare en la ventura mía;
fálteme el postrero día
una común sepultura,
que si yo busqué ventura,
por ti sola la quería.
Húyame el contentamiento,
nada me preste favor,
conviértaseme en dolor
cualquier causa de contento,
déme el cielo sólo aliento
para conocer mi mengua,
no quiera llegar la lengua
do no alcanza el sentimiento.
Bien puede, Elisa, subir
atrás el corriente río,
y el más importuno frío
nuevas flores producir;
mas no podrán permitir
tiempo, fortuna ó estrella
que cesse nuestra querella
hasta que cesse el vivir.

En tanto que Galafrón cantaba


desta suerte, muchas de las
pastoras habían traído blancos
tabaques de hierbas y rosas de la
florestas y en un punto, sobre sus
luengos cabellos poniendo
artificiosas guirnaldas, alrededor
de la alta pira, presas por las
manos sus anchas mangas, de
blanco lienzo colgando, mientras
cantaban, iban en sossegado
corro, y acabado el cantar, vueltas
las unas á las otras con gran
donaire bailaban. Ya en esto, el
gran planeta parecía, que,
agradecido de la solene fiesta,
quería dejar libre sombra para
que los pastores buscassen sus
moradas, y al trasponer del
monte, su rostro alegre y bello
(recogiendo la lumbre de sus
rayos) desde el Ocaso arrojó una
viva y templada claridad, que,
bordando de fina plata y luciente
oro las varias nubes, dejó nuestro
cielo hermosíssimo. Y luego las
pastoras, trocando las guirnaldas
de sus frentes con las que en el
sepulcro estaban, y los pastores
ramos con ramos, todos juntos
comenzaron á seguir al viejo
Sileno hasta la salida del valle,
que allí con alegre rostro y dulces
abrazos se despidió (uno por uno)
de todos, y dejando con él sus
cuatro pastores y el rabadán
Alfesibeo, se comenzaron por las
sendas y caminos á dividir desde
la verde floresta.
TERCERA PARTE
DEL PASTOR DE FILIDA

Alegremente vinieron nuestros


pastores al fresco valle de la
celebrada Elisa, y no menos se
dividieron al salir dél, porque no
quedó senda, atajo ni camino
donde no sonassen voces
acordadas, liras, rabeles, flautas y
otros alegres instrumentos; solos
Finea y Alfeo, como solos
entraron por la vereda de los
salces, camino poco usado, por
ser áspero y estrecho, al principio
dél dixo Finea: ¿Qué te ha
parecido, Alfeo, de los pastores
del Tajo? Tan bien, dixo Alfeo, que
no te lo sabré decir: su gala es
mucha; discreción y cortesía,
grande, y lo que es habilidad y
mesura, aventajado á cuanto he
visto. Paréceme que de España lo
mejor se recoge en estas selvas.
Esso puedes creer, dixo Finea,
que aunque lo natural dellas es
bueno, todos essos ricos pastores
que hoy has visto y essas
pastoras de tanta gracia y
hermosura, cuál es del Ebro, cuál
del Tormes, Pisuerga, Henares,
Guadiana, y algunos de donde,
mudando nuestro Tajo el nombre,
se llama Tejo; pero como el sitio
es tan acomodado á la crianza de
los ganados, á la labor de la tierra
y á la recreación de la gente,
muchos que aquí vienen por
poco, se quedan por mucho,
como á mí me ha sucedido y á ti
creo que será otro tanto. No hará,
pastora, dixo Alfeo, que aunque
entiendo que no me estaba mal,
véome impossibilitado para ello.
¿Qué podría yo hacer aquí, ó en
qué entretendría el tiempo que no
pareciesse feo á todos? Yo te lo
diré, dixo Finea: lo que yo hago, ó
lo que hace Siralvo, forastero
pastor que aqui habita. Yo compré
ovejas y cabras conforme á mi
poco caudal, y con pocos zagales
las apaciento. Siralvo, aunque
pudo hacer otro tanto, gustó de
entrar á soldada con el rabadán
Mendino, por poder mudar lugar
cuando gusto ó comodidad le
viniesse, sin tener cosa que se lo
estorbasse. ¿Quién es esse
Siralvo? dixo Alfeo. Es un noble
pastor, dixo Finea, de tu misma
edad, honesto y de llaníssimo
trato: amado generalmente de los
pastores y pastoras de más y
menos suerte, aunque hasta
agora no se sabe de las suya más
de lo que muestran sus respetos,
que son buenos, y sus exercicios,
de mucha virtud. ¿Cómo vería yo
á Siralvo? dixo Alfeo. Bien
fácilmente, dixo Finea; porque las
cabañas de Mendino están muy
cerca de aquí, y Siralvo por
maravilla sale dellas, y más agora
que está su radabán ausente y él
no podrá apartarse del ganado.
Assí hayas ventura, dixo Alfeo,
que vamos allá. Vamos, pastor,
dixo Finea; y volviendo el camino
sobre la mano derecha, mientras
Alfeo, agradeciendo á la serrana
su voluntad y trabajo, ella
nuevamente con amor se le
ofrecia, llegaron á la fuente de
Mendino, que poca distancia de
las cabañas estaba, y á un lado
della, cerca del arroyo, oyeron
una flauta, que al son del agua y
de los inquietos árboles
acordadamente sonaba. Aquella
flauta, dixo Finea, es de Siralvo,
y si él canta, á buen tiempo
hemos venido, que no es menos
músico el pastor que enamorado,
aunque él, no preciado desto,
siempre busca la soledad para
cantar sus versos. Oyámosle,
dixo Alfeo, que no es possible que
el aparejo tan conforme á su
condición no le incite. Y con esto,
sentándose los dos junto á la
fuente casi á un punto, Siralvo,
dejando la zampoña, comenzó á
cantar aquestas rimas:

SIRALVO
Ojos á gloria de mis ojos
hechos,
beldad inmensa en ojos
abreviada,
rayos que heláis los más
ardientes pechos,
hielos que derretís la nieve
helada,
mares mansos de amor,
bravos estrechos,
amigos, enemigos en celada,
volveos á mí, pues sólo con
mirarme
podéis verme y oirme y
ayudarme.
Si me miráis, veréis en mí,
primero,
cuanto con Vos Amor hace y
deshace;
si me escucháis, oiréis decir
que muero,
y que es la vida que me
satisface;
si me ayudáis, lo que pretendo
y quiero,
que es alabaros, fácil se me
hace;
en tan altas empressas
alumbradme,
mis ojos, vedme, oídme y
ayudadme.
Siendo verdad que el alma
que me ampara
es sólo un rayo dessa luz
pendiente,
cuando no me miráis, es cosa
clara
que estoy del alma con que
vivo ausente;
mas no tan presto á la
marchita cara
vuelve la vuestra, soles de mi
oriente,
cuando, el espíritu mío
renovado,
quedo vivo, contento y
mejorado.
La causa fuistes de mi
devaneo,
y podéis serlo de mi buena
andanza,
que si á vuestra beldad cansa
el deseo,
vuestra color ofrece la
esperanza,
esmeraldas preciosas, donde
veo
más perfeción que el ser
humano alcanza,
viva mi alma entre essas dos
serenas
lumbres divinas, de vitorias
llenas.
¡Cuánto mejor en vuestra
compañía
que con la lira ó con el tierno
canto,
pudiera Orfeo, el malhadado
día,
robar la esposa al reino del
quebranto!
pues la amorosa ardiente
ánima mía,
al resplandor de vuestro viso
santo
suspende tantas penas
infernales,
Ojos verdes, rasgados,
celestiales.
¿Sois celestiales, soberanos
ojos?
Si que lo sois, aunque os
alberga el suelo,
pues solas almas son vuestros
despojos,
almas que os buscan como á
propio cielo;
fundó el Amor sus gustos, sus
enojos,
estableció su pena y su
consuelo,
dejó las armas frágiles de
tierra,
y escogió vuestra luz en paz y
en guerra.
Estrellas, nortes, soles, que
á la diestra
del Sol salís, por soles
verdaderos,
si en cuanto el lugar cielo al
mundo muestra,
no hay cosa que merezca
pareceros,
¿quién verá sola una pestaña
vuestra
que presuma, aun con muerte,
mereceros?
Bástale á aquel que os ve, si
os conociere,
morir, y ver que por miraros
muere.
Pues los que os miran
quedan condenados
á arder de amores si miráis
piadosos
y á rabia eterna si volvéis
airados,
ved si los que abrasáis son
venturosos;
yo que con pensamientos
inflamados,
Ojos, os miro, y con deseos
rabiosos,
ó rabie, ó arda, ó muera, ó
viva, al menos
no dejéis de mirarme, Ojos
serenos.
Al revolver de vuestra luz
serena,
se alegran monte y valle, llano
y cumbre;
la triste noche de tinieblas
llena,
halla su día en vuestra clara
lumbre,
sois, Ojos, vida y muerte,
gloria y pena;
el bien es natural; el mal,
costumbre:
no más, Ojos, no más, que es
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

ebooknice.com

You might also like