0% found this document useful (0 votes)
20 views8 pages

Preface 2012 Matlab

This document provides an overview and motivation for a book that teaches programming concepts and MATLAB skills. It takes a hybrid approach, introducing both programming constructs and efficient uses of MATLAB's built-in functions. Key features include teaching programming concepts and functions side-by-side, a systematic approach, coverage of file input/output, user-defined functions, advanced concepts, problem-solving tools, and vectorized code. The book aims to equip students with both programming knowledge and skills to efficiently use MATLAB.

Uploaded by

wataya
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
0% found this document useful (0 votes)
20 views8 pages

Preface 2012 Matlab

This document provides an overview and motivation for a book that teaches programming concepts and MATLAB skills. It takes a hybrid approach, introducing both programming constructs and efficient uses of MATLAB's built-in functions. Key features include teaching programming concepts and functions side-by-side, a systematic approach, coverage of file input/output, user-defined functions, advanced concepts, problem-solving tools, and vectorized code. The book aims to equip students with both programming knowledge and skills to efficiently use MATLAB.

Uploaded by

wataya
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/ 8

Preface

Motivation
The purpose of this book is to teach fundamentals of programming concepts and
skills needed for basic problem solving, all using MATLABW as the vehicle.
MATLAB is a powerful software package that has built-in functions to accomplish
a diverse range of tasks, from mathematical operations to three-dimensional
imaging. Additionally, MATLAB has a complete set of programming constructs
that allows users to customize programs to their own specifications.
The many books that introduce MATLAB come in two basic flavors: those that
demonstrate the use of the built-in functions in MATLAB, with a chapter or two
on some programming concepts; and those that cover only the programming
constructs without mentioning many of the built-in functions that make
MATLAB efficient to use. Someone who learns just the built-in functions will
be well-prepared to use MATLAB, but would not understand basic program-
ming concepts. That person would not be able to then learn a language such
as Cþþ or Java without taking another introductory course or reading another
book on the programming concepts. Conversely, anyone who learns only pro-
gramming concepts first (using any language) would tend to write highly inef-
ficient code using control statements to solve problems, not realizing that in
many cases these are not necessary in MATLAB.
This book instead takes a hybrid approach, introducing both the programming
and efficient uses. The challenge for students is that it is nearly impossible to
predict whether they will in fact need to know programming concepts later
or whether a software package such as MATLAB will suffice for their careers.
Therefore, the best approach for beginning students is to give them both: the
programming concepts and the efficient built-in functions. Since MATLAB is
very easy to use, it is a perfect platform for this approach to teaching program-
ming and problem solving.
Since programming concepts are critically important to this book, emphasis is
not placed on the time-saving features that evolve with every new MATLAB re-
lease. For example, in current versions of MATLAB, statistics on variables are xi
xii Preface

available readily in the Workspace Window. This is not shown in any detail in
the book, since whether this feature is available depends on the software ver-
sion, and because of the desire to explain the concepts in the book.

Modifications in Second Edition


Changes in the second edition of this book include:
n Vectorized code has been made into a separate chapter to emphasize the
importance of using MATLAB efficiently.
n There are expanded examples on:
n Low-level file input functions
n Plots
n Graphical user interfaces
n Vectorized code, including functions diff, meshgrid, tic, and toc
n Use of MATLAB version R2011a
n Concepts used in image processing, such as three-dimensional matrices and
unsigned integers, are now introduced early, in Chapter 1.
n Modified and new end-of-chapter exercises.
n The introduction to Handle Graphics was moved to Chapter 11, Advanced
Plotting Techniques.
n Discussion of symbolic mathematics was moved to Chapter 15, Advanced
Mathematics.
n Improved labeling of plots.
n Improved standards for variable names and documentation.
n Added end to the end of all functions.

