You are on page 1of 53

Essential MATLAB for engineers and

scientists Hahn
Visit to download the full and correct content document:
https://textbookfull.com/product/essential-matlab-for-engineers-and-scientists-hahn-3/
More products digital (pdf, epub, mobi) instant
download maybe you interests ...

Essential MATLAB for engineers and scientists Hahn

https://textbookfull.com/product/essential-matlab-for-engineers-
and-scientists-hahn-2/

Essential MATLAB for engineers and scientists Hahn

https://textbookfull.com/product/essential-matlab-for-engineers-
and-scientists-hahn-3/

Essential MATLAB for engineers and scientists Sixth


Edition. Edition Hahn

https://textbookfull.com/product/essential-matlab-for-engineers-
and-scientists-sixth-edition-edition-hahn/

Essential Quotes For Scientists And Engineers


Konstantin K. Likharev

https://textbookfull.com/product/essential-quotes-for-scientists-
and-engineers-konstantin-k-likharev/
Numerical Methods for Engineers and Scientists Using
MATLAB Second Edition Esfandiari

https://textbookfull.com/product/numerical-methods-for-engineers-
and-scientists-using-matlab-second-edition-esfandiari/

Numerical Methods for Engineers and Scientists Using


MATLAB® Ramin S. Esfandiari

https://textbookfull.com/product/numerical-methods-for-engineers-
and-scientists-using-matlab-ramin-s-esfandiari/

MATLAB Programming for Biomedical Engineers and


Scientists Andrew P. King And Paul Aljabar (Auth.)

https://textbookfull.com/product/matlab-programming-for-
biomedical-engineers-and-scientists-andrew-p-king-and-paul-
aljabar-auth/

Applied Numerical Methods with MATLAB for Engineers and


Scientists Fourth Edition Steven C. Chapra Dr.

https://textbookfull.com/product/applied-numerical-methods-with-
matlab-for-engineers-and-scientists-fourth-edition-steven-c-
chapra-dr/

The oceanographer's companion : essential nautical


skills for seagoing scientists and engineers 1st
Edition Maul

https://textbookfull.com/product/the-oceanographers-companion-
essential-nautical-skills-for-seagoing-scientists-and-
engineers-1st-edition-maul/
Essential MATLAB
for Engineers and Scientists
This page intentionally left blank
Essential MATLAB
for Engineers and Scientists
Sixth Edition

Brian H. Hahn
Daniel T. Valentine

AMSTERDAM • BOSTON • HEIDELBERG • LONDON


NEW YORK • OXFORD • PARIS • SAN DIEGO
SAN FRANCISCO • SINGAPORE • SYDNEY • TOKYO
Academic Press is an imprint of Elsevier
Academic Press is an imprint of Elsevier
50 Hampshire Street, 5th Floor, Cambridge, MA 02139, United States
525 B Street, Suite 1800, San Diego, CA 92101-4495, United States
The Boulevard, Langford Lane, Kidlington, Oxford OX5 1GB, United Kingdom
125, London Wall, EC2Y, 5AS, United Kingdom

Copyright © 2017, 2013, 2010 Daniel T. Valentine. Published by Elsevier Ltd. All rights reserved.
Copyright © 2007, 2006, 2002 Brian D. Hahn and Daniel T. Valentine. Published by Elsevier Ltd.

MATLAB® is a trademark of The MathWorks, Inc. and is used with permission.


The MathWorks does not warrant the accuracy of the text or exercises in this book.
This book’s use or discussion of MATLAB® software or related products does not constitute endorsement
or sponsorship by The MathWorks of a particular pedagogical approach or particular use of the
MATLAB® software.

No part of this publication may be reproduced, stored in a retrieval system, or transmitted in any form
or by any means, electronic, mechanical, photocopying, recording, or otherwise, without the prior
written permission of the publisher.

