100% found this document useful (2 votes)
10 views

Matlab Global Optimization Toolbox Users Guide R2020a The Mathworks download

The document is the User's Guide for the MATLAB Global Optimization Toolbox R2020a, detailing its features, functions, and usage. It includes sections on optimization workflows, solver characteristics, and instructions for writing objective functions and constraints. Additionally, it provides links to related MATLAB resources and contact information for MathWorks support.

Uploaded by

tsxtsomu
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 (2 votes)
10 views

Matlab Global Optimization Toolbox Users Guide R2020a The Mathworks download

The document is the User's Guide for the MATLAB Global Optimization Toolbox R2020a, detailing its features, functions, and usage. It includes sections on optimization workflows, solver characteristics, and instructions for writing objective functions and constraints. Additionally, it provides links to related MATLAB resources and contact information for MathWorks support.

Uploaded by

tsxtsomu
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/ 77

Matlab Global Optimization Toolbox Users Guide

R2020a The Mathworks download

https://ebookbell.com/product/matlab-global-optimization-toolbox-
users-guide-r2020a-the-mathworks-11236246

Explore and download more ebooks at ebookbell.com


Here are some recommended products that we believe you will be
interested in. You can click the link to download.

Matlab Global Optimization Toolbox Documentation

https://ebookbell.com/product/matlab-global-optimization-toolbox-
documentation-6741682

Matlab For Engineers Global Edition 5th Edition Holly Moore

https://ebookbell.com/product/matlab-for-engineers-global-edition-5th-
edition-holly-moore-51057064

Matlab A Practical Introduction To Programming And Problem Solving 6th


Edition Stormy Attaway

https://ebookbell.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-6th-edition-stormy-attaway-46075418

Matlab For Engineering Applications 5e Ise 5thise William J Palm Iii

https://ebookbell.com/product/matlab-for-engineering-
applications-5e-ise-5thise-william-j-palm-iii-46562738
Matlab And Simulink Crash Course For Engineers 1st Ed 2022 Eklas
Hossain

https://ebookbell.com/product/matlab-and-simulink-crash-course-for-
engineers-1st-ed-2022-eklas-hossain-46608958

Matlab Medical Imaging Toolbox Users Guide The Mathworks

https://ebookbell.com/product/matlab-medical-imaging-toolbox-users-
guide-the-mathworks-46611260

Matlab For Engineering Applications 5th Edition William Palm

https://ebookbell.com/product/matlab-for-engineering-applications-5th-
edition-william-palm-46651690

Matlab For Engineering Berardino Dacunto

https://ebookbell.com/product/matlab-for-engineering-berardino-
dacunto-48710470

Matlab For Medical Physics Reallife Clinical Scenarios And Projects


Jidi Sun

https://ebookbell.com/product/matlab-for-medical-physics-reallife-
clinical-scenarios-and-projects-jidi-sun-49034592
Global Optimization Toolbox
User's Guide

R2020a
How to Contact MathWorks

Latest news: www.mathworks.com

Sales and services: www.mathworks.com/sales_and_services

User community: www.mathworks.com/matlabcentral

Technical support: www.mathworks.com/support/contact_us

Phone: 508-647-7000

The MathWorks, Inc.


1 Apple Hill Drive
Natick, MA 01760-2098
Global Optimization Toolbox User's Guide
© COPYRIGHT 2004–2020 by The MathWorks, Inc.
The software described in this document is furnished under a license agreement. The software may be used or copied
only under the terms of the license agreement. No part of this manual may be photocopied or reproduced in any form
without prior written consent from The MathWorks, Inc.
FEDERAL ACQUISITION: This provision applies to all acquisitions of the Program and Documentation by, for, or through
the federal government of the United States. By accepting delivery of the Program or Documentation, the government
hereby agrees that this software or documentation qualifies as commercial computer software or commercial computer
software documentation as such terms are used or defined in FAR 12.212, DFARS Part 227.72, and DFARS 252.227-7014.
Accordingly, the terms and conditions of this Agreement and only those rights specified in this Agreement, shall pertain
to and govern the use, modification, reproduction, release, performance, display, and disclosure of the Program and
Documentation by the federal government (or other entity acquiring for or through the federal government) and shall
supersede any conflicting contractual terms or conditions. If this License fails to meet the government's needs or is
inconsistent in any respect with federal procurement law, the government agrees to return the Program and
Documentation, unused, to The MathWorks, Inc.
Trademarks
MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See
www.mathworks.com/trademarks for a list of additional trademarks. Other product or brand names may be
trademarks or registered trademarks of their respective holders.
Patents
MathWorks products are protected by one or more U.S. patents. Please see www.mathworks.com/patents for
more information.
Revision History
January 2004 Online only New for Version 1.0 (Release 13SP1+)
June 2004 First printing Revised for Version 1.0.1 (Release 14)
October 2004 Online only Revised for Version 1.0.2 (Release 14SP1)
March 2005 Online only Revised for Version 1.0.3 (Release 14SP2)
September 2005 Second printing Revised for Version 2.0 (Release 14SP3)
March 2006 Online only Revised for Version 2.0.1 (Release 2006a)
September 2006 Online only Revised for Version 2.0.2 (Release 2006b)
March 2007 Online only Revised for Version 2.1 (Release 2007a)
September 2007 Third printing Revised for Version 2.2 (Release 2007b)
March 2008 Online only Revised for Version 2.3 (Release 2008a)
October 2008 Online only Revised for Version 2.4 (Release 2008b)
March 2009 Online only Revised for Version 2.4.1 (Release 2009a)
September 2009 Online only Revised for Version 2.4.2 (Release 2009b)
March 2010 Online only Revised for Version 3.0 (Release 2010a)
September 2010 Online only Revised for Version 3.1 (Release 2010b)
April 2011 Online only Revised for Version 3.1.1 (Release 2011a)
September 2011 Online only Revised for Version 3.2 (Release 2011b)
March 2012 Online only Revised for Version 3.2.1 (Release 2012a)
September 2012 Online only Revised for Version 3.2.2 (Release 2012b)
March 2013 Online only Revised for Version 3.2.3 (Release 2013a)
September 2013 Online only Revised for Version 3.2.4 (Release 2013b)
March 2014 Online only Revised for Version 3.2.5 (Release 2014a)
October 2014 Online only Revised for Version 3.3 (Release 2014b)
March 2015 Online only Revised for Version 3.3.1 (Release 2015a)
September 2015 Online only Revised for Version 3.3.2 (Release 2015b)
March 2016 Online only Revised for Version 3.4 (Release 2016a)
September 2016 Online only Revised for Version 3.4.1 (Release 2016b)
March 2017 Online only Revised for Version 3.4.2 (Release 2017a)
September 2017 Online only Revised for Version 3.4.3 (Release 2017b)
March 2018 Online only Revised for Version 3.4.4 (Release 2018a)
September 2018 Online only Revised for Version 4.0 (Release 2018b)
March 2019 Online only Revised for Version 4.1 (Release 2019a)
September 2019 Online only Revised for Version 4.2 (Release 2019b)
March 2020 Online only Revised for Version 4.3 (Release 2020a)
Contents

Getting Started

Introducing Global Optimization Toolbox Functions


1
Global Optimization Toolbox Product Description . . . . . . . . . . . . . . . 1-2
Key Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2

Comparison of Six Solvers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3


Function to Optimize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-3
Six Solution Methods . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4
Compare Syntax and Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-9

Solver Behavior with a Nonsmooth Problem . . . . . . . . . . . . . . . . . . . 1-11

What Is Global Optimization? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18


Local vs. Global Optima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-18
Basins of Attraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-19

Optimization Workflow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-22

Table for Choosing a Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-23

Global Optimization Toolbox Solver Characteristics . . . . . . . . . . . . 1-24


Solver Choices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Explanation of “Desired Solution” . . . . . . . . . . . . . . . . . . . . . . . . . . 1-24
Choosing Between Solvers for Smooth Problems . . . . . . . . . . . . . . . 1-26
Choosing Between Solvers for Nonsmooth Problems . . . . . . . . . . . . 1-26
Solver Characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-27
Why Are Some Solvers Objects? . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-29

Write Files for Optimization Functions


2
Compute Objective Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Objective (Fitness) Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Write a Function File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
Write a Vectorized Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-3
Gradients and Hessians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-4

Maximizing vs. Minimizing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-5

v
Write Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Consult Optimization Toolbox Documentation . . . . . . . . . . . . . . . . . . 2-6
Set Bounds . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-6
Ensure ga Options Maintain Feasibility . . . . . . . . . . . . . . . . . . . . . . . 2-6
Gradients and Hessians . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7
Vectorized Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-7

Set and Change Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-9

View Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-10

Using GlobalSearch and MultiStart


3
Problems That GlobalSearch and MultiStart Can Solve . . . . . . . . . . . . . . . 3-2

Workflow for GlobalSearch and MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . 3-3

Create Problem Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4


About Problem Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Using the createOptimProblem Function . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
Exporting from the Optimization app . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6

Create Solver Object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10


What Is a Solver Object? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
Properties (Global Options) of Solver Objects . . . . . . . . . . . . . . . . . . . . . 3-10
Creating a Nondefault GlobalSearch Object . . . . . . . . . . . . . . . . . . . . . . 3-11
Creating a Nondefault MultiStart Object . . . . . . . . . . . . . . . . . . . . . . . . . 3-12

Set Start Points for MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13


Four Ways to Set Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13
Positive Integer for Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13
RandomStartPointSet Object for Start Points . . . . . . . . . . . . . . . . . . . . . 3-13
CustomStartPointSet Object for Start Points . . . . . . . . . . . . . . . . . . . . . . 3-14
Cell Array of Objects for Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-15

Run the Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16


Optimize by Calling run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
Example of Run with GlobalSearch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-16
Example of Run with MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-17

Single Solution . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-19

Multiple Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20


About Multiple Solutions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-20
Change the Definition of Distinct Solutions . . . . . . . . . . . . . . . . . . . . . . . 3-22

Iterative Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24


Types of Iterative Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24
Examine Types of Iterative Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-24

Global Output Structures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-26

vi Contents
Visualize the Basins of Attraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-27

Output Functions for GlobalSearch and MultiStart . . . . . . . . . . . . . . . . . 3-30


What Are Output Functions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
GlobalSearch Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-30
No Parallel Output Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-31

Plot Functions for GlobalSearch and MultiStart . . . . . . . . . . . . . . . . . . . 3-33


What Are Plot Functions? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
MultiStart Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-33
No Parallel Plot Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-35

How GlobalSearch and MultiStart Work . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37


Multiple Runs of a Local Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
Differences Between the Solver Objects . . . . . . . . . . . . . . . . . . . . . . . . . 3-37
GlobalSearch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-38
MultiStart Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-41
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-43

Can You Certify That a Solution Is Global? . . . . . . . . . . . . . . . . . . . . . . . . 3-44


No Guarantees . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-44
Check if a Solution Is a Local Solution with patternsearch . . . . . . . . . . . 3-44
Identify a Bounded Region That Contains a Global Solution . . . . . . . . . . 3-45
Use MultiStart with More Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . 3-45

Refine Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47


About Refining Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47
Methods of Generating Start Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-47
Example: Searching for a Better Solution . . . . . . . . . . . . . . . . . . . . . . . . 3-49

Change Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-54


How to Determine Which Options to Change . . . . . . . . . . . . . . . . . . . . . 3-54
Changing Local Solver Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-54
Changing Global Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-55

Reproduce Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-57


Identical Answers with Pseudorandom Numbers . . . . . . . . . . . . . . . . . . . 3-57
Steps to Take in Reproducing Results . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-57
Example: Reproducing a GlobalSearch or MultiStart Result . . . . . . . . . . 3-57
Parallel Processing and Random Number Streams . . . . . . . . . . . . . . . . . 3-58

Find Global or Multiple Local Minima . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-60


Function to Optimize . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-60
Single Global Minimum Via GlobalSearch . . . . . . . . . . . . . . . . . . . . . . . . 3-61
Multiple Local Minima Via MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-62

Maximizing Monochromatic Polarized Light Interference Patterns Using


GlobalSearch and MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-66

Optimize Using Only Feasible Start Points . . . . . . . . . . . . . . . . . . . . . . . . 3-78

MultiStart Using lsqcurvefit or lsqnonlin . . . . . . . . . . . . . . . . . . . . . . . . . 3-81

Parallel MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-85


Steps for Parallel MultiStart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-85

vii
Speedup with Parallel Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-86

Isolated Global Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-88