Key Features
Side-by-Side Programming Concepts and Built-in Functions
The most important, and unique, feature of this book is that it teaches program-
ming concepts and the use of the built-in functions in MATLAB side by side. It
starts with basic programming concepts such as variables, assignments, input/
output, selection, and loop statements. Then throughout the rest of the book,
many times a problem will be introduced and then solved using the “program-
ming concept” and also using the “efficient method.” This will not be done in
every case to the point that it becomes tedious, but just enough to get the ideas
across.

Systematic Approach
Another key feature is that the book takes a very systematic, step-by-step ap-
proach, building on concepts throughout the book. It is very tempting in a
MATLAB text to show built-in functions or features early on with a note that
says “we’ll do this later.” This does not happen in this edition; all functions
are covered before they are used in examples. Additionally, basic programming
Preface xiii

concepts will be explained carefully and systematically. Very basic concepts, such
as looping to calculate a sum, counting in a conditional loop, and error-checking,
are not found in many texts but will be covered here.

File Input/Output
Many applications in engineering and the sciences involve manipulating large
data sets that are stored in external files. Most MATLAB texts at least mention the
save and load functions, and in some cases selected lower-level file input/out-
put functions as well. Since file input and output is so fundamental to so many
applications, this book will cover several low-level file input/output functions,
as well as reading from and writing to spreadsheet files. Later chapters will also
deal with audio and image files. These file input/output concepts are intro-
duced gradually: first load and save in Chapter 2, then lower-level functions
in Chapter 9, and finally sound and images in Chapter 14.

User-Defined Functions
User-defined functions are a very important programming concept, and yet
many times the nuances and differences among concepts such as types of func-
tions and function calls versus function headers can be very confusing to begin-
ning programmers. Therefore, these concepts are introduced gradually. First,
functions that calculate and return one single value—arguably the easiest type
of functions to understand—are demonstrated in Chapter 2. Later, functions
that return no values and functions that return multiple values are introduced
in Chapter 6. Finally, advanced function features are shown in Chapter 10.

Advanced Programming Concepts


In addition to the basics, some advanced programming concepts, such as string
manipulation, data structures (e.g., structures and cell arrays), recursion, anon-
ymous functions, and variable number of arguments to functions, are covered.
Sorting, searching, and indexing are also addressed. All of these are again
approached systematically; for example, cell arrays are covered before they
are used in file input functions and as labels on pie charts.

Problem-Solving Tools
In addition to the programming concepts, some basic mathematics necessary
for solving many problems will be introduced. These will include statistical
functions, solving sets of linear algebraic equations, and fitting curves to data.
The use of complex numbers and some calculus (integration and differentia-
tion) will also be introduced. The basic math will be explained and the
built-in functions in MATLAB to perform these tasks will be described.
xiv Preface

Plots, Imaging, and Graphical User Interfaces


Simple two-dimensional plots are introduced very early in the book in
Chapter 2 so that plot examples can be used throughout. Chapter 11 then
shows more plot types, and demonstrates customizing plots and how the
graphics properties are handled in MATLAB. This chapter makes use of strings
and cell arrays to customize labels. Also, there is an introduction to image pro-
cessing and the basics necessary to understand programming graphical user in-
terfaces (GUIs) in Chapter 14.

Vectorized Code
Efficient uses of the capabilities of the built-in operators and functions in
MATLAB are demonstrated throughout the book. However, to emphasize the im-
portance of using MATLAB efficiently, vectorized code is treated in a separate
chapter. Techniques, such as preallocating vectors and using logical vectors,
are featured, as well as methods of determining how efficient the code is.

