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

(Ebook) MATLAB Mathematics by MathWorks - The full ebook with all chapters is available for download

The document provides access to various MATLAB eBooks available for instant download at ebooknice.com. It includes guides and user manuals for different MATLAB toolboxes and functionalities, catering to a range of topics in mathematics and engineering. Additionally, it contains contact information for MathWorks and details about software licensing and revisions.

Uploaded by

selahvenaro60
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 (3 votes)
2K views

(Ebook) MATLAB Mathematics by MathWorks - The full ebook with all chapters is available for download

The document provides access to various MATLAB eBooks available for instant download at ebooknice.com. It includes guides and user manuals for different MATLAB toolboxes and functionalities, catering to a range of topics in mathematics and engineering. Additionally, it contains contact information for MathWorks and details about software licensing and revisions.

Uploaded by

selahvenaro60
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/ 80

Instant Ebook Access, One Click Away – Begin at ebooknice.

com

(Ebook) MATLAB Mathematics by MathWorks

https://ebooknice.com/product/matlab-mathematics-49473892

OR CLICK BUTTON

DOWLOAD EBOOK

Get Instant Ebook Downloads – Browse at https://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) Audio Toolbox User's Guide: MATLAB & Simulink by MathWorks

https://ebooknice.com/product/audio-toolbox-user-s-guide-matlab-
simulink-49474718

ebooknice.com

(Ebook) Learning Matlab 6, Release 12, Matlab Student Version by The MathWorks ISBN
9780967219530, 0967219531

https://ebooknice.com/product/learning-matlab-6-release-12-matlab-student-
version-1857530

ebooknice.com

(Ebook) MATLAB - R2020a - Symbolic Math Toolbox - User's Guide by MathWorks

https://ebooknice.com/product/matlab-r2020a-symbolic-math-toolbox-user-s-
guide-11236344

ebooknice.com