Difficult-To-Locate Global Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-88
Default Settings Cannot Find the Global Minimum — Add Bounds . . . . . 3-89
GlobalSearch with Bounds and More Start Points . . . . . . . . . . . . . . . . . . 3-90
MultiStart with Bounds and Many Start Points . . . . . . . . . . . . . . . . . . . . 3-90
MultiStart Without Bounds, Widely Dispersed Start Points . . . . . . . . . . . 3-91
MultiStart with a Regular Grid of Start Points . . . . . . . . . . . . . . . . . . . . . 3-91
MultiStart with Regular Grid and Promising Start Points . . . . . . . . . . . . 3-92

Using Direct Search


4
What Is Direct Search? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-2

Optimize Using the GPS Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3


Objective Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3
Finding the Minimum of the Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-4
Plotting the Objective Function Values and Mesh Sizes . . . . . . . . . . . . . . . 4-5

Coding and Minimizing an Objective Function Using Pattern Search . . . 4-7

Constrained Minimization Using Pattern Search . . . . . . . . . . . . . . . . . . . 4-11

Effects of Pattern Search Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-15

Pattern Search Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21


Patterns . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
Meshes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-21
Polling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22
Expanding and Contracting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-22

How Pattern Search Polling Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24


Context . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-24
Successful Polls . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-25
An Unsuccessful Poll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-27
Successful and Unsuccessful Polls in MADS . . . . . . . . . . . . . . . . . . . . . . 4-27
Displaying the Results at Each Iteration . . . . . . . . . . . . . . . . . . . . . . . . . 4-28
More Iterations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-28
Poll Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-29
Complete Poll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-30
Stopping Conditions for the Pattern Search . . . . . . . . . . . . . . . . . . . . . . 4-30
Robustness of Pattern Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-32

Searching and Polling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33


Definition of Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-33
How to Use a Search Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-34
Search Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35
When to Use Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-35

Setting Solver Tolerances . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-37

viii Contents
Search and Poll . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38
Using a Search Method . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-38
Search Using a Different Solver . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-40

Nonlinear Constraint Solver Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-42

Custom Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44


About Custom Plot Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44
Creating the Custom Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44
Setting Up the Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-44
Using the Custom Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-45
How the Plot Function Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-47

Pattern Search Climbs Mount Washington . . . . . . . . . . . . . . . . . . . . . . . . 4-48

Set Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-53


Set Options Using optimoptions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-53
Create Options and Problems Using the Optimization App . . . . . . . . . . . 4-54

Polling Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-56


Using a Complete Poll in a Generalized Pattern Search . . . . . . . . . . . . . . 4-56
Compare the Efficiency of Poll Options . . . . . . . . . . . . . . . . . . . . . . . . . . 4-59

Set Mesh Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-66


Mesh Expansion and Contraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-66
Mesh Accelerator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-71

Linear and Nonlinear Constrained Minimization Using patternsearch . 4-74


Linearly Constrained Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-74
Nonlinearly Constrained Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-77

Use Cache . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-80

Vectorize the Objective and Constraint Functions . . . . . . . . . . . . . . . . . . 4-84


Vectorize for Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-84
Vectorized Objective Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-84
Vectorized Constraint Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-86
Example of Vectorized Objective and Constraints . . . . . . . . . . . . . . . . . . 4-86

Optimize an ODE in Parallel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-88

Optimization of Stochastic Objective Function . . . . . . . . . . . . . . . . . . . . . 4-97

Using the Genetic Algorithm


5
What Is the Genetic Algorithm? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2

Minimize Rastrigin's Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3


Rastrigin's Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-3
Finding the Minimum of Rastrigin's Function . . . . . . . . . . . . . . . . . . . . . . 5-4
Finding the Minimum from the Command Line . . . . . . . . . . . . . . . . . . . . . 5-5

ix
Displaying Plots . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6

Genetic Algorithm Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9


Fitness Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Individuals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Populations and Generations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Diversity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-9
Fitness Values and Best Fitness Values . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10
Parents and Children . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-10

How the Genetic Algorithm Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11


Outline of the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
Initial Population . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-11
Creating the Next Generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12
Plots of Later Generations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Stopping Conditions for the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . 5-14
Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-15
Reproduction Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16
Mutation and Crossover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-16

Coding and Minimizing a Fitness Function Using the Genetic Algorithm


......................................................... 5-18

Constrained Minimization Using the Genetic Algorithm . . . . . . . . . . . . . 5-23

Effects of Genetic Algorithm Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-28

Mixed Integer ga Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-35


Solving Mixed Integer Optimization Problems . . . . . . . . . . . . . . . . . . . . . 5-35
Characteristics of the Integer ga Solver . . . . . . . . . . . . . . . . . . . . . . . . . 5-36
Effective Integer ga . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-41
Integer ga Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-41

Solving a Mixed Integer Engineering Design Problem Using the Genetic


Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-43

Nonlinear Constraint Solver Algorithms . . . . . . . . . . . . . . . . . . . . . . . . . . 5-52


Augmented Lagrangian Genetic Algorithm . . . . . . . . . . . . . . . . . . . . . . . 5-52
Penalty Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-53

Create Custom Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-55


About Custom Plot Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-55
Creating the Custom Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-55
Using the Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-56
How the Plot Function Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-57

Reproduce Results in Optimization App . . . . . . . . . . . . . . . . . . . . . . . . . . 5-58

Resume ga . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-59
Resuming ga From the Final Population . . . . . . . . . . . . . . . . . . . . . . . . . 5-59
Resuming ga From a Previous Run . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-62

Options and Outputs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-64


Running ga with the Default Options . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-64
Setting Options at the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-64

x Contents
Additional Output Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-65

Use Exported Options and Problems . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-67

Reproduce Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-68

Run ga from a File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-70

Population Diversity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-72


Importance of Population Diversity . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-72
Setting the Initial Range . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-72
Custom Plot Function and Linear Constraints in ga . . . . . . . . . . . . . . . . . 5-75
Setting the Population Size . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-79

Fitness Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-80


Scaling the Fitness Scores . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-80
Comparing Rank and Top Scaling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-81

Vary Mutation and Crossover . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-83


Setting the Amount of Mutation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-83
Setting the Crossover Fraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-85
Comparing Results for Varying Crossover Fractions . . . . . . . . . . . . . . . . 5-88

Global vs. Local Minima Using ga . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-90


Searching for a Global Minimum . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-90
Running the Genetic Algorithm on the Example . . . . . . . . . . . . . . . . . . . 5-91

Hybrid Scheme in the Genetic Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . 5-96

Set Maximum Number of Generations . . . . . . . . . . . . . . . . . . . . . . . . . . 5-101

Vectorize the Fitness Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-103


Vectorize for Speed . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-103
Vectorized Constraints . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-103

Nonlinear Constraints Using ga . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-105

Custom Output Function for Genetic Algorithm . . . . . . . . . . . . . . . . . . . 5-109

Custom Data Type Optimization Using the Genetic Algorithm . . . . . . . 5-113

When to Use a Hybrid Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-120

Particle Swarm Optimization


6
What Is Particle Swarm Optimization? . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2

Optimize Using Particle Swarm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-3

Particle Swarm Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-6

xi
Particle Swarm Optimization Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Algorithm Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9
Iteration Steps . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-10
Stopping Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-11

Tune Particle Swarm Optimization Process . . . . . . . . . . . . . . . . . . . . . . . . 6-12

Surrogate Optimization
7
What Is Surrogate Optimization? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2

Surrogate Optimization Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3


Serial surrogateopt Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-3
Mixed-Integer surrogateopt Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-7
surrogateopt Algorithm with Nonlinear Constraints . . . . . . . . . . . . . . . . . 7-9
Parallel surrogateopt Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9
Parallel Mixed-Integer surrogateopt Algorithm . . . . . . . . . . . . . . . . . . . . 7-10

Surrogate Optimization of Multidimensional Function . . . . . . . . . . . . . . 7-11

Modify surrogateopt Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-18

Interpret surrogateoptplot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-24

Compare Surrogate Optimization with Other Solvers . . . . . . . . . . . . . . . 7-30

Surrogate Optimization with Nonlinear Constraint . . . . . . . . . . . . . . . . . 7-40

Surrogate Optimization of Six-Element Yagi-Uda Antenna . . . . . . . . . . . 7-46

Work with Checkpoint Files . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-55


Checkpoint for Restarting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-55
Change Options to Extend or Monitor Optimization . . . . . . . . . . . . . . . . 7-57
Code for Robust Surrogate Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 7-59

Mixed-Integer Surrogate Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-61

Fix Variables in surrogateopt . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-63

Integer Optimization with Custom Output Function . . . . . . . . . . . . . . . . 7-66

Convert Nonlinear Constraints Between surrogateopt Form and Other


Solver Forms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-73
Why Convert Constraint Forms? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-73
Convert from surrogateopt Structure Form to Other Solvers . . . . . . . . . . 7-73
Convert from Other Solvers to surrogateopt Structure Form . . . . . . . . . . 7-75

Solve Feasibility Problem . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-77

xii Contents
Solve Nonlinear Problem with Integer and Nonlinear Constraints . . . . . 7-82

Using Simulated Annealing


8
What Is Simulated Annealing? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-2

Minimize Function with Many Local Minima . . . . . . . . . . . . . . . . . . . . . . . 8-3


Description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-3
Minimize at the Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4
Minimize Using the Optimization App . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-4

Simulated Annealing Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6


Objective Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Temperature . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Annealing Parameter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6
Reannealing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-6

How Simulated Annealing Works . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8


Outline of the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-8
Stopping Conditions for the Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-9
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-10

Reproduce Your Results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-11

Minimization Using Simulated Annealing Algorithm . . . . . . . . . . . . . . . . 8-13

Simulated Annealing Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-16

Multiprocessor Scheduling using Simulated Annealing with a Custom


Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-22

Multiobjective Optimization
9
What Is Multiobjective Optimization? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2

gamultiobj Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5


Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
Multiobjective Terminology . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-5
Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Iterations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Stopping Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-7
Bibliography . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-8

paretosearch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-9


paretosearch Algorithm Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-9
Definitions for paretosearch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-9
Sketch of paretosearch Algorithm . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12

xiii
Initialize Search . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13
Create Archive and Incumbents . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13
Poll to Find Better Points . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-13
Update archive and iterates Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14
Stopping Conditions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-14
Returned Values . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15
Modifications for Parallel Computation and Vectorized Function Evaluation
..................................................... 9-15
Run paretosearch Quickly . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-15

gamultiobj Options and Syntax: Differences from ga . . . . . . . . . . . . . . . . 9-17

Pareto Front for Two Objectives . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-18


Multiobjective Optimization with Two Objectives . . . . . . . . . . . . . . . . . . 9-18
Performing the Optimization with Optimization App . . . . . . . . . . . . . . . . 9-18
Performing the Optimization at the Command Line . . . . . . . . . . . . . . . . . 9-21
Alternate Views . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-21

Compare paretosearch and gamultiobj . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-23

Plot 3-D Pareto Front . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-34

Performing a Multiobjective Optimization Using the Genetic Algorithm


......................................................... 9-39

Multiobjective Genetic Algorithm Options . . . . . . . . . . . . . . . . . . . . . . . . 9-44

Design Optimization of a Welded Beam . . . . . . . . . . . . . . . . . . . . . . . . . . 9-53

Parallel Processing
10
How Solvers Compute in Parallel . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-2
Parallel Processing Types in Global Optimization Toolbox . . . . . . . . . . . . 10-2
How Toolbox Functions Distribute Processes . . . . . . . . . . . . . . . . . . . . . 10-3

How to Use Parallel Processing in Global Optimization Toolbox . . . . . . 10-11


Multicore Processors . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-11
Processor Network . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12
Parallel Search Functions or Hybrid Functions . . . . . . . . . . . . . . . . . . . 10-14
Testing Parallel Optimization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-16

Minimizing an Expensive Optimization Problem Using Parallel Computing


Toolbox™ . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-17

xiv Contents
Options Reference
11
GlobalSearch and MultiStart Properties (Options) . . . . . . . . . . . . . . . . . 11-2
How to Set Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
Properties of Both Objects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-2
GlobalSearch Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5
MultiStart Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-6

Pattern Search Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7


Optimization App vs. Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Plot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-7
Poll Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-10
Multiobjective Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11
Search Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-12
Mesh Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-15
Constraint Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-16
Cache Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-16
Stopping Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-17
Output Function Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-18
Display to Command Window Options . . . . . . . . . . . . . . . . . . . . . . . . . . 11-19
Vectorized and Parallel Options (User Function Evaluation) . . . . . . . . . 11-20
Options Table for Pattern Search Algorithms . . . . . . . . . . . . . . . . . . . . 11-22