Layout of Text
The book consists of two parts. The first part covers programming constructs
and demonstrates the programming method versus efficient use of built-in
functions to solve problems. The second part covers tools that are used for basic
problem solving, including plotting, image processing, and mathematical tech-
niques to solve systems of linear algebraic equations, fit curves to data, and per-
form basic statistical analyses. The first six chapters cover the very basics in
MATLAB and in programming, and are all prerequisites for the rest of the book.
After that, many chapters in the problem-solving section can be introduced
when desired, to produce a customized flow of topics in the book. This is true
to an extent, although the order of the chapters has been chosen carefully to
ensure that the coverage is systematic.
The individual chapters are described here, as well as which topics are required
for each chapter. Part I, Introduction to Programming Using MATLAB, includes
the following chapters.
Chapter 1: Introduction to MATLAB covers expressions, operators, char-
acters, variables, and assignment statements. Scalars, vectors, and matrices
are all introduced as are many built-in functions that manipulate them.
Chapter 2: Introduction to MATLAB Programming introduces the idea of
algorithms and scripts. This includes simple input and output, and com-
menting. Scripts are then used to create and customize simple plots, and to
do file input and output. Finally, the concept of a user-defined function is
introduced with only the type of function that calculates and returns a
single value.
Preface xv

Chapter 3: Selection Statements introduces relational expressions and


their use in if statements, with else and elseif clauses. The switch statement
is also demonstrated, as is the concept of choosing from a menu. Also,
functions that return logical true or false are introduced.
Chapter 4: Loop Statements introduces the concepts of counted (for) and
conditional loops (while). Many common uses, such as summing and
counting, are covered. Nested loops are also introduced. Some more so-
phisticated uses of loops, such as error-checking and combining loops and
selection statements, are also covered.
Chapter 5: Vectorized Code introduces the idea of “vectorizing” code,
which essentially means rewriting code that uses loops to more efficiently
make use of built-in functions, and the fact that operations can be done on
vectors and matrices in MATLAB. Functions that are useful in vectorizing
code are emphasized in this chapter. Functions that time the speed of code
are also introduced.
Knowledge of the concepts presented in the first five chapters is assumed
throughout the rest of the book.
Chapter 6: MATLAB Programs covers more on scripts and user-defined
functions. User-defined functions that return more than one value and also
that do not return anything are introduced. The concept of a program in
MATLAB, which consists of a script that calls user-defined functions, is
demonstrated with examples. A longer menu-driven program is shown as a
reference, but could be omitted. Subfunctions and scope of variables are
also introduced, as are some debugging techniques.
This program concept is used throughout the rest of the book.
Chapter 7: String Manipulation covers many built-in string manipulation
functions as well as converting between string and number types. Several
examples include using custom strings in plot labels and input prompts.
Chapter 8: Data Structures: Cell Arrays and Structures introduces two
main data structures: cell arrays and structures. Once structures are covered,
more complicated data structures, such as nested structures and vectors of
structures, are also introduced. Cell arrays are used in several applications in
later chapters, such as file input in Chapter 9, variable number of function
arguments in Chapter 10, and plot labels in Chapter 11, and are therefore
considered important and are covered first. The rest of the chapter on
structures can be omitted.
Chapter 9: Advanced File Input and Output covers lower-level file input/
output statements that require opening and closing the file. Functions that
can read the entire file at once as well as those that require reading one line
at a time are introduced, and examples that demonstrate the differences in
their use are shown. Additionally, reading from and writing to spreadsheet
xvi Preface

