Matlab A Practical Introduction To Programming and Problem Solving 1st Edition by Stormy Attaway ISBN 008094325X 9780080943251 Instant Download
Matlab A Practical Introduction To Programming and Problem Solving 1st Edition by Stormy Attaway ISBN 008094325X 9780080943251 Instant Download
https://ebookball.com/product/a-practical-introduction-to-data-
structures-and-algorithm-analysis-3rd-edition-by-clifford-
shaffer-15310/
https://ebookball.com/product/50-cases-in-clinical-cardiology-a-
problem-solving-approach-1st-edition-by-atul-luthra-
isbn-9789351521105-9351521109-4698/
https://ebookball.com/product/data-structures-and-problem-solving-
using-c-2nd-edition-by-malik-isbn-0324782012-978-0324782011-16350/
Matlab:
A Practical Introduction to
Programming and Problem Solving
Matlab:
A Practical Introduction to
Programming and Problem
Solving
By
Stormy Attaway
College of Engineering, Boston University
Boston, MA
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: [email protected]. You may also complete your request online
via the Elsevier homepage (http://elsevier.com), by selecting “Support & Contact”
then “Copyright and Permission” and then “Obtaining Permissions.”
ISBN: 978-0-75-068762-1
Attribution
MATLAB® and Handle Graphics® are registered trademarks
of The MathWorks, Inc.
Printed in Canada
08╇ 09╇ 10╇╇ 9╇ 8╇ 7╇ 6╇ 5╇ 4╇ 3╇ 2╇ 1
Dedication
This book is dedicated to my two mentors at Boston University: the late
Bill Henneman of the Computer Science Department, and the late Merrill Ebner
of the Department of Manufacturing Engineering.
Stormy Attaway
This page intentionally left blank
Contents
Preface................................................................................................... xiii
Part I rogramming and Problem Solving
P
Using MATLAB............................................................. 1
Chapter 1 Introduction to MATLAB.................................................... 3
1.1 Getting into MATLAB............................................................. 4
1.2 Variables and Assignment Statements................................. 6
1.2.1 Initializing, Incrementing, and Decrementing............. 8
1.2.2 Variable Names.............................................................. 8
1.3 Expressions........................................................................... 10
1.3.1 The Format Function and Ellipsis.............................. 10
1.3.2 Operators...................................................................... 11
1.3.3 Built-In Functions and Help........................................ 12
1.3.4 Constants...................................................................... 14
1.3.5 Types............................................................................. 14
1.3.6 Random Numbers........................................................ 16
1.4 Characters and Encoding..................................................... 18
1.5 Vectors and Matrices............................................................ 20
1.5.1 Creating Row Vectors.................................................. 21
1.5.2 Creating Column Vectors............................................ 24
1.5.3 Creating Matrix Variables........................................... 24
1.5.4 Dimensions................................................................... 28
1.5.5 Using Functions with Vectors and Matrices.............. 33
1.5.6 Empty Vectors.............................................................. 33
vii
viii Contents 
Index......................................................................................................... 447
Preface
Motivation
The purpose of this book is to teach basic programming concepts and skills
needed for basic problem solving, all using MATLAB® 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.
There are many books that introduce MATLAB. There are two basic flavors
of these books: 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 under-
stand basic programming concepts. That person then would not be able to 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 programming concepts first (using any language) would tend to
write highly inefficient 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 the efficient uses. The challenge for students is that it is nearly impossi-
ble to predict whether they will in fact need to know programming concepts
later on 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
�programming 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
release. For example, in current versions of MATLAB statistics on variables are xiii
xiv 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 version of the
software, and because of the desire to explain the concepts in the book.
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,
often a problem will be introduced and then solved using the “Â�programming
concept” and also using the “efficient method.”
Systematic Approach
Another key feature is that the book takes a very systematic, step-by-step
approach, 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 book does not do that; all functions are covered
before they are used in examples. Additionally, basic programming concepts
will be explained carefully and systematically. Very basic concepts such as loop-
ing 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 also some of the lower level
file input/output functions. 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 chap-
ters will also deal with audio and image files. These file input/output concepts
are introduced gradually: first load and save in Chapter 2, then lower level
functions in Chapter 8, and finally sound and images in Chapter 13.
User-Defined Functions
User-defined functions are a very important programming concept, and yet
many times the nuances and differences between types of functions, function
calls versus function headers, and so on, can be very confusing to beginning
programmers. Therefore these concepts are introduced gradually. First, �arguably
Random documents with unrelated
content Scribd suggests to you:
A couple minutes more,
In hopes to see the worms come out
Which he was rapping for;
But after he went b-r-r-r! and b-r-r-r!
A while, he flew away,
And Johnny said he guessed there were
No worms at home that day.
An’ my! I’m still, ’ist like a mouse. I never went outdoors,
But ’ist sat down, inside the house, an’ took her bureau drawers
An’ emptied ’em ’ist one by one, an’ w’en they’re emptied ’en
I ’ist looked through what’s there for fun an’ put ’em back again!
An’ ’en I found the nicest ink, an’ one of ’em was red,
An’ one was black an’ ’en I think I spilt some on the bed,
But my! I wiped it up, ’ist so, an’ sopped it with a quilt
So clean you wouldn’t hardly know it’s ever once been spilt.
Well, ’en I looked up on the shelf an’ found her scissors there
An’ got ’em down all by myself an’ cut off all my hair,
’Tuz I don’t think it’s nice for girls like me ’at’s almost through
First reader to wear such a curls like Mamma makes me do.
’En Flo gave me some bread and jam, ’tuz I ’ist cried and cried
’Ist tuz I’m hungry now, I am, an’ ’en I went inside,
An’ maybe I did let it lay around the room somewhere,
’Tuz Flo came in to watch me play and squoshed it on a chair.
An’ after while I wish my Ma would ’ist come back, she would,
’Tuz my, I’m gettin’ drefful tired of simply bein’ good.
My eyes, ’ey’re ’ist so full of sand an’ heavy, ’ist like lead,
Oh-oh! I dess it’s Sleepyland! I dess I’ll go to bed!
THE OWNERLESS TOYS
O UR Uncle Bill’s attic is half full of toys,
With some that are almost brand-new;
He’s got things up there for most all kinds of boys
From ten years old clear down to two.
And one day he gave me some books from up there
Like boys had a long time ago;
And I asked if the boy they belong to would care,
But he just sort of smiled and said no.
And my! There were sleds with their runners all rust,
And five or six good pairs of skates,
Some old-fashioned toys that were covered with dust,
And fishlines and schoolbooks and slates,
Which Uncle Bill told us we fellows might share,
But always put back when we go;
And we thought that the boy they belong to might care,
But he just sort of smiled and said no.
Blessed am I to be just
Worthy of your childish trust
Worthy of your childish trust,
More than conqueror of kings
When the wild bird of your wings
Bids you fly not forth but see
Something tender, kind, in me;
Oh, the gladness you have laid
At my heart’s gate, little maid!
IN VACATION TIME
My! he was black and curly once, when he was new and young,
And he would open up his mouth at us and curl his tongue,
Just like he laughed, and play with us; and he would go into
The creek, and bring our hats to us, or anything we threw.
In winter we would hitch him up, and he would haul our sled,
And walk or trot or run with it, or anything we said;
So when he wagged his tail at me I laid him right beside
The cellar door, and then I went behind the barn and cried.
He was a friend of all the boys, and when they came to play
He’d wag his tail and bark and look at them the smartest way;
And he’d pretend to bite at them and nip their pants, but he
Would never bite, ’cause he was just as kind as he could be.
And Henry Watson looked at him beside the cellar door,
And said, “He’ll never haul us boys on our sled any more.”
He turned his ears back straight and nice; he liked him awful well;
Because he had tears in his eyes, and then a big one fell.
My! it was awful sad that day! And Tommy said he thought
We wouldn’t play that afternoon because he’d rather not
We wouldn t play that afternoon, because he d rather not.
And Mamma made some nice ice-cream, which cheered us up, but when
We wanted her to eat she said she couldn’t eat just then.
And Amy Robbins heard of it, and brought some leaves and flowers
To scatter over him, because he was a friend of ours;
And I told her I patted him, and when he heard me call
He looked at me and wagged his tail, which died the last of all.
TWO LITTLE MAIDS
It’s really a well-behaved people—they put by their slates and their books
And have little use for an army except as a matter of looks;
But nobody dares say addition, division, subtraction—if you
Should mention a one of these subjects the tin sword would run you right
through!
But you can say swinging or jumping or follow-my-leader, nor fear
You break any law of the country—and if from your window you hear
A chorus of voices or laughter, when evening grows twilit and cool,
You’ll know ’tis the music they make in the Kingdom of Right-After-
School!
There’s not a sad heart in the Kingdom, nor ever or ever a tear,
And all of the sorrows of schooldays are lost or forgotten in here;
The make-believe fairies go singing with songs that are wondrously sweet;
The green turf is flecked with white dresses and patters with fast-flying feet;
It’s just between School’s-Out and Teatime—an hour or so of the day,
And often I see them there crowning with daisies the Princess of Play;
Then some one calls: “Supper-time, children!”—when evening grows twilit
and cool
and cool.
It fades from my sight till tomorrow—the Kingdom of Right-After-School!
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookball.com