Permissions may be sought directly from Elsevier’s Science & Technology Rights Department in Oxford,
UK: phone: (+44) 1865 843830, fax: (+44) 1865 853333, E-mail: permissions@elsevier.com. You may
also complete your request online via the Elsevier homepage (http://www.elsevier.com), by selecting
“Support & Contact” then “Copyright and Permission” and then “Obtaining Permissions.”

Library of Congress Cataloging-in-Publication Data


A catalog record for this book is available from the Library of Congress.

British Library Cataloguing-in-Publication Data


A catalogue record for this book is available from the British Library.

ISBN: 978-0-08-100877-5

For information on all Academic Press publications


visit our website at https://www.elsevierdirect.com

Publisher: Todd Green


Acquisition Editor: Stephen Merken
Editorial Project Manager: Nate McFadden
Production Project Manager: Stalin Viswanathan
Designer: Matthew Limbert

Typeset by VTeX
Contents

PREFACE .............................................................................................................xv

Part 1 Essentials................................................................. 1
CHAPTER 1 Introduction............................................................................... 3
1.1 Using MATLAB..............................................................................5
1.1.1 Arithmetic .........................................................................5
1.1.2 Variables............................................................................7
1.1.3 Mathematical functions ...................................................8
1.1.4 Functions and commands ...............................................8
1.1.5 Vectors...............................................................................9
1.1.6 Linear equations.............................................................11
1.1.7 Tutorials and demos.......................................................12
1.2 The desktop ................................................................................13
1.2.1 Using the Editor and running a script ..........................13
1.2.2 Help, publish and view ...................................................16
1.2.3 Symbolics and the MuPAD notebook APP....................18
1.2.4 Other APPS .....................................................................23
1.2.5 Additional features .........................................................23
1.3 Sample program ........................................................................25
1.3.1 Cut and paste..................................................................25
1.3.2 Saving a program: script files .......................................27
Current directory ................................................................................28
Running a script from the current folder browser ..........................29
1.3.3 A program in action........................................................29
Summary ....................................................................................30
Exercises.....................................................................................31

CHAPTER 2 MATLAB Fundamentals ......................................................... 33


2.1 Variables .....................................................................................33
2.1.1 Case sensitivity ...............................................................34
2.2 The workspace ...........................................................................34
2.2.1 Adding commonly used constants to the workspace ..35
2.3 Arrays: Vectors and matrices....................................................36
2.3.1 Initializing vectors: Explicit lists ...................................36
v
vi Contents

2.3.2 Initializing vectors: The colon operator ........................37


2.3.3 The linspace and logspace functions.........................38
2.3.4 Transposing vectors .......................................................39
2.3.5 Subscripts .......................................................................39
2.3.6 Matrices ..........................................................................40
2.3.7 Capturing output ............................................................40
2.3.8 Structure plan.................................................................41
2.4 Vertical motion under gravity....................................................42
2.5 Operators, expressions, and statements .................................44
2.5.1 Numbers .........................................................................45
2.5.2 Data types .......................................................................45
2.5.3 Arithmetic operators......................................................46
2.5.4 Operator precedence .....................................................46
2.5.5 The colon operator .........................................................47
2.5.6 The transpose operator .................................................47
2.5.7 Arithmetic operations on arrays ...................................48
2.5.8 Expressions.....................................................................49
2.5.9 Statements......................................................................49
2.5.10 Statements, commands, and functions........................50
2.5.11 Formula vectorization ....................................................51
2.6 Output..........................................................................................54
2.6.1 The disp statement........................................................54
2.6.2 The format command ....................................................55
2.6.3 Scale factors ...................................................................56
2.7 Repeating with for.....................................................................57
2.7.1 Square roots with Newton’s method ............................58
2.7.2 Factorials! .......................................................................59
2.7.3 Limit of a sequence ........................................................59
2.7.4 The basic for construct .................................................60
2.7.5 for in a single line..........................................................61
2.7.6 More general for ...........................................................61
2.7.7 Avoid for loops by vectorizing!......................................62
2.8 Decisions.....................................................................................64
2.8.1 The one-line if statement ............................................64
2.8.2 The if-else construct...................................................66
2.8.3 The one-line if-else statement ..................................67
2.8.4 elseif .............................................................................67
2.8.5 Logical operators ...........................................................68
2.8.6 Multiple ifs versus elseif ...........................................69
2.8.7 Nested ifs ......................................................................70
2.8.8 Vectorizing ifs?..............................................................71
2.8.9 The switch statement....................................................71
2.9 Complex numbers......................................................................72
Summary ....................................................................................74
Exercises.....................................................................................76

CHAPTER 3 Program Design and Algorithm Development ..................... 83


3.1 The program design process.....................................................84
Contents vii

3.1.1 The projectile problem ...................................................87


3.2 Programming MATLAB functions .............................................92
3.2.1 Inline objects: Harmonic oscillators.............................92
3.2.2 MATLAB function: y = f (x ).............................................93
Summary ....................................................................................96
Exercise.......................................................................................96

CHAPTER 4 MATLAB Functions and Data Import-Export Utilities.......... 99


4.1 Common functions.....................................................................99
4.2 Importing and exporting data..................................................104
4.2.1 The load and save commands....................................104
4.2.2 Exporting text (ASCII) data...........................................104
4.2.3 Importing text (ASCII) data ..........................................105
4.2.4 Exporting binary data...................................................105
4.2.5 Importing binary data...................................................106
Summary ..................................................................................106
Exercises...................................................................................106

CHAPTER 5 Logical Vectors ..................................................................... 109


5.1 Examples ..................................................................................110
5.1.1 Discontinuous graphs ..................................................110
5.1.2 Avoiding division by zero ..............................................111
5.1.3 Avoiding infinity.............................................................112
5.1.4 Counting random numbers .........................................113
5.1.5 Rolling dice ...................................................................114
5.2 Logical operators .....................................................................114
5.2.1 Operator precedence ...................................................116
5.2.2 Danger...........................................................................116
5.2.3 Logical operators and vectors.....................................117
5.3 Subscripting with logical vectors............................................118
5.4 Logical functions ......................................................................119
5.4.1 Using any and all ........................................................120
5.5 Logical vectors instead of elseif ladders.............................121
Summary ..................................................................................123
Exercises...................................................................................124

CHAPTER 6 Matrices and Arrays ............................................................. 127


6.1 Matrices ....................................................................................127
6.1.1 A concrete example......................................................127
6.1.2 Creating matrices.........................................................129
6.1.3 Subscripts .....................................................................129
6.1.4 Transpose......................................................................130
6.1.5 The colon operator .......................................................130
6.1.6 Duplicating rows and columns: tiling .........................133
6.1.7 Deleting rows and columns .........................................134
6.1.8 Elementary matrices....................................................135
6.1.9 Specialized matrices....................................................136
6.1.10 Using MATLAB functions with matrices .....................137
viii Contents

6.1.11 Manipulating matrices .................................................138


6.1.12 Array (element-by-element) operations on matrices138
6.1.13 Matrices and for ..........................................................139
6.1.14 Visualization of matrices .............................................140
6.1.15 Vectorizing nested fors: loan repayment tables .......140
6.1.16 Multi-dimensional arrays ............................................142
6.2 Matrix operations .....................................................................143
6.2.1 Matrix multiplication....................................................143
6.2.2 Matrix exponentiation ..................................................145
6.3 Other matrix functions.............................................................146
6.4 Population growth: Leslie matrices .......................................146
6.5 Markov processes ....................................................................150
6.5.1 A random walk..............................................................150
6.6 Linear equations ......................................................................152
6.6.1 MATLAB’s solution .......................................................153
6.6.2 The residual ..................................................................154
6.6.3 Over-determined systems ...........................................154
6.6.4 Under-determined systems ........................................155
6.6.5 Ill conditioning ..............................................................155
6.6.6 Matrix division...............................................................156
6.7 Sparse matrices .......................................................................158
Summary ..................................................................................160
Exercises...................................................................................161

CHAPTER 7 Function M-files.................................................................... 163


7.1 Example: Newton’s method again ..........................................163
7.2 Basic rules ................................................................................165
7.2.1 Subfunctions .................................................................170
7.2.2 Private functions ..........................................................170
7.2.3 P-code files ...................................................................170
7.2.4 Improving M-file performance with the profiler ........171
7.3 Function handles......................................................................171
7.4 Command/function duality......................................................173
7.5 Function name resolution .......................................................174
7.6 Debugging M-files....................................................................174
7.6.1 Debugging a script .......................................................174
7.6.2 Debugging a function ...................................................176
7.7 Recursion..................................................................................176
Summary ..................................................................................178
Exercises...................................................................................179

CHAPTER 8 Loops ..................................................................................... 181


8.1 Determinate repetition with for .............................................181
8.1.1 Binomial coefficient .....................................................181
8.1.2 Update processes .........................................................182
8.1.3 Nested fors ..................................................................184
8.2 Indeterminate repetition with while ......................................184
8.2.1 A guessing game ..........................................................184
Contents ix

8.2.2 The while statement....................................................185


8.2.3 Doubling time of an investment ..................................185
8.2.4 Prime numbers ............................................................187
8.2.5 Projectile trajectory......................................................188
8.2.6 break and continue.....................................................190
8.2.7 Menus............................................................................190
Summary ..................................................................................191
Exercises...................................................................................192

CHAPTER 9 MATLAB Graphics................................................................. 197


9.1 Basic 2-D graphs......................................................................197
9.1.1 Labels............................................................................198
9.1.2 Multiple plots on the same axes .................................199
9.1.3 Line styles, markers and color....................................200
9.1.4 Axis limits......................................................................200
9.1.5 Multiple plots in a figure: subplot..............................202
9.1.6 figure, clf and cla.....................................................203
9.1.7 Graphical input .............................................................203
9.1.8 Logarithmic plots .........................................................203
9.1.9 Polar plots.....................................................................204
9.1.10 Plotting rapidly changing mathematical functions:
fplot .............................................................................205
9.1.11 The property editor.......................................................206
9.2 3-D plots ...................................................................................206
9.2.1 plot3 .............................................................................206
9.2.2 Animated 3-D plots with comet3 .................................207
9.2.3 Mesh surfaces ..............................................................207
9.2.4 Contour plots ................................................................209
9.2.5 Cropping a surface with NaNs ......................................211
9.2.6 Visualizing vector fields ...............................................211
9.2.7 Visualization of matrices .............................................212
9.2.8 Rotation of 3-D graphs.................................................213
9.3 Handle graphics .......................................................................214
9.3.1 Getting handles ............................................................214
9.3.2 Graphics object properties and how to change them215
9.3.3 A vector of handles.......................................................217
9.3.4 Graphics object creation functions .............................218
9.3.5 Parenting.......................................................................218
9.3.6 Positioning figures .......................................................219
9.4 Editing plots..............................................................................220
9.4.1 Plot edit mode...............................................................220
9.4.2 Property Editor .............................................................221
9.5 Animation..................................................................................222
9.5.1 Animation with Handle Graphics.................................222
9.6 Color etc....................................................................................225
9.6.1 Colormaps.....................................................................225
9.6.2 Color of surface plots...................................................226
9.6.3 Truecolor .......................................................................228
x Contents

9.7 Lighting and camera ................................................................228


9.8 Saving, printing and exporting graphs ...................................229
9.8.1 Saving and opening figure files ...................................229
9.8.2 Printing a graph............................................................229
9.8.3 Exporting a graph .........................................................229
Summary ..................................................................................230
Exercises...................................................................................231

CHAPTER 10 Vectors as Arrays and Other Data Structures.................... 235


10.1 Update processes.....................................................................235
10.1.1 Unit time steps .............................................................236
10.1.2 Non-unit time steps .....................................................238
10.1.3 Using a function............................................................239
10.1.4 Exact solution ...............................................................241
10.2 Frequencies, bar charts and histograms ...............................242
10.2.1 A random walk..............................................................242
10.2.2 Histograms ...................................................................243
10.3 Sorting.......................................................................................244
10.3.1 Bubble Sort ...................................................................244
10.3.2 MATLAB’s sort .............................................................246
10.4 Structures .................................................................................247
10.5 Cell arrays ................................................................................249
10.5.1 Assigning data to cell arrays .......................................249
10.5.2 Accessing data in cell arrays.......................................250
10.5.3 Using cell arrays ..........................................................251
10.5.4 Displaying and visualizing cell arrays ........................252
10.6 Classes and objects .................................................................252
Summary ..................................................................................253

CHAPTER 11 Errors and Pitfalls ................................................................ 255


11.1 Syntax errors ............................................................................255
11.1.1 Incompatible vector sizes ............................................256
11.1.2 Name hiding..................................................................256
11.2 Logic errors ..............................................................................256
11.3 Rounding error .........................................................................257
Summary ..................................................................................258
Chapter exercises ....................................................................258

Part 2 Applications ..........................................................261


CHAPTER 12 Dynamical Systems .............................................................. 263
12.1 Cantilever beam .......................................................................265
12.2 Electric current ........................................................................266
12.3 Free fall .....................................................................................269
12.4 Projectile with friction..............................................................278
Summary ..................................................................................281
Exercises...................................................................................282

CHAPTER 13 Simulation ............................................................................. 283


Contents xi

13.1 Random number generation ...................................................283


13.1.1 Seeding rand.................................................................284
13.2 Spinning coins ..........................................................................284
13.3 Rolling dice ...............................................................................285
13.4 Bacteria division.......................................................................286
13.5 A random walk .........................................................................286
13.6 Traffic flow ................................................................................288
13.7 Normal (Gaussian) random numbers ....................................291
Summary ..................................................................................291
Exercises...................................................................................292

CHAPTER 14 Introduction to Numerical Methods.................................... 295


14.1 Equations ..................................................................................295
14.1.1 Newton’s method .........................................................295
14.1.2 The Bisection method ..................................................297
14.1.3 fzero .............................................................................299
14.1.4 roots .............................................................................299
14.2 Integration ................................................................................300
14.2.1 The Trapezoidal rule ....................................................300
14.2.2 Simpson’s rule..............................................................301
14.2.3 quad ...............................................................................302
14.3 Numerical differentiation ........................................................302
14.3.1 diff ...............................................................................303
14.4 First-order differential equations ...........................................304
14.4.1 Euler’s method .............................................................304
14.4.2 Example: bacteria growth............................................305
14.4.3 Alternative subscript notation.....................................307
14.4.4 A predictor-corrector method .....................................307
14.5 Linear ordinary differential equations (LODEs) .....................308
14.6 Runge-Kutta methods .............................................................309
14.6.1 A single differential equation ......................................309
14.6.2 Systems of differential equations: chaos ...................310
14.6.3 Passing additional parameters to an ODE solver ......312
14.7 A partial differential equation .................................................314
14.7.1 Heat conduction............................................................314
14.8 Complex variables and conformal mapping ..........................317
14.9 Other numerical methods .......................................................319
Summary ..................................................................................320
Exercises...................................................................................321

CHAPTER 15 Signal Processing ................................................................. 325


15.1 Harmonic analysis ...................................................................326
15.2 Fast Fourier Transform (FFT)..................................................331

CHAPTER 16 SIMULINK Toolbox............................................................. 337


16.1 Mass-spring-damper dynamic system ..................................342
16.2 Bouncing ball dynamic system ...............................................345
16.3 The van der Pol oscillator........................................................347
xii Contents

16.4 The Duffing oscillator ..............................................................350


Exercises...................................................................................351

CHAPTER 17 Symbolics Toolbox ................................................................ 355


17.1 Algebra......................................................................................356
17.1.1 Polynomials ..................................................................357
17.1.2 Vectors...........................................................................359
17.1.3 Matrices ........................................................................360
17.2 Calculus ....................................................................................363
17.3 Laplace and Z transforms .......................................................366
17.4 Generalized functions..............................................................367
17.5 Differential equations ..............................................................369
17.6 Implementation of funtool, MuPAD and help.........................370
17.6.1 The funtool ....................................................................370
17.6.2 The MuPAD notebook∗ and Symbolic help.................370
Exercises...................................................................................373
APPENDIX A Syntax: Quick Reference ...................................................... 375
A.1 Expressions ..............................................................................375
A.2 Function M-files .......................................................................375
A.3 Graphics ....................................................................................375
A.4 if and switch...........................................................................376
A.5 for and while...........................................................................377
A.6 Input/output..............................................................................377
A.7 load/save..................................................................................378
A.8 Vectors and matrices ...............................................................378
APPENDIX B Operators .............................................................................. 381
APPENDIX C Command and Function: Quick Reference......................... 383
C.1 General-purpose commands ..................................................383
C.1.1 Managing variables and the workspace .....................383
C.1.2 Files and the operating system...................................383
C.1.3 Controlling the Command Window .............................384
C.1.4 Starting and quitting MATLAB.....................................384
C.2 Logical functions ......................................................................384
C.3 MATLAB programming tools...................................................384
C.3.1 Interactive input............................................................385
C.4 Matrices ....................................................................................385
C.4.1 Special variables and constants..................................385
C.4.2 Time and date ...............................................................385
C.4.3 Matrix manipulation .....................................................385
C.4.4 Specialized matrices....................................................386
C.5 Mathematical functions ...........................................................386
C.6 Matrix functions .......................................................................387
C.7 Data analysis ............................................................................387
C.8 Polynomial functions ...............................................................387
C.9 Function functions ...................................................................387
C.10 Sparse matrix functions ..........................................................388
C.11 Character string functions ......................................................388
Contents xiii

C.12 File I/O functions ......................................................................388


C.13 2D graphics...............................................................................388
C.14 3D graphics...............................................................................389
C.15 General......................................................................................389
APPENDIX D Solutions to Selected Exercises .......................................... 391
INDEX ............................................................................................................... 403
This page intentionally left blank
Preface

The main reason for a sixth edition of Essential MATLAB for Engineers and Scien-
tists is to keep up with MATLAB, now in its latest version (9.0 Version R2016a).
Like the previous editions, this one presents MATLAB as a problem-solving
tool for professionals in science and engineering, as well as students in those
fields, who have no prior knowledge of computer programming.
In keeping with the late Brian D. Hahn’s objectives in previous editions, the
sixth edition adopts an informal, tutorial style for its “teach-yourself” ap-
proach, which invites readers to experiment with MATLAB as a way of discov-
ering how it works. It assumes that readers have never used this tool in their
technical problem solving.
MATLAB, which stands for “Matrix Laboratory,” is based on the concept of
the matrix. Because readers will be unfamiliar with matrices, ideas and con-
structs are developed gradually, as the context requires. The primary audience
for Essential MATLAB is scientists and engineers, and for that reason certain ex-
amples require some first-year college math, particularly in Part II. However,
these examples are self-contained and can be skipped without detracting from
the development of readers’ programming skills.
MATLAB can be used in two distinct modes. One, in keeping the modern-age
craving for instant gratification, offers immediate execution of statements (or
groups of statements) in the Command Window. The other, for the more pa-
tient, offers conventional programming by means of script files. Both modes
are put to good use here: The former encouraging cut and paste to take full
advantage of Windows’ interactive environment. The latter stressing program-
ming principles and algorithm development through structure plans.
Although most of MATLAB’s basic (“essential”) features are covered, this book
is neither an exhaustive nor a systematic reference. This would not be in keep-
ing with its informal style. For example, constructs such as for and if are not
always treated, initially, in their general form, as is common in many texts, but
are gradually introduced in discussions where they fit naturally. Even so, they
xv
xvi Preface

are treated thoroughly here, unlike in other texts that deal with them only su-
perficially. For the curious, helpful syntax and function quick references can be
found in the appendices.
The following list contains other highlights of Essential MATLAB for Engineers
and Scientists, Sixth Edition:
 Warnings of the many pitfalls that await the unwary beginner
 Numerous examples taken from science and engineering (simulation, pop-
ulation modeling, numerical methods) as well as business and everyday
life
 An emphasis on programming style to produce clear, readable code
 Comprehensive chapter summaries
 Chapter exercises (answers and solutions to many of which are given in an
appendix)
 A thorough, instructive index
Essential MATLAB is meant to be used in conjunction with the MATLAB soft-
ware. The reader is expected to have the software at hand in order to work
through the exercises and thus discover how MATLAB does what it is com-
manded to do. Learning any tool is possible only through hands-on expe-
rience. This is particularly true with computing tools, which produce correct
answers only when the commands they are given and the accompanying data
input are correct and accurate.

ACKNOWLEDGMENTS
I would like to thank Mary, Clara, Zoe Rae and Zach T. for their support and
encouragement. I dedicate the sixth edition of Essential MATLAB for Engineers
and Scientists to them.
Daniel T. Valentine
1
Part 1 concerns those aspects of MATLAB that you need to know in order to
come to grips with MATLAB’s essentials and those of technical computing. Be-
cause this book is a tutorial, you are encouraged to use MATLAB extensively
while you go through the text.
PART

Essentials
This page intentionally left blank
CHAPTER 1

Introduction

THE OBJECTIVES OF THIS CHAPTER ARE: CONTENTS


 To enable you to use some simple MATLAB commands from the Using MATLAB ...... 5
Command Window. Arithmetic ................. 5
 To examine various MATLAB desktop and editing features. Variables .................... 7
 To learn some of the new features of the MATLAB R2016a Desktop. Mathematical
 To learn to write scripts in the Editor and Run them from the Editor. functions.................... 8
 To learn some of the new features associated with the tabs (in particular, Functions and
the PUBLISH and APPS features). commands ................. 8
Vectors....................... 9
Linear equations ...... 11
Tutorials and demos 12
MATLAB is a powerful technical computing system for handling scientific and The desktop ......... 13
engineering calculations. The name MATLAB stands for Matrix Laboratory, be- Using the Editor and
cause the system was designed to make matrix computations particularly easy. running a script ....... 13
A matrix is an array of numbers organized in m rows and n columns. An exam- Help, publish and
ple is the following m × n = 2 × 3 array: view ......................... 16
Symbolics and the
  MuPAD notebook
1 3 5 APP .......................... 18
A= Other APPS.............. 23
2 4 6
Additional features .. 23
Any one of the elements in a matrix can be plucked out by using the row
and column indices that identify its location. The elements in this example Sample program . 25
Cut and paste .......... 25
are plucked out as follows: A(1, 1) = 1, A(1, 2) = 3, A(1, 3) = 5, A(2, 1) = 2,
Saving a program:
A(2, 2) = 4, A(2, 3) = 6. The first index identifies the row number counted from
script files................ 27
top to bottom; the second index is the column number counted from left to Current directory ....... 28
right. This is the convention used in MATLAB to locate information in an array. Running a script from
A computer is useful because it can do numerous computations quickly, so the current folder
operating on large numerical data sets listed in tables as arrays or matrices of browser .................... 29
rows and columns is quite efficient. A program in action . 29

This book assumes that you have never used a computer before to do the sort
of scientific calculations that MATLAB handles, but are able to find your way
3
Essential MATLAB for Engineers and Scientists. DOI:10.1016/B978-0-08-100877-5.00002-5
Copyright © 2017 Daniel T. Valentine. Published by Elsevier Ltd. All rights reserved.
4 CHAPTER 1: Introduction

Summary .............. 30 around a computer keyboard and know your operating system (e.g., Windows,
UNIX or MAC-OS). The only other computer-related skill you will need is
Exercises ............... 31
some very basic text editing.
Supplementary
material ................. 31 One of the many things you will like about MATLAB (and that distinguishes
it from many other computer programming systems, such as C++ and Java) is
that you can use it interactively. This means you type some commands at the
special MATLAB prompt and get results immediately. The problems solved in
this way can be very simple, like finding a square root, or very complicated, like
finding the solution to a system of differential equations. For many technical
problems, you enter only one or two commands—MATLAB does most of the
work for you.
There are three essential requirements for successful MATLAB applications:
 You must learn the exact rules for writing MATLAB statements and using
MATLAB utilities.
 You must know the mathematics associated with the problem you want to
solve.
 You must develop a logical plan of attack—the algorithm—for solving a
particular problem.
This chapter is devoted mainly to the first requirement: learning some basic
MATLAB rules. Computer programming is a precise science (some would also
say an art); you have to enter statements in precisely the right way. There is a
saying among computer programmers: Garbage in, garbage out. It means that if
you give MATLAB a garbage instruction, you will get a garbage result.
With experience, you will be able to design, develop and implement compu-
tational and graphical tools to do relatively complex science and engineering
problems. You will be able to adjust the look of MATLAB, modify the way you
interact with it, and develop a toolbox of your own that helps you solve prob-
lems of interest. In other words, you can, with significant experience, customize
your MATLAB working environment.
As you learn the basics of MATLAB and, for that matter, any other computer
tool, remember that applications do nothing randomly. Therefore, as you use
MATLAB, observe and study all responses from the command-line operations
that you implement, to learn what this tool does and does not do. To begin
an investigation into the capabilities of MATLAB, we will do relatively simple
problems that we know the answers because we are evaluating the tool and its
capabilities. This is always the first step. As you learn about MATLAB, you are
also going to learn about programming, (1) to create your own computational
tools, and (2) to appreciate the difficulties involved in the design of efficient,
robust and accurate computational and graphical tools (i.e., computer pro-
grams).
1.1 Using MATLAB 5

In the rest of this chapter we will look at some simple examples. Don’t be
concerned about understanding exactly what is happening. Understanding will
come with the work you need to do in later chapters. It is very important for
you to practice with MATLAB to learn how it works. Once you have grasped
the basic rules in this chapter, you will be prepared to master many of those
presented in the next chapter and in the Help files provided with MATLAB.
This will help you go on to solve more interesting and substantial problems.
In the last section of this chapter you will take a quick tour of the MATLAB
desktop.

1.1 USING MATLAB


Either MATLAB must be installed on your computer or you must have access
to a network where it is available. Throughout this book the latest version at
the time of writing is assumed (Version R2016a).
To start from Windows, double-click the MATLAB icon on your Windows desk-
top. To start from UNIX, type matlab at the operating system prompt. To start
from MAC-OS open X11 (i.e., open an X-terminal window), then type mat-
lab at the prompt. The MATLAB desktop opens as shown in Figure 1.1. The
window in the desktop that concerns us for now is the Command Window,
where the special >> prompt appears. This prompt means that MATLAB is
waiting for a command. You can quit at any time with one of the following
ways:
 Click the X (close box) in the upper right-hand corner of the MATLAB desk-
top.
 Type quit or exit at the Command Window prompt followed by pressing
the ‘enter’ key.
Starting MATLAB automatically creates a folder named MATLAB in the user’s
Documents Folder. This feature is quite convenient because it is the default
working folder. It is in this folder that anything saved from the Command
Window will be saved. Now you can experiment with MATLAB in the Com-
mand Window. If necessary, make the Command Window active by placing
the cursor in the Command Window and left-clicking the mouse button any-
where inside its border.

1.1.1 Arithmetic
Since we have experience doing arithmetic, we want to examine if MATLAB
does it correctly. This is a required step to gain confidence in any tool and in
our ability to use it.
Type 2+3 after the >> prompt, followed by Enter (press the Enter key) as
indicated by <Enter>:
>> 2+3 <Enter>
6 CHAPTER 1: Introduction

FIGURE 1.1 MATLAB desktop illustrating the Home task bar (version 2016a).

Commands are only carried out when you enter them. The answer in this case
is, of course, 5. Next try
>> 3-2 <Enter>
>> 2*3 <Enter>
>> 1/2 <Enter>
>> 23 <Enter>
>> 2\11 <Enter>
What about (1)/(2) and (2)^(3)? Can you figure out what the symbols *,
/, and ^ mean? Yes, they are multiplication, division and exponentiation. The
backslash means the denominator is to the left of the symbol and the numer-
ator is to the right; the result for the last command is 5.5. This operation is
equivalent to 11/2.
Now enter the following commands:
>> 2 .* 3 <Enter>
>> 1 ./ 2 <Enter>
>> 2 .ˆ 3 <Enter>
A period in front of the *, /, and ^, respectively, does not change the results
because the multiplication, division, and exponentiation is done with single
numbers. (An explanation for the need for these symbols is provided later
when we deal with arrays of numbers.)
1.1 Using MATLAB 7

Here are hints on creating and editing command lines:


 The line with the >> prompt is called the command line.
 You can edit a MATLAB command before pressing Enter by using various
combinations of the Backspace, Left-arrow, Right-arrow, and Del keys.
This helpful feature is called command-line editing.
 You can select (and edit) commands you have entered using Up-arrow and
Down-arrow. Remember to press Enter to have the command carried out
(i.e., to run or to execute the command).
 MATLAB has a useful editing feature called smart recall. Just type the first few
characters of the command you want to recall. For example, type the charac-
ters 2* and press the Up-arrow key—this recalls the most recent command
starting with 2*.
How do you think MATLAB would handle 0/1 and 1/0? Try it. If you insist
on using ∞ in a calculation, which you may legitimately wish to do, type the
symbol Inf (short for infinity). Try 13+Inf and 29/Inf.
Another special value that you may meet is NaN, which stands for Not-a-
Number. It is the answer to calculations like 0/0.

1.1.2 Variables
Now we will assign values to variables to do arithmetic operations with the
variables. First enter the command (statement in programming jargon) a = 2.
The MATLAB command line should look like this:
>> a = 2 <Enter>
The a is a variable. This statement assigns the value of 2 to it. (Note that this
value is displayed immediately after the statement is executed.) Now try enter-
ing the statement a = a + 7 followed on a new line by a = a * 10. Do you
agree with the final value of a? Do we agree that it is 90?
Now enter the statement
>> b = 3; <Enter>
The semicolon (;) prevents the value of b from being displayed. However, b
still has the value 3, as you can see by entering without a semicolon:
>> b <Enter>
Assign any values you like to two variables x and y. Now see if you can assign
the sum of x and y to a third variable z in a single statement. One way of doing
this is
>> x = 2; y = 3; <Enter>
>> z = x + y <Enter>
8 CHAPTER 1: Introduction

Notice that, in addition to doing the arithmetic with variables with assigned
values, several commands separated by semicolons (or commas) can be put
on one line.

1.1.3 Mathematical functions


MATLAB has all of the usual mathematical functions found on a scientific-
electronic calculator, like sin, cos, and log (meaning the natural logarithm).
See Appendix B.5 for many more examples.

 Find π with the command sqrt(pi). The answer should be 1.7725. Note
that MATLAB knows the value of pi because it is one of its many built-in
functions.
 Trigonometric functions like sin(x) expect the argument x to be in radians.
Multiply degrees by π/180 to get radians. For example, use MATLAB to cal-
culate sin(90◦ ). The answer should be 1 (sin(90*pi/180)).
x
 The exponential function e is computed in MATLAB as exp(x). Use this

information to find e and 1/e (2.7183 and 0.3679).


Because of the numerous built-in functions like pi or sin, care must be taken
in the naming of user-defined variables. Names should not duplicate those
of built-in functions without good reason. This problem can be illustrated as
follows:
>> pi = 4 <Enter>
>> sqrt(pi) <Enter>
>> whos <Enter>
>> clear pi <Enter>
>> whos <Enter>
>> sqrt(pi) <Enter>
>> clear <Enter>
>> whos <Enter>
Note that clear executed by itself clears all local variables in the workspace;
>>clear pi clears the locally defined variable pi. In other words, if you de-
cide to redefine a built-in function or command, the new value is used! The
command whos is executed to determine the list of local variables or com-
mands presently in the workspace. The first execution of the command pi = 4
in the above example displays your redefinition of the built-in pi: a 1-by-1 (or
1x1) double array, which means this data type was created when pi was assigned
a number (you will learn more about other data types later, as we proceed in
our investigation of MATLAB).

1.1.4 Functions and commands


MATLAB has numerous general functions. Try date and calendar for starters.
It also has numerous commands, such as clc (for clear command window). help
is one you will use a lot (see below). The difference between functions and
1.1 Using MATLAB 9

commands is that functions usually return with a value (e.g., the date), while
commands tend to change the environment in some way (e.g., clearing the
screen or saving some statements to the workspace).

1.1.5 Vectors
Variables such as a and b that were used in Section 1.1.2 above are called scalars;
they are single-valued. MATLAB also handles vectors (generally referred to as
arrays), which are the key to many of its powerful features. The easiest way
of defining a vector where the elements (components) increase by the same
amount is with a statement like
>> x = 0 : 10; <Enter>
That is a colon (:) between the 0 and the 10. There is no need to leave a space
on either side of it, except to make it more readable. Enter x to check that x
is a vector; it is a row vector—consisting of 1 row and 11 columns. Type the
following command to verify that this is the case:
>> size(x) <Enter>
Part of the real power of MATLAB is illustrated by the fact that other vectors
can now be defined (or created) in terms of the just defined vector x. Try
>> y = 2 .* x <Enter>
>> w = y ./ x <Enter>
and
>> y = sin(x) <Enter>
(no semicolons). Note that the first command line creates a vector y by multi-
plying each element of x by the factor 2. The second command line is an array
operation, creating a vector w by taking each element of y and dividing it by
the corresponding element of x. Since each element of y is two times the cor-
responding element of x, the vector w is a row vector of 11 elements all equal
to 2. Finally, z is a vector with sin(x) as its elements.
To draw a reasonably nice graph of sin(x), simply enter the following com-
mands:
>> x = 0 : 0.1 : 10; <Enter>
>> z = sin(x); <Enter>
>> plot(x,z), grid <Enter>
The graph appears in a separate figure window. To draw the graph of the sine
function illustrated in Figure 1.2 replace the last line above with
>> plot(x,y,’-rs’,’LineWidth’,2,’MarkerEdgeColor’,’k’,’MarkerSize’,5),grid
<Enter>
10 CHAPTER 1: Introduction

FIGURE 1.2 Figure window.

>> xlabel(’ x ’), ylabel(’ sin(x) ’) <Enter>


>> whitebg(’y’) <Enter>
You can select the Command Window or figure windows by clicking anywhere
inside them. The Windows pull-down menus can be used in any of them.
Note that the first command line above has three numbers after the equal sign.
When three numbers are separated by two colons in this way, the middle num-
ber is the increment. The increment of 0.1 was selected to give a reasonably
smooth graph. The command grid following the comma in the last command
line adds a grid to the graph.
Modifying the plot function as illustrated above, of the many options available
within this function, four were selected. A comma was added after the variable
y followed by ’-rs’. This selects a solid red line (-r) to connect the points at which
the sine is computed; they are surrounded by square (s) markers in the figure.
The line width is increased to 2 and the marker edge color is black (k) with
size 5. Axis labels and the background color were changed with the statements
following the plot command. (Additional changes in background color, object
colors etc. can be made with the figure properties editor; it can be found in the
pull-down menu under Edit in the figure toolbar. Many of the colors in the
figures in this book were modified with the figure-editing tools.)
If you want to see more cycles of the sine graph, use command-line editing to
change sin(x) to sin(2*x).
Try drawing the graph of tan(x) over the same domain. You may find aspects
of your graph surprising. To help examine this function you can improve the
graph by using the command axis([0 10 -10 10]) as follows:
1.1 Using MATLAB 11

>> x = 1:0.1:10; <Enter>


>> z = tan(x); <Enter>
>> plot(x,z),axis([0 10 -10 10]) <Enter>
An alternative way to examine mathematical functions graphically is to use the
following command:
>> ezplot(’tan(x)’) <Enter>
The apostrophes around the function tan(x) are important in the ezplot
command. Note that the default domain of x in ezplot is not 0 to 10.
A useful Command Window editing feature is tab completion: Type the first
few letters of a MATLAB name and then press Tab. If the name is unique, it is
automatically completed. If it is not unique, press Tab a second time to see all
the possibilities. Try by typing ta at the command line followed by Tab twice.

1.1.6 Linear equations


Systems of linear equations are very important in engineering and scientific
analysis. A simple example is finding the solution to two simultaneous equa-
tions:

x + 2y = 4
2x − y = 3

Here are two approaches to the solution.


Matrix method. Type the following commands (exactly as they are):
>> a = [1 2; 2 -1]; <Enter >
>> b = [4; 3]; <Enter >
>> x = a\b <Enter >
The result is

x =
2
1

i.e., x = 2, y = 1.
Built-in solve function. Type the following commands (exactly as they are):
>> [x,y] = solve(’x+2*y=4’,’2*x - y=3’) <Enter >
>> whos <Enter >
>> x = double(x), y=double(y) <Enter >
>> whos <Enter >
12 CHAPTER 1: Introduction

FIGURE 1.3 The Help documentation on MATLAB Examples.

The function double converts x and y from symbolic objects (another data type
in MATLAB) to double arrays (i.e., the numerical-variable data type associated
with an assigned number).
To check your results, after executing either approach, type the following com-
mands (exactly as they are):
>> x + 2*y % should give ans = 4 <Enter >
>> 2*x - y % should give ans = 3 <Enter >
The % symbol is a flag that indicates all information to the right is not part of
the command but a comment. (We will examine the need for comments when
we learn to develop coded programs of command lines later on.)

1.1.7 Tutorials and demos


If you want a spectacular sample of what MATLAB has to offer, type the com-
mand demo on the command line. After entering this command the Help
documentation is opened at MATLAB Examples (see Figure 1.3). Left-click on
“Getting Started”. This points you to the list of tutorials and demonstrations of
MATLAB applications that are at your disposal. Click on any of the other top-
ics to learn more about the wealth of capabilities of MATLAB. You may wish to
review the tutorials appropriate to the topics you are examining as part of your
technical computing needs. Scroll down to the “New Features Video” to learn
more about the Desktop and other new features, some of which are introduced
next.
Another random document with
no related content on Scribd:
should have been apparent to the delegates that this was a blocking
motion and might prevent the committee from doing anything, but it
was evidently not so regarded, or else the delegates could not make
up their minds on the subject, for it was agreed to without comment.
The committee did not allow the motion for reopening the question
in six months to hinder them from going on with the new branch, for
immediately the meeting was over they gave instructions to the sub-
committee to secure temporary premises in the vicinity.
THE END OF THE PROPOSAL.
The subject again arose at the 34th quarterly meeting, held on 1st
September, when Paisley Provident was again forward with a
motion: “That if a branch be required after Barrhead had left the
Federation, it be established at Paisley or Johnstone, and that the
present branch in Glasgow be not retaken.” To this it was moved by
Mr Gardiner, Cathcart, and seconded by Mr M‘Murran, Glasgow
Eastern, as an amendment, “That this question lie over for six
months.” After a long discussion the Paisley motion was withdrawn,
on condition that the amendment limit the period of lying over to
three months, and that, meantime, a special committee, constituted
from the delegates present and from the committee, be appointed to
investigate the matter and report to the next quarterly meeting. This
was agreed to, and Messrs M‘Murran, O’May, Aitchison, Brown, and
Slater were appointed the special committee. In less than three
months’ time the committee sent out their report to the societies.
The report contained details of three plans which the sub-committee
had considered. The first of these, that of a branch bakery in Paisley,
they considered could not be worked except at a slight loss. With
regard to the second one, that of a branch at Johnstone, they
considered that the loss would be slightly greater; while, with the
branch at Johnstone, the trade would be more difficult to work. The
third proposal which had been considered was that of increasing the
number of ovens in the present premises, and in the report they
stated they were not prepared to recommend any one of the schemes
in the meantime, but recommended, instead, that the branch in
Paisley Road be taken for another year. The reason they gave for this
recommendation was that they considered that an inquiry should be
made into the advisability of introducing machinery into the
bakehouse, as the whole of their premises would be vacant in
eighteen months and could be utilised; if the result of the inquiry was
satisfactory, steps should then be taken to have it introduced. This
report was accepted by the delegates at the quarterly meeting, and so
a subject which had been a fruitful source of controversy at the
general meetings of the Federation for nearly two years disappeared.
It was again raised at a quarterly meeting some years later, when the
question of removing altogether from St James Street was being
discussed, but was summarily disposed of by the delegates.
BARRHEAD, JOHNSTONE, AND PAISLEY
PROVIDENT WITHDRAW.
Meantime the Barrhead bakery was ready for work and baking was
commenced in the last week of the year, but the society, although it
had withdrawn a large proportion of the loan capital invested with
the Baking Society in order to pay for the erection of its own bakery,
retained membership of the Federation until requested by the
committee to withdraw as the interest on the share capital was an
unnecessary burden on the Federation’s funds. The society was
allowed to withdraw without any of its capital being retained, being
the first of the withdrawing societies to which this privilege was
extended. In 1894, after fancy biscuit baking had been firmly
established by the Baking Society, Barrhead Society rejoined again,
taking up 1,500 shares.
Another withdrawal which occurred in a comparatively short time,
and which was doubtless influenced to some extent by the refusal to
establish a branch in the West, was that of Johnstone Society. At a
meeting of the committee which took place on 15th February 1879,
the minutes record a conversation which took place regarding a
decision of that society, come to the previous evening, to start baking
for themselves. The effect of the information that they were likely to
lose Johnstone Society’s custom so soon after having lost that of
Barrhead had a damping effect on the spirits of the committee, and it
was decided that in the meantime the erection of the new ovens
which they had proposed to build be not proceeded with. With the
withdrawal of Paisley Provident Society at the end of 1880,
consequent on having a bakery of their own ready for occupation, the
controversy with respect to the branch, and also its effects on the
welfare of the Federation, may be said to have ended.
The Federation had lost three of its best customers, but it had
succeeded in keeping its business centralised. It must always remain
a matter of argument whether it would have been better to branch
out at an earlier date and do for the societies in Renfrewshire that
which in later years it has done for Clydebank and the North of
Ireland. The question of branches is still one on which there is
considerable controversy, and, at any rate, it is certain that the
committee, and latterly the delegates, played for safety, and chose to
conserve the strength of the Federation at a time when all its
strength was needed rather than weaken it by widening the scope of
the society’s energies. The majority of the committee, it is quite
evident, were opposed to branching out, for had this not been so,
they would have gone ahead when two general meetings of the
Society gave them the mandate.
It is difficult to see that any great harm was done by the course
which was adopted. The growth of the three societies has been so
great that each of them is large enough to maintain a bakery of its
own, and although the Federation had one or two temporary
setbacks, none of them was serious enough to affect its stability or its
efficiency. It is possible, therefore, to argue that either decision
would have had equally good results. There we may leave what was
undoubtedly a stirring controversy while it lasted, the importance of
which at the time forms sufficient justification for the space which
has been devoted to it.
CHAPTER VI.
ST JAMES STREET: DEVELOPMENTS.

IMPROVED MANAGEMENT—PRIVATE LOANS—


IRREGULARITY OF ORDERS AND OTHER DIFFICULTIES—
A NEW FOREMAN BAKER—SHORT WEIGHT IN FLOUR—
DELIVERY DIFFICULTIES CONTINUE—UNINFORMED
CRITICISM—AN ECHO OF THE IRONWORKS FAILURE—
NEW MEMBERS—AMENDING THE RULES—EXTENSIONS
—MANAGER RESIGNS: SECRETARY APPOINTED—
OAKMILL SOCIETY—APPEAL FOR FUNDS—TRADE AND
FINANCIAL POSITION IMPROVING—ANDERSTON
SOCIETY’S FAILURE—GOOD NEWS—MACHINERY
INSTALLED—BECOMING RICH—TEN YEARS’ WORK.

In tracing the development of the agitation for and against the


establishment of a branch bakery we have been running ahead of the
calendar. A new cashier, who was virtually manager of the business,
had been appointed in the last days of 1872, and during the next two
and a half years he carried on the business with as much success as
the conditions under which he was compelled to work permitted. In
these two and a half years he inaugurated a system of private loans to
the Federation for the purpose of increasing the working capital of
the Society; the smallness of the capital having been until then the
greatest difficulty under which the Federation laboured; and so
successful was this venture that by April 1875 the Society was in a
position to deposit £500 on loan with the S.C.W.S., while six months
earlier he was in a position to recommend to the committee that the
acceptance of private loans except from those who had already
deposits with the Society, and from the employees, be discontinued;
a recommendation which was put in force by the committee a month
later.
In other ways, too, Mr Craig brought prosperity to the Federation.
He found it in a position of peril. For a long time after his
appointment he found himself in the position, meeting after meeting,
of having to present to the committee accounts which had been
incurred by his predecessor without being able to check them in any
way. One of these, presented in 1874, had been incurred from 1870
to 1872, and the explanation offered by the contractor was that he
thought the U.C.B.S. and the S.C.W.S. were all the same, and had
kept the invoice back until the building was finished. Mr Craig was
given the job of arranging on the best terms possible. For several
years the difficulty already alluded to, that societies did not pay their
accounts promptly, continued. This was particularly the case with
two of the societies which were in very low water about this time, one
of them eventually succumbing. There was also continuous difficulty
about the maintenance of sales. Sometimes a society would take
bread for a number of weeks or months, and then cease all at once
without any reason being given. At other times there would be a
series of complaints about the quality of the bread and the reluctance
of members to purchase, and investigation showed that these
complaints emanated from the shopman and had very little
foundation in fact. In some cases the shopman was the society, the
committee seeming to exercise little or no supervision; while in other
cases there was, of course, genuine cause for complaint owing to bad
or irregular deliveries or to barm going wrong with the baker. Such
causes were not sufficient to account for the constant stream of
complaints which were launched at the heads of the committee,
however, and doubtless close investigation would have shown that
many of them had their origin in a desire on the part of salesmen to
do business with firms which made it worth their while. With the
appointment of Mr Lang as foreman baker there was certainly a
decrease in the number of complaints, and the sales improved.
A discussion which took place at a committee meeting in June
1873 showed that there was not only a dispute with Barrhead Society,
a deputation having been sent to that society’s meeting and been
refused admission to the meeting, but also that the Baking Society’s
committee had not yet been placed on a satisfactory basis. The
chairman stated at the committee meeting that his committee had
only heard of the Barrhead meeting casually, and expressed the
opinion that it was the duty of the member of the board from
Barrhead Society to have informed the Bakery board of the fact that
it was being held. On the other hand the Barrhead delegate said that
he had forgotten all about it, and that in any case he had no authority
from Barrhead committee to say anything on the matter. It would
appear that a long discussion took place on the subject, and
especially on the position of members of the Baking Society’s
committee in relation to the work of that society, the opinion being
freely expressed that to members of the board of the Baking Society
the affairs of the Baking Society should be the first consideration.
The subject was ultimately dropped, on the understanding that it was
the duty of any member of the Baking Society’s committee to inform
that board forthwith of anything which affected the interests of the
Society.
About this time, also, some trouble was being experienced with
one of the millers who were supplying them with flour. Several sacks
of flour had been weighed by the manager, and each had been found
to be short in weight to the extent of several pounds. The result was
that the committee determined to purchase a “beam and scales” in
order that the flour might be weighed as it came into the bakery, and
meantime it was decided that at present no more flour be purchased
from the defaulting miller. At the same time a claim was made
against him for short weight. About this time, also, some difficulty
arose with respect to the delivery of bread to Lennoxtown Society.
For some time the committee had been of the opinion that they were
losing money by delivering bread to this society, and several
suggestions had been made as to the most economical means of
delivery. No one of these seemed to find favour with the Lennoxtown
people, however, and that committee ultimately decided to ask the
Bakery board to supply them with bread by means of the van as
usual, and, if necessary, to retain the dividend. The Bakery
committee, however, after considering the matter, came to the
conclusion that, apart from the principle, this method would not pay
them, and decided to make no alteration. The secretary was
instructed to reply to this effect, and also to state that the Bakery
would stop supplying bread to Lennoxtown as soon as that society
was able to make other arrangements.
At the quarterly meeting the attention of the delegates was called
by the chairman to the cases of one or two societies in Glasgow which
were members of the Federation, but which purchased little or no
bread from the Society. At this meeting, also, attention was again
called to the needs of the Federation for more capital. The work of
Mr Craig in securing individual depositors had not yet begun to have
any noticeable effect on the finances of the Society. At this time
propaganda work was engaging the attention of the committee, and a
conference of societies in and near Glasgow was held for the purpose
of inducing them to become better customers of the Federation. At
one of the meetings about this time the chairman suggested that
another meeting place be got for their committee meetings, as the
business was being overheard where they met at present. Societies
were now beginning to join up more freely. Applications from some
of the outlying societies were held up for consideration, but in
November 1873 Kinning Park joined the Federation, taking up 100
shares, and a short time later London Road Society became a
member.
UNINFORMED CRITICISM.
About this time the editor of the Co-operative News seems to have
been criticising the Society’s balance-sheet, for a discussion took
place in committee on the subject, and it was duly minuted that “the
remarks of the editor with regard to the balance-sheet were wrong;
that it had been the same with the quarter previous, and he
considered the editor should make himself better acquainted with
the circumstances of the business before commenting on it.” At this
period the Federation had been caught on a rising market with a very
small stock of flour on hand. The master bakers of the city had a
meeting, but two of them refused to raise the price of bread, having
evidently large stocks in hand. Flour was eight shillings a sack dearer
than when the price of bread had been fixed. It was decided to
maintain the price of bread in a line with Glasgow prices; but it was
agreed that if a general rise took place in the various districts the
members of committee should notify the manager so that he could
act accordingly.
At the meeting of the committee which was held on 17th January
1874 the overdrawing by the Ironworks of their account with the
Wholesale Society was referred to. It was stated that the amount
overdrawn was £9,000. A lengthy conversation took place as to the
advisability of having a more thorough check upon the transactions
of the Bakery manager so as to prevent the possibility of a like
occurrence; but, after the matter had been discussed in all its
bearings and various plans had been suggested, no definite decision
was arrived at, except that the finance committee were instructed to
make a regular inspection of the books and use every means to
ascertain the real position of the Society. The delegates to the
Wholesale meeting had also reported that it had been agreed by that
society to charge 5 per cent. on overdue accounts after a certain date.
This was going to hit the Baking Society heavily, and the committee
expressed the opinion that they should not be liable as they were
only receiving half bonus. There is no reason given, however, why
they should be receiving only half bonus, as they had become
members of the Wholesale Society quite a long time previously.
Bridge of Weir and Kilbarchan societies were admitted members of
the Federation, but the admission of Milngavie Society was held over
for a further period. It was decided in February 1874 to recommend
the delegates to the quarterly meeting to amend the rule relating to
the representation of societies on the committee, as it was thought
that with the increase in the number of the societies who were
members of the Federation the committee was becoming unwieldy
because of its size. From the beginning each society which joined the
Federation had been entitled to be represented on the committee.
There were now twenty societies in the Federation, and, although the
average attendance at a committee meeting was about fourteen, the
more the membership of the Federation was added to the larger the
committee would become. After having been considered by the
societies for a year, the recommendation of the committee was
agreed to, and the membership of the committee was fixed at twelve
—president, secretary, treasurer, and nine representatives of
societies.
The trade of the Federation had fallen off somewhat during the
fifth year, owing to the fact that several of the societies had been
asked to withdraw and that the trade of one or two others was
declining. The turnover was 7,514 sacks, as compared with 7,955 for
the preceding year, thus showing a decline of 441 sacks. The average
price of bread had been slightly higher, however, for the cash value of
the goods sold was £22,153, an increase of £131. The average
dividend paid had been 5½d.—4d., 6d., 6d., and 6d. respectively for
the four quarters—and the reserve fund had been more than doubled
during the year, while depreciations to the amount of £719 had been
made. The capital of the society was still very small in proportion to
the turnover, however, being only £2,300. The societies themselves
were mostly small; they had not very much capital to spare for
investment, and those of them which were members of the U.C.B.S.
had to divide that between that Federation and the S.C.W.S. Added
to this was the fact that several of the societies which were members
of the Federation were in a position which was gradually becoming
more hopeless, with the result that not only were they unable to
invest in the Federation, but they were barely able to pay for the
bread they bought.
EXTENSIONS AND A FIRE.
At the quarterly meeting which took place in December 1874 it was
decided that the erection of the flour loft, which had been held over
for more than a year, should be proceeded with, but a disaster which
befell the Society at the end of the month put a stop to the carrying
out of that particular proposal for some time. This disaster was the
burning down of the premises adjacent to the bakery and the
property of the Society, which were being utilised as a bolt and rivet
works by tenants of theirs. The reconstruction of this property
occupied the attention of the committee for the next few months, and
it was not until May that estimates for the completion of the flour loft
were received and the contracts placed. When the accounts for the
rebuilding of the burned-out property had all been submitted it was
found that they were £70 less than the sum which had been received
in insurances on the property, and the manager was presented with
£5 and was granted a fortnight’s leave of absence. The insurance on
the property and stock of the Society was now increased by £2,000
to £7,000.
RESIGNATION OF MR CRAIG.
At the next meeting of the committee, held on 10th July 1875, a
letter was received from Mr Craig, in which he stated that owing to a
sudden change in health he was compelled to resign his position as
cashier and manager. The committee were unanimous in their
expressions of regret, and a deputation was appointed to meet with
Mr Craig and learn whether it would be possible for him to return to
his position in the event of assistance being given in the office. At the
next meeting this deputation reported that they had met Mr Craig,
who stated that the medical advice he had received was that he
should leave the country, and that he had decided to do so. They had
therefore advertised the position. The committee thereupon recorded
their appreciation of the work which Mr Craig had done for the
Society in the following terms:—
“While we accept Mr Craig’s resignation as manager, we desire to record our
heartfelt sympathy with him in his circumstances and the high esteem in
which he is held by all the members of this committee as an honest and
upright individual, an intelligent and energetic man of business, and a faithful
servant who, for the past two and a half years, has conducted the business to
the great pecuniary advantage of all the members connected with it. While we
regret the loss of such a valuable servant, we hope that he may secure in the
country to which he is emigrating a restoration of health and strength,
together with a due amount of worldly prosperity.”
Alas, it was not to be. No improvement took place in Mr Craig’s
health from his residence abroad, and in a short time he was back in
Glasgow again, his death taking place in the summer of 1877.
At the August quarterly meeting of the Society a grant of £20 was
made to a testimonial which was being got up for Mr Craig, and the
secretary was instructed to record in the minute of the proceedings
that the grant was made
“In recognition of his sterling worth as a man and the able business abilities
he showed by the successful manner in which he conducted the affairs of this
Society during the period he held the office of manager to the Society.”
Mr David Smith, who had been acting as secretary since Mr
Borrowman had resigned from that office, was appointed manager,
and Mr Thomas Slater, London Road Society, was elected secretary.
A BAD INVESTMENT.
In the middle of September there came an appeal from the Oakmill
Society that the Baking Society should invest in its funds. The matter
was delayed for one reason or another, but finally, at the quarterly
meeting which was held in March 1876, it was agreed to invest £200.
At this time the financial position was improving every week. The
profits on working were well over £30 per week, and the committee
were not so chary of spending money as they had been in earlier
years. Among other donations to which the Society agreed was one of
£20 towards the expenses of the Co-operative Congress which was to
be held in Glasgow in 1876. Several of the societies which were
affiliated with the Baking Society were in a bad way at this time.
Blairdardie Society had had their premises destroyed by fire, and a
deputation was received by the Bakery directors. The deputation
explained that the purpose of their visit was to get some
consideration shown to them by giving them their regular supply of
bread until they were able to complete their arrangements. The
committee agreed that Blairdardie should receive their usual supply
of bread for a month, at the end of which period the question would
be further considered. Anderston Society also had fallen on evil days.
For some time the Bakery committee had had considerable difficulty
in securing prompt payment by that society for bread supplied to it,
and early in 1876 they reduced by half the number of shares they
held in the Bakery, as their membership was declining. They
struggled on until the middle of 1878, but after taking stock in July of
that year they gave up in despair and closed the shop. At the time
when they closed down they were owing the Baking Society some
money, and Mr Smith transferred that amount from their share
account to their goods account. The chairman had, however, some
doubt as to the legality of this action, and it was afterwards decided
that should any of the other creditors object the Society would not
take any action to uphold their claim. The debts of the Anderston
Society were taken up by the Wholesale Society, however, and after a
considerable amount of correspondence between the committees of
the two Federations the balance of the share capital of Anderston
Society was transferred by the Bakery committee to the Wholesale
Society, the latter Federation agreeing to relieve the Baking Society
from any responsibility they might incur by so doing.
At the beginning of the year 1878, Barrhead Society ceased to
purchase bread from the Baking Society. This meant a reduction in
turnover of nearly 600 dozens of bread every week, and for the time
being put an end to all thoughts of branching out. Other societies,
too, were going the way of Anderston, and about this time the most
remarkable point in the minutes of the Baking Society is their record
of the names of societies which have long ceased to have any separate
existence. Maryhill, Petershill, Bloomvale, Anderston, and Southern
all lived a more or less precarious existence during the first decade of
the Federation’s existence, and all disappeared. One result of the
failure of Anderston Society was an alteration in the rules of the
Baking Society for the purpose of giving a lien on the shares of a
debtor member. It was also decided about this time that societies
which had ceased to be purchasers be removed from membership,
and have their shares paid out to them. It was at the quarterly
meeting held in December 1876 that the first mention is made of a
practice which has since that time gladdened the hearts of many
hundreds of weary delegates. At that meeting, Mr Neil, Kilbarchan,
moved, and Mr M‘Duff, Linwood, seconded a motion: “That at our
quarterly meetings in future the delegates be supplied with tea.” The
motion was agreed to unanimously. The tenants of the bolt and rivet
works in property owned by the Society wished for an extension of
their lease or, alternatively, to be allowed to break their lease and
remove, and the Society agreed to allow them to remove provided the
removal was carried out in three months. At the end of May 1877 the
Society’s stable in St James Street was destroyed by fire and six
horses were killed; at the same time some doubts were being
entertained as to the stability of the bakery itself, as it was feared that
the back wall was too weak for the load of flour it had to bear. Then
the members of the committee were again being worried with
complaints about the quality of the bread, and especially of the fine
bread. When they came to compare their bread with that
manufactured by competing bakers, however, they usually were of
the opinion that the bread they were baking was as good as any.
PAST PRESIDENTS

1. GABRIEL THOMSON. 2. WM.


BARCLAY.
3. DONALD CAMERON. 4. ANDREW
BROWN.
PAST PRESIDENTS

1. ALEXANDER FRASER. 2. JOHN


FERGUSON.
3. DUNCAN M‘CULLOCH. 4. DANIEL H.
GERRARD. J.P.
GOOD NEWS.
At one of the meetings of the committee, held towards the end of
1877, an interesting report was given by the Johnstone
representative, which was not without its humorous side. Nearly a
year earlier the Bakery committee had installed machinery for biscuit
baking, and had been building up a good trade. Nevertheless, the
Johnstone committee had thought it necessary to inquire into
complaints which were being made by their members. The biscuits
manufactured by the Baking Society were sold in paper bags which
contained 28 for 1/, and the members complained that other grocers
gave 30 biscuits for 1/. The committee of Johnstone Society had
carried out their investigation in a practical manner. They had
purchased a bag of each of the other makers’ biscuits and had
weighed them. The result showed that the U.C.B.S. 28 biscuits were
heavier by 5½ oz. than were the 30 biscuits of one maker, and were
as heavy as 34 biscuits of another maker, while in each case the
Society’s biscuits were pronounced to be the better in quality. It is
easy to imagine how heartening to a committee who were
continuously being pestered with complaints about the quality of
their wares such a report would be, and the chuckles with which the
humorists amongst them would agree that it should be engrossed in
the minutes “for the information of the delegates attending the
quarterly meeting, so that they may be in a position to lay the matter
before their respective committees; which may result in a
considerable extension of this branch of trade.”
MACHINERY INSTALLED.
For some months the committee had been discussing tentatively
the installation of baking machinery, but without coming to any
definite decision on the matter. In the beginning of 1878, however,
they began to inquire into the subject in earnest, and appointed a
committee to get all necessary particulars as to cost, effect on
working expenses, and effect on the quality and appearance of the
bread, of such machinery. After this committee had reported, the
subject was discussed by the general committee and then remitted to
the quarterly meeting. There the delegates ordered the report to be
printed in circular form and sent out to the societies, so that the
delegates might come to the next quarterly meeting with
instructions. At the next meeting a motion that machinery be
installed in the bakery was agreed to by a small majority. The
amendment, “that it be not installed,” seems to have been the last
protest from those societies who wished a branch to be established at
Paisley or Johnstone, but with the installation of machinery their last
hope of achieving their purpose disappeared.

You might also like