(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
MATLAB®
Mathematics

R2023a
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
MATLAB® Mathematics
© COPYRIGHT 1984–2023 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
June 2004 First printing New for MATLAB 7.0 (Release 14), formerly part of
Using MATLAB
October 2004 Online only Revised for MATLAB 7.0.1 (Release 14SP1)
March 2005 Online only Revised for MATLAB 7.0.4 (Release 14SP2)
June 2005 Second printing Minor revision for MATLAB 7.0.4
September 2005 Second printing Revised for MATLAB 7.1 (Release 14SP3)
March 2006 Second printing Revised for MATLAB 7.2 (Release 2006a)
September 2006 Second printing Revised for MATLAB 7.3 (Release 2006b)
September 2007 Online only Revised for MATLAB 7.5 (Release 2007b)
March 2008 Online only Revised for MATLAB 7.6 (Release 2008a)
October 2008 Online only Revised for MATLAB 7.7 (Release 2008b)
March 2009 Online only Revised for MATLAB 7.8 (Release 2009a)
September 2009 Online only Revised for MATLAB 7.9 (Release 2009b)
March 2010 Online only Revised for MATLAB 7.10 (Release 2010a)
September 2010 Online only Revised for MATLAB 7.11 (Release 2010b)
April 2011 Online only Revised for MATLAB 7.12 (Release 2011a)
September 2011 Online only Revised for MATLAB 7.13 (Release 2011b)
March 2012 Online only Revised for MATLAB 7.14 (Release 2012a)
September 2012 Online only Revised for MATLAB 8.0 (Release 2012b)
March 2013 Online only Revised for MATLAB 8.1 (Release 2013a)
September 2013 Online only Revised for MATLAB 8.2 (Release 2013b)
March 2014 Online only Revised for MATLAB 8.3 (Release 2014a)
October 2014 Online only Revised for MATLAB 8.4 (Release 2014b)
March 2015 Online only Revised for MATLAB 8.5 (Release 2015a)
September 2015 Online only Revised for MATLAB 8.6 (Release 2015b)
October 2015 Online only Rereleased for MATLAB 8.5.1 (Release 2015aSP1)
March 2016 Online only Revised for MATLAB 9.0 (Release 2016a)
September 2016 Online only Revised for MATLAB 9.1 (Release 2016b)
March 2017 Online only Revised for MATLAB 9.2 (Release 2017a)
September 2017 Online only Revised for MATLAB 9.3 (Release 2017b)
March 2018 Online only Revised for MATLAB 9.4 (Release 2018a)
September 2018 Online only Revised for MATLAB 9.5 (Release 2018b)
March 2019 Online only Revised for MATLAB 9.6 (Release 2019a)
September 2019 Online only Revised for MATLAB 9.7 (Release 2019b)
March 2020 Online only Revised for MATLAB 9.8 (Release 2020a)
September 2020 Online only Revised for MATLAB 9.9 (Release 2020b)
March 2021 Online only Revised for MATLAB 9.10 (Release 2021a)
September 2021 Online only Revised for MATLAB 9.11 (Release 2021b)
March 2022 Online only Revised for MATLAB 9.12 (Release 2022a)
September 2022 Online only Revised for MATLAB 9.13 (Release 2022b)
March 2023 Online only Revised for MATLAB 9.14 (Release 2023a)
Contents

Matrices and Arrays


1
Creating, Concatenating, and Expanding Matrices . . . . . . . . . . . . . . . . . . 1-2

Removing Rows or Columns from a Matrix . . . . . . . . . . . . . . . . . . . . . . . . . 1-8

Reshaping and Rearranging Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

Multidimensional Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-14

Array Indexing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-21

Linear Algebra
2
Matrices in the MATLAB Environment . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Creating Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Adding and Subtracting Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Vector Products and Transpose . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Multiplying Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5
Identity Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Matrix Inverse . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Kronecker Tensor Product . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Vector and Matrix Norms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8
Using Multithreaded Computation with Linear Algebra Functions . . . . . . . 2-9

Systems of Linear Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10


Computational Considerations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10
General Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Square Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11
Overdetermined Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-13
Underdetermined Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-15
Solving for Several Right-Hand Sides . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-17
Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18
Multithreaded Computation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18

Factorizations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
Cholesky Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-20
LU Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-21
QR Factorization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-22
Using Multithreaded Computation for Factorization . . . . . . . . . . . . . . . . 2-25

v
Powers and Exponentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-26

Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Eigenvalue Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-30
Multiple Eigenvalues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31
Schur Decomposition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-31

Singular Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-33


Batched SVD Calculation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35
Low-Rank SVD Approximations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-35

LAPACK in MATLAB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37


A Brief History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-37

Matrix Exponentials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-38

Graphical Comparison of Exponential Functions . . . . . . . . . . . . . . . . . . . 2-42

Basic Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-46

Determine Whether Matrix Is Symmetric Positive Definite . . . . . . . . . . . 2-54

Image Compression with Low-Rank SVD . . . . . . . . . . . . . . . . . . . . . . . . . . 2-56

Random Numbers
3
Why Do Random Numbers Repeat After Startup? . . . . . . . . . . . . . . . . . . . 3-2

Create Arrays of Random Numbers ............................... 3-3


Random Number Functions . . . . ............................... 3-3
Random Number Generators . . . ............................... 3-4
Random Number Data Types . . . ............................... 3-4

Random Numbers Within a Specific Range . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

Random Integers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-7

Random Numbers from Normal Distribution with Specific Mean and


Variance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8

Random Numbers Within a Sphere . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9

Generate Random Numbers That Are Repeatable . . . . . . . . . . . . . . . . . . 3-11


Specify the Seed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11
Save and Restore the Generator Settings . . . . . . . . . . . . . . . . . . . . . . . . 3-12

Generate Random Numbers That Are Different . . . . . . . . . . . . . . . . . . . . 3-14

Managing the Global Stream Using RandStream . . . . . . . . . . . . . . . . . . . 3-16

vi Contents
Creating and Controlling a Random Number Stream . . . . . . . . . . . . . . . 3-19
Substreams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19
Choosing a Random Number Generator . . . . . . . . . . . . . . . . . . . . . . . . . 3-21
Configuring a Stream . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
Restore State of Random Number Generator to Reproduce Output . . . . . 3-25

Multiple Streams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-28

Replace Discouraged Syntaxes of rand and randn . . . . . . . . . . . . . . . . . . 3-32


Description of the Discouraged Syntaxes . . . . . . . . . . . . . . . . . . . . . . . . 3-32
Description of Replacement Syntaxes . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-32
Replacement Syntaxes for Initializing the Generator with an Integer Seed
..................................................... 3-33
Replacement Syntaxes for Initializing the Generator with a State Vector
..................................................... 3-34
If You Are Unable to Upgrade from Discouraged Syntax . . . . . . . . . . . . . 3-34

Controlling Random Number Generation . . . . . . . . . . . . . . . . . . . . . . . . . 3-36

Sparse Matrices
4
Computational Advantages of Sparse Matrices . . . . . . . . . . . . . . . . . . . . . 4-2
Memory Management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2
Computational Efficiency . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

Constructing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4


Creating Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Importing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-7

Accessing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8


Nonzero Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-8
Indices and Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
Indexing in Sparse Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-9
Visualizing Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12

Sparse Matrix Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14


Efficiency of Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
Permutations and Reordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-14
Factoring Sparse Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-17
Eigenvalues and Singular Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-26

Finite Difference Laplacian . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28

Graphical Representation of Sparse Matrices . . . . . . . . . . . . . . . . . . . . . 4-32

Graphs and Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38

Sparse Matrix Reordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44

vii
Iterative Methods for Linear Systems . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56
Direct vs. Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56
Generic Iterative Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-57
Summary of Iterative Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-57
Choosing an Iterative Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59
Preconditioners . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-60
Equilibration and Reordering . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-62
Using Linear Operators Instead of Matrices . . . . . . . . . . . . . . . . . . . . . . 4-64
References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-64

Graph and Network Algorithms


5
Directed and Undirected Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
What Is a Graph? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
Creating Graphs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-5
Graph Node IDs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8
Modify or Query Existing Graph . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-8

Modify Nodes and Edges of Existing Graph . . . . . . . . . . . . . . . . . . . . . . . 5-10

Add Graph Node Names, Edge Weights, and Other Attributes . . . . . . . . 5-13

Graph Plotting and Customization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-17

Visualize Breadth-First and Depth-First Search . . . . . . . . . . . . . . . . . . . . 5-28

Partition Graph with Laplacian Matrix . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-33

Add Node Properties to Graph Plot Data Tips . . . . . . . . . . . . . . . . . . . . . . 5-36

Build Watts-Strogatz Small World Graph Model . . . . . . . . . . . . . . . . . . . . 5-41

Use PageRank Algorithm to Rank Websites . . . . . . . . . . . . . . . . . . . . . . . 5-48

Label Graph Nodes and Edges . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-55

Functions of One Variable


6
Create and Evaluate Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2

Roots of Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4


Numeric Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Roots Using Substitution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
Roots in a Specific Interval . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-5
Symbolic Roots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-7

Integrate and Differentiate Polynomials . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9

viii Contents
Polynomial Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11

Predicting the US Population . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-13

Roots of Scalar Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-18

Computational Geometry
7
Triangulation Representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
2-D and 3-D Domains . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2
Triangulation Matrix Format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Querying Triangulations Using the triangulation Class . . . . . . . . . . . . . . . 7-4

Working with Delaunay Triangulations . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14


Definition of Delaunay Triangulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-14
Creating Delaunay Triangulations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-15
Triangulation of Point Sets Containing Duplicate Locations . . . . . . . . . . . 7-35

Creating and Editing Delaunay Triangulations . . . . . . . . . . . . . . . . . . . . . 7-38

Spatial Searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-53

Voronoi Diagrams . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-58


Plot 2-D Voronoi Diagram and Delaunay Triangulation . . . . . . . . . . . . . . 7-58
Computing the Voronoi Diagram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-61

Types of Region Boundaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65


Convex Hulls vs. Nonconvex Polygons . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-65
Alpha Shapes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-67

Computing the Convex Hull . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-71


Computing the Convex Hull Using convhull and convhulln . . . . . . . . . . . 7-71
Convex Hull Computation Using the delaunayTriangulation Class . . . . . . 7-74
Convex Hull Computation Using alphaShape . . . . . . . . . . . . . . . . . . . . . 7-75

Interpolation
8
Gridded and Scattered Sample Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Interpolation versus Curve Fitting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2
Grid Approximation Techniques . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3

Interpolating Gridded Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5


MATLAB Gridded Interpolation Functions . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Grid Representations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-5
Example: Temperature Interpolation on 2-D Grid . . . . . . . . . . . . . . . . . . . 8-8
Gridded Interpolation Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10

ix
Interpolation of Multiple 1-D Value Sets . . . . . . . . . . . . . . . . . . . . . . . . . . 8-13

Interpolation of 2-D Selections in 3-D Grids . . . . . . . . . . . . . . . . . . . . . . . 8-15

Interpolating Scattered Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17


Scattered Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-17
Interpolating Scattered Data Using griddata and griddatan . . . . . . . . . . 8-20
scatteredInterpolant Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-22
Interpolating Scattered Data Using the scatteredInterpolant Class . . . . . 8-23
Interpolation of Complex Scattered Data . . . . . . . . . . . . . . . . . . . . . . . . 8-30
Addressing Problems in Scattered Data Interpolation . . . . . . . . . . . . . . . 8-32

Interpolation Using a Specific Delaunay Triangulation . . . . . . . . . . . . . . 8-41


Nearest-Neighbor Interpolation Using a delaunayTriangulation Query . . 8-41
Linear Interpolation Using a delaunayTriangulation Query . . . . . . . . . . . 8-42

Extrapolating Scattered Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-44


Factors That Affect the Accuracy of Extrapolation . . . . . . . . . . . . . . . . . . 8-44
Compare Extrapolation of Coarsely and Finely Sampled Scattered Data
..................................................... 8-44
Extrapolation of 3-D Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-48

Normalize Data with Differing Magnitudes . . . . . . . . . . . . . . . . . . . . . . . . 8-50

Resample Image with Gridded Interpolation . . . . . . . . . . . . . . . . . . . . . . 8-53

Optimization
9
Optimizing Nonlinear Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Minimizing Functions of One Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2
Minimizing Functions of Several Variables . . . . . . . . . . . . . . . . . . . . . . . . 9-3
Maximizing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4
fminsearch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-4
Reference . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-6

Curve Fitting via Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7

Set Optimization Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-10


How to Set Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-10
Options Table . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-10
Tolerances and Stopping Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-11
Output Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12

Optimization Solver Iterative Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13

Optimization Solver Output Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14


What Is an Output Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14
Creating and Using an Output Function . . . . . . . . . . . . . . . . . . . . . . . . . 9-14
Structure of the Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15
Example of a Nested Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-16
Fields in optimValues . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17

x Contents
States of the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-17
Stop Flag . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-18

Optimization Solver Plot Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20


What Is a Plot Function? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20
Example: Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-20

Optimize Live Editor Task . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-22


What Is the Optimize Live Editor Task? . . . . . . . . . . . . . . . . . . . . . . . . . . 9-22
Minimize a Nonlinear Function of Several Variables . . . . . . . . . . . . . . . . 9-23
Solve a Scalar Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-25

Optimization Troubleshooting and Tips . . . . . . . . . . . . . . . . . . . . . . . . . . 9-28

Function Handles
10
Parameterizing Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Parameterizing Using Nested Functions . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Parameterizing Using Anonymous Functions . . . . . . . . . . . . . . . . . . . . . . 10-3

Ordinary Differential Equations (ODEs)


11
Choose an ODE Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Ordinary Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Types of ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Systems of ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
Higher-Order ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-3
Complex ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-4
Basic Solver Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
Summary of ODE Examples and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7

Summary of ODE Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10


Options Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10
Compatibility of Options with Each Solver . . . . . . . . . . . . . . . . . . . . . . 11-10
Usage Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-12

ODE Event Location . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13


What is Event Location? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13
Writing an Event Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-13
Event Information . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14
Limitations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-14
Simple Event Location: A Bouncing Ball . . . . . . . . . . . . . . . . . . . . . . . . 11-14
Advanced Event Location: Restricted Three Body Problem . . . . . . . . . . 11-15

Solve Nonstiff ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-19

xi
Solve Stiff ODEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-23

Solve Differential Algebraic Equations (DAEs) . . . . . . . . . . . . . . . . . . . . 11-30


What is a Differential Algebraic Equation? . . . . . . . . . . . . . . . . . . . . . . 11-30
Consistent Initial Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-31
Differential Index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-31
Imposing Nonnegativity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-32
Solve Robertson Problem as Semi-Explicit Differential Algebraic Equations
(DAEs) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-32

Nonnegative ODE Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-35

Troubleshoot Common ODE Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-38


Error Tolerances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-38
Problem Scale . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-39
Solution Components . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-40
Problem Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-42

Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-43

Solve Predator-Prey Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-52

Solve Equations of Motion for Baton Thrown into Air . . . . . . . . . . . . . . 11-56

Solve ODE with Strongly State-Dependent Mass Matrix . . . . . . . . . . . . 11-62

Solve Stiff Transistor Differential Algebraic Equation . . . . . . . . . . . . . . 11-75

Solve System of ODEs with Multiple Initial Conditions . . . . . . . . . . . . . 11-80

Solve Celestial Mechanics Problem with High-Order Solvers . . . . . . . . 11-88

Boundary Value Problems (BVPs)


12
Solving Boundary Value Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
Boundary Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-2
Initial Guess of Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-3
Finding Unknown Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-3
Singular BVPs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-4
BVP Solver Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-4
Evaluating the Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-5
BVP Examples and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-6

Solve BVP with Two Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-8

Solve BVP with Unknown Parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-11

Solve BVP Using Continuation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-15

Verify BVP Consistency Using Continuation . . . . . . . . . . . . . . . . . . . . . . 12-20

xii Contents
Solve BVP with Singular Term . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-25

Solve BVP with Multiple Boundary Conditions . . . . . . . . . . . . . . . . . . . . 12-29

Partial Differential Equations (PDEs)


13
Solving Partial Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
What Types of PDEs Can You Solve with MATLAB? . . . . . . . . . . . . . . . . . 13-2
Solving 1-D PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-2
Example: The Heat Equation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-5
PDE Examples and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-8

Solve Single PDE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-9

Solve PDE with Discontinuity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-16

Solve PDE and Compute Partial Derivatives . . . . . . . . . . . . . . . . . . . . . . 13-23

Solve System of PDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-32

Solve System of PDEs with Initial Condition Step Functions . . . . . . . . 13-39

Delay Differential Equations (DDEs)


14
Solving Delay Differential Equations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
Constant Delay DDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
Time-Dependent and State-Dependent DDEs . . . . . . . . . . . . . . . . . . . . . 14-2
DDEs of Neutral Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-2
Evaluating the Solution at Specific Points . . . . . . . . . . . . . . . . . . . . . . . . 14-3
History and Initial Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-3
Discontinuities in DDEs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-3
Propagation of Discontinuities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-4
DDE Examples and Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-4

DDE with Constant Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-6

DDE with State-Dependent Delays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-10

Cardiovascular Model DDE with Discontinuities . . . . . . . . . . . . . . . . . . 14-14

DDE of Neutral Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-19

Initial Value DDE of Neutral Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-23

xiii
Numerical Integration
15
Integration to Find Arc Length . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2

Complex Line Integrals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-3

Singularity on Interior of Integration Domain . . . . . . . . . . . . . . . . . . . . . 15-5

Analytic Solution to Integral of Polynomial . . . . . . . . . . . . . . . . . . . . . . . 15-7

Integration of Numeric Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-8

Calculate Tangent Plane to Surface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-12

Fourier Transforms
16
Fourier Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-2

Basic Spectral Analysis . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-10


Spectral Analysis Quantities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-10
Noisy Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-10
Audio Signal . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-12

Polynomial Interpolation Using FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-16


FFT in Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-16
Interpolate Asteroid Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-16

2-D Fourier Transforms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-19


Two-Dimensional Fourier Transform . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-19
2-D Diffraction Pattern . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-19

Square Wave from Sine Waves . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-23

Analyzing Cyclical Data with FFT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-28

Gate-Based Quantum Algorithms


17
Introduction to Quantum Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
Qubit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2
Quantum Gate . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-9
Quantum Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-11
Helper Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-16

Types of Quantum Gates . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-18


Creation Functions for SimpleGate Objects . . . . . . . . . . . . . . . . . . . . . . 17-18

xiv Contents
Creation Functions for CompositeGate Objects . . . . . . . . . . . . . . . . . . . 17-22

Local Quantum State Simulation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-25


Create Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-25
Simulate Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-25
Display State Formula . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-26
Plot Possible States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-27
Query Possible States . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-27
Query Qubit State Probabilities . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-27
Simulate Quantum State Measurement . . . . . . . . . . . . . . . . . . . . . . . . . 17-28

Run Quantum Circuit on Hardware Using AWS . . . . . . . . . . . . . . . . . . . 17-29


Requirements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-29
Set Up Access to AWS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-29
Device Availability . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-30
Connect to Quantum Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-31
Create Task to Run Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-31
Fetch Measurement Output . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-32

Graph Coloring with Grover's Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 17-34


Create State Oracle for Graph Coloring Problem . . . . . . . . . . . . . . . . . 17-34
Create Diffuser Circuit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-38
Apply Grover's Algorithm to Graph Coloring Oracle . . . . . . . . . . . . . . . 17-39
Run Circuit on AWS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-42

Ground-State Protein Folding Using Variational Quantum Eigensolver


(VQE) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-45
Model Protein Fold with Qubits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-45
Write Function to Calculate Energy of Folds . . . . . . . . . . . . . . . . . . . . . 17-46
Compute Minimum Energy for All Folds . . . . . . . . . . . . . . . . . . . . . . . . 17-48
Write CVaR-VQE Objective Function . . . . . . . . . . . . . . . . . . . . . . . . . . 17-48
Create Circuit Ansatz . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-49
Simulate Iterations of CVaR-VQE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-50
Run Final Iteration on QPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-54

xv
1

Matrices and Arrays

• “Creating, Concatenating, and Expanding Matrices” on page 1-2


• “Removing Rows or Columns from a Matrix” on page 1-8
• “Reshaping and Rearranging Arrays” on page 1-9
• “Multidimensional Arrays” on page 1-14
• “Array Indexing” on page 1-21
1 Matrices and Arrays

Creating, Concatenating, and Expanding Matrices

The most basic MATLAB® data structure is the matrix. A matrix is a two-dimensional, rectangular
array of data elements arranged in rows and columns. The elements can be numbers, logical values
(true or false), dates and times, strings, categorical values, or some other MATLAB data type.

Even a single number is stored as a matrix. For example, a variable containing the value 100 is stored
as a 1-by-1 matrix of type double.

A = 100;
whos A

Name Size Bytes Class Attributes

A 1x1 8 double

Constructing a Matrix of Data

If you have a specific set of data, you can arrange the elements in a matrix using square brackets. A
single row of data has spaces or commas in between the elements, and a semicolon separates the
rows. For example, create a single row of four numeric elements. The size of the resulting matrix is 1-
by-4 because it has one row and four columns. A matrix of this shape is often referred to as a row
vector.

A = [12 62 93 -8]

A = 1×4

12 62 93 -8

sz = size(A)

sz = 1×2

1 4

Now create a matrix with the same numbers, but arrange them in two rows. This matrix has two rows
and two columns.

A = [12 62; 93 -8]

A = 2×2

12 62
93 -8

sz = size(A)

sz = 1×2

2 2

1-2
Creating, Concatenating, and Expanding Matrices

Specialized Matrix Functions

MATLAB has many functions that help create matrices with certain values or a particular structure.
For example, the zeros and ones functions create matrices of all zeros or all ones. The first and
second arguments of these functions are the number of rows and number of columns of the matrix,
respectively.
A = zeros(3,2)

A = 3×2

0 0
0 0
0 0

B = ones(2,4)

B = 2×4

1 1 1 1
1 1 1 1

The diag function places the input elements on the diagonal of a matrix. For example, create a row
vector A containing four elements. Then, create a 4-by-4 matrix whose diagonal elements are the
elements of A.
A = [12 62 93 -8];
B = diag(A)

B = 4×4

12 0 0 0
0 62 0 0
0 0 93 0
0 0 0 -8

Concatenating Matrices

You can also use square brackets to append existing matrices. This way of creating a matrix is called
concatenation. For example, concatenate two row vectors to make an even longer row vector.
A = ones(1,4);
B = zeros(1,4);
C = [A B]

C = 1×8

1 1 1 1 0 0 0 0

To arrange A and B as two rows of a matrix, use the semicolon.


D = [A; B]

D = 2×4

1-3
1 Matrices and Arrays

1 1 1 1
0 0 0 0

To concatenate several matrices, they must have compatible sizes. In other words, when you
concatenate matrices horizontally, they must have the same number of rows. When you concatenate
them vertically, they must have the same number of columns.

For example, create two matrices that both have two rows. Horizontally append the second matrix to
the first by using square brackets.

A = ones(2,3)

A = 2×3

1 1 1
1 1 1

B = zeros(2,2)

B = 2×2

0 0
0 0

C = [A B]

C = 2×5

1 1 1 0 0
1 1 1 0 0

An alternative way to concatenate compatible matrices is to use concatenation functions, such as


horzcat, vertcat, and cat. Horizontally append the second matrix to the first by using horzcat.

D = horzcat(A,B)

D = 2×5

1 1 1 0 0
1 1 1 0 0

Generating a Numeric Sequence

The colon is a handy way to create matrices whose elements are sequential and evenly spaced. For
example, create a row vector whose elements are the integers from 1 to 10.

A = 1:10

A = 1×10

1 2 3 4 5 6 7 8 9 10

1-4
Creating, Concatenating, and Expanding Matrices

You can use the colon operator to create a sequence of numbers within any range, incremented by
one.

A = -2.5:2.5

A = 1×6

-2.5000 -1.5000 -0.5000 0.5000 1.5000 2.5000

To change the value of the sequence increment, specify the increment value in between the starting
and ending range values, separated by colons.

A = 0:2:10

A = 1×6

0 2 4 6 8 10

To decrement, use a negative number.

A = 6:-1:0

A = 1×7

6 5 4 3 2 1 0

You can also increment by noninteger values. If an increment value does not evenly partition the
specified range, MATLAB automatically ends the sequence at the last value it can reach before
exceeding the range.

A = 1:0.2:2.1

A = 1×6

1.0000 1.2000 1.4000 1.6000 1.8000 2.0000

Expanding a Matrix

You can add one or more elements to a matrix by placing them outside of the existing row and column
index boundaries. MATLAB automatically pads the matrix with zeros to keep it rectangular. For
example, create a 2-by-3 matrix and add an additional row and column to it by inserting an element in
the (3,4) position.

A = [10 20 30; 60 70 80]

A = 2×3

10 20 30
60 70 80

A(3,4) = 1

A = 3×4

1-5
1 Matrices and Arrays

10 20 30 0
60 70 80 0
0 0 0 1

You can also expand the size by inserting a new matrix outside of the existing index ranges.

A(4:5,5:6) = [2 3; 4 5]

A = 5×6

10 20 30 0 0 0
60 70 80 0 0 0
0 0 0 1 0 0
0 0 0 0 2 3
0 0 0 0 4 5

To expand the size of a matrix repeatedly, such as within a for loop, it is a best practice to
preallocate space for the largest matrix you anticipate creating. Without preallocation, MATLAB has
to allocate memory every time the size increases, slowing down operations. For example, preallocate
a matrix that holds up to 10,000 rows and 10,000 columns by initializing its elements to zero.

A = zeros(10000,10000);

If you need to preallocate additional elements later, you can expand it by assigning outside of the
matrix index ranges or concatenate another preallocated matrix to A.

Empty Arrays

An empty array in MATLAB is an array with at least one dimension length equal to zero. Empty arrays
are useful for representing the concept of "nothing" programmatically. For example, suppose you
want to find all elements of a vector that are less than 0, but there are none. The find function
returns an empty vector of indices, indicating that it did not find any elements less than 0.

A = [1 2 3 4];
ind = find(A<0)

ind =

1x0 empty double row vector

Many algorithms contain function calls that can return empty arrays. It is often useful to allow empty
arrays to flow through these algorithms as function arguments instead of handling them as a special
case. If you do need to customize empty array handling, you can check for them using the isempty
function.

TF = isempty(ind)

1-6
Creating, Concatenating, and Expanding Matrices

TF = logical
1

See Also

Related Examples
• “Array Indexing” on page 1-21
• “Reshaping and Rearranging Arrays” on page 1-9
• “Multidimensional Arrays” on page 1-14
• “Create String Arrays”
• “Represent Dates and Times in MATLAB”

1-7
1 Matrices and Arrays

Removing Rows or Columns from a Matrix

The easiest way to remove a row or column from a matrix is to set that row or column equal to a pair
of empty square brackets []. For example, create a 4-by-4 matrix and remove the second row.

A = magic(4)

A = 4×4

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

A(2,:) = []

A = 3×4

16 2 3 13
9 7 6 12
4 14 15 1

Now remove the third column.

A(:,3) = []

A = 3×3

16 2 13
9 7 12
4 14 1

You can extend this approach to any array. For example, create a random 3-by-3-by-3 array and
remove all of the elements in the first matrix of the third dimension.

B = rand(3,3,3);
B(:,:,1) = [];

See Also

Related Examples
• “Reshaping and Rearranging Arrays” on page 1-9
• “Array Indexing” on page 1-21

1-8
Reshaping and Rearranging Arrays

Reshaping and Rearranging Arrays

Many functions in MATLAB® can take the elements of an existing array and put them in a different
shape or sequence. This can be helpful for preprocessing your data for subsequent computations or
analyzing the data.

Reshaping

The reshape function changes the size and shape of an array. For example, reshape a 3-by-4 matrix
to a 2-by-6 matrix.
A = [1 4 7 10; 2 5 8 11; 3 6 9 12]

A = 3×4

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

B = reshape(A,2,6)

B = 2×6

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

As long as the number of elements in each shape are the same, you can reshape them into an array
with any number of dimensions. Using the elements from A, create a 2-by-2-by-3 multidimensional
array.
C = reshape(A,2,2,3)

C =
C(:,:,1) =

1 3
2 4

C(:,:,2) =

5 7
6 8

C(:,:,3) =

9 11
10 12

Transposing and Flipping

A common task in linear algebra is to work with the transpose of a matrix, which turns the rows into
columns and the columns into rows. To do this, use the transpose function or the .' operator.

1-9
1 Matrices and Arrays

Create a 3-by-3 matrix and compute its transpose.


A = magic(3)

A = 3×3

8 1 6
3 5 7
4 9 2

B = A.'

B = 3×3

8 3 4
1 5 9
6 7 2

A similar operator ' computes the conjugate transpose for complex matrices. This operation
computes the complex conjugate of each element and transposes it. Create a 2-by-2 complex matrix
and compute its conjugate transpose.
A = [1+i 1-i; -i i]

A = 2×2 complex

1.0000 + 1.0000i 1.0000 - 1.0000i


0.0000 - 1.0000i 0.0000 + 1.0000i

B = A'

B = 2×2 complex

1.0000 - 1.0000i 0.0000 + 1.0000i


1.0000 + 1.0000i 0.0000 - 1.0000i

flipud flips the rows of a matrix in an up-to-down direction, and fliplr flips the columns in a left-
to-right direction.
A = [1 2; 3 4]

A = 2×2

1 2
3 4

B = flipud(A)

B = 2×2

3 4
1 2

C = fliplr(A)

1-10
Reshaping and Rearranging Arrays

C = 2×2

2 1
4 3

Shifting and Rotating

You can shift elements of an array by a certain number of positions using the circshift function.
For example, create a 3-by-4 matrix and shift its columns to the right by 2. The second argument [0
2] tells circshift to shift the rows 0 places and shift the columns 2 places to the right.

A = [1 2 3 4; 5 6 7 8; 9 10 11 12]

A = 3×4

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

B = circshift(A,[0 2])

B = 3×4

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

To shift the rows of A up by 1 and keep the columns in place, specify the second argument as [-1 0].

C = circshift(A,[-1 0])

C = 3×4

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

The rot90 function can rotate a matrix counterclockwise by 90 degrees.

A = [1 2; 3 4]

A = 2×2

1 2
3 4

B = rot90(A)

B = 2×2

2 4
1 3

1-11
1 Matrices and Arrays

If you rotate 3 more times by using the second argument to specify the number of rotations, you end
up with the original matrix A.

C = rot90(B,3)

C = 2×2

1 2
3 4

Sorting

Sorting the data in an array is also a valuable tool, and MATLAB offers a number of approaches. For
example, the sort function sorts the elements of each row or column of a matrix separately in
ascending or descending order. Create a matrix A and sort each column of A in ascending order.

A = magic(4)

A = 4×4

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

B = sort(A)

B = 4×4

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

Sort each row in descending order. The second argument value 2 specifies that you want to sort row-
wise.

C = sort(A,2,'descend')

C = 4×4

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

To sort entire rows or columns relative to each other, use the sortrows function. For example, sort
the rows of A in ascending order according to the elements in the first column. The positions of the
rows change, but the order of the elements in each row are preserved.

D = sortrows(A)

D = 4×4

4 14 15 1

1-12
Reshaping and Rearranging Arrays

5 11 10 8
9 7 6 12
16 2 3 13

See Also

Related Examples
• “Removing Rows or Columns from a Matrix” on page 1-8
• “Array Indexing” on page 1-21

1-13
1 Matrices and Arrays

Multidimensional Arrays

A multidimensional array in MATLAB® is an array with more than two dimensions. In a matrix, the
two dimensions are represented by rows and columns.

Each element is defined by two subscripts, the row index and the column index. Multidimensional
arrays are an extension of 2-D matrices and use additional subscripts for indexing. A 3-D array, for
example, uses three subscripts. The first two are just like a matrix, but the third dimension
represents pages or sheets of elements.

Creating Multidimensional Arrays

You can create a multidimensional array by creating a 2-D matrix first, and then extending it. For
example, first define a 3-by-3 matrix as the first page in a 3-D array.
A = [1 2 3; 4 5 6; 7 8 9]

A = 3×3

1 2 3
4 5 6
7 8 9

Now add a second page. To do this, assign another 3-by-3 matrix to the index value 2 in the third
dimension. The syntax A(:,:,2) uses a colon in the first and second dimensions to include all rows
and all columns from the right-hand side of the assignment.
A(:,:,2) = [10 11 12; 13 14 15; 16 17 18]

A =
A(:,:,1) =

1-14
Multidimensional Arrays

1 2 3
4 5 6
7 8 9

A(:,:,2) =

10 11 12
13 14 15
16 17 18

The cat function can be a useful tool for building multidimensional arrays. For example, create a new
3-D array B by concatenating A with a third page. The first argument indicates which dimension to
concatenate along.

B = cat(3,A,[3 2 1; 0 9 8; 5 3 7])

B =
B(:,:,1) =

1 2 3
4 5 6
7 8 9

B(:,:,2) =

10 11 12
13 14 15
16 17 18

B(:,:,3) =

3 2 1
0 9 8
5 3 7

Another way to quickly expand a multidimensional array is by assigning a single element to an entire
page. For example, add a fourth page to B that contains all zeros.

B(:,:,4) = 0

B =
B(:,:,1) =

1 2 3
4 5 6
7 8 9

B(:,:,2) =

10 11 12
13 14 15

1-15
1 Matrices and Arrays

16 17 18

B(:,:,3) =

3 2 1
0 9 8
5 3 7

B(:,:,4) =

0 0 0
0 0 0
0 0 0

Accessing Elements

To access elements in a multidimensional array, use integer subscripts just as you would for vectors
and matrices. For example, find the 1,2,2 element of A, which is in the first row, second column, and
second page of A.
A

A =
A(:,:,1) =

1 2 3
4 5 6
7 8 9

A(:,:,2) =

10 11 12
13 14 15
16 17 18

elA = A(1,2,2)

elA = 11

Use the index vector [1 3] in the second dimension to access only the first and last columns of each
page of A.
C = A(:,[1 3],:)

C =
C(:,:,1) =

1 3
4 6
7 9

C(:,:,2) =

1-16
Multidimensional Arrays

10 12
13 15
16 18

To find the second and third rows of each page, use the colon operator to create your index vector.

D = A(2:3,:,:)

D =
D(:,:,1) =

4 5 6
7 8 9

D(:,:,2) =

13 14 15
16 17 18

Manipulating Arrays

Elements of multidimensional arrays can be moved around in many ways, similar to vectors and
matrices. reshape, permute, and squeeze are useful functions for rearranging elements. Consider
a 3-D array with two pages.

Reshaping a multidimensional array can be useful for performing certain operations or visualizing the
data. Use the reshape function to rearrange the elements of the 3-D array into a 6-by-5 matrix.

A = [1 2 3 4 5; 9 0 6 3 7; 8 1 5 0 2];
A(:,:,2) = [9 7 8 5 2; 3 5 8 5 1; 6 9 4 3 3];
B = reshape(A,[6 5])

B = 6×5

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

reshape operates columnwise, creating the new matrix by taking consecutive elements down each
column of A, starting with the first page then moving to the second page.

Permutations are used to rearrange the order of the dimensions of an array. Consider a 3-D array M.

1-17
1 Matrices and Arrays

M(:,:,1) = [1 2 3; 4 5 6; 7 8 9];
M(:,:,2) = [0 5 4; 2 7 6; 9 3 1]

M =
M(:,:,1) =

1 2 3
4 5 6
7 8 9

M(:,:,2) =

0 5 4
2 7 6
9 3 1

Use the permute function to interchange row and column subscripts on each page by specifying the
order of dimensions in the second argument. The original rows of M are now columns, and the
columns are now rows.
P1 = permute(M,[2 1 3])

P1 =
P1(:,:,1) =

1 4 7
2 5 8
3 6 9

P1(:,:,2) =

0 2 9
5 7 3
4 6 1

Similarly, interchange row and page subscripts of M.


P2 = permute(M,[3 2 1])

P2 =
P2(:,:,1) =

1 2 3
0 5 4

P2(:,:,2) =

4 5 6
2 7 6

P2(:,:,3) =

7 8 9

1-18
Multidimensional Arrays

9 3 1

When working with multidimensional arrays, you might encounter one that has an unnecessary
dimension of length 1. The squeeze function performs another type of manipulation that eliminates
dimensions of length 1. For example, use the repmat function to create a 2-by-3-by-1-by-4 array
whose elements are each 5, and whose third dimension has length 1.

A = repmat(5,[2 3 1 4])

A =
A(:,:,1,1) =

5 5 5
5 5 5

A(:,:,1,2) =

5 5 5
5 5 5

A(:,:,1,3) =

5 5 5
5 5 5

A(:,:,1,4) =

5 5 5
5 5 5

szA = size(A)

szA = 1×4

2 3 1 4

numdimsA = ndims(A)

numdimsA = 4

Use the squeeze function to remove the third dimension, resulting in a 3-D array.

B = squeeze(A)

B =
B(:,:,1) =

5 5 5
5 5 5

B(:,:,2) =

1-19
1 Matrices and Arrays

5 5 5
5 5 5

B(:,:,3) =

5 5 5
5 5 5

B(:,:,4) =

5 5 5
5 5 5

szB = size(B)

szB = 1×3

2 3 4

numdimsB = ndims(B)

numdimsB = 3

See Also

Related Examples
• “Creating, Concatenating, and Expanding Matrices” on page 1-2
• “Array Indexing” on page 1-21
• “Reshaping and Rearranging Arrays” on page 1-9

1-20
Array Indexing

Array Indexing

In MATLAB®, there are three primary approaches to accessing array elements based on their
location (index) in the array. These approaches are indexing by position, linear indexing, and logical
indexing.

Indexing with Element Positions

The most common way is to explicitly specify the indices of the elements. For example, to access a
single element of a matrix, specify the row number followed by the column number of the element.

A = [1 2 3 4; 5 6 7 8; 9 10 11 12; 13 14 15 16]

A = 4×4

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

e = A(3,2)

e = 10

e is the element in the 3,2 position (third row, second column) of A.

You can also reference multiple elements at a time by specifying their indices in a vector. For
example, access the first and third elements of the second row of A.

r = A(2,[1 3])

r = 1×2

5 7

To access elements in a range of rows or columns, use the colon. For example, access the elements
in the first through third row and the second through fourth column of A.

r = A(1:3,2:4)

r = 3×3

2 3 4
6 7 8
10 11 12

An alternative way to compute r is to use the keyword end to specify the second column through the
last column. This approach lets you specify the last column without knowing exactly how many
columns are in A.

r = A(1:3,2:end)

r = 3×3

1-21
1 Matrices and Arrays

2 3 4
6 7 8
10 11 12

If you want to access all of the rows or columns, use the colon operator by itself. For example, return
the entire third column of A.

r = A(:,3)

r = 4×1

3
7
11
15

In general, you can use indexing to access elements of any array in MATLAB regardless of its data
type or dimensions. For example, directly access a column of a datetime array.

t = [datetime(2018,1:5,1); datetime(2019,1:5,1)]

t = 2x5 datetime
01-Jan-2018 01-Feb-2018 01-Mar-2018 01-Apr-2018 01-May-2018
01-Jan-2019 01-Feb-2019 01-Mar-2019 01-Apr-2019 01-May-2019

march1 = t(:,3)

march1 = 2x1 datetime


01-Mar-2018
01-Mar-2019

For higher-dimensional arrays, expand the syntax to match the array dimensions. Consider a random
3-by-3-by-3 numeric array. Access the element in the second row, third column, and first sheet of the
array.

A = rand(3,3,3);
e = A(2,3,1)

e = 0.5469

For more information on working with multidimensional arrays, see “Multidimensional Arrays” on
page 1-14.

Indexing with a Single Index

Another method for accessing elements of an array is to use only a single index, regardless of the size
or dimensions of the array. This method is known as linear indexing. While MATLAB displays arrays
according to their defined sizes and shapes, they are actually stored in memory as a single column of
elements. A good way to visualize this concept is with a matrix. While the following array is displayed
as a 3-by-3 matrix, MATLAB stores it as a single column made up of the columns of A appended one
after the other. The stored vector contains the sequence of elements 12, 45, 33, 36, 29, 25, 91, 48,
11, and can be displayed using a single colon.

A = [12 36 91; 45 29 48; 33 25 11]

1-22
Array Indexing

A = 3×3

12 36 91
45 29 48
33 25 11

Alinear = A(:)

Alinear = 9×1

12
45
33
36
29
25
91
48
11

For example, the 3,2 element of A is 25, and you can access it using the syntax A(3,2). You can also
access this element using the syntax A(6), since 25 is sixth element of the stored vector sequence.
e = A(3,2)

e = 25

elinear = A(6)

elinear = 25

While linear indexing can be less intuitive visually, it can be powerful for performing certain
computations that are not dependent on the size or shape of the array. For example, you can easily
sum all of the elements of A without having to provide a second argument to the sum function.
s = sum(A(:))

s = 330

The sub2ind and ind2sub functions help to convert between original array indices and their linear
version. For example, compute the linear index of the 3,2 element of A.
linearidx = sub2ind(size(A),3,2)

linearidx = 6

Convert from the linear index back to its row and column form.
[row,col] = ind2sub(size(A),6)

row = 3

col = 2

Indexing with Logical Values

Using true and false logical indicators is another useful way to index into arrays, particularly when
working with conditional statements. For example, say you want to know if the elements of a matrix A

1-23
1 Matrices and Arrays

are less than the corresponding elements of another matrix B. The less-than operator returns a
logical array whose elements are 1 when an element in A is smaller than the corresponding element
in B.

A = [1 2 6; 4 3 6]

A = 2×3

1 2 6
4 3 6

B = [0 3 7; 3 7 5]

B = 2×3

0 3 7
3 7 5

ind = A<B

ind = 2x3 logical array

0 1 1
0 1 0

Now that you know the locations of the elements meeting the condition, you can inspect the
individual values using ind as the index array. MATLAB matches the locations of the value 1 in ind to
the corresponding elements of A and B, and lists their values in a column vector.

Avals = A(ind)

Avals = 3×1

2
3
6

Bvals = B(ind)

Bvals = 3×1

3
7
7

MATLAB "is" functions also return logical arrays that indicate which elements of the input meet a
certain condition. For example, check which elements of a string vector are missing using the
ismissing function.

str = ["A" "B" missing "D" "E" missing];


ind = ismissing(str)

ind = 1x6 logical array

1-24
Array Indexing

0 0 1 0 0 1

Suppose you want to find the values of the elements that are not missing. Use the ~ operator with the
index vector ind to do this.

strvals = str(~ind)

strvals = 1x4 string


"A" "B" "D" "E"

For more examples using logical indexing, see “Find Array Elements That Meet a Condition”.

See Also

Related Examples
• “Access Data Using Categorical Arrays”
• “Access Data in Tables”
• “Structure Arrays”
• “Access Data in Cell Array”

External Websites
• Programming: Organizing Data (MathWorks Teaching Resources)

1-25
2

Linear Algebra

• “Matrices in the MATLAB Environment” on page 2-2


• “Systems of Linear Equations” on page 2-10
• “Factorizations” on page 2-20
• “Powers and Exponentials” on page 2-26
• “Eigenvalues” on page 2-30
• “Singular Values” on page 2-33
• “LAPACK in MATLAB” on page 2-37
• “Matrix Exponentials” on page 2-38
• “Graphical Comparison of Exponential Functions” on page 2-42
• “Basic Matrix Operations” on page 2-46
• “Determine Whether Matrix Is Symmetric Positive Definite” on page 2-54
• “Image Compression with Low-Rank SVD” on page 2-56
2 Linear Algebra

Matrices in the MATLAB Environment


This topic contains an introduction to creating matrices and performing basic matrix calculations in
MATLAB.

The MATLAB environment uses the term matrix to indicate a variable containing real or complex
numbers arranged in a two-dimensional grid. An array is, more generally, a vector, matrix, or higher
dimensional grid of numbers. All arrays in MATLAB are rectangular, in the sense that the component
vectors along any dimension are all the same length. The mathematical operations defined on
matrices are the subject of linear algebra.

Creating Matrices
MATLAB has many functions that create different kinds of matrices. For example, you can create a
symmetric matrix with entries based on Pascal's triangle:

A = pascal(3)

A =
1 1 1
1 2 3
1 3 6

Or, you can create an unsymmetric magic square matrix, which has equal row and column sums:

B = magic(3)

B =
8 1 6
3 5 7
4 9 2

Another example is a 3-by-2 rectangular matrix of random integers. In this case the first input to
randi describes the range of possible values for the integers, and the second two inputs describe the
number of rows and columns.

C = randi(10,3,2)

C =

9 10
10 7
2 1

A column vector is an m-by-1 matrix, a row vector is a 1-by-n matrix, and a scalar is a 1-by-1 matrix.
To define a matrix manually, use square brackets [ ] to denote the beginning and end of the array.
Within the brackets, use a semicolon ; to denote the end of a row. In the case of a scalar (1-by-1
matrix), the brackets are not required. For example, these statements produce a column vector, a row
vector, and a scalar:

u = [3; 1; 4]

v = [2 0 -1]

s = 7

2-2
Matrices in the MATLAB Environment

u =
3
1
4

v =
2 0 -1

s =
7

For more information about creating and working with matrices, see “Creating, Concatenating, and
Expanding Matrices” on page 1-2.

Adding and Subtracting Matrices


Addition and subtraction of matrices and arrays is performed element-by-element, or element-wise.
For example, adding A to B and then subtracting A from the result recovers B:

X = A + B

X =
9 2 7
4 7 10
5 12 8

Y = X - A

Y =
8 1 6
3 5 7
4 9 2

Addition and subtraction require both matrices to have compatible dimensions. If the dimensions are
incompatible, an error results:

X = A + C

Error using +
Matrix dimensions must agree.

For more information, see “Array vs. Matrix Operations”.

Vector Products and Transpose


A row vector and a column vector of the same length can be multiplied in either order. The result is
either a scalar, called the inner product, or a matrix, called the outer product:

u = [3; 1; 4];
v = [2 0 -1];
x = v*u

x =

X = u*v

2-3
Random documents with unrelated
content Scribd suggests to you:
MIRACLES IN FRUITS.

When a traveller was relating, in Cowper’s presence, some prodigious


marvels, the poet smiled somewhat incredulously. “Well, sir, don’t
you believe me? I saw it with my own eyes.” “Oh, certainly, I believe
it if you saw it, but I would not if I had seen it myself.” Even so we
feel about the thousand and one physiological fooleries which run
the monthly rounds of the papers.
How on earth do men suppose a fruit to receive its characteristic
quality? Is it from the root, trunk, pith, bark, branch, or leaf? One
would think that it made no difference which. We have long
supposed that the leaf digested the sap, returned it to the passages
of distribution to be employed in the formation of fruit, wood, tissue,
etc. Is this the function of the leaf? or have recent investigations
exploded this doctrine? If not, it will be apparent that all grafting of
scions together, cannot change the quality of fruit, unless the leaves
are also amalgamated. Is a red, green, yellow, and white fruit,
sweet, sour, or bitter, be put upon the same tree, each will maintain
its characteristics; because, each bud or scion has its own peculiar
leaves, from whose laboratory the fruit is sweetened or acidulated
and colored with all its hues. To be sure, fruits are affected by the
stock on which they are put; but their characteristic elements are
not altered, but only pushed along in the same line and made more
perfect.
There is no doubt that trees indulge, occasionally, in rare antics. A
sober apple-tree will sometimes let down its dignity, in what
gardeners call a “sport,” e. g. a sweet apple may grow on a sour
tree, and vice versâ. An apple may on one side be sweet and on the
other sour. But, in such cases, the same general law is seen
governing yet. We all know that great changes of temperament
occur in men. A nervous temperament often becomes abdominal,
and a little, wiry, fussy, peevish, minikin, becomes a round, plump,
rosy, corpulent spot of good nature. Similar changes may occur,
through disease, or the peculiarity of the season, or from unknown
causes, in the structure of the leaves of a branch, and then the fruit
will follow the change of the leaf.
But the fruit itself digests still further the elaborated sap sent to it
from the leaf. If, then, from any hidden causes, the fruit should in
part change its structure, the juices elaborated would be altered. If
stamens and pistils may change to petals, if petals may change to
leaves, if leaves may extend to branches, we know of no reason why
the whole or the half of a fruit may not, also, alter its structure; and
with its peculiarity of function, also, of course, the character of the
fruit. While then we are not skeptical of “monsters,” “marvels,”
“sports,” “singularities,” we think we can trace the original law
through all the transmutations.
PROTECTING THE ROOTS OF FRUIT-
TREES.

Cultivators are frequently urged in Horticultural papers to cover the


roots of the peach-trees with heaps of snow, etc., that they may be
retarded in the spring, and escape injury from late frosts upon their
blossoms. This direction takes it for granted that the warmth of the
ground starts the root, and the root starts the sap, and the sap
wakes up the dormant branch. By covering the soil and keeping it
back, the whole tree is supposed to be secured. But, unfortunately
for this process, the motion of the sap is first in the BRANCHES, and
last in the roots. Light and heat, exerted upon the branches for any
considerable length of time, produce a high state of excitability; the
sap begins to move toward the bud, its place is supplied by a portion
lower down, and so on until the whole column of sap through the
trunk is in motion, and last of all in the ROOT. But suppose warm,
spring days, with a temperature of from sixty degrees to sixty-five
degrees, have produced a vigorous motion of the sap in the
branches and trunk, while the root, (thanks to snow and ice piled
over it to keep it frozen), is dormant, what will result? The sap
already within the tree will be exhausted, the root will supply none,
the light and heat still push on the development of bud and leaf and
the tree will exhaust itself and die. We not long since observed a
remarkable confirmation of these reasonings. A gentleman of our
acquaintance, in reading these unskilfull directions to cover the
peach-tree root, opened trenches about his trees, and filled them
with snow, heaping bountifully also all about the trees. The next
spring, long after his trees should have been at work, the snow held
the root fast; the buds swelled and burst, lingered, shrivelled and
died—and the trees too. This might have been prognosticated. There
are partial methods of protecting the peach from too early
development, but they all have respect to the protection of the
limbs. If the branches can be covered during the random and
prematurely hot days of spring, the tree will not suffer. High, and
cool-aired aspects, north hill-sides, northern sides of houses, barns,
etc., will answer this purpose. When it can be afforded, long boards
may be set up upon the east and south sides of choice trees, upon a
frame slightly made and easily removed.
The reason why more damage has not been done by covering
peach-tree roots, than has occurred, is, that the ground has been
superficially frozen, and many of the roots extending deeper and
laterally beyond the congealed portions, have afforded a supply of
sap after a motion had been imparted to it in the branches.
PRUNING GRAPE VINES.

All know that after the sap begins to flow in the spring, a vine, if
cut, will bleed. It seems that at this early period of its development
the sap vessels have no power of contraction. Many suppose that
the same state of things continues throughout the growing season,
and are afraid to cut their vines. But after the vine has begun to
grow freely (when the leaves, for example, are as large as the palm
of one’s hand), a wound very soon contracts, bleeds little or none,
and heals over as in a tree. Any pruning which is necessary upon the
old wound may, therefore, be fearlessly performed.
Some inexpert cultivators, in order to let the sun fall upon the
grapes, pluck off the leaves; hoping thus to procure sweeter grapes.
This is the very way to have acid fruit. Where is the sugar prepared
for the cluster but in these very leaves which are taken off? Without
leaves, the sap which flows into the cluster has undergone but
imperfectly those chemical changes on which the fruit depends.
Every leaf in the neighborhood of the fruit is precious.
MILDEW ON GRAPES.

Many permit the fruit of the vines to perish before their eyes from
the ravages of mildew, ignorant that an effectual remedy is within
their reach. It is simply to dust the branches with flowers of sulphur.
It is best done while the dew is on.
When vines are trained upon the sides of a house or fence, it is well
to whitewash the surfaces on which they are fastened with a wash in
which flowers of sulphur has been largely mixed.
It is recommended by some cultivators to employ such a whitewash
for the wood of the vine, covering all the main stems with it; but all
these methods result in the one thing—the application of sulphur as
a remedy for mildew.
HOW TO OBTAIN GRAPE VINES.

Grafting is only practised on the vine for special reasons, and we


have never had occasion to try it. We shall speak of a better mode of
obtaining vines.
The best method of “getting a start” of grape vines is, by the
employment of cuttings. These may be planted immediately after
the spring pruning of established vines. But cuttings of native grapes
are as well planted in the fall. The granulation, from which the roots
spring, will form during the winter, and the cuttings, starting early in
the spring, will make good growth the first year. Cuttings are the
best, because they can be procured easily, abundantly, and cheaply;
they will bear carriage to any distance, are exceedingly tenacious of
life, and they make thriftier plants. Cuttings may be set, either
where they are to remain, in which case several should be set, to
allow for failures, and only the strongest finally retained; or, they
may be set in nursery rows, eight inches apart. Cuttings should be
inserted about eight inches deep, and have two eyes or buds above
the surface. The two buds are merely precautionary; that if one fails
the other may sprout; one only, and that the strongest, should finally
be permitted to grow.
An old and skillful cultivator of the vine says that cuttings are the
best of all modes of securing a supply of vines. “For my part I am for
scions without roots, after many experiments. All the advantage the
one with roots has over the other, is that they are more sure to live;
but they will not in general, make as thrifty plants.”—J. J. Dufour.
This only objection to cuttings—that a part of them fail to root—is of
little practical importance, as they are easily obtained in any
quantity.
AUTUMNAL MANAGEMENT OF FRUIT-
TREES.

Orchardists and cultivators of garden-fruit will have need of all their


skill to prepare tender fruit-trees for winter. It is the misfortune, alike
of the English summers, and of ours in the West, that trees do not
properly ripen their wood. But in Great Britain it is from the want of
enough, and in America, from too much summer. Our long and hot
summers give two or three separate growths to fruit-trees, and the
last one is usually in progress at a period so late that severe frosts
and freezings overtake the tree while yet in an excitable state,
pushing new wood, and with a top quite unripened for severe frosty
handling.
The year 1845 furnished a fine type of western summers. The spring
came in very properly, and at so late a period that the usual frosts,
after the expansion of leaves, were avoided. The summer opened
warmly and continued with almost unvarying heat throughout. At the
same time there were frequent and copious rains.
By this statement the average temperature of June was 71°, and the
rain 6-1/ , inches; of July, average noon heat 80°, rain 3¼ inches; of
August, average noon heat 80°, rain 5½ inches. Nights were
exceedingly warm. The day repeatedly opened and closed at 80°.
Our thermometer on the north of our house, in a shady yard, stood
for eight and ten days together between 94° and 100°, twice
attaining the latter height.
Under such stimulus our pear, apple and plum-trees, made their first
growth by the first of July. They soon started into a second growth,
which wound up during the last of August and the first of
September, plum-trees entirely shedding their leaves and standing as
bare as in January.
Let orchards be examined when frosts begin to occur, and every
side-shoot, sucker or water-sprout, cut cleanly out. These succulent,
raw sprouts are the breeding-spots of disease. Cold-blight invariably
manifests itself in them in the most positive form..
Garden trees, choice pears, and stone-fruits, should, in addition to
this operation, if still in growth at the last of September, receive a fall
pruning. From the first to the middle of October, according to the
season, cut off two-thirds of the new growth, or back to strong, ripe
wood. It is well known that the newest buds, near the extremity of
young wood, are the most sensitive and apt to break and grow,
whereas the buds near the base of a branch are dormant. It is the
repose of the older buds which makes fall pruning, if performed with
judgment, so valuable. Because it forces the tree to expend its
energies in ripening its wood instead of making more, and it also
tends to induce fruitfulness by changing leaf-buds to fruit-buds. The
great art of fall pruning is to relieve the tree of its crude wood
without causing its dormant buds to break. If performed too early, or
if but the tips of the fine wood are removed, the new buds may
break and side-shoots issue, leaving the tree worse off than before.
Young trees just coming into bearing should have their trunks
protected. That there is a change in the economy of a tree when it
begins to bear is plain; and experience seems to teach that trees are
peculiarly tender at the time of this change, since they are far more
apt to die when coming to fruit, than either before or afterward.
Cherry-trees and pear-trees should have brush, or corn-stalks, or
straw, or matting, as is most convenient, so placed from the ground
to the branches, as to exclude the sun without excluding air. An
hour’s attention may save much regret.
PEARS GRAFTED UPON THE APPLE
STOCK.

We do not think the pear does so well in any other way as on its own
root. But it has been found extremely difficult to obtain the requisite
stock. Pear-seeds are scarce. When obtained, the seedlings have
proved intractable, and left the nurseryman oftentimes in the lurch.
The first and best substitute for pear-stock, is the root of the pear—
great quantities may be obtained when removing pear-trees in the
autumn from the nursery, and also without any injury to the trees,
roots may be taken from old bearing-trees. These are to be grafted
in the manner already described in our pages. Next to this, the
quince stock is to be chosen. The pear is dwarfed upon it. In other
words, the two are but imperfectly suited to each other, and the
scion does not develop according to its original nature. But this very
dwarfing adds something to the good qualities of the fruit, affords
trees so small that, at eight feet apart, they make beautiful linings to
a walk or border, and, morever, brings the pear to its fruit several
years earlier than if it were on its own bottom. But on the other
hand, the pear on quince is comparatively short-lived. The white-
thorn has been tried as a stock and not without success, but it is
hardly to be used except in extremities.
Last, and worst of all, comes the apple. The scion grows as
vigorously upon the apple as upon a stock of its own species, and
we do not know that the fruit deteriorates. But the trees seem to
have no constitution. After a few bearings they seem struck with
irremediable weakness, and soon run down and die. Nurserymen
ought not, therefore, to graft the pear upon the apple. To do so, if
advised of the foregoing facts, cannot be honest. Our attention has
been called to the subject by some painful experience of our own.
Neshanoc Potato.—This potato (pronounced Meshanoc), was raised
from the seed about the year 1800, by John Gilkey, Mercer county,
Pennsylvania. He called it Neshanoc, from a creek near to which he
lived. It was called by some, Mercer, from the county in which it was
raised. It is extensively cultivated, and deserves to be. Mr. Gilkey
was an Irishman—of course a judge of good potatoes.
SEEDLINGS FROM BUDDED PEACHES.

Mr. Nicholas Longworth inquires: “Will the pit of the budded peach
produce the same fruit as the bud, or as the stock, or a mixture of
the two?” And he also says, “I have never fairly tested the question,
but my experience led me to believe that the budded pit produced
the same fruit as the original stock.”
So far as this question can be determined (independently of
experiment) upon the known laws of the vegetable kingdom, we say
that it will not produce fruit like that of the original stock; nor will it,
on the other hand, with any certainty, reproduce the budded kind.
If the pit of a budded variety takes after the stock, we must very
much change our theory of the office of leaves, and perhaps of the
bark. At present, the received and orthodox teaching is, that the sap
from the root is crude and undigested until it has received in the leaf
a chemical change. Until then, the sap does not materially influence
the vegetable tissue, nor form new substance, or affect the fruit. But
after its elaboration in the leaf, a returning current of prepared sap
(similar in its functions to arterial blood), sets downward, distributing
to every part of the vegetable economy the properties required by
each. The sap arising from the root, does not touch the channel of
fruit until it has been chemically changed; and the difference
exhibited in the fruit of one tree compared with another, arises,
primarily from the nature of the sap which it receives; the sap
receives its qualities by a digestion in the leaf.[15] In all cases, then,
we suppose the leaf to determine the nature of the fruit (and the
root in no case, and the trunk in no case), since the stem is, so far
as sap is concerned, but a bundle of canals for its passage—a mere
highway for transmission—and not like the leaf, a laboratory for its
preparation![16]
We may be reminded that a stock, in point of fact, does influence
the fruit. It is indisputable that pears are changed on quince roots.
The Wilkinson, grafted upon the quince, is smaller, more prolific,
higher flavored, and of a brighter red cheek than if grafted on the
pear. The Duchesse d’Angoulême is larger and better on the quince
than on its own roots. But what is the influence in this case? When a
free-grower is put upon a slow-grower, the point of junction
becomes a point of comparative obstruction to the return-sap. It is
only a wholesome process of ringing, or decortication. Lindley says:
“When pears are worked upon the wild species, apples upon crabs,
and peaches upon peaches, the scion is, in regard to fertility, exactly
in the same state as if it had not been grafted at all: while, on the
other hand, a great increase of fertility, is the result of grafting pears
upon quinces, peaches upon plums, apples upon the thorn, and the
like. In these cases, the food absorbed from the earth by the root of
the stock is communicated slowly.” And Manning adds: “No other
influence have we ever noticed exercised by the scion upon the
stock.”
But if, after all, it can be shown by actual trial, that the pits of
budded peaches DO go back to the fruit of the stock, why we must
receive it, in spite of all theory; for, (and some would do well to heed
the maxim), facts must rule our theories, and not theories our fact.
But we may properly put any facts seeming to contravene the
received theory of the functions of plants in producing fruit, upon
their oath, and refuse them, unless they are unquestionable and
relevant.
Suppose a budded peach not to yield a fruit at all like the bud,
suppose it to resemble the fruit of the stock, it does not follow that
the stock influenced the fruit to such a change. Mr. Longworth
knows how freely some peaches “sport,” and that all peaches may
be made to do it. If a Melacatune be budded upon a Red Rareripe,
and the Melacatune pit shows a fruit resembling the Red Rareripe, it
must be shown that the blossom had not been crossed by the busy
offices of flies, bees, etc., with the pollen of contiguous Red
Rareripe-trees.
When a tree is even solitary, it does not follow that a change in fruit
which shall make it resemble the stock more than the graft, results
from the force of the stock on the grafted fruit, for seedlings of
grafted fruit are, notoriously often, base and degenerate; and the
resemblance might be accidental, for seedlings of different origin are
often strikingly alike.
While we are aware of no facts which justify Mr. Longworth’s
suspicion, that the pits of budded varieties produce kinds like the
stock on which the bud was put, we have facts enough showing that
“budded pits” produce their own kind.
It may be added that thoroughly ripe peaches are less inclined to
“sport” than those which are partially green.

[15]The fruit itself still further elaborates the sap, else a peach would be
as acrid as the juice of the peach leaf.
[16]Loudon (Encyclopædia of Gardening, p. 448), has the following
remarks:
“The bark is the medium in which the proper juices of the plant, in their
descent from the leaves, are finally elaborated and brought to the state
which is peculiar to the species. From the bark these juices are
communicated to the medullary rays, to be by them deposited in the
tissue of the wood. The character of timber, therefore, depends chiefly
upon the influence of the bark: and hence, it is that the wood formed
above a graft never partakes, in the slightest degree, of the nature of the
wood below it. The bark, when young and green, like the leaves, is
supposed, like them, to elaborate the sap, and hence may be considered
as the universal leaf of a plant.”
These views corroborate the reasoning above, although Loudon extends
the functions of the leaf to the bark. We have not been able, in our limited
range of books, to find any other authority for this statement, respecting
the “young and green bark.”
CARE OF PEACH-TREES.

Take a light hoe and remove the earth from the trunk of your trees.
If there are worms there you may detect them from the gum which
has exuded, or by the channels which they have made in the bark,
or if by neither of these, by the discoloration of the bark in spots.
Scrape the bark gently with the back of a knife, and you can easily
detect the traces of worms if any are there. Cut freely and boldly
both ways along their track so as to lay bare the channel in its whole
length—remove the worm, and the bark will very soon heal.
Sometimes four, six, and even more will be found in one tree. The
ashes of stone coal, blacksmiths’ cinders, wood ashes, lime, the
refuse stems of tobacco, planting tansy around the trunk, these, and
dozens of other remedies are proposed. For our own part we rely
solely on our jack-knife. In March or April, and then again in August
or September, according to the season, we search the trunk
thoroughly. We can attend to twenty trees in an hour or two; and
when eating freely of delicious peaches we never had a qualm of
regret for having so spent the time.
We have practised sowing salt under fruit-trees with decided
advantage. If one pound of saltpetre be added to every six pounds
of salt, it will be yet better. We sow enough to make the ground look
moderately white, and prefer to do it in wet weather.

The most salable butter, quality being equal, is that which is neatest
done up. There is a great deal in the looks of a thing. You’ll always
find it so.
RENOVATING PEACH-TREES.

The peach-tree inclines to thicken at the top, the small inside


branches die, and are removed by every neat cultivator. As the
branches shoot up, this tree is disposed to abandon its lower
branches, and, like the vine, to bear on the wood the farthest from
the root, i. e. the young and new wood. In a few years the tree has
a long-necked trunk, sometimes several of them; while the weight of
foliage and fruit is situated so as to act like a power applied to a
lever; and as the fruit grows heavy, or a storm occurs, the tree is
broken down. We have practised the following method with success.
In the month of July we saw off the top of one half of the tree,
leaving about ten or twelve feet of stem, measuring from the
ground. New shoots will now put out along the whole trunk; a part
of these should be rubbed off, according to the judgment of the
cultivator, leaving such as will give symmetry to the tree, and form a
head low down. The second year, these branches will bear fruit, and
the other side may then be treated in the same way.
This new head will require little meddling with for about four years.
At this time, or whenever the tree is outrunning itself, the same
process is to be renewed. But this time the tree will be composed of
a multitude of smaller branches, instead of two or three main ones
as at first. Some of these should be wholly cut out, and the wound
smeared with a residuum of paint, or a thick white paint, or grafting
wax, or anything that will exclude the air while the cut is
granulating. The others are to be cut within, say, five inches of the
old, original wood—leaving, thus, a stem of mere stumps. If the
branches are taken entirely off, leaving only the oldest wood, the
buds which would break from it would not be as healthy or vigorous
as those which will spring from the stumps of the later branches.
Probably twenty or thirty whips will come to each stump; these
should from day to day be reduced in number, until, at last, all are
removed but one, and that one should, if possible, spring from the
nearest point where the stump joins the old stem. When this new
branch is obtained and fairly established, remove the stump with a
fine saw, so as to leave the new branch, as nearly as possible, in the
place of the old one. We remove the whips from a stump gradually
in order to give the tree the advantage of their leaves as long as it
can be done without interfering with the branch or branches which
we are training out.
This method is to the peach what pruning is to the grape. The tree is
kept in hand instead of sprawling abroad, a prey to its own weight
and to storms; there is always a plenty of young wood for the fruit,
which can be easily reached when one thins out, or gathers for use.
One of our trees taught us this method of its own accord in the
summer of 1843. The weight of fruit was so great that we applied a
prop to the middle of the branch; in a few days the branch broke
short off at the point of the prop. It so happened that the three main
limbs on one side of the tree acted in this manner. That same fall a
strong growth of new wood shot out, and the next season I had on
that side as fine a top as ever I had on any peach-tree.

Every farmer who expects his wife to make good butter, after
furnishing her with some good, well-fed milk cows, should provide
her with good milk-pans—large and shallow, so as to present a large
surface for the cream to rise on, and enough of them to hold all her
milk, and allow it to remain undisturbed long enough for all the
cream to rise. These pans should be nicely washed every time the
milk is emptied out of them, and always be clear and bright when
filled.
AN APOLOGUE OR APPLE-LOGUE.

Two men planted out each one hundred apple-trees. In six or seven
years they began to bear. One had spared no pains to bring his
orchard into the highest condition. He had constantly cultivated the
soil about them, scraped off the rough bark, washed them with
urinated soap, picked off every worm and nursed them as if they
had been children. The other, pursuing a cheaper plan, simply let his
trees alone; but the moss, and canker-worms took his place and
attended to them every year. When the orchards began to bear, the
careful man had the best fruit, and the careless man covered his
folly by cursing the nursery-man for selling him poor trees. In a year
or two the careful man had two bushels to the other’s one from each
tree. Not to be outdone, the latter determined to have as many
apples as the former, and set out another hundred trees. By and by,
when they bore, the other orchard had so improved that it produced
twice as many yet; another hundred trees were therefore planted. In
process of time the first orchard of one hundred trees still sent more
fruit to market than the three hundred trees of the careless man,
who now gave up and declared that he never did have luck, and it
was of no use to try on his soil to raise good fruit.
1. When a man is too shiftless to take good care of two horses, he
buys two more, and gets from the four what he might get from two.
2. A farmer who picks up a cow simply because it is not an ox, and
is, nominally, lactiferous, and then lets the creature work for a living,
very soon buys a second, and a third, and a fourth, and gets from
them all, what he should have had from one good one.
3. A farmer had one hundred acres. Instead of getting seventy-five
bushels of corn to the acre, he gets forty and makes it up by
cultivating twice as many acres; instead of thirty bushes of wheat he
gets twelve, and puts in acres enough to make up; instead of
making one hundred acres do the work of three hundred, he buys
more land, and allows three hundred to do only the work of one
hundred.
4. A young woman, with a little pains, can have three times as many
clothes as she needs, and then not look so well as a humble
neighbor who has not half her wardrobe; wherefore, we close with
some proverbs made for the occasion:
Active little is better than lazy much.
Carefulness is richer than abundance.
Large farming is not always good farming, and small farming is often
the largest.
SELECT LIST OF APPLES.

It is impossible to frame a list of apples which will suit every


cultivator. Men’s taste in fruits is widely different. The delicacy and
mildness of flavor which some admire, is to others mere insipidity.
The sharp acid, and coarse grain and strong flavor which disgust
many palates, are with others the very marks of a first-rate apple.
The object of the cultivator in planting an orchard, whether for his
own use, for a home market, for exportation, for cider-making, or for
stock-feeding, will very materially vary his selection.
The soil on which an orchard is to be planted should also determine
the use of many varieties, which are admirable only when well suited
in their locality.
Regard is to be had to climate, since some of the finest fruits in one
latitude entirely betray our expectations in another. The hardiness
and health of different varieties ought to be more an object of
attention than hitherto. As in building, so in planting an orchard, a
mistake lasts for a century, and a bad tree in a good orchard is like
bad timber in good mansion.
However select, then, a list may be, every cultivator must exercise
his own judgment in adapting it to his own circumstances.

SUMMER APPLES.

1. Carolina June.—This is identical with the Red June of the principal


nurseries; but many inferior varieties scattered through the country,
called Red June, are to be discriminated from it.
The tree is upright with slender wood, which, when loaded with
fruit, droops like a willow. It is a healthy tree, ripens its wood early
in the fall, and is not subject to frost-blight. It comes early into
bearing, is productive and bears every year. The fruit is of medium
size though specimens grow large; the flavor is sprightly, subacid,
the flesh tender. It has flourished well on sand-loams, common
clays, and on strong limestone clay. Ripens from the first to the
twentieth of July. A valuable market fruit. Four trees, in one county,
sent eighty dollars’ worth to market in one season. Not mentioned
by eastern writers, nor found in eastern catalogues, but described at
the West by Hampton and Plummer, and found in Ohio and Indiana
nurseries.
2. Sweet June.—Tree upright, wood moderately strong; ripens its
wood early in fall; not subject to frost-blight; flourishes on all soils,
even if quite wet; bears very young, often while in nursery rows;
bears every year and abundantly. The fruit is of medium size; color a
pale yellow; form globular; flavor sweet and pleasant. Ripens at
same time as the Carolina June.
3. Kirkbridge White.—Not found in any catalogues but those of
Western nurseries. Tree upright, wood strong and stubbed; grows
slow while young, but vigorously when fully established; ripens its
wood early in autumn; not subject to frost-blight; bears moderately
young, and is very productive. Its fruit ripens in succession for six
weeks from first of July to middle of August, and is peculiarly
valuable on that account; color nearly white; it is largest at base and
tapers regularly to the eye, and is ribbed; flavor, mild, pleasant acid;
flesh melting, and, if fully ripe breaks to pieces in falling to the
ground.
4. Prince’s Harvest.—Manning pronounces this “the earliest apple
worthy of cultivation.” It may be in Massachusetts, but it is preceded
by many at the West. Manning’s description is good.
“The form is flat, of medium size; the skin, when perfectly
ripe, is of a beautifully bright straw color; the flesh tender and
sprightly; if gathered before they are fully ripe, it has too
much acidity. The finest fruits are those which drop ripe from
the tree; the branches make very acute angles, by which it is
readily distinguished from most other trees in the orchard; it
bears young. Ripe early in July.”
Our nurserymen regard it as a shy bearer.
5. Summer Queen.—Extensively cultivated in the West under the name
of Orange Apple. The tree is spreading; a rapid grower; not subject
to frost-blight; wood moderately strong; comes late into bearing;
productive when the tree is fully grown, according to the books, but
in this region with some exceptions has proved to be a poor bearer.
Fruit large, yellow, striped with red; flesh, breaking; flavor strong,
and not delicate.
6. Sweet Bough.—Two varieties of this name are cultivated in the
West—Coxe’s and Mount’s. Coxe’s sweet bough, is that of the books
and catalogues. Ripens at the same time; not quite so high in flavor.
Coxe’s trees are large limbed and spreading; bearing on the point of
the limbs, and are shy bearers; Mount’s variety is of upright growth;
bears on spurs along the branches; is a good bearer and ripens from
middle of July to August.
“A variety under the name of Philadelphia Jennetting is known
in Trumbull County, Ohio. It ripens two weeks later than the
common kind, otherwise it is not essentially different.”—Dr. J.
P. Kirtland.
7. Summer Pearmain.—There seem to be two varieties of this name
cultivated in Ohio and Indiana.
(1.) That of Coxe, which is the one generally cultivated, and
deservedly popular.
“The fruit-buds seem to be unusually hardy, and often resist the
impression of late spring frosts, while others are killed. In 1834,
when our fruits were universally cut off by that destructive agent, a
tree of the summer pearmain and another of the Vandeveer,
matured a dozen or two apples, while not another tree in an orchard
containing over five hundred, bore a solitary fruit. It is worthy of
more extensive cultivation.”—Dr. Kirtland.
(2.) A variety evidently allied to Coxe’s, but all things considered a
more desirable variety. The fruit resembles Coxe’s, but is larger; the
flavor is the same, but not quite as high; Coxe’s is oblong; this
variety is Vandeveer pippin shape; color the same, and the period of
ripening, viz., July and August. The trees are very distinct; Coxe’s is
upright, this is spreading; Coxe’s of a slender growth, and stinted
habit, and is hard to bring forward in the nursery; this has a
vigorous growth, and strong wood, and strikingly resembles the
Vandeveer pippin-tree. It bears early and abundantly in all soils.
This second variety was brought, by a man named Harlan, Fayette
County, Indiana, from South Carolina, where it is extensively
cultivated.
8. Daniel.—The tree is upright, nearly pear-tree shape; wood strong
and healthy; leaves, above all varieties, dark green and glossy; bears
young and abundantly. Fruit medium size; it has a yellow ground
covered with blotches of dull red; flavor rich, sweetish, and high.
Ripens in succession from first to middle of August. A desirable
variety.
9. Hoss, improperly pronounced Horse, and so written in Prince’s
catalogue. Originated in North Carolina; largely cultivated in both
Carolinas and southern Virginia; named from the originator. It has
been propagated by suckers, grafts, and even by seeds; in this latter
case, the product very nearly resembles the parent. Three varieties,
however, may be discriminated. Tree upright, wood strong and
healthy; bears yearly and abundantly; flesh melting: flavor rather too
acid until thoroughly ripe, and then fine. Ripens in August and
September. Desirable in the most select orchards.
The time of ripening I have set down for the latitude of Indianapolis.
Upon the Ohio River, near Cincinnati, it will be ten days earlier.

AUTUMN APPLES.

10. Maiden’s Blush.—Tree moderately spreading, open top, limbs


slender; grows late in fall, and somewhat liable to winter-killing;
grows well on all good soils; bears young and very abundantly every
year. The fruit large when the tree is not allowed to ripen too large a
crop; white, and blush toward the sun; tender, melting, very juicy,
decidedly acid. The fruit is, even in unfavorable seasons, very free
from cracks, knots, and is always fair; one of the best for drying and
excellent for marketing; should be plucked before it is dead ripe;
ripens from August to October. It is the same as the English
Horthornden. It does not do well grafted on the root; being apt to
burst the first or second winter; buds well, and should be thus
propagated in the nursery. It is a native of New Jersey.
11. Wine Apple.—Tree spreading but not sprawling; medium grower,
healthy; limbs rather slender; does well on all soils; bears very
young, largely, and every year. Fruit large on young, and medium-
sized on old trees; deep yellow ground covered with red, and russet
about the stem; tender, melting, very juicy, high-flavored, sweet,
with a spicy dash of subacid. One of the richest cooking apples; one
of the most desirable for drying, resembling dried pears. Where
known, it is worth, dried, a dollar and a half a bushel, when other
apples command but seventy-five cents. Ripens first of September
and has passed its prime by November. Eastern writers call it a
winter apple, and Kenrick gives October to March as its season; but,
in the West, it seldom sees the first winter month. Takes by graft
and bud pretty well; does well grafted upon the root; favorable for
nursery purposes.
12. Holland Pippin.—Tree large and spreading; strong growth; wood
short and stubbed, healthy; bears moderately young; they are
averse to heavy clay and wet soils; on light, dry, rich, sandy soils
bears largely, and of high color and flavor; bears every other year.
Fruit large, very bright yellow, tender, juicy, subacid. The pulp in the
mouth becomes rather viscid, as if the fruit were mucilaginous,
which is agreeable or otherwise according to the taste of the eater.
It is sometimes, but rarely, water-cored. Ripens in October and
November; will keep later, but apt to lose in flavor. Good for drying,
but usually sold green, being a very marketable fruit. Not a good
tree for nurserymen; not willing to come if grafted on the root; does
well by crown-grafting; moderately well by budding, the eye being
apt to put out simply a spur, which can seldom be forced into a
branch if permitted to harden.
13. Rambo.—This apple is known in New Jersey by the names of
Romanite, Seek-no-further, and Bread and Cheese. The first two
names belong to entirely different apples. The rambo is not to be
confounded with the Rambours, of which there are several varieties.
Tree upright, and the most vigorous growth of all trees cultivated in
the West; the easiest of all to bud with, a bud seldom misses, and
makes extraordinary growth the first season; it may well be called
the nurseryman’s favorite; bears very young, abundantly every year,
good on all soils. Fruit medium size, yellow ground with red stripes
and the whole overlaid with a bloom, like a plum; tender, juicy,
melting, subacid, rich; it has a peculiarity of ripening; it begins at the
skin and ripens toward the core; often soft and seemingly ripe on
the outside while the inside is yet hard. Ripens from October to
December. One of the best of all fruits.
14. Golden Russet.—This admirable apple is put in the list of fall
fruits, because, though it will keep through the winter, it ripens in
November, and sometimes even in October. Tree, strong grower,
upright, compact top-healthy, grows late in fall and therefore subject
to winter-killing; will grow on all soils, but delights in rich sandy
loams, on which it bears larger and finer fruit. Fruit small, rather
oblong; color yellow, slight red next to the sun; although called
russet, there is but a trace of it on the fruit of healthy trees; tender,
melting, spicy, very juicy; in flavor it resembles the St. Michael’s pear
(Doyenné) more nearly than any other apple.
This fruit is the most popular of all late, fall, or early winter apples,
and deservedly, and should be put at the head of the list. A
gentleman near Belfre, Ohio, being applied to for a list of apples to
furnish an orchard of a thousand trees for marketing purposes,
replied, “Take nine hundred and ninety-nine golden russets, and the
rest you can choose to suit yourself.” For nursery purposes it is
rather a backward apple; the buds apt to fail, which occasions much
resetting. It will not do well grafted on the root, being tender and
always largely winter-killed when so wrought. They graft kindly on
well established stocks.
If a larger list of fall apples is desired, we recommend the Fall
Harvey, Gravenstein, Lyscom, Porter, Red Ingestrie, Yellow do. The
Ashmore is a desirable fruit—difficult to raise in the nursery, and
therefore avoided, but the fruit is fine. The Ross Nonpareil is a very
admirable fall fruit of Irish origin.
The list of autumn apples is very large and continually augmenting.
But fall apples are, ordinarily, less desirable than any others; not
from inferior quality, but because they ripen at the season of the
year when peaches and pears are in their glory.

WINTER APPLES.

15. Gloria Mundi or Monstrous Pippin. Tree, one of the most upright,
top close, and resembling the pear. Wood medium sized, healthy,
vigorous growth, wood ripens early, not subject to frost-blight; bears
on moderately young trees. It works well from the bud, and also
extremely well grafted on roots, and grows straight and finely for
nursery purposes. Fruit very large, green, changes when dead-ripe
to a yellowish white. Flavor mild, subacid; flesh melting and spicy.
Ripens in November, at the same time with the Golden Russet, but
will not keep as long. A native.
16. Black Apple.—Tree low, spreading, and round topped; wood of
medium vigor, healthy, ripens early, and not subject to frost-blight.
Grafts on the root kindly; not so favorable for budding as the No. 15;
bears remarkably young, and abundantly to a fault. Fruit medium
sized; color very dark red, almost black, with grey rusty spots about
the stem; flesh tender, breaking; moderately juicy, flavor rather
sweet, though not a real sweet apple. No apple would stand fairer as
an early winter fruit, were it not for a peculiar, dry, raw taste,
somewhat resembling the taste of uncooked corn meal. Ripens from
November to January. It is a native.
17. Newton Spitzenburg.—Tree, not large, upright but not compact,
top open; wood of medium size and vigor of growth; healthy, ripens
early, and yet, now and then, it takes the frost-blight; bears
moderately young, every other year, very abundantly; grafts well on
the root, buds only moderately well, good for nursery handling.
Fruit, varying much in size, but often large, flesh melting, juicy;
flavor rich, spicy, subacid; ripens from November to January.
18. Rhode Island Greening.—Tree large, very spreading and drooping,
grows vigorously, healthy, ripens early, not subject to frost-blight;
bud takes well; but, whether grafted on the root, or budded, it will
plague the nurseryman by its disposition to spread and twist about
like a quince bush. It should be budded on strong stocks at the
height at which the top is to be formed; but it always overgrows the
stock. Fruit very large, color green, with cloudy spots dotted with
pin-point black specks; flesh breaking, tender and juicy: flavor mild,
rich, subacid; a very popular fruit. Ripens from November to
January.
19. Hubbardston Nonesuch.—Admirable in nursery; works well on root
or by bud. We give Downing’s description, as it has not fruited in this
region.
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