Download full Essential MATLAB for engineers and scientists Hahn ebook all chapters
Download full Essential MATLAB for engineers and scientists Hahn ebook all chapters
com
https://textbookfull.com/product/essential-matlab-for-
engineers-and-scientists-hahn-3/
OR CLICK BUTTON
DOWNLOAD NOW
https://textbookfull.com/product/essential-matlab-for-engineers-and-
scientists-hahn-2/
textboxfull.com
https://textbookfull.com/product/essential-matlab-for-engineers-and-
scientists-hahn-3/
textboxfull.com
https://textbookfull.com/product/essential-matlab-for-engineers-and-
scientists-sixth-edition-edition-hahn/
textboxfull.com
https://textbookfull.com/product/essential-quotes-for-scientists-and-
engineers-konstantin-k-likharev/
textboxfull.com
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/
textboxfull.com
https://textbookfull.com/product/numerical-methods-for-engineers-and-
scientists-using-matlab-ramin-s-esfandiari/
textboxfull.com
https://textbookfull.com/product/matlab-programming-for-biomedical-
engineers-and-scientists-andrew-p-king-and-paul-aljabar-auth/
textboxfull.com
https://textbookfull.com/product/applied-numerical-methods-with-
matlab-for-engineers-and-scientists-fourth-edition-steven-c-chapra-dr/
textboxfull.com
https://textbookfull.com/product/the-oceanographers-companion-
essential-nautical-skills-for-seagoing-scientists-and-engineers-1st-
edition-maul/
textboxfull.com
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
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.
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: [email protected]. 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.”
ISBN: 978-0-08-100877-5
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
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
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.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
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.
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
x + 2y = 4
2x − y = 3
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
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.)
afghan women
The indoor costume of an Afghan woman is no less picturesque
than that of her lord and master. Even to a plain and awkward
woman it imparts some appearance of grace. The piran extends
from the throat to just above the ankles, with sleeves that reach to
the wrist. It is of cloth of gold, velvet, silk, cashmere or calico, and in
shape not unlike our own Princess robe. Beneath this are the tom-
bons, very similar to the garment worn by men.[43] These may be of
cloth of gold, silk, cashmere or calico; they are finished off at the
ankles by a fringe of diamonds, gold or silver. A round cap, worked
all over with gold thread, so that it looks like gold cloth, is fitted
closely to the back of the head. The hair, parted in the centre, is
done up in tiny braids, which are caught in a black silk embroidered
bag, worn underneath the gold cap, but hanging down the back to
below the waist. Married women wear a fringe of hair, often curled,
on either side of the face. Descending from the top of the head to the
hem of the piran, leaving the face uncovered, is the gracefully-
draped chadar—a large wrapping of finest muslin, filmy gauze, or
delicately tinted chiffon. Black hair is in vogue among the belles of
the harem; if their locks reveal any shade of fairness or show
indications of turning grey the vain creatures, adopting the custom of
their Western sisters, at once dye them. Like all their sex, too, they
delight in jewellery and conspicuous ornaments, and a considerable
portion of their savings is expended upon the purchase of necklaces,
ear-rings and bracelets. All who can afford it wear flowers just above
the right ear, while they also indulge in the use of cosmetics. Paint
and powder, rouge for the lips and the blackening pencil for
eyebrows and eyelashes are the adventitious aids to whatever
natural charms they may possess.
Proud of their prepossessing qualities, the women of Afghanistan
have exploited their charms so much that it was left to Habib Ullah to
impose a check upon the increasing attractiveness of the street
costume of the feminine portion of his subjects. One day, in the
spring of 1903, to the unspeakable dismay of many pretty women
and of all young girls, he issued orders, changing the white burka,
which, although covering the head and figure and leaving a latticed
insertion before the face, was in a measure attractive. Thereafter
these white street robes were to be dyed kharki for Mahommedan
women, red or mustard-yellow for Hindu women and slate colour for
other women. Disobedience of this law was threatened with a fine of
fifty rupees, while its requirements had to be fulfilled within fourteen
days. Unhappily, by this change an attractive feature in the life of the
city has disappeared, the lamentable hues enforced upon the poor
ladies by the Amir’s edict emphasising the dirt and discomfort of the
Kabul streets.
In Afghanistan, as in all Mahommedan countries, the women lead
a very secluded life, seldom venturing into the streets. The
conditions of their married life are unfortunate, since the religion of
the Afghan permits him to possess four wives, while no restrictions
are imposed upon the number of concubines that he may support.
This law in regard to wives is broken at will; and, while plurality of
wives may be conducive to the satisfaction of the husband, it is
unnecessary to say that the practice is not in favour among the
women, who, in this matter, incline their hearts after the customs of
the West. Moreover, women are not the sole companions of their
husbands, for in Afghanistan, as in most Oriental countries, the
small, but comely, boy is the more frequent intimate of their masters.
At Court and in the households of the several princes this
characteristic feature of the East may be observed, the existence of
these boys being accepted by the priests, who themselves indulge in
this most peculiar vice.
a saint’s tomb
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.
textbookfull.com