Genetic Algorithm Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-24


Optimization App vs. Command Line . . . . . . . . . . . . . . . . . . . . . . . . . . 11-24
Plot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-25
Population Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-28
Fitness Scaling Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-30
Selection Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-31
Reproduction Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-33
Mutation Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-33
Crossover Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-35
Migration Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-38
Constraint Parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-38
Multiobjective Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-39
Hybrid Function Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-40
Stopping Criteria Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-41
Output Function Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-42
Display to Command Window Options . . . . . . . . . . . . . . . . . . . . . . . . . . 11-44
Vectorize and Parallel Options (User Function Evaluation) . . . . . . . . . . 11-44

Particle Swarm Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-46


Specifying Options for particleswarm . . . . . . . . . . . . . . . . . . . . . . . . . . 11-46
Swarm Creation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-46
Display Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-47
Algorithm Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-47
Hybrid Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-48
Output Function and Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-49
Parallel or Vectorized Function Evaluation . . . . . . . . . . . . . . . . . . . . . . 11-50
Stopping Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-51

Surrogate Optimization Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-52


Algorithm Control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-52
Stopping Criteria . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-52

xv
Command-Line Display . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-53
Output Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-54
Plot Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-56
Parallel Computing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-56
Checkpoint File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-57

Simulated Annealing Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-59


Set Simulated Annealing Options at the Command Line . . . . . . . . . . . . 11-59
Plot Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-59
Temperature Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-60
Algorithm Settings . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-61
Hybrid Function Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-62
Stopping Criteria Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-63
Output Function Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-63
Display Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-64

Options Changes in R2016a . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-66


Use optimoptions to Set Options . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-66
Options that optimoptions Hides . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-66
Table of Option Names in Legacy Order . . . . . . . . . . . . . . . . . . . . . . . . 11-68
Table of Option Names in Current Order . . . . . . . . . . . . . . . . . . . . . . . . 11-71

Functions
12

xvi Contents
Getting Started

17
1

Introducing Global Optimization Toolbox


Functions

• “Global Optimization Toolbox Product Description” on page 1-2


• “Comparison of Six Solvers” on page 1-3
• “Solver Behavior with a Nonsmooth Problem” on page 1-11
• “What Is Global Optimization?” on page 1-18
• “Optimization Workflow” on page 1-22
• “Table for Choosing a Solver” on page 1-23
• “Global Optimization Toolbox Solver Characteristics” on page 1-24
1 Introducing Global Optimization Toolbox Functions

Global Optimization Toolbox Product Description


Solve multiple maxima, multiple minima, and nonsmooth optimization problems

Global Optimization Toolbox provides functions that search for global solutions to problems that
contain multiple maxima or minima. Toolbox solvers include surrogate, pattern search, genetic
algorithm, particle swarm, simulated annealing, multistart, and global search. You can use these
solvers for optimization problems where the objective or constraint function is continuous,
discontinuous, stochastic, does not possess derivatives, or includes simulations or black-box
functions. For problems with multiple objectives, you can identify a Pareto front using genetic
algorithm or pattern search solvers.

You can improve solver effectiveness by adjusting options and, for applicable solvers, customizing
creation, update, and search functions. You can use custom data types with the genetic algorithm and
simulated annealing solvers to represent problems not easily expressed with standard data types. The
hybrid function option lets you improve a solution by applying a second solver after the first.

Key Features
• Surrogate solver for problems with lengthy objective function execution times and bound
constraints
• Pattern search solvers for single and multiple objective problems with linear, nonlinear, and bound
constraints
• Genetic algorithm for problems with linear, nonlinear, bound, and integer constraints
• Multiobjective genetic algorithm for problems with linear, nonlinear, and bound constraints
• Particle swarm solver for bound constraints
• Simulated annealing solver for bound constraints
• Multistart and global search solvers for smooth problems with linear, nonlinear, and bound
constraints

1-2
Comparison of Six Solvers

Comparison of Six Solvers


In this section...
“Function to Optimize” on page 1-3
“Six Solution Methods” on page 1-4
“Compare Syntax and Solutions” on page 1-9

Function to Optimize
This example shows how to minimize Rastrigin’s function with six solvers. Each solver has its own
characteristics. The characteristics lead to different solutions and run times. The results, examined in
“Compare Syntax and Solutions” on page 1-9, can help you choose an appropriate solver for your
own problems.

Rastrigin’s function has many local minima, with a global minimum at (0,0):

Ras(x) = 20 + x12 + x22 − 10 cos2πx1 + cos2πx2 .

Usually you don't know the location of the global minimum of your objective function. To show how
the solvers look for a global solution, this example starts all the solvers around the point [20,30],
which is far from the global minimum.

The rastriginsfcn.m file implements Rastrigin’s function. This file comes with Global Optimization
Toolbox software. This example employs a scaled version of Rastrigin’s function with larger basins of
attraction. For information, see “Basins of Attraction” on page 1-19.

rf2 = @(x)rastriginsfcn(x/10);

1-3
1 Introducing Global Optimization Toolbox Functions

This example minimizes rf2 using the default settings of fminunc (an Optimization Toolbox™
solver), patternsearch, and GlobalSearch. The example also uses ga and particleswarm with
nondefault options to start with an initial population around the point [20,30]. Because
surrogateopt requires finite bounds, the example uses surrogateopt with lower bounds of -70
and upper bounds of 130 in each variable.

Six Solution Methods


• “fminunc” on page 1-4
• “patternsearch” on page 1-5
• “ga” on page 1-6
• “particleswarm” on page 1-7
• “surrogateopt” on page 1-8
• “GlobalSearch” on page 1-8

fminunc

To solve the optimization problem using the fminunc Optimization Toolbox solver, enter:
rf2 = @(x)rastriginsfcn(x/10); % objective
x0 = [20,30]; % start point away from the minimum
[xf,ff,flf,of] = fminunc(rf2,x0)

fminunc returns

1-4
Comparison of Six Solvers

Local minimum found.

Optimization completed because the size of the gradient is


less than the default value of the function tolerance.

xf =
19.8991 29.8486
ff =
12.9344
flf =
1
of =

struct with fields:

iterations: 3
funcCount: 15
stepsize: 1.7776e-06
lssteplength: 1
firstorderopt: 5.9907e-09
algorithm: 'quasi-newton'
message: 'Local minimum found.…'

• xf is the minimizing point.


• ff is the value of the objective, rf2, at xf.
• flf is the exit flag. An exit flag of 1 indicates xf is a local minimum.
• of is the output structure, which describes the fminunc calculations leading to the solution.

patternsearch

To solve the optimization problem using the patternsearch Global Optimization Toolbox solver,
enter:
rf2 = @(x)rastriginsfcn(x/10); % objective
x0 = [20,30]; % start point away from the minimum
[xp,fp,flp,op] = patternsearch(rf2,x0)

patternsearch returns
Optimization terminated: mesh size less than options.MeshTolerance.
xp =
19.8991 -9.9496
fp =
4.9748
flp =
1
op =

struct with fields:

function: @(x)rastriginsfcn(x/10)
problemtype: 'unconstrained'
pollmethod: 'gpspositivebasis2n'
maxconstraint: []
searchmethod: []
iterations: 48
funccount: 174

1-5
1 Introducing Global Optimization Toolbox Functions

meshsize: 9.5367e-07
rngstate: [1x1 struct]
message: 'Optimization terminated: mesh size less than options.MeshTolerance.'

• xp is the minimizing point.


• fp is the value of the objective, rf2, at xp.
• flp is the exit flag. An exit flag of 1 indicates xp is a local minimum.
• op is the output structure, which describes the patternsearch calculations leading to the
solution.

ga

To solve the optimization problem using the ga Global Optimization Toolbox solver, enter:

rng default % for reproducibility


rf2 = @(x)rastriginsfcn(x/10); % objective
x0 = [20,30]; % start point away from the minimum
initpop = 10*randn(20,2) + repmat(x0,20,1);
opts = optimoptions('ga','InitialPopulationMatrix',initpop);
[xga,fga,flga,oga] = ga(rf2,2,[],[],[],[],[],[],[],opts)

initpop is a 20-by-2 matrix. Each row of initpop has mean [20,30], and each element is normally
distributed with standard deviation 10. The rows of initpop form an initial population matrix for the
ga solver.

opts is the options that set initpop as the initial population.

The final line calls ga, using the options.

ga uses random numbers, and produces a random result. In this case ga returns:

Optimization terminated: maximum number of generations exceeded.

xga =

-0.0042 -0.0024

fga =

4.7054e-05

flga =

oga =

struct with fields:

problemtype: 'unconstrained'
rngstate: [1×1 struct]
generations: 200
funccount: 9453

1-6
Comparison of Six Solvers

message: 'Optimization terminated: maximum number of generations exceeded.'


maxconstraint: []

• xga is the minimizing point.


• fga is the value of the objective, rf2, at xga.
• flga is the exit flag. An exit flag of 0 indicates that ga reached a function evaluation limit or an
iteration limit. In this case, ga reached an iteration limit.
• oga is the output structure, which describes the ga calculations leading to the solution.

particleswarm

Like ga, particleswarm is a population-based algorithm. So for a fair comparison of solvers,


initialize the particle swarm to the same population as ga.

rng default % for reproducibility


rf2 = @(x)rastriginsfcn(x/10); % objective
opts = optimoptions('particleswarm','InitialSwarmMatrix',initpop);
[xpso,fpso,flgpso,opso] = particleswarm(rf2,2,[],[],opts)

Optimization ended: relative change in the objective value


over the last OPTIONS.MaxStallIterations iterations is less than OPTIONS.FunctionTolerance.

xpso =

9.9496 0.0000

fpso =

0.9950

flgpso =

opso =

struct with fields:

rngstate: [1×1 struct]


iterations: 56
funccount: 1140
message: 'Optimization ended: relative change in the objective value ↵over the last OPTION

• xpso is the minimizing point.


• fpso is the value of the objective, rf2, at xpso.
• flgpso is the exit flag. An exit flag of 1 indicates xpso is a local minimum.
• opso is the output structure, which describes the particleswarm calculations leading to the
solution.

1-7
1 Introducing Global Optimization Toolbox Functions

surrogateopt

surrogateopt does not require a start point, but does require finite bounds. Set bounds of –70 to
130 in each component. To have the same sort of output as the other solvers, disable the default plot
function.
rng default % for reproducibility
lb = [-70,-70];
ub = [130,130];
rf2 = @(x)rastriginsfcn(x/10); % objective
opts = optimoptions('surrogateopt','PlotFcn',[]);
[xsur,fsur,flgsur,osur] = surrogateopt(rf2,lb,ub,opts)

Surrogateopt stopped because it exceeded the function evaluation limit set by


'options.MaxFunctionEvaluations'.

xsur =

-0.0033 0.0005

fsur =

2.2456e-05

flgsur =

osur =

struct with fields:

elapsedtime: 2.3877
funccount: 200
rngstate: [1×1 struct]
message: 'Surrogateopt stopped because it exceeded the function evaluation limit set by ↵

• xsur is the minimizing point.


• fsur is the value of the objective, rf2, at xsur.
• flgsur is the exit flag. An exit flag of 0 indicates that surrogateopt halted because it ran out of
function evaluations or time.
• osur is the output structure, which describes the surrogateopt calculations leading to the
solution.

GlobalSearch

To solve the optimization problem using the GlobalSearch solver, enter:


rf2 = @(x)rastriginsfcn(x/10); % objective
x0 = [20,30]; % start point away from the minimum
problem = createOptimProblem('fmincon','objective',rf2,...
'x0',x0);
gs = GlobalSearch;
[xg,fg,flg,og] = run(gs,problem)

1-8
Comparison of Six Solvers

problem is an optimization problem structure. problem specifies the fmincon solver, the rf2
objective function, and x0=[20,30]. For more information on using createOptimProblem, see
“Create Problem Structure” on page 3-4.

Note You must specify fmincon as the solver for GlobalSearch, even for unconstrained problems.

gs is a default GlobalSearch object. The object contains options for solving the problem. Calling
run(gs,problem) runs problem from multiple start points. The start points are random, so the
following result is also random.

In this case, the run returns:


GlobalSearch stopped because it analyzed all the trial points.

All 10 local solver runs converged with a positive local solver exit flag.

xg =

1.0e-07 *

-0.1405 -0.1405

fg =

flg =

og =

struct with fields:

funcCount: 2350
localSolverTotal: 10
localSolverSuccess: 10
localSolverIncomplete: 0
localSolverNoSolution: 0
message: 'GlobalSearch stopped because it analyzed all the trial points.↵↵All 10 local solver runs converged with a po

• xg is the minimizing point.


• fg is the value of the objective, rf2, at xg.
• flg is the exit flag. An exit flag of 1 indicates all fmincon runs converged properly.
• og is the output structure, which describes the GlobalSearch calculations leading to the
solution.

Compare Syntax and Solutions


One solution is better than another if its objective function value is smaller than the other. The
following table summarizes the results, accurate to one decimal.

Results fminunc patternsearch ga particleswar surrogateopt GlobalSearch


m
solution [19.9 29.9] [19.9 -9.9] [0 0] [10 0] [0 0] [0 0]
objective 12.9 5 0 1 0 0
# Fevals 15 174 9453 1140 200 2178

1-9
1 Introducing Global Optimization Toolbox Functions

These results are typical:

• fminunc quickly reaches the local solution within its starting basin, but does not explore outside
this basin at all. fminunc has a simple calling syntax.
• patternsearch takes more function evaluations than fminunc, and searches through several
basins, arriving at a better solution than fminunc. The patternsearch calling syntax is the
same as that of fminunc.
• ga takes many more function evaluations than patternsearch. By chance it arrived at a better
solution. In this case, ga found a point near the global optimum. ga is stochastic, so its results
change with every run. ga has a simple calling syntax, but there are extra steps to have an initial
population near [20,30].
• particleswarm takes fewer function evaluations than ga, but more than patternsearch. In
this case, particleswarm found a point with lower objective function value than
patternsearch, but higher than ga. Because particleswarm is stochastic, its results change
with every run. particleswarm has a simple calling syntax, but there are extra steps to have an
initial population near [20,30].
• surrogateopt stops when it reaches a function evaluation limit, which by default is 200 for a
two-variable problem. surrogateopt has a simple calling syntax, but requires finite bounds.
surrogateopt attempts to find a global solution, and in this case succeeded. Each function
evaluation in surrogateopt takes a longer time than in most other solvers, because
surrogateopt performs many auxiliary computations as part of its algorithm.
• GlobalSearch run takes the same order of magnitude of function evaluations as ga and
particleswarm, searches many basins, and arrives at a good solution. In this case,
GlobalSearch found the global optimum. Setting up GlobalSearch is more involved than
setting up the other solvers. As the example shows, before calling GlobalSearch, you must
create both a GlobalSearch object (gs in the example), and a problem structure (problem).
Then, you call the run method with gs and problem. For more details on how to run
GlobalSearch, see “Workflow for GlobalSearch and MultiStart” on page 3-3.

See Also

More About
• “Optimization Problem Setup”
• “Solver Behavior with a Nonsmooth Problem” on page 1-11

1-10
Solver Behavior with a Nonsmooth Problem

Solver Behavior with a Nonsmooth Problem


This example shows the importance of choosing an appropriate solver for optimization problems. It
also shows that a single point of non-smoothness can cause problems for Optimization Toolbox™
solvers.

In general, the solver decision tables provide guidance on which solver is likely to work best for your
problem. For smooth problems, see “Optimization Decision Table” (Optimization Toolbox). For
nonsmooth problems, see “Table for Choosing a Solver” on page 1-23 first, and for more information
consult “Global Optimization Toolbox Solver Characteristics” on page 1-24.

A Function with a Single Nonsmooth Point

1/2
The function f (x) = x is nonsmooth at the point 0, which is the minimizing point. Here is a 2-D
x(1) x(2)
plot using the matrix norm for the 4-D point .
0 0

figure
x = linspace(-5,5,51);
[xx,yy] = meshgrid(x);
zz = zeros(size(xx));
for ii = 1:length(x)
for jj = 1:length(x)
zz(ii,jj) = sqrt(norm([xx(ii,jj),yy(ii,jj);0,0]));
end
end

surf(xx,yy,zz)
xlabel('x(1)')
ylabel('x(2)')
title('Norm([x(1),x(2);0,0])^{1/2}')

1-11
1 Introducing Global Optimization Toolbox Functions

This example uses matrix norm for a 2-by-6 matrix x. The matrix norm relates to the singular value
decomposition, which is not as smooth as the Euclidean norm. See “2-Norm of Matrix” (MATLAB).

Minimize Using patternsearch

patternsearch is the recommended first solver to try for nonsmooth problems. See “Table for
Choosing a Solver” on page 1-23. Start patternsearch from a nonzero 2-by-6 matrix x0, and
attempt to locate the minimum of f . For this attempt, and all others, use the default solver options.

Return the solution, which should be near zero, the objective function value, which should likewise be
near zero, and the number of function evaluations taken.
fun = @(x)norm([x(1:6);x(7:12)])^(1/2);
x0 = [1:6;7:12];
rng default
x0 = x0 + rand(size(x0))

x0 = 2×6

1.8147 2.1270 3.6324 4.2785 5.9575 6.1576


7.9058 8.9134 9.0975 10.5469 11.9649 12.9706

[xps,fvalps,eflagps,outputps] = patternsearch(fun,x0);

Optimization terminated: mesh size less than options.MeshTolerance.

xps,fvalps,eflagps,outputps.funccount

1-12
Solver Behavior with a Nonsmooth Problem

xps = 2×6
10-4 ×

0.1116 -0.1209 0.3503 -0.0520 -0.1270 0.2031


-0.3082 -0.1526 0.0623 0.0652 0.4479 0.1173

fvalps = 0.0073

eflagps = 1

ans = 10780

patternsearch reaches a good solution, as evinced by exit flag 1. However, it takes over 10,000
function evaluations to converge.

Minimize Using fminsearch

The documentation states that fminsearch sometimes can handle discontinuities, so this is a
reasonable option.

[xfms,fvalfms,eflagfms,outputfms] = fminsearch(fun,x0);

Exiting: Maximum number of function evaluations has been exceeded


- increase MaxFunEvals option.
Current function value: 3.197063

xfms,fvalfms,eflagfms,outputfms.funcCount

xfms = 2×6

2.2640 1.1747 9.0693 8.1652 1.7367 -1.2958


3.7456 1.2694 0.2714 -3.7942 3.8714 1.9290

fvalfms = 3.1971

eflagfms = 0

ans = 2401

Using default options, fminsearch runs out of function evaluations before it converges to a solution.
Exit flag 0 indicates this lack of convergence. The reported solution is poor.

Use particleswarm

particleswarm is recommended as the next solver to try. See “Choosing Between Solvers for
Nonsmooth Problems” on page 1-26.

[xpsw,fvalpsw,eflagpsw,outputpsw] = particleswarm(fun,12);

Optimization ended: relative change in the objective value


over the last OPTIONS.MaxStallIterations iterations is less than OPTIONS.FunctionTolerance.

xpsw,fvalpsw,eflagpsw,outputpsw.funccount

xpsw = 1×12
10-12 ×

1-13
1 Introducing Global Optimization Toolbox Functions

-0.0386 -0.1282 -0.0560 0.0904 0.0771 -0.0541 -0.1189 0.1290 -0.0032 0.0

fvalpsw = 4.5222e-07

eflagpsw = 1

ans = 37200

particleswarm finds an even more accurate solution than patternsearch, but takes over 35,000
function evaluations. Exit flag 1 indicates that the solution is good.

Use ga

ga is a popular solver, but is not recommended as the first solver to try. See how well it works on this
problem.
[xga,fvalga,eflagga,outputga] = ga(fun,12);

Optimization terminated: average change in the fitness value less than options.FunctionTolerance.

xga,fvalga,eflagga,outputga.funccount

xga = 1×12

-0.0061 -0.0904 0.0816 -0.0484 0.0799 -0.1925 0.0048 0.3581 0.0848 0.0

fvalga = 0.6257

eflagga = 1

ans = 65190

ga does not find as good a solution as patternsearch or particleswarm, and takes about twice as
many function evaluations as particleswarm. Exit flag 1 is misleading in this case.

Use fminunc from Optimization Toolbox

fminunc is not recommended for nonsmooth functions. See how it performs on this one.
[xfmu,fvalfmu,eflagfmu,outputfmu] = fminunc(fun,x0);

Local minimum possible.

fminunc stopped because the size of the current step is less than
the value of the step size tolerance.

xfmu,fvalfmu,eflagfmu,outputfmu.funcCount

xfmu = 2×6

-0.5844 -0.9726 -0.4356 0.1467 0.3263 -0.1002


-0.0769 -0.1092 -0.3429 -0.6856 -0.7609 -0.6524

fvalfmu = 1.1269

eflagfmu = 2

ans = 442

1-14
Solver Behavior with a Nonsmooth Problem

The fminunc solution is not as good as the ga solution. However, fminunc reaches the rather poor
solution in relatively few function evaluations. Exit flag 2 means you should take care, the first-order
optimality conditions are not met at the reported solution.

Use fmincon from Optimization Toolbox

fmincon can sometimes minimize nonsmooth functions. See how it performs on this one.

[xfmc,fvalfmc,eflagfmc,outputfmc] = fmincon(fun,x0);

Local minimum possible. Constraints satisfied.

fmincon stopped because the size of the current step is less than
the value of the step size tolerance and constraints are
satisfied to within the value of the constraint tolerance.

xfmc,fvalfmc,eflagfmc,outputfmc.funcCount

xfmc = 2×6
10-10 ×

-0.4534 -0.5599 0.1599 0.8530 0.8112 -0.0575


0.4979 0.4522 0.6556 -0.2374 -0.8218 -0.5604

fvalfmc = 1.3880e-05

eflagfmc = 2

ans = 1066

fmincon with default options produces an accurate solution after fewer than 1000 function
evaluations. Exit flag 2 does not mean that the solution is inaccurate, but that the first-order
optimality conditions are not met. This is because the gradient of the objective function is not zero at
the solution.

Summary of Results

Choosing the appropriate solver leads to better, faster results. This summary shows how disparate
the results can be. The solution quality is 'Poor' if the objective function value is greater than 0.1,
'Good' if the value is smaller than 0.01, and 'Mediocre' otherwise.

Solver = {'patternsearch';'fminsearch';'particleswarm';'ga';'fminunc';'fmincon'};
SolutionQuality = {'Good';'Poor';'Good';'Poor';'Poor';'Good'};
FVal = [fvalps,fvalfms,fvalpsw,fvalga,fvalfmu,fvalfmc]';
NumEval = [outputps.funccount,outputfms.funcCount,outputpsw.funccount,...
outputga.funccount,outputfmu.funcCount,outputfmc.funcCount]';
results = table(Solver,SolutionQuality,FVal,NumEval)

results=6×4 table
Solver SolutionQuality FVal NumEval
_________________ _______________ __________ _______

{'patternsearch'} {'Good'} 0.0072656 10780


{'fminsearch' } {'Poor'} 3.1971 2401
{'particleswarm'} {'Good'} 4.5222e-07 37200
{'ga' } {'Poor'} 0.62572 65190
{'fminunc' } {'Poor'} 1.1269 442

1-15
1 Introducing Global Optimization Toolbox Functions

{'fmincon' } {'Good'} 1.388e-05 1066

Another view of the results.

figure
hold on
for ii = 1:length(FVal)
clr = rand(1,3);
plot(NumEval(ii),FVal(ii),'o','MarkerSize',10,'MarkerEdgeColor',clr,'MarkerFaceColor',clr)
text(NumEval(ii),FVal(ii)+0.2,Solver{ii},'Color',clr);
end
ylabel('FVal')
xlabel('NumEval')
title('Reported Minimum and Evaluations By Solver')
hold off

While particleswarm achieves the lowest objective function value, it does so by taking over three
times as many function evaluations as patternsearch, and over 30 times as many as fmincon.

1-16
Solver Behavior with a Nonsmooth Problem

fmincon is not generally recommended for nonsmooth problems. It is effective in this case, but this
case has just one nonsmooth point.

See Also

More About
• “Comparison of Six Solvers” on page 1-3
• “Table for Choosing a Solver” on page 1-23
• “Global Optimization Toolbox Solver Characteristics” on page 1-24

1-17
1 Introducing Global Optimization Toolbox Functions

What Is Global Optimization?

In this section...
“Local vs. Global Optima” on page 1-18
“Basins of Attraction” on page 1-19

Local vs. Global Optima


Optimization is the process of finding the point that minimizes a function. More specifically:

• A local minimum of a function is a point where the function value is smaller than or equal to the
value at nearby points, but possibly greater than at a distant point.
• A global minimum is a point where the function value is smaller than or equal to the value at all
other feasible points.

Generally, Optimization Toolbox solvers find a local optimum. (This local optimum can be a global
optimum.) They find the optimum in the basin of attraction of the starting point. For more
information, see “Basins of Attraction” on page 1-19.

In contrast, Global Optimization Toolbox solvers are designed to search through more than one basin
of attraction. They search in various ways:

• GlobalSearch and MultiStart generate a number of starting points. They then use a local
solver to find the optima in the basins of attraction of the starting points.
• ga uses a set of starting points (called the population) and iteratively generates better points from
the population. As long as the initial population covers several basins, ga can examine several
basins.
• particleswarm, like ga, uses a set of starting points. particleswarm can examine several
basins at once because of its diverse population.
• simulannealbnd performs a random search. Generally, simulannealbnd accepts a point if it is
better than the previous point. simulannealbnd occasionally accepts a worse point, in order to
reach a different basin.
• patternsearch looks at a number of neighboring points before accepting one of them. If some
neighboring points belong to different basins, patternsearch in essence looks in a number of
basins at once.
• surrogateopt begins by quasirandom sampling within bounds, looking for a small objective
function value. surrogateopt uses a merit function that, in part, gives preference to points that
are far from evaluated points, which is an attempt to reach a global solution. After it cannot
improve the current point, surrogateopt resets, causing it to sample widely within bounds
again. Resetting is another way surrogateopt searches for a global solution.

1-18
What Is Global Optimization?

Basins of Attraction
If an objective function f(x) is smooth, the vector –∇f(x) points in the direction where f(x) decreases
most quickly. The equation of steepest descent, namely

d
x(t) = − ∇ f (x(t)),
dt

yields a path x(t) that goes to a local minimum as t gets large. Generally, initial values x(0) that are
close to each other give steepest descent paths that tend to the same minimum point. The basin of
attraction for steepest descent is the set of initial values leading to the same local minimum.

The following figure shows two one-dimensional minima. The figure shows different basins of
attraction with different line styles, and it shows directions of steepest descent with arrows. For this
and subsequent figures, black dots represent local minima. Every steepest descent path, starting at a
point x(0), goes to the black dot in the basin containing x(0).

The following figure shows how steepest descent paths can be more complicated in more dimensions.

The following figure shows even more complicated paths and basins of attraction.

1-19
1 Introducing Global Optimization Toolbox Functions

Constraints can break up one basin of attraction into several pieces. For example, consider
minimizing y subject to:

• y ≥ |x|
• y ≥ 5 – 4(x–2)2.

The figure shows the two basins of attraction with the final points.

1-20
What Is Global Optimization?

The steepest descent paths are straight lines down to the constraint boundaries. From the constraint
boundaries, the steepest descent paths travel down along the boundaries. The final point is either
(0,0) or (11/4,11/4), depending on whether the initial x-value is above or below 2.

See Also

More About
• “Visualize the Basins of Attraction” on page 3-27
• “Comparison of Six Solvers” on page 1-3

1-21
1 Introducing Global Optimization Toolbox Functions

Optimization Workflow
To solve an optimization problem:

1 Decide what type of problem you have, and whether you want a local or global solution (see
“Local vs. Global Optima” on page 1-18). Choose a solver per the recommendations in “Table for
Choosing a Solver” on page 1-23.
2 Write your objective function and, if applicable, constraint functions per the syntax in “Compute
Objective Functions” on page 2-2 and “Write Constraints” on page 2-6.
3 Set appropriate options using optimoptions, or prepare a GlobalSearch or MultiStart
problem as described in “Workflow for GlobalSearch and MultiStart” on page 3-3. For details,
see “Pattern Search Options” on page 11-7, “Particle Swarm Options” on page 11-46,
“Genetic Algorithm Options” on page 11-24, “Simulated Annealing Options” on page 11-59, or
“Surrogate Optimization Options” on page 11-52.
4 Run the solver.
5 Examine the result. For information on the result, see “Solver Outputs and Iterative Display”
(Optimization Toolbox) or Examine Results for GlobalSearch or MultiStart.
6 If the result is unsatisfactory, change options or start points or otherwise update your
optimization and rerun it. For information, see “Global Optimization Toolbox Solver
Characteristics” on page 1-24 or Improve Results. For information on improving solutions that
applies mainly to smooth problems, see “When the Solver Fails” (Optimization Toolbox), “When
the Solver Might Have Succeeded” (Optimization Toolbox), or “When the Solver Succeeds”
(Optimization Toolbox).

See Also

More About
• “Optimization Problem Setup”
• “What Is Global Optimization?” on page 1-18

1-22
Table for Choosing a Solver

Table for Choosing a Solver


Choose a solver based on problem characteristics and on the type of solution you want. “Solver
Characteristics” on page 1-27 contains more information to help you decide which solver is likely to
be most suitable. This table gives recommendations that are suitable for most problems.

Problem Type Recommended Solver


Smooth (objective twice differentiable), and you An appropriate Optimization Toolbox solver; see
want a local solution “Optimization Decision Table” (Optimization
Toolbox)
Smooth (objective twice differentiable), and you GlobalSearch or MultiStart
want a global solution or multiple local solutions
Nonsmooth, and you want a local solution patternsearch
Nonsmooth, and you want a global solution or surrogateopt or patternsearch with several
multiple local solutions initial points x0

To start patternsearch at multiple points when you have finite bounds lb and ub on every
component, try:

x0 = lb + rand(size(lb)).*(ub - lb);

Many other solvers provide different solution algorithms, including the genetic algorithm solver ga
and the particleswarm solver. Try some of them if the recommended solvers do not perform well on
your problem. For details, see “Global Optimization Toolbox Solver Characteristics” on page 1-24.

See Also

Related Examples
• “Solver Behavior with a Nonsmooth Problem”

More About
• “Optimization Workflow” on page 1-22
• “Global Optimization Toolbox Solver Characteristics” on page 1-24

1-23
1 Introducing Global Optimization Toolbox Functions

Global Optimization Toolbox Solver Characteristics


In this section...
“Solver Choices” on page 1-24
“Explanation of “Desired Solution”” on page 1-24
“Choosing Between Solvers for Smooth Problems” on page 1-26
“Choosing Between Solvers for Nonsmooth Problems” on page 1-26
“Solver Characteristics” on page 1-27
“Why Are Some Solvers Objects?” on page 1-29

Solver Choices
This section describes Global Optimization Toolbox solver characteristics. The section includes
recommendations for obtaining results more effectively.

To achieve better or faster solutions, first try tuning the recommended solvers on page 1-23 by
setting appropriate options or bounds. If the results are unsatisfactory, try other solvers.

Desired Solution Smooth Objective and Constraints Nonsmooth Objective or


Constraints
“Explanation of “Desired “Choosing Between Solvers for Smooth “Choosing Between Solvers for
Solution”” on page 1-24 Problems” on page 1-26 Nonsmooth Problems” on page 1-26
Single local solution Optimization Toolbox functions; see fminbnd, patternsearch,
“Optimization Decision Table” fminsearch, ga, particleswarm,
(Optimization Toolbox) simulannealbnd, surrogateopt
Multiple local solutions GlobalSearch, MultiStart patternsearch, ga,
particleswarm, simulannealbnd,
or surrogateopt started from
multiple initial points x0 or from
multiple initial populations
Single global solution GlobalSearch, MultiStart, patternsearch, ga,
patternsearch, particleswarm, particleswarm, simulannealbnd,
ga, simulannealbnd, surrogateopt surrogateopt
Single local solution using MultiStart, Optimization Toolbox patternsearch, ga,
parallel processing functions particleswarm, surrogateopt
Multiple local solutions using MultiStart patternsearch, ga, or
parallel processing particleswarm started from multiple
initial points x0 or from multiple initial
populations
Single global solution using MultiStart patternsearch, ga,
parallel processing particleswarm, surrogateopt

Explanation of “Desired Solution”


To understand the meaning of the terms in “Desired Solution,” consider the example

1-24
Global Optimization Toolbox Solver Characteristics

f(x)=100x2(1–x)2–x,

which has local minima x1 near 0 and x2 near 1:

The minima are located at:

fun = @(x)(100*x^2*(x - 1)^2 - x);


x1 = fminbnd(fun,-0.1,0.1)
x1 =
0.0051

x2 = fminbnd(fun,0.9,1.1)
x2 =
1.0049

Description of the Terms

Term Meaning
Single local solution Find one local solution, a point x where the objective function f(x)
is a local minimum. For more details, see “Local vs. Global Optima”
on page 1-18. In the example, both x1 and x2 are local solutions.
Multiple local solutions Find a set of local solutions. In the example, the complete set of
local solutions is {x1,x2}.
Single global solution Find the point x where the objective function f(x) is a global
minimum. In the example, the global solution is x2.

1-25
1 Introducing Global Optimization Toolbox Functions

Choosing Between Solvers for Smooth Problems


• “Single Global Solution” on page 1-26
• “Multiple Local Solutions” on page 1-26

Single Global Solution

1 Try GlobalSearch first. It is most focused on finding a global solution, and has an efficient local
solver, fmincon.
2 Try MultiStart next. It has efficient local solvers, and can search a wide variety of start points.
3 Try patternsearch next. It is less efficient, since it does not use gradients. However,
patternsearch is robust and is more efficient than the remaining local solvers To search for a
global solution, start patternsearch from a variety of start points.
4 Try surrogateopt next. surrogateopt attempts to find a global solution using the fewest
objective function evaluations. surrogateopt has more overhead per function evaluation than
most other solvers. surrogateopt requires finite bounds, and accepts both integer constraints
and nonlinear inequality constraints.
5 Try particleswarm next, if your problem is unconstrained or has only bound constraints.
Usually, particleswarm is more efficient than the remaining solvers, and can be more efficient
than patternsearch.
6 Try ga next. It can handle all types of constraints, and is usually more efficient than
simulannealbnd.
7 Try simulannealbnd last. It can handle problems with no constraints or bound constraints.
simulannealbnd is usually the least efficient solver. However, given a slow enough cooling
schedule, it can find a global solution.

Multiple Local Solutions

GlobalSearch and MultiStart both provide multiple local solutions. For the syntax to obtain
multiple solutions, see “Multiple Solutions” on page 3-20. GlobalSearch and MultiStart differ in
the following characteristics:

• MultiStart can find more local minima. This is because GlobalSearch rejects many generated
start points (initial points for local solution). Essentially, GlobalSearch accepts a start point only
when it determines that the point has a good chance of obtaining a global minimum. In contrast,
MultiStart passes all generated start points to a local solver. For more information, see
“GlobalSearch Algorithm” on page 3-38.
• MultiStart offers a choice of local solver: fmincon, fminunc, lsqcurvefit, or lsqnonlin.
The GlobalSearch solver uses only fmincon as its local solver.
• GlobalSearch uses a scatter-search algorithm for generating start points. In contrast,
MultiStart generates points uniformly at random within bounds, or allows you to provide your
own points.
• MultiStart can run in parallel. See “How to Use Parallel Processing in Global Optimization
Toolbox” on page 10-11.

Choosing Between Solvers for Nonsmooth Problems


Choose the applicable solver with the lowest number. For problems with integer constraints, use ga.

1-26
Global Optimization Toolbox Solver Characteristics

1 Use fminbnd first on one-dimensional bounded problems only. fminbnd provably converges
quickly in one dimension.
2 Use patternsearch on any other type of problem. patternsearch provably converges, and
handles all types of constraints.
3 Try surrogateopt for problems that have time-consuming objective functions. surrogateopt
searches for a global solution. surrogateopt requires finite bounds, and accepts both integer
constraints and nonlinear inequality constraints.
4 Try fminsearch next for low-dimensional unbounded problems. fminsearch is not as general
as patternsearch and can fail to converge. For low-dimensional problems, fminsearch is
simple to use, since it has few tuning options.
5 Try particleswarm next on unbounded or bound-constrained problems. particleswarm has
little supporting theory, but is often an efficient algorithm.
6 Try ga next. ga has little supporting theory and is often less efficient than patternsearch or
particleswarm. ga handles all types of constraints. ga and surrogateopt are the only Global
Optimization Toolbox solvers that accept integer constraints.
7 Try simulannealbnd last for unbounded problems, or for problems with bounds.
simulannealbnd provably converges only for a logarithmic cooling schedule, which is
extremely slow. simulannealbnd takes only bound constraints, and is often less efficient than
ga.