files and also .mat files that store MATLAB variables are introduced. Cell
arrays and string functions are used extensively in this chapter.
Chapter 10: Advanced Functions covers more advanced features of and
types of functions such as anonymous functions, nested functions, and
recursive functions. Function handles and their use both with anonymous
functions and function functions are introduced. The concept of having a
variable number of input and/or output arguments to a function is intro-
duced; this is implemented using cell arrays. String functions are also used
in several examples in this chapter. The section on recursive functions is at
the end and may be omitted.
Part II, Advanced Topics for Problem Solving with MATLAB, contains the fol-
lowing chapters.
Chapter 11: Advanced Plotting Techniques continues with more on the
plot functions introduced in Chapter 2. Various two-dimensional plot
types, such as pie charts and histograms, are introduced, as is customizing
plots using cell arrays and string functions. Three-dimensional plot func-
tions as well as selected functions that create the coordinates for specified
objects are demonstrated. The notion of Handle GraphicsW is covered, and
selected graphics properties, such as line width and color, are introduced.
Applications that involve reading data from files and then plotting use both
cell arrays and string functions.
Chapter 12: Matrix Representation of Linear Algebraic Equations intro-
duces a basic method that can be used in MATLAB to solve systems of equa-
tions using a matrix representation. First, matrix and vector operations and
matrix definitions are described. This section can be covered at any point after
Chapter 5. Then, matrix solutions using the Gauss-Jordan and Gauss-Jordan
elimination methods are described. This section includes mathematical
techniques and also the MATLAB functions that implement them.
Chapter 13: Basic Statistics, Sets, Sorting, and Indexing starts with some
of the built-in statistical and set operations in MATLAB. Since some of these
require a sorted data set, methods of sorting are described. Finally, the
concepts of indexing into a vector and searching a vector are introduced.
Sorting a vector of structures and indexing into a vector of structures are
described, but these sections can be omitted. A recursive binary search
function is in the end and may be omitted.
Chapter 14: Sights and Sounds briefly discusses sound files and introduces
image processing. An introduction to programming graphical user interfaces
is also given, including the creation of a button group. Nested functions are
used in the GUI examples. A patch function example uses a structure.
Chapter 15: Advanced Mathematics covers three basic topics: curve fitting,
complex numbers, and integration and differentiation in calculus. Finally,
Preface xvii

some of the Symbolic Math Toolbox functions are shown, including those
that solve equations. This method returns a structure as a result.

Pedagogical Features
There are several pedagogical tools that are used throughout this book that are
intended to make it easier to learn the material. A list of Key Terms covered in
each chapter, in sequence, is on the first page.
First, the book takes a conversational tone with sections called Quick Ques-
tion! These are designed to stimulate thought about the material that has just
been covered. A question is posed, and then the answer is given. It will be most
beneficial to the reader to try to think about the question before reading the
answer! In any case, these sections should not be skipped over as the answers
often contain very useful information.
Practice problems are given throughout the chapters. These are very simple
problems that serve as drills of the material just covered.
When certain problems are introduced, they are solved both using The Pro-
gramming Concept and The Efficient Method. This facilitates understanding
the built-in functions and operators in MATLAB as well as the underlying pro-
gramming concepts. The Efficient Method boxes highlight methods that will
save time for the programmer, and in many cases are faster to execute in
MATLAB, as well.
Additionally, to aid the reader:
n Identifier names (variables and user-defined functions) are shown in italics
(as are filenames and file extensions).
n MATLAB function names are shown in bold.
n Reserved words are shown in bold and underline.
n Key important terms are shown in bold and italic.
The end-of-chapter summary contains, where applicable, several sections:
n Common Pitfalls: A list of common mistakes that are made, and how to
avoid them.
n Programming Style Guidelines: To encourage the creation of “good”
programs that others can actually understand, the programming chapters
have guidelines that make programs easier to read and understand, and
therefore easier to work with and to modify.
n MATLAB Reserved Words: A list of the reserved key words in MATLAB.
Throughout the text, these are shown in bold, underlined type.
xviii Preface

n MATLAB Functions and Commands: A boxed list of the MATLAB built-in


functions and commands covered in the chapter, in the order covered.
Throughout the text, these are shown in bold type.
n MATLAB Operators: A boxed list of the MATLAB operators covered in the
chapter in the order covered.
n Exercises: A comprehensive set of exercises, ranging from the rote to more
engaging applications.

Additional Book Resources


A companion web site is available with downloadable .m files for all examples
in the text, at www.elsevierdirect.com/9780123850812. Other book-related re-
sources will also be posted on the web site from time to time.
Additional teaching resources are available for faculty using this book as a text for
their course(s). Please visit www.textbooks.elsevier.com to register for access to:
n Instructor solutions manual for end-of-chapter problems
n Electronic figures from the text for creation of lecture slides
n Downloadable M-files for all examples in the text

You might also like