Solver Characteristics
Solver Convergence Characteristics
GlobalSearch Fast convergence to local optima for Deterministic iterates
smooth problems Gradient-based
Automatic stochastic start points
Removes many start points heuristically
MultiStart Fast convergence to local optima for Deterministic iterates
smooth problems Can run in parallel; see “How to Use
Parallel Processing in Global Optimization
Toolbox” on page 10-11
Gradient-based
Stochastic or deterministic start points, or
combination of both
Automatic stochastic start points
Runs all start points
Choice of local solver: fmincon, fminunc,
lsqcurvefit, or lsqnonlin
patternsearch Proven convergence to local Deterministic iterates
optimum; slower than gradient- Can run in parallel; see “How to Use
based solvers Parallel Processing in Global Optimization
Toolbox” on page 10-11
No gradients

1-27
1 Introducing Global Optimization Toolbox Functions

Solver Convergence Characteristics


User-supplied start point
surrogateopt Proven convergence to global Stochastic iterates
optimum for bounded problems; Can run in parallel; see “How to Use
slower than gradient-based solvers; Parallel Processing in Global Optimization
generally stops by reaching a Toolbox” on page 10-11
function evaluation limit or other
limit Best used for time-consuming objective
functions
Requires bound constraints, accepts
nonlinear inequality constraints
Allows integer constraints; see “Mixed-
Integer Surrogate Optimization” on page
7-61
No gradients
Automatic start points or user-supplied
points, or a combination of both
particleswarm No convergence proof Stochastic iterates
Can run in parallel; see “How to Use
Parallel Processing in Global Optimization
Toolbox” on page 10-11
Population-based
No gradients
Automatic start population or user-
supplied population, or a combination of
both
Only bound constraints
ga No convergence proof Stochastic iterates
Can run in parallel; see “How to Use
Parallel Processing in Global Optimization
Toolbox” on page 10-11
Population-based
No gradients
Allows integer constraints; see “Mixed
Integer ga Optimization” on page 5-35
Automatic start population or user-
supplied population, or a combination of
both
simulannealbnd Proven to converge to global Stochastic iterates
optimum for bounded problems with No gradients
very slow cooling schedule
User-supplied start point
Only bound constraints

Explanation of some characteristics:

1-28
Global Optimization Toolbox Solver Characteristics

• Convergence — Solvers can fail to converge to any solution when started far from a local
minimum. When started near a local minimum, gradient-based solvers converge to a local
minimum quickly for smooth problems. patternsearch provably converges for a wide range of
problems, but the convergence is slower than gradient-based solvers. Both ga and
simulannealbnd can fail to converge in a reasonable amount of time for some problems,
although they are often effective.
• Iterates — Solvers iterate to find solutions. The steps in the iteration are iterates. Some solvers
have deterministic iterates. Others use random numbers and have stochastic iterates.
• Gradients — Some solvers use estimated or user-supplied derivatives in calculating the iterates.
Other solvers do not use or estimate derivatives, but use only objective and constraint function
values.
• Start points — Most solvers require you to provide a starting point for the optimization in order to
obtain the dimension of the decision variables. ga and surrogateopt do not require any starting
points, because they take the dimension of the decision variables as an input or infer dimensions
from bounds. These solvers generate a start point or population automatically, or they accept a
point or points that you supply.

Compare the characteristics of Global Optimization Toolbox solvers to Optimization Toolbox solvers.

Solver Convergence Characteristics


fmincon, fminunc, Proven quadratic convergence to Deterministic iterates
fseminf, lsqcurvefit, local optima for smooth problems Gradient-based
lsqnonlin
User-supplied starting point
fminsearch No convergence proof — Deterministic iterates
counterexamples exist. No gradients
User-supplied start point
No constraints
fminbnd Proven convergence to local optima Deterministic iterates
for smooth problems, slower than No gradients
quadratic.
User-supplied start interval
Only one-dimensional problems

All these Optimization Toolbox solvers:

• Have deterministic iterates


• Require a start point or interval
• Search just one basin of attraction

Why Are Some Solvers Objects?


GlobalSearch and MultiStart are objects. What does this mean for you?

• You create a GlobalSearch or MultiStart object before running your problem.


• You can reuse the object for running multiple problems.
• GlobalSearch and MultiStart objects are containers for algorithms and global options. You
use these objects to run a local solver multiple times. The local solver has its own options.

1-29
1 Introducing Global Optimization Toolbox Functions

For more information, see the “Classes” (MATLAB) documentation.

See Also

Related Examples
• “Solver Behavior with a Nonsmooth Problem”

More About
• “Optimization Workflow” on page 1-22
• “Table for Choosing a Solver” on page 1-23

1-30
2

Write Files for Optimization Functions

• “Compute Objective Functions” on page 2-2


• “Maximizing vs. Minimizing” on page 2-5
• “Write Constraints” on page 2-6
• “Set and Change Options” on page 2-9
• “View Options” on page 2-10
2 Write Files for Optimization Functions

Compute Objective Functions


In this section...
“Objective (Fitness) Functions” on page 2-2
“Write a Function File” on page 2-2
“Write a Vectorized Function” on page 2-3
“Gradients and Hessians” on page 2-4

Objective (Fitness) Functions


To use Global Optimization Toolbox functions, first write a file (or an anonymous function) that
computes the function you want to optimize. This is called an objective function for most solvers, or
fitness function for ga. The function should accept a vector, whose length is the number of
independent variables, and return a scalar. For gamultiobj, the function should return a row vector
of objective function values. For vectorized solvers, the function should accept a matrix, where each
row represents one input vector, and return a vector of objective function values. This section shows
how to write the file.

Write a Function File


This example shows how to write a file for the function you want to optimize. Suppose that you want
to minimize the function

f (x) = exp − x12 + x22 x12 − 2x1x2 + 6x1 + 4x22 − 3x2 .

The file that computes this function must accept a vector x of length 2, corresponding to the variables
x1 and x2, and return a scalar equal to the value of the function at x.

1 Select New > Script (Ctrl+N) from the MATLAB® File menu. A new file opens in the editor.
2 Enter the following two lines of code:

function z = my_fun(x)
z = x(1)^2 - 2*x(1)*x(2) + 6*x(1) + 4*x(2)^2 - 3*x(2);
3 Save the file in a folder on the MATLAB path.

Check that the file returns the correct value.

my_fun([2 3])

ans =
31

For gamultiobj, suppose you have three objectives. Your objective function returns a three-element
vector consisting of the three objective function values:

function z = my_fun(x)
z = zeros(1,3); % allocate output
z(1) = x(1)^2 - 2*x(1)*x(2) + 6*x(1) + 4*x(2)^2 - 3*x(2);
z(2) = x(1)*x(2) + cos(3*x(2)/(2+x(1)));
z(3) = tanh(x(1) + x(2));

2-2
Other documents randomly have
different content
Fourth. Excellent silks and cloth of gold were also made at Málaga,
Seville, Toledo, and Valencia. Indeed, no better source exists for
studying the character of this important industry in older Spain than
the Ordinances of the cities I have just enumerated.[9] We learn
from these municipal provisions, most of which were framed or
ratified in the reign of Ferdinand and Isabella, that the mingling of
fine with base material was forbidden in the strictest terms, and that
the styles and classes of even the luxurious and elaborate stuffs,
which bore an infinite variety of devices, were very numerous. Thus,
there were satins, taffetas, azeytunis, double and single velvets
(Plates iv. and vii.), brocades, and silken serges; as well as fabrics
interwoven with gold and silver thread, including the gorgoranes,
restaños, sargas, and jergas de filigrana de plata. The Ordinances of
Toledo mention the following fabrics as manufactured in that city in
the reigns of Ferdinand and Isabella, and of Charles the Fifth:—

“Stuffs of gold and silver made in the same manner as satin.

“Satins woven with gold.

“Satins brocaded with silk and gold, or silver flowers.

“Silver serges with double filigree.

“Silver and gold materials, which are made like gorgoran or serge.

“Silver and gold stuffs which are made like taffetas, or in silver
with silk flowers.

“Embroidered stuffs.

“Embroidered stuffs called silver serge, or berguilla.


“Lama, cloth of silver, shaded with watering in silver.

“Plain silk-stuffs woven with silver or gold, and called restaño.

“Silk-stuffs woven with gold or silver, and called relampagos.

“Serges woven with gold and silver for church vestments.

“Plain filigree serges.

“Velillo of silver.

“Satin woven with gold and silver.

“Brocades of different kinds.

“Church vestments.

“Silver primaveras.

“Serges for church vestments.”

It was usual for ladies of the Christian-Spanish aristocracy to trim


their clothes, in Moorish fashion, with strings of larger pearls or of
aljofar-work—a custom which continued until the extinction of the
House of Austria. The Alburquerque inventory includes “a marlota of
crimson satin, trimmed with pearls and with aljofar, as to the hem,
the sleeves, and the hood; with twelve buttons of aljofar-pearls in
the front thereof, that on a time were thirteen; but one is missing
which was ground up for the said Duchess when she was sick, and
six buttons on each sleeve, and the same where each sleeve meets
the shoulder.”
Early in the seventeenth century, Pinheiro da Veiga mentions the
same fashion at Valladolid:—“At the sale of the Marchioness of
Mondejar, I saw twelve of her sayas with long trains to them, and
satin bodices, all of embroidered silk, and some with aljofar-work,
besides a number of all kinds of diabluras.”

It is stated by Ibn-Said, Al-Makkari, Al-Kattib, and Ibn-Khaldun,


that the Moors of Granada occasionally adopted Christian clothing,
and we know that the Sultan Mohammed, a contemporary of Alfonso
the Learned of Castile, was assassinated by Abrahim and Abomet,
the sons of Osmin, because he was so clothed, and because he had
further violated the precepts of the Koran by eating at Alfonso's
table.[10] But as a rule the costume of the Spanish Moors was
almost wholly that of orientals. Where they were tolerated in a city
under Christian rule, a certain dress was sometimes forced upon
them by their subjugators, as by the Ordenamiento (a.d. 1408) of
Doña Catalina, issued on behalf of her son, Juan the Second, and
which prescribed for the Moorish men a capuz of yellow cloth with a
mark upon it in the form of a blue half-moon measuring an inch
from point to point, and which was to be worn on the right shoulder.
The garments of the women were to be similarly marked, on pain of
fifty lashes administered publicly, together with the forfeiture of all
such clothes as lacked this necessary and humiliating token.

But where the Spanish Moors were in possession of the soil, their
clothes were similar in most respects to those of eastern peoples.
Detailed notices of these costumes are furnished us by Ibn-Said and
other writers. Fray Pedro de Alcalá explains in his Vocabulary that,
among the Granadinos, the use of one garment in particular was
limited to royalty, or nobles of high rank. This was the libas (or, in
the Granadino dialect, libis), shaped like roomy breeches, and
greatly resembling the zaragüelles worn until this hour by the
peasants of the Huerta of Valencia. Ibn-Said, quoted by Al-Makkari
(see Gayangos, History of the Mohammedan Dynasties in Spain, Vol.
I., p. 116) says that the dress of the Moors of Andalusia was not
identical with that of the Asiatic Mussulman. The former, he declares,
would often discard the turban; especially those who lived towards
the eastern frontier. In the western region the turban continued to
be generally worn by the upper classes and by the leading State
officials. Thus, at Cordova and Seville every cadi and alfaqui would
wear a turban, while at Valencia and Murcia even the nobles went
without it, and among the lower classes it had fallen into absolute
disuse. Neither officers nor soldiers of the army wore the turban.

We learn from Casiri (Bibl. Arabico-Hispana, II., p. 258) that the


imama[11] was the only form of head-dress used by the cheiks,
cadis, and ulemas of Granada. At this capital red was the distinctive
colour of the sovereigns of the Alahmar dynasty, who took their very
title from this circumstance, the Arabic word alahmar meaning “red.”
The distinctive colour of the Nasrite sultans was purple, which was
replaced by black in time of mourning. In this last fashion the
sultans were probably influenced by the Christian usage, for Ibn-
Khaldun remarks that black was not a colour approved of by the
orientals, who considered it to be related with the spirits of evil.
However this may be, the manuscript History of the House of
Cordova quoted by Eguilaz Yanguas, says that when Boabdil el Chico
entered that city as a prisoner, “the captive monarch was dressed in
black velvet, in token of his adverse fortune and defeat. He rode a
richly caparisoned charger, whose coat was black and glossy.”

The Moors regarded green or white as pleasant and well-omened


colours, symbolic of the angels and of all good fortune. Perhaps this
preference was suggested to them by the cool oasis in the desert.
Nevertheless, when Ibn-Hud became ruler of Andalusia, his shields
and banners were black, as well as his costume. Black, too, was the
colour adopted by the Abbaside Sultans, to whom Ibn-Hud was
subject. Under the Beni-Nasr and Beni-Alahmar, this gloomy hue was
changed, as we have seen, to purple or to scarlet, though black
continued to be used in sign of mourning.

V
THE TUNIC OF BOABDIL EL CHICO
(National Museum of Artillery, Madrid)
The chronicle says that Abu-Said, “the Red,” who was assassinated
at Tablada, under the walls of Seville, by Pedro the Cruel, was
clothed in scarlet at the time of that atrocious deed. Boabdil was
also clothed in red at the battle of Lucena. The History of the House
of Cordova, from which I have already quoted, says: “Il était armé
d'une forte cuirasse à clous dorés, doublée de velours cramoisi, d'un
morion teint de grenat et doré…. Sur sa cuirasse était passé un
caban de brocart et de velours cramoisi” (Plate v.). Eguilaz quotes a
further passage from Hurtado de Mendoza, to prove that red
continued to be the official colour of the Moorish rulers of Granada;
for when the Moriscos had risen in the Alpujarra, and met together
to invest their leaders, Aben-Abu and Aben-Humeya, with the
insignia of royalty, they clothed the former in a red costume and the
latter in purple, “passing about his neck and shoulders a red token in
the form of a scarf.”[12]

As I remarked in speaking of the tiraz, the clothing of the Moorish


kings of Spain was of the richest quality obtainable, massively
wrought, embroidered in colours and in gold, and bearing
“sometimes a prince's name, sometimes his device or motto, or even
a portrait of himself embroidered on the right breast of his caban or
robe, thus following the fashion of the monarchs of Assyria and
Persia.”

Footnotes:

[1] “Perco con los draps d'or é d'argent, é de seda


axi brocats d'or é d'argent con altres é velluts,
xamelots, tafetanes, é sendats se usen molt de vestir
en lo dit Principat d'alguna generalitat ne dret no y sia
posat, mes solament vi liners per liura per la entrada.”

[2] “We have seen many instances of such opposed


animals and birds on the metal-work and carving of
the thirteenth century, and there is no doubt that the
design is much older than Mohammedan times, and
goes back to the productions of the old artists of
Mesopotamia and Persia. We read in Quintus Curtius
of robes worn by Persian satraps, adorned with birds
beak to beak—aurei accipitres veluti rostri in se
irruerunt pallam adornabant. Plautus mentions
Alexandrian carpets ornamented with beasts:
Alexandrina belluata conchyliata tapetia. There is
indeed reason to believe that the notion of such pairs
of birds or beasts may have originated with the
weavers of ancient Persia, and have been borrowed
from them by the engravers of metal-work; for the
advantage of such double figures would be specially
obvious to a weaver. The symmetrical repetition of the
figure of the bird or animal, reversed, saved both
labour and elaboration of the loom. The old weavers,
not yet masters of mechanical improvements, were
obliged to work their warp up and down by means of
strings, and the larger the design the more numerous
became these strings and the more complicated the
loom. Hence, to be able to repeat the pattern in
reverse was a considerable economy of labour, and
could be effected very simply on a loom constructed to
work à pointe et à reverse. Examples of such
repetitions of patterns, especially of symmetrical pairs
of animals within circles, are common in Byzantine and
Sassanian woven work, and the Saracens followed
these models.”—Stanley Lane-Poole, The Art of the
Saracens in Egypt, p. 288.

[3] Elogio de la Reina Católica, p. 374.

[4] These are defined by the Count of Clonard as “a


kind of clog (chapín) with a cork sole, and which was
introduced by the Moors under the name al-kork.”

[5] Specifically, tartari was a costly fabric, heavily


embroidered. Ducange considers that it came, or came
originally, from Tartary. We read of it twice in the
Chronicle of the Cid, and again, in the Chronicle of
Ferdinand the Fourth:—“tiraron los paños de marhega
que tenia vestidos por su padre é vistiéronle unos
paños nobles de tartari.”

[6] Quoted by Fernandez y Gonzalez, Mudejares de


Castilla, p. 231, from the originals in the Archiepiscopal
Library of Toledo.

[7] “An interesting parallel to the royal silk factory,


or Dār-et-tirāz of Kay-Kubād, and to that of the Fātimy
Khalif at Tinnīs, is found in the similar institution at
Palermo, which owed its foundation to the Kelby Amīrs
who ruled Sicily as vassals of the Fātimis in the ninth
and tenth centuries, though it maintained its special
character and excellence of work under the Norman
kings. The factory was in the palace, and the weavers
were Mohammedans, as indeed is obvious from a
glance at the famous silk cloth preserved at Vienna,
and called the “Mantle of Nürnberg,” where a long
Arabic inscription testifies to the hands that made it,
by order of King Roger, in the year of the Hijra 528, or
a.d. 1133.”—Stanley Lane-Poole, The Art of the

Saracens in Egypt, p. 289.

[8] The Alburquerque inventory mentions, in 1560,


“two Almería sheets, one with green and purple
edging, and the other with white and red”; also “two
short holland shirts for sleeping in at night.”
Commenting on the word short, Señor de la Torre de
Trassierra aptly recalls the thrifty proverb of the
Spaniards,—“A shirt which reaches below the navel is
so much linen wasted.”

[9] See particularly Las Ordenanzas de los tejedores


de seda de Sevilla (officially proclaimed on March 2nd,
1502), and also Las Ordenanzas para el buen régimen
y gobierno de la muy noble, muy leal, é imperial
cuidad de Toledo. (Tit. cxxxv: “silk-weavers.”)

[10] On the other hand, Rosmithal recorded in his


narrative of a tour of Spain that Henry the Second of
Castile affected the costume of the Mohammedans.

[11] This was a large form of turban. In the well-


known painting in the Hall of Justice of the Alhambra,
the head-dress is the aharim or almaizar.

[12] Eguilaz Yanguas, Les Peintures de l'Alhambra.


SPANISH SILK
A very fair idea of the magnitude of the craft and trade of Spanish
silk in bygone epochs may be formed by tracing chronologically the
production and treatment of the raw material in various parts of the
Peninsula. During the centuries of Moorish rule, Spain's principal silk-
producing centre was the kingdom of Granada, which then
embraced a large extent of coast, together with Málaga and other
thriving ports. In proof of this, and in his interesting memorial on the
silk factories of Seville,[13] Ulloa quotes old Spanish ordinances of
the weavers, stating that quantities of this substance were exported
from “tierra de Moros” for use by Christian craftsmen, and also the
Chronology of the Kings of Granada, concluded by Al-Khattib in the
year 1364. A fragment of this chronicle is preserved at the Escorial,
and states, in the well-known version of Casiri, that the silk
produced at Granada was both abundant and of excellent quality,
surpassing even the Assyrian.

The growing of mulberry trees and rearing of silkworms was also


busily pursued in the kingdom of Aragon, which formerly included
Cataluña, Valencia, and the Balearic Islands. Hence, though
somewhat gradually, it seems to have spread to Seville. In the
ordinances of this town relating to her weavers of silks and velvets,
and which are dated 1492, it is stated that her oficiales de texer
sedas were so few that, as a stimulus to augment their number, all
who wished might join them in the practice of this craft without
examination. Between that year and 1502 they evidently multiplied,
since subjects of examination of no easy character are formulated in
the ordinances of this later date, examined and confirmed by
Ferdinand and Isabella. Nevertheless, it is impossible to credit the
assertion of some authors that by the year 1519 Seville possessed
no less than sixteen thousand looms, affording occupation to one
hundred and fifty thousand persons. As Ulloa suggests, it is far more
reasonable to suppose that her silk trade grew in proportion as the
Spaniards continued to discover, and to open up to commerce, new
regions of America; and that it reached the maximum of its
development in the reigns of Charles the Fifth and Philip the Second.
The same writer attributes its decline and downfall to the “piracies
and insults” of Spain's foreign enemies and rivals.

The price of Seville silks was also raised and the trade injuriously
affected, by the imposition, at the close of the reign of Philip the
Second, of the onerous millones tax, as well as of the minor dues
denominated alcavalas and cientos; while finally, when Philip the
Third was on the throne, the expulsion of the Moriscos precipitated
the utter ruin of this industry.

VI
THE “BANNER OF SAINT FERDINAND”
(Seville Cathedral)

The Spanish government proved quite incapable of grappling with


these wrongs and difficulties. There were, however, numerous
attempts to legislate in the direction of reform. Measures forbidding
the introduction of silk proceeding from abroad received the royal
signature in 1500, 1514, 1525, 1532, and 1552. A petition to the
same effect, framed by the procurators of the Cortes, was presented
to the king in 1618, urging that no skein or twisted silk proceeding
from the Portuguese Indies, China, or Persia should be imported into
Spain in view of the damage thus inflicted on the silk-producing
regions of Granada, Murcia, and Valencia. At the same time the
petitioners suggested that if it should be found impracticable to
suppress such importation altogether, the foreign silk should be
required to be in the form of stuffs already woven.

Matters grew steadily worse all through the reign of Philip the
Fourth. The principal cause of this additional decline lay in the
constant depreciation of the national currency, which kept at an
intolerable pitch of dearness the price of home-grown silk, and
enabled foreign traders to undersell the Spaniard. This will be better
understood if we consider that the composition of the copper and
silver coinage was often tampered with by Crown and Parliament in
such a way as to allow the foreigner to rid the country of nearly all
her gold and silver, leaving in exchange only the baser metal. At
intervals of a few years, proclamations were issued altering the
values of the coinage in the most capricious and disastrous terms,
and Ulloa mentions as still in circulation in the eighteenth century,
ochavos of Philip the Third which bore inscribed the value of twelve
maravedis in Roman numerals, and also (owing to the restamping of
the coins by order of the Crown), the second and successive value of
eight maravedis, marked in ordinary numerals. In fact, so grave
were these abuses, that the arbitrary value imposed upon the coins
in question grew to be six times that of the actual value of the
metal.

At the close of the seventeenth century, when Charles the Second


was on the throne, a couple of well-meant and not completely
ineffectual attempts were made to bring about a fresh revival in the
growth of Spanish silk. On November 18th, 1683, the silk-makers of
Toledo, Seville, Granada, and Valencia were summoned to a council
at Madrid, and the dispositions they then agreed upon received the
royal signature and became law on January 30th of the following
year, the pragmatic which embodied them being issued to the public
ten days later. It was commanded by this document that all the silk
produced at the above-named towns should be examined and
approved by the veedores or mayorales, and bear the official stamp
which guaranteed their quality. The effect of these ordinances was
further strengthened by a Crown cedula of July 15th, 1692,
confirming other dispositions dated 1635; and later still, in June of
1699, a law was passed prohibiting the exportation of all home-
made silks to other countries.

The accession of the Bourbon kings heralded a further slight


improvement. Philip the Fifth had barely mounted the throne when
the Junta de Comercio was revived by his command, and drafted
various laws for bettering this and other industries. Royal decrees of
June 20th and September 17th, 1718, renewed in June of 1728 and
in April and August of 1734, forbade the introduction of silk and
certain other stuffs from China and the rest of Asia—a measure
which was made more strict as time went on, the prohibition being
extended to linens and cottons produced and printed in Africa or
Asia or imitated in Europe. In the meantime another cedula, signed
at the Escorial on November 10th, 1726, had ordered that every
Spanish citizen of either sex should dress exclusively in silks or cloths
of Spanish manufacture.

These laws, though founded on mistaken principles, undoubtedly


restored the national silk trade for a while. In 1713 the silk looms of
Seville had increased to four hundred and five, and by 1732—in
which year the Court resided at that capital—to a thousand; but on
the return of the royal family to Madrid, and the declaration of war
against England in 1739, the number dropped to a hundred and
forty. In 1743 an effort was made to remedy this by exempting
Seville silks from payment of the alcabalas and cientos, and further
support was rendered in 1749 by Ferdinand the Sixth, who lowered
to eighty maravedis per pound weight the tax on Spanish silks
exported from the kingdom, and issued, in 1752, 1753, and 1756,
additional decrees intended to encourage and protect this industry.
In 1748 the same ruler established the celebrated silk factories of
Talavera de la Reina, sparing no pains to bring their products to a
level with the best in Europe, and choosing as director of the works
a thoroughly proficient Frenchman named Jean Roulière, a native of
Nîmes, who was assisted by a carefully selected staff of experts, also
principally foreigners.

About the end of the century Laborde described this enterprise as


follows:—“The manufactures of silks, gildings, and galloons are
highly useful and important…. There has also been raised at
Cervera, a village two leagues from Talavera, another large edifice,
in which are twelve mills for twisting the silk, four large windles for
winding it, and six machines for doubling it. This complicated
machinery is put in motion by four oxen, and the various processes
of twisting, winding, and doubling seven thousand and seventy-two
threads of silk are thus performed at once.

“This establishment was rapidly augmented under the direction of


Roulière and the other French mechanics who succeeded him in its
superintendence. So successful were their labours that, in a short
time, stuffs were fabricated in Spain not unworthy of competition
with those of France, the demand for which was found to diminish.
In 1762, Roulière being obliged to withdraw from this manufactory,
the care of it was committed to a company to the exclusion of
almost all the French who had previously assisted in its
establishment. The consequences of this change were soon
discovered; the manufacture declined, the stuffs deteriorated, and
the consumption diminished; the artisans were discharged from the
loom, and everything threatened the total subversion of the
establishment, when the king interposed, and again extended to it
his care and protection, It has since been yielded to the incorporated
society of the Gremios at Madrid, but has never recovered its former
splendour and prosperity.

“Taffetas, satins, silk cloths, and serges are fabricated here, as are
silk ribbons, plain and figured velvets, stuffs of silk and silver, stuffs
of silk and gold, galloons, gold and silver fringes, and silk stockings.
The factory employs three hundred and sixty-six looms, and affords
occupation to two thousand persons. There are annually consumed
in it about a hundred thousand pounds of silk, four thousand marks
of silver, and seventy marks of gold.

“Some of the stuffs issuing from the manufactory are beautiful


and good, but they want the gloss and lustre of the French stuffs;
and as they are dearer than those, with all the contingent expense
of commission and transportation, they are far from being able to
maintain a competition with them. The stockings are of the vilest
quality, being thin, shaggy, and ill-dressed. The greater part of these
articles are exported to the Spanish colonies.”

Further efforts to improve the quality of Spanish silk were made


by Charles the Third, in whose reign the silk looms of Seville
increased to four hundred and sixty-two for weaving larger pieces,
sixty-two for silver and gold galloons, three hundred and fifty-four
for finely-worked ribbons, twenty-three for small pieces of gold and
silver stuffs, eight for fringes and cintas de rizo, sixty-three for
stockings, sixty-five for redecillas, three for caps, and one thousand
three hundred and ninety-one for ordinary ribbon. At the same time,
according to Ulloa, one hundred thousand pounds of silk required to
be annually brought to Seville to supply these factories.

“In its fortunate days,” wrote Alexander de Laborde, “Seville had


many splendid manufactures; it wove silks of every kind, gold and
silver tissues, linens, and cottons.[14] A memoir presented in 1601
by the seventeen companies of arts and trades of this city gives us
an idea of the brilliant state of those manufactures: the amount of
the silk looms is there stated to be 16,000, and the persons of both
sexes employed at them, 130,000. These manufactures had greatly
declined even in the last century. We learn from Francisco Martínez
de la Mata, in his Discursos, published in 1659, according to a
memoir presented to the king by an alcalde of the silk manufactures
of Seville, that there were no more, at that time, than sixty-five
looms, that a great number of persons having no work had quitted
the town, that the population had decreased a third, and that many
houses were shut up, uninhabited, and going to ruin. The silk
manufactures began to look up again in the eighteenth century, but
they are very far below the brilliant state they formerly displayed: in
1779 there were 2318 silk looms in Seville, including those for
stockings, slight stuffs, and ribbons.”[15]

Turning our attention from Seville to Granada, we find that the


fame of the silks produced in this latter city, or rather kingdom (for
silk was raised in great quantities throughout the entire region)
extended as far abroad as Constantinople, and that they were used
in Greece in the reign of Comnenus. The Muzarabs, who petitioned
Alfonso el Batallador to bring an expedition to their rescue and wrest
Granada from her Mussulman lords, reported to him in enthusiastic
terms the quality and abundance of the silk of that locality, and
many a document and chronicle record its vogue among the Spanish
Christians of the Middle Ages.

The Alcaicería or silk-market of Granada is referred to by various


of the older writers, including Marineus Siculus, Navagiero, Lalaing,
Bertaut de Rouen, and Alvarez de Colmenar. The name itself is
stated in Fray Pedro de Alcalá's Vocabulario to be derived from the
Arabic al-aqqisariya, meaning “an exchange for merchants.”
Buildings, or groups of buildings, of this kind existed both in Spain
and in Morocco. Early in the eighteenth century a Spanish friar wrote
of Fez; “The Moorish portion of this city is the Alcaicería. It stands
nearly in the centre of the level part of the town, and near the
principal mosque, resembling a town in itself, with solid walls and
doors, and chains across it to keep out the horses. It consists of
fifteen streets of wealthy shops, stretching without a break, and
what is sold in them—whether of linen, silk, or cloth—is of the
richest and the noblest quality.”
Very similar are the descriptions relative to the Alcaicería of
Granada in the olden time. Bertaut de Rouen wrote of it, and of the
adjoining Zacatin; “En retournant devers la porte d'Elvire est le
Zacatin, qui est une rue paralelle au Canal du Darro, longue et assez
estroite, qui vient de la place de la Chancellerie à la place de
Vivarambla. Dans cette rue sont tous les orfévres, les marchands de
soie, de rubans, de vermillon, qui croist assez prés de Grenade, dont
on fait là grand trafic. C'est une plante semblable à celle du Safran,
dont il y a beaucoup dans ces quartiers-là.

“Dans cette mesme rue du Zacatin donne d'un costé l'Alcayzerie,


qui est une espèce de Halle couverte à la manière de la Foire Saint
Germain, où sont plusieurs boutiques remplies des Marchandises les
plus curieuses. Ils disent que cette place, aussi bien que beaucoup
d'autres des autres Villes d'Andalousie, se nomme ainsi à cause d'un
privilege que donnerent les Cesars aux Arabes de travailler en Soye.”

Alvarez de Colmenar wrote of the same edifice, a few years later


than Bertaut; “Vis-à-vis de la Chancellerie on voit une maison fort
longue, nommée Alcacéria (sic), partagée en près de deux cent
boutiques, où les Marchands ètalent tout sorte de marchandises,
particulièrement des étoffes en soie.” On the authority of the same
writer, the makers and the dyers of silk-stuffs inhabited another
quarter of the town. “Le dernier quartier de la Ville, nommé
Antiqueruela, est dans une plaine, peuplé de gens venus
d'Antechera, d'où lui vient le nom qu'il porte. Ses habitants sont pour
la plupart ouvriers en soie, tisseurs de satin, de tafetas, de damas;
teinturiers qui teignent en pourpre, en écarlate, et autres ouvriers
semblables.” He adds; “Il s'y fait grand commerce d'étoffe de soie;
et la Ville et les environs sont pour cet effet plantés d'un si grand
nombre de meuriers, que le seul impôt sur les feuilles de ces arbres
vaut annuellement trente mille écus au Roi.”

About the beginning of the nineteenth century Laborde wrote:


“The Alcaicería is in the Bivarambla: it is merely an immense edifice,
without ornament, covering a considerable extent of ground. The
Moors used it as a bazaar, and a good many tradesmen still carry on
their business there. It contains about two hundred shops.” It
remained, in fact, in much the same condition as when the Moors
possessed it, until the year 1843, when a fire, which broke out on
the night of July 20th of that year, reduced it almost totally to ashes.
To-day the historic silk trade is no more; but the Alcaicería,
consisting of a chapel and a street which call to mind the graceful
and effective decoration of its predecessor, has been rebuilt with
taste and accuracy from the model of the old.

The Ordenanzas of Granada city, the first edition of which was


published in 1552, and the second in 1678, inform us very closely of
the silk trade of that region in the times immediately succeeding the
reconquest. Having regard to the fact that the silk was now spun in
skeins in an imperfect manner, “with much deceit and trickery,” and
that its quality was of the worst (Ordinance of a.d. 1535), nobody
was allowed henceforth to spin silk in or about Granada without
being qualified through examination by the veedores or inspectors
appointed for this purpose by the corporation. The inspector might
charge for this examination a fee of twenty-five maravedis, and if
the candidate were successful he was permitted to set up his loom
forthwith, and engage two lads or girls, not less than twelve years
old, to fetch and carry at his wheel, “so that the work may be
continued all day long.”
Minute instructions follow as to the method of spinning the silk,
wages, the treatment of apprentices, and other detail. Many of these
narrow points of city law were troublesome and senseless, and must
have tended to destroy the trade. For instance, the earnings of a
master-spinner, after paying the lads or girls who worked for him,
were limited to a maximum of two reales and a half per day. Women
were allowed to spin upon the following conditions: “Also, seeing
that there be some honest women here who have no access to a
public wheel, but work within their dwellings only, we (i.e. the city
councillors) command that these may spin per thousand of cocoons,
or at a daily wage, not to exceed two reales and a half.” The silk was
not to be spun with an escobilla or brush, but with the hand,
obedient to the rhyming Spanish proverb which says, or used to say,
con escobilla el paño, y la seda con la mano (“brush cloth with a
brush, and silk with the hand”).

The laws affecting the dyers of silk contain the following


provisions. They were not to dye with pomegranate or sumach, and
if the rind of the former fruit were found in their houses, they were
liable to a fine of six thousand maravedis and thirty days'
imprisonment. Dyeing with Brazil-wood was also prohibited in the
case of silks of finer quality exposed for sale in the Alcaicería.
Elaborate directions follow as to the manner of applying the dye. In
the case of silks dyed blue or purple, the dyer, before he drew the
fabric from the vat, was required to show it to the alamin or
inspector of the silk, or else to one of the veedores nominated by
the city councillors. The fines imposed upon the dyers who were
found to contravene these regulations were distributed in the
following proportion: one-third towards repairing the ramparts or
adarves of Granada; another third between the alamin, the
veedores, and the other officials who discovered and denounced the
culprit; and the remaining third between the magistrates and other
authorities who tried and sentenced him.

Further, each silk-dyer was to have six tinajas, or large jars (see
Vol. II., pp. 120 et seq.), kept continually full of dye, well settled,
and liable at any hour to be analyzed by the veedores. In dyeing
fabrics black, each pound of silk was to be treated with ten ounces
of foreign galls of fine quality, two ounces of copperas, and two
ounces of gum-arabic.

It is evident that nearly all this legislation was of a mischievous


character, nor can it cause surprise that certain of the silk-makers of
this locality should have been in the habit of committing many kinds
of fraud, such as mixing salt or oil with the raw material, in order to
increase its weight. Thus, at the same time that the laws themselves
were made more numerous and stringent, the more elaborate and
various were the shifts invented by the citizens as a means to violate
those laws. The inspectors were empowered to enter a shop and
examine its contents at any hour. Sometimes, we read, such ingress
was denied them, and the door was kept closed, or slammed in their
faces. The penalty for this resistance was a fine of two thousand
maravedis and twenty days imprisonment. No silk-spinner was
allowed to possess more than two spinning-wheels (Ordinance of
November 18th, 1501), or to keep these working after midnight, for
we are told that in this way the veedores were impeded from paying
their official visit in the small hours of the morning, and much
“deceit and insult” was the consequence. This Ordinance was
confirmed by a royal rescript of 1542.
Welcome to our website – the perfect destination for book lovers and
knowledge seekers. We believe that every book holds a new world,
offering opportunities for learning, discovery, and personal growth.
That’s why we are dedicated to bringing you a diverse collection of
books, ranging from classic literature and specialized publications to
self-development guides and children's books.

More than just a book-buying platform, we strive to be a bridge


connecting you with timeless cultural and intellectual values. With an
elegant, user-friendly interface and a smart search system, you can
quickly find the books that best suit your interests. Additionally,
our special promotions and home delivery services help you save time
and fully enjoy the joy of reading.

Join us on a journey of knowledge exploration, passion nurturing, and


personal growth every day!

ebookbell.com

You might also like