100% found this document useful (1 vote)
16 views

Engineering Computation: An Introduction Using MATLAB and Exce, 2nd Edition Musto - The ebook is ready for download with just one simple click

The document provides information about various eBooks available for download at ebookmeta.com, focusing on topics related to engineering and computation. It highlights a specific title, 'Engineering Computation: An Introduction Using MATLAB and Excel, 2nd Edition' by Joseph C. Musto and others, which serves as a foundational text for engineering students. The content covers computational tools, programming, and engineering applications, emphasizing the importance of software like MATLAB and Excel in solving engineering problems.

Uploaded by

gungumuktat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
16 views

Engineering Computation: An Introduction Using MATLAB and Exce, 2nd Edition Musto - The ebook is ready for download with just one simple click

The document provides information about various eBooks available for download at ebookmeta.com, focusing on topics related to engineering and computation. It highlights a specific title, 'Engineering Computation: An Introduction Using MATLAB and Excel, 2nd Edition' by Joseph C. Musto and others, which serves as a foundational text for engineering students. The content covers computational tools, programming, and engineering applications, emphasizing the importance of software like MATLAB and Excel in solving engineering problems.

Uploaded by

gungumuktat
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 70

Read Anytime Anywhere Easy Ebook Downloads at ebookmeta.

com

Engineering Computation: An Introduction Using


MATLAB and Exce, 2nd Edition Musto

https://ebookmeta.com/product/engineering-computation-an-
introduction-using-matlab-and-exce-2nd-edition-musto/

OR CLICK HERE

DOWLOAD EBOOK

Visit and Get More Ebook Downloads Instantly at https://ebookmeta.com


Recommended digital products (PDF, EPUB, MOBI) that
you can download immediately if you are interested.

Engineering Biostatistics : An Introduction using MATLAB


and WinBUGS 1st Edition Brani Vidakovic

https://ebookmeta.com/product/engineering-biostatistics-an-
introduction-using-matlab-and-winbugs-1st-edition-brani-vidakovic/

ebookmeta.com

An Introduction to Bayesian Inference, Methods and


Computation Nick Heard

https://ebookmeta.com/product/an-introduction-to-bayesian-inference-
methods-and-computation-nick-heard/

ebookmeta.com

Textile Engineering: An Introduction 2nd Edition Yasir


Nawab

https://ebookmeta.com/product/textile-engineering-an-introduction-2nd-
edition-yasir-nawab/

ebookmeta.com

Customizing Dynamics 365: Implementing and Releasing


Business Solutions 1st Edition Sanjaya Yapa

https://ebookmeta.com/product/customizing-dynamics-365-implementing-
and-releasing-business-solutions-1st-edition-sanjaya-yapa/

ebookmeta.com
Shifter Origins II Series Starter Shifter Variety Packs 2
1st Edition Aimee Easterling Easterling Aimee

https://ebookmeta.com/product/shifter-origins-ii-series-starter-
shifter-variety-packs-2-1st-edition-aimee-easterling-easterling-aimee/

ebookmeta.com

500 ACT Science Questions to Know by Test Day, 3rd Edition


Inc. Anaxos

https://ebookmeta.com/product/500-act-science-questions-to-know-by-
test-day-3rd-edition-inc-anaxos/

ebookmeta.com

The Fetish of Theology The Challenge of the Fetish Object


to Modernity 1st Edition Colby Dickinson

https://ebookmeta.com/product/the-fetish-of-theology-the-challenge-of-
the-fetish-object-to-modernity-1st-edition-colby-dickinson/

ebookmeta.com

Mechanics of the Middle Class: Work and Politics Among


American Engineers Robert Zussman

https://ebookmeta.com/product/mechanics-of-the-middle-class-work-and-
politics-among-american-engineers-robert-zussman/

ebookmeta.com

A Simple Guide To Funeral Rites In Islam From The Point of


Death To The Burial 2nd Edition Abu Khadeejah Abdul-W■hid
Alam
https://ebookmeta.com/product/a-simple-guide-to-funeral-rites-in-
islam-from-the-point-of-death-to-the-burial-2nd-edition-abu-khadeejah-
abdul-wahid-alam/
ebookmeta.com
Religion Materialism and Ecology 1st Edition Sigurd
Bergmann Editor Kate Rigby Editor Peter Manley Scott
Editor
https://ebookmeta.com/product/religion-materialism-and-ecology-1st-
edition-sigurd-bergmann-editor-kate-rigby-editor-peter-manley-scott-
editor/
ebookmeta.com
Page i

ENGINEERING
COMPUTATIONS
An Introduction Using
MATLAB® and Excel®

Joseph C. Musto
Milwaukee School of Engineering

William E. Howard
East Carolina University

Richard R. Williams
Auburn University
Page ii

ENGINEERING COMPUTATION
Published by McGraw-Hill Education, 2 Penn Plaza, New York, NY
10121. Copyright ©2021 by McGraw-Hill Education. All rights
reserved. Printed in the United States of America. No part of this
publication may be reproduced or distributed in any form or by any
means, or stored in a database or retrieval system, without the prior
written consent of McGraw-Hill Education, including, but not limited
to, in any network or other electronic storage or transmission, or
broadcast for distance learning.
Some ancillaries, including electronic and print components, may not
be available to customers outside the United States.
This book is printed on acid-free paper.
1 2 3 4 5 6 7 8 9 QVS 24 23 22 21 20
ISBN 978-1-260-57071-7
MHID 1-260-57071-1
Cover Image: ©Ingram Publishing
All credits appearing on page or at the end of the book are
considered to be an extension of the copyright page.
The Internet addresses listed in the text were accurate at the time of
publication. The inclusion of a website does not indicate an
endorsement by the authors or McGraw-Hill Education, and McGraw-
Hill Education does not guarantee the accuracy of the information
presented at these sites.
mheducation.com/highered
Page iii

CONTENTS

Preface v

PART 1
Computational Tools 1

CHAPTER 1
Computing Tools 3
Introduction 3
1.1 Analytic and Algorithmic Solutions 4
1.2 Approaches to Engineering Computation 11
1.3 Data Representation 13

CHAPTER 2
Excel Fundamentals 21
Introduction 21
2.1 The Excel Interface 21
2.2 Tutorial: Entering and Formatting Data With Excel 24
2.3 Tutorial: Entering and Formatting Formulas With Excel 29
2.4 Tutorial: Using Built-in Functions 37
2.5 Tutorial: Performing Logical Tests Using the IF Statement
42
2.6 Tutorial: Using Lookup Tables 49
2.7 Tutorial: Interpolating With Excel 53

CHAPTER 3
MATLAB Fundamentals 63
Introduction 63
3.1 The MATLAB Interface 63
3.2 Tutorial: Using the Command Window for Interactive
Computation 65
3.3 Tutorial: Using MATLAB Script Files 74
3.4 Tutorial: Using MATLAB Function Files 81
3.5 Tutorial: Computing With One-Dimensional Arrays 85
3.6 Tutorial: Computing With Two-Dimensional Arrays 92
3.7 Tutorial: Saving a MATLAB Session 96

CHAPTER 4
MATLAB Programming 103
Introduction 103
4.1 Flowcharts 103
4.2 Tutorial: Loop Commands 106
4.3 Tutorial: Logical Branching Statements 115
4.4 Tutorial: Combining Loops and Logic 125
4.5 Tutorial: Formatting MATLAB Output 134

CHAPTER 5
Plotting Data 143
Introduction 143
5.1 Types of Graphs 143
5.2 XY Graphs 147
5.3 Guidelines for Producing Good Graphs 178
5.4 Tutorial: Creating Other Types of Graphs With Excel 180
Page iv

PART 2
Engineering Applications 193

CHAPTER 6
Finding the Roots of Equations 195
Introduction 195
6.1 Motivation 196
6.2 Roots of Equations: Theory 197
6.3 Tutorial: Solution of General Nonlinear Equations Using
MATLAB 207
6.4 Tutorial: Solution of Polynomial Equations Using MATLAB
210
6.5 Tutorial: Solution of General Nonlinear Equations Using
Excel 213

CHAPTER 7
Matrix Mathematics 219
Introduction 219
7.1 Properties of Matrices 219
7.2 Tutorial: Matrix Operations Using Excel 223
7.3 Tutorial: Matrix Operations Using MATLAB 228

CHAPTER 8
Solving Simultaneous Equations 237
Introduction 237
8.1 Systems of Linear Equations 237
8.2 Tutorial: Solutions of Linear Equations Using Excel 238
8.3 Tutorial: Solutions to Simultaneous Linear Equations Using
MATLAB 244
8.4 Tutorial: Solving Nonlinear Simultaneous Equations Using
Excel 248
8.5 Tutorial: Solving Nonlinear Simultaneous Equations Using
MATLAB 250

CHAPTER 9
Numerical Integration 263
Introduction 263
9.1 Concepts From Calculus 263
9.2 Tutorial: Numerical Integration of Functions 267
9.3 Tutorial: Numerical Integration of Measured Data 279

CHAPTER 10
Optimization 289
Introduction 289
10.1 Engineering Optimization 290
10.2 Formulating an Optimization Problem 292
10.3 Solution of an Optimization Problem 294
10.4 Solution of an Optimization Problem Using MATLAB 302
10.5 Solution of an Optimization Problem Using Excel 309
10.6 Tutorial: Engineering Application of Linear Constrained
Optimization 317
INDEX 327
Page v

PREFACE

This text has grown out of the authors’ experiences teaching


introductory computation courses to engineering students from a
variety of disciplines at three different institutions. The integration of
computational tools in engineering programs is a constant challenge
for educators. The broad goals associated with an introductory
course in computer applications often include:

▪ Teaching the concept of “procedural thinking” and algorithm


development.

▪ Teaching the mechanics of the computational tools required in


both the subsequent academic program and professional
practice.

▪ Teaching the techniques for developing a computational solution


to a physical problem.

▪ Providing the context for the selection of a computational tool


appropriate for the task at hand.

▪ Teaching the accepted techniques for documenting and verifying


computer-based solutions to engineering problems.

▪ Stimulating interest in upper-division coursework by introducing


the students to realistic, interesting, and exciting problems and
applications.
This text will emphasize these concepts, using MATLAB® and Excel®
as the software packages of choice. These packages were chosen
because:

▪ MATLAB is widely accepted as a first computation tool in


numerous engineering programs.

▪ MATLAB has the unique ability to be both used as an


introductory programming tool and a high-level computational
tool; the programming constructs (loops and logic) allow it to be
used as a first programming language for engineering students,
while the numerous mathematical and analysis “toolboxes” allow
it to be readily applied to high-level engineering applications.

▪ Excel is a ubiquitous spreadsheet application, which nearly every


engineering student will have access to during their academic
and professional careers. Excel has powerful built-in functions
that allow it to be applied to high-level engineering problems.

▪ Since spreadsheet solutions are so fundamentally different than


the procedural solutions developed using programming tools like
MATLAB, the contrasting approach allows for demonstration and
discussion about implication of the choice of software tool on the
type and complexity of the solution technique.

Philosophy of the Text


The underlying philosophy behind the approach taken in this text is:

▪ Computer tools will change during the professional careers of a


freshman engineering student. While it is important to teach the
mechanics of using the relevant tools, the focus of this text
should be on the fundamentals of engineering computing:
algorithm development, selection of appropriate tools,
documentation of solutions, and verification and interpretation of
results.

▪ Programming is a fundamental concept for engineers; while


“shortcut” solutions (such as implied loops in MATLAB) and
“canned” software are certainly appropriate for upper-division
students and practicing engineers, introductory students should
be focused on the basics of structured programming: loops,
logic, and array structures. These basic concepts, which are
language-independent, are the critical building blocks for
programming, and should be introduced early.

With this in mind, the text was developed in two parts. The Page vi
first part generally covers the mechanics of programming
and spreadsheet usage; including:

▪ An introduction to computational theory,

▪ An introduction to number representation (scalars, arrays, and


matrices),

▪ An introduction to programming constructs, including algorithm


development and flowcharting,

▪ The mechanics of MATLAB and Excel usage, and

▪ Best practices in computer tool usage, including tool selection,


documentation of solutions, and checking of results.

These chapters include detailed “keystroke-level” instructions, which


will guide the reader through the use of the MATLAB and Excel tools.
The second part focuses on typical applications of engineering
computation; these applications are motivated with engineering
problems, and include:

▪ Root finding,

▪ Matrix methods,

▪ Simultaneous equations,

▪ Numerical integration, and

▪ Optimization.

These applications are intended to motivate not only engineering


computation, but the use of concepts from upper-division
engineering courses as well. Both theoretical concepts and
“keystroke-level” tutorials are presented in these applications
chapters.

New In This Edition


This edition has been updated for the latest versions of MATLAB and
Excel. In addition, many new end-of-chapter problems have been
created, and a tutorial involving symbolic computation in MATLAB
has been developed.

Instructor Resources
Additional resources for instructors are available on the web at
www.mhhe.com/musto2e. These resources include solutions to the
end-of-chapter problems and book figures in PowerPoint format.
Instructors can contact a McGraw-Hill representative for a password.

Acknowledgments
We are grateful to our friends at McGraw-Hill for their support and
encouragement during this project. Theresa Collins, our production
developer, has provided invaluable support and guidance during this
project. We wish to thank Fleck’s Communications for page layout,
and Kim Haas for copyediting. Additionally, the cooperation and
support of the MathWorks Book Program was invaluable.
Feedback provided during the review process was greatly
appreciated, and helped to shape the final form of this text. We wish
to thank the following reviewers for their careful reviews of the initial
manuscript:
Ali Elkamel, University of Waterloo
Bill Elmore, Mississippi State University
Howard Fulmer, Villanova University
Brian Grady, Oklahoma University
Mark Kerstetter, Western Michigan University
Leo Pérez y Pérez, California State University at Long Beach
Michael Robinson, Rose-Hulman Institute of Technology
David Rockstraw, New Mexico State University
Scott Short, Northern Illinois University
Elisa H. Barney Smith, Boise State University
J. Steven Swinnea, University of Texas at Austin
Michael Weinstein, University of Rochester
Students in the Computing Applications in Engineering course at East
Carolina University class tested an early version of this text; their
feedback was appreciated. Also at East Carolina University, Scott
Martin provided a thorough reading and review of this text, and we
thank him for his insight and input.
Joe Musto
Ed Howard
Rick Williams
MATLAB is a registered trademark of TheMathWorks, Inc.
Excel is a registered trademark of The Microsoft Corporation.
Page 1
PART 1
COMPUTATIONAL TOOLS
Chapter 1: Computing Tools
Chapter 2: Excel Fundamentals
Chapter 3: MATLAB Fundamentals
Chapter 4: MATLAB Programming
Chapter 5: Plotting Data
Page 2
Page 3
CHAPTER 1

Computing Tools
Introduction
The engineering profession is a discipline devoted to problem
solving, applying principles of mathematics and science to develop
solutions to practical problems involving structures, machines,
electrical circuits, and various other physical systems and devices.
With their ability to perform numerical analysis and data handling,
computers are important tools for practicing engineers. Engineering
graduates from all disciplines are expected to have proficiency in a
wide range of computational tools and software. New engineering
graduates should expect to have proficiency in:

▪ communication tools (for e-mail and messaging),

▪ Internet search tools (for research),

▪ word processing tools (for report preparation and memo writing),

▪ presentation tools (for audiovisual presentation),

▪ data acquisition tools (for running and reading data from


experiments), and

▪ computational tools (for programming, data analysis, equation


solving, and plotting).
In addition to these basic tools that cross all engineering disciplines,
there are specific computer tools that are considered part of the core
skill set for each engineering discipline. Examples of these tools
include:

▪ solid modeling and computer-aided design/drafting software (for


mechanical and civil engineers),

▪ electric circuit simulation software (for electrical and computer


engineers),

▪ finite element analysis software (for mechanical, civil, and


electrical engineers),

▪ advanced programming languages (for computer and software


engineers), and

▪ statistical analysis software (for industrial engineers).

This text is devoted to an introduction to the application of Page 4


computational tools to the solution of engineering problems.
These are the types of tools used for mathematical analysis and data
processing across a wide variety of engineering disciplines. While no
individual software product can truly be considered a “standard” for
all engineers, two widely available and widely used software
packages are introduced in this text: MATLAB® and Excel®. Besides
being two of the most popular computational packages for
engineers, they also provide the opportunity to demonstrate two
very different approaches to engineering computation: programming
tools and spreadsheet tools. While these two platforms offer very
different ways to approach the solution of engineering problems,
there are some similarities between them, particularly in the way
data is represented, stored, and handled. These similarities are
important to understand, in that they offer a common language for
these, and other, computational tools.
In this chapter, you will:

▪ learn the difference between an analytic and an algorithmic


solution,

▪ learn the essentials of algorithm development and pseudocode,

▪ learn the basic difference between programming tools and


spreadsheet tools,

▪ learn the basic terminology of data storage and handling, and

▪ learn the difference between accuracy and precision, and the


implications of both in engineering computation.

1.1 Analytic and Algorithmic Solutions


The computational tools introduced in this text allow us to automate
the mathematical analysis required to solve an engineering problem.
In order to understand both the advantages and limitations of the
application of computational tools to engineering problems, we must
first understand the essential difference between the analytic
solution and the algorithmic solution to an engineering problem.
Consider the classic projectile motion problem addressed in
introductory physics classes. A ball will be fired from a toy cannon,
with an initial speed of 10.0 meters per second at an angle of 35.0°,
as shown in Figure 1.1. An engineer has been asked to predict the
peak height that the cannonball will reach, the location at which the
cannonball will hit the ground, and the total flight time of the
projectile.
Figure 1.1
MATLAB® is a trademark of The MathWorks, Inc. Excel® is a trademark of the
Microsoft group of companies.

1.1.1 The Mathematical Model Page 5


The first step in the solution of this problem is the development of
the mathematical model that the engineer will use to predict the
behavior of the system. In this case, it requires the application of the
principles of the physics of mechanics. The engineer creates a sketch
of the system, as shown in Figure 1.2.

Figure 1.2

In developing the mathematical equations that will be used to


predict the behavior of the system, the engineer must make some
decisions as to what to include in the model. In doing so, the
engineer balances the accuracy of the model (the ability of the
equations to properly predict the behavior of the system) and the
simplicity of the model. In this case, the engineer makes the
following decisions:
▪ The ground will be considered flat and level.

▪ The launch point will be considered to be at ground level.

▪ Wind resistance will not be considered in the equations.

These decisions, called simplifying assumptions, require considerable


engineering judgment. The engineer must decide that the
complexity introduced by including these effects into the equations
will not lead to any significant increase in the accuracy of the
solution. In this case, with these assumptions made, principles of
physics can be used to write the following equations for height and
horizontal distance as functions of time:

(1.1)

(1.2)
where h is the height of the cannon ball, x is the horizontal distance
travelled, ν is the initial speed of the cannonball, θ is the launch
angle, g is gravitational acceleration, and t is the time after launch
(in seconds). With this model in place, the engineer must now select
a solution technique to solve the equations. We will now contrast the
analytic solution to the algorithmic solution of this problem.

1.1.2 The Analytic Solution


An analytic solution is an exact solution, based on the application of
the mathematical principles of algebra, calculus, etc. In the model
we have developed, an analytic solution is possible. In order to find
the peak height the ball will reach, the engineer uses principles of
calculus to take the first derivative of Equation 1.1:
(1.3)

When this derivative is equal to zero, the height is at an Page 6


extreme (maximum or minimum) value. Setting the
derivative equal to zero and solving for t yields:

(1.4)

Substituting in the known values for launch speed, angle, and


gravitational acceleration and carrying out the arithmetic yields:

(1.5)

or t = 0.585 seconds. This indicates that the ball will reach its peak
height after 0.585 seconds of flight time. Substituting this value for
time into Equation 1.1 yields:

(1.6)

or the peak height is determined to be hmax = 1.68 meters.


To determine the total flight time and horizontal distance travelled,
the engineer uses Equation 1.1 to determine the time at which the
height of the ball is zero:

(1.7)

The engineer uses algebra to factor out t, leading to two solutions:


(1.8)

The engineer recognizes that t = 0 corresponds to the launch time,


and t = 1.17 seconds corresponds to the time at which the ball hits
the ground again. This value can be substituted into Equation 1.2 to
determine the horizontal distance travelled during 1.17 seconds of
flight: Page 7

(1.9)

yielding a horizontal distance travelled of 9.58 meters.


The engineer reports the results in Table 1.1, with appropriate units:

Table 1.1 Results of the Analytic Solution

1.1.3 The Algorithmic Solution


An algorithmic solution is an approximate solution, based on the
application of a computational procedure. In an algorithmic solution,
the engineer will define a series of steps or rules to be followed that
will lead to the discovery of the solution of the problem. The
algorithm will generally rely on principles of arithmetic only to solve
the problem; therefore, while the solution is approximate, it also
eliminates the need to apply more complicated mathematics to the
problem. An algorithmic approach will be demonstrated in our
sample problem.
The engineer has an equation to compute the height of the ball at
any time t. The engineer recognizes that the cannonball starts and
ends at a height of zero, and will reach its peak somewhere in the
middle. For the first part of the flight, height is increasing; during the
second part of the flight, height is decreasing. If the engineer can
identify the point where the height stops increasing and starts
decreasing, the point of peak height will be identified. The engineer
constructs the following algorithm for identifying the peak height;
the solution steps, provided in verbal descriptions called
pseudocode, are as follows:

▪ Step 1: Start at a time value of t = 0 and h = 0.

▪ Step 2: Increase time by adding some small value ∆t to t (e.g.,


tnew = t + ∆t).

▪ Step 3: Plug the new value of tnew into Equation 1.1 to get a new
value of h, which we will call hnew.

▪ Step 4: Compare h and hnew:

▪ If h < hnew, then the height is still increasing, and the peak
has not been reached. Set t = tnew, h = hnew, and return to
Step 2.

▪ If h > hnew, then the height has started decreasing. This tells
us that the ball reached its peak somewhere in the
neighborhood of h (either in the interval between h and hnew,
or in the previous interval).

▪ Step 5: Assume that the maximum height occurs at the height at


the start of the interval, or hmax = h.
The algorithmic solution is a “road map” to the solution of Page 8
the problem; it is not an answer itself, but is a series of
specified steps that will lead to an answer. The main computational
part of the algorithm, embodied in Steps 2 through 4, may need to
be repeated multiple times before a solution is reached; there is no
particular way to tell ahead of time how many times the algorithm
will “loop” back to Step 2 before a solution is found. Note that this
algorithmic solution uses arithmetic operations only; unlike the
analytic approach, no principles of calculus or algebra are required.
However, note that there is a critical approximation used in the
algorithm; the height is only computed for specific values of t, but it
is likely that the actual peak value occurs at some intermediate
value.
The engineer carries out the algorithmic solution, using a time step
value of ∆t = 0.1 seconds. The values of each variable at each
“loop” through Steps 2 through 4 are shown in Table 1.2:

Table 1.2 Step-by-Step Solution Algorithm


for Finding hmax

The algorithm leads to a solution value of hmax = 1.68 meters.


The engineer proceeds to construct a solution algorithm for finding
the point at which the cannonball strikes the ground. The engineer
recognizes that a height value of zero indicates the point at which
the cannonball hits the ground, and the time at which this happens
is the total flight time. The algorithm is as follows:
▪ Step 1: Start at a time value of t = 0 and h = 0.

▪ Step 2: Increase time by adding some small value ∆t to t (e.g.,


tnew = t + ∆t).

▪ Step 3: Plug the new value of tnew into Equation 1.1 to get a new
value of h, which we will call hnew.

▪ Step 4: Check the value of hnew:

▪ If hnew > 0, then the cannonball is still in flight. Set t = tnew,


h = hnew, and return to Step 2.

▪ If hnew < 0, then the cannonball hits the ground somewhere


between h and hnew.

▪ Step 5: Approximate the total flight time by setting Page 9

▪ Step 6: Find the horizontal distance travelled during the flight by


substituting tflight into Equation 1.2. End the algorithm.

The engineer again executes the algorithm, with ∆t = .1 seconds.


The values at each step of the algorithm are shown in Table 1.3:

Table 1.3 Step-by-Step Solution Algorithm


for Finding Flight Time and Distance Travelled
The results from these two algorithms are reported by the engineer,
as shown in Table 1.4:

Table 1.4 Results of the Algorithmic


Solution

1.1.4 Comparison of the Analytic and the


Algorithmic Solutions
Examining both the process and results of the analytic and
algorithmic solutions can tell us much about the nature of each
solution. The most important differentiation between the two
solutions is that the analytic solution is exact. As long as the
mathematical techniques of algebra and calculus were properly
applied, and the arithmetic computation was performed correctly,
the result is valid to the appropriate number of significant digits
allowed by the given data. The algorithmic solution is Page 10
approximate; the equations are not solved exactly, but are
merely evaluated at specified values of the independent time
variable. These specified values of time, known as discrete values,
limit the accuracy of the final solution. By the nature of the
algorithm, the only possible solutions occur at time values at, or
midway between, our discrete points. However, while the algorithm
will always produce an approximate solution, the spacing between
the discrete points is under the engineer’s control; the solution can
be made more accurate by decreasing the value of ∆t used in the
algorithm. For example, if the algorithm was repeated, but with a
value of ∆t = 0.001 seconds, the results would be the same as those
reported for the analytic solution to three significant digits. However,
to achieve this increased accuracy, the algorithm would need to
“loop” through Steps 2 through 4 many more times (1680 times to
find hmax, instead of seven).
While algorithmic solutions are approximate by their nature, we can
increase their accuracy by decreasing the interval between discrete
points and simply running through the algorithm more times.
Approaching an algorithmic solution “by hand” would prove
impractical if increased accuracy was required. Within practical limits,
however, it is no more difficult to run through the algorithm tens,
hundreds, or even thousands of times. This is because algorithmic
solutions lend themselves readily to implementation with computer
tools. The algorithms developed in this chapter were presented as
verbal descriptions of the step-by-step problem-solving strategy;
these verbal descriptions are known as pseudocode. A computer
programming language, such as the MATLAB software introduced in
this text, can be readily used to translate our software-independent
pseudocode into software-specific computer code, providing clear
instructions that the computer can follow. While computers can be
applied to automate the arithmetic part of an analytic solution, it is
in the implementation of algorithmic solutions where computational
tools are best suited.
Since analytic solutions are exact, and algorithmic solutions are
approximate, why should algorithmic solutions be used at all? In our
example case, there is really no need for an algorithmic solution,
since the problem is readily solved using analytic techniques. An
engineer with a background in differential calculus and algebra could
readily arrive at an analytic solution. When this is the case, an
analytic solution is the preferred approach. However, in the
professional practice of engineering, this is not always the case.
Even in your undergraduate studies, you will soon encounter
problems that you lack the mathematical background to solve, and
even some where no analytic solution exists. It is at these times that
algorithmic solutions become an important option. You have likely
already used algorithmic solutions to solve otherwise difficult or
unsolvable problems; if you have used a root finding function on
your programmable graphic calculator to find the roots of a higher-
order algebraic equation, you have used an algorithmic solution
technique derived and implemented by the calculator’s manufacturer.
(Did you realize that the answers you obtained with your calculator
were approximate?) Page 11
Another hallmark of an algorithmic solution is that there is
not one unique algorithm that will solve a specific problem.
Development of solution algorithms requires a combination of
mathematical reasoning and creativity. Computer scientists focus on
the development of efficient computational algorithms that minimize
the computer time and memory used when running a program
based on their algorithm. In this text, we will focus on implementing
and using many standard solution algorithms; however, there is still
much room in the field of engineering computation for the
development of new and creative algorithms for solving engineering
problems.

1.2 Approaches to Engineering Computation


In this text, we will contrast two distinct approaches to the
implementation of engineering computation: programming tools and
spreadsheet tools.
Programming tools allow the translation of pseudocoded algorithms
into instruction sets that can be followed by the computer. These
instruction sets are called computer programs or computer code.
There are many programming languages used by practicing
engineers; we will use the MATLAB platform to introduce the concept
of programming tools in this text. As an example, the MATLAB
implementation of the pseudocoded algorithm for finding maximum
height is shown below. The details of developing your own MATLAB
code will be covered in Chapters 3 and 4 of this text.

Programming tools allow us to specify the logic and Page 12


decision-making structure that the computer will follow in
the implementation of an algorithm. From the earliest days of
computing, users communicated with the machines through
instruction sets provided by the programming tools available. While
the look of the programming languages and the interface used to
communicate with the machine have evolved significantly, the idea
of translating an algorithm into software-specific instructions is a
classic paradigm for computation.
A spreadsheet tool is a completely different paradigm for
computation; a spreadsheet resembles a large data table. The user
of a spreadsheet tool fills some of the cells of the table with data,
and fills other cells with mathematical equations and logical
expressions that use the data cells as their input. This tabular
structure provides an intuitive graphical approach to data
manipulation and computation, but it differs significantly from the
step-by-step instruction sets used in programming approaches.
While the graphical approach to computation is appealing, the direct
link with pseudocoded algorithms is sometimes lost with spreadsheet
implementations. Although other spreadsheet products do exist, we
will use the Excel product from Microsoft Corporation as the
spreadsheet platform in this text. As an example, a spreadsheet
used to implement the maximum height algorithm and generate the
data shown in Table 1.1 is shown in Figures 1.3 (with numerical
values shown) and 1.4 (with formulas relating the cells shown).

Figure 1.3
Figure 1.4

As we introduce the various problem-solving approaches in this text,


we will highlight the advantages and disadvantages of these two
approaches to engineering computation. Some problems are best
suited to solution by programming, while others are best suited to
spreadsheet solutions. That said, the MATLAB and Excel tools that
we introduce in this text are very advanced and capable
computational tools, and have to some extent adapted the best
features of each approach into their functionality. Excel has
implemented a programming interface, where more traditional
computer code can be developed to operate on and fill cells in the
spreadsheet. MATLAB has developed an array editing interface that
looks and acts similar to a spreadsheet. Both have developed
preprogrammed utilities for plotting, root finding, Page 13
optimization, and other common operations that allow the
user access to advanced algorithms for engineering problem solving.
The goals of this text involve both proficiency with the computational
tools and the insight into selection of an appropriate tool for a given
engineering application.

1.3 Data Representation


Despite the differences between various computational platforms,
there are some similarities between packages in the way data is
represented, stored, and manipulated. In this section, the
terminology of data representation will be introduced and related
back to the MATLAB and Excel tools used in this text.

1.3.1 Variables and Functions


A variable is the symbolic representation of a quantity that can take
on more than a single value. Consider the equation:

(1.10)
In this equation, x and y are variables, since they can take on many
values. We often refer to variables as independent or dependent. A
variable is dependent when its value depends on the value of other
variables. Usually we write equations so that the dependent variable
is on the left side of the equal sign. For example, in Equation 1.10,
we would assume that y is the dependent variable, since its value
depends on the value of the independent variable x. Of course, we
could rearrange the equation so that x is on the left side:

(1.11)

Does this mean that y is the independent variable? We must go


beyond the equation and examine the problem that it represents in
order to determine which one is the independent variable. We do
know that both x and y cannot be independent, because when we
assign a value to one of them, the value of the other can be
determined from the equation.
Let’s go back to the example of the cannonball’s trajectory. We wrote
an equation for the height h of the cannonball as:

(1.12)

where ν = initial velocity


t = time
θ = launch angle
g = gravitational acceleration
There are five quantities related by symbols in this equation;
however, they are not all variables in the problem. We are
considering the initial velocity, launch angle, and gravitational
acceleration to be constants rather than variables. This is Page 14
not evident in the equation, but rather in the problem
statement. Suppose the problem statement was changed so that we
were asked to calculate the height at time t = 2 seconds for various
values of the launch angle. In this case, time would be a constant
and the launch angle a variable, but the equation would be
unchanged. In another version of the problem, we might be asked to
find the maximum height that can be attained for any launch angle.
In this case, height, launch angle, and time would all be variables.
Going back to the original problem, with the initial velocity, launch
angle, and gravitational acceleration all considered to be constants,
we say that the height is a function of time, and will often write the
left side of the equation as h(t), as in Equation 1.1. Therefore, time t
is the independent variable, while height h is dependent on time. To
be more precise, a function is defined as follows: A function is a
mathematical operation that returns a single value for a given input
value or set of values. The input values are called the arguments of
the function.
While not identical, computational functions are similar to
mathematical functions in that they compute an output value from a
number of input arguments. Both Excel and MATLAB have many
built-in functions. Many of these functions require a single argument.
For example, the cos function in MATLAB returns the cosine of an
input value of an angle in radians. Other functions require a specific
number of multiple arguments. For example, Excel has a function
called ROUND which requires two arguments: the number to be
rounded off and the number of decimal places to which the number
is to be rounded. Still other functions have a variable number of
arguments. An example is the AVERAGE function in Excel, which
finds the average of a group of values entered as arguments. In
MATLAB, there are a number of functions that use arrays or matrices
as arguments, which we shall discuss in subsequent chapters. (Note
that the convention in this text is to refer to MATLAB functions in
italics, and Excel functions in capital letters).

1.3.2 Scalars and Arrays


In the algorithmic solution presented in Section 1.1, we chose the
values of the independent variable t (time) to evaluate, and
calculated the value of the height at each increment. We continued
to make calculations until the value of the height began to decrease,
indicating that the peak height was attained. We chose a time
increment of 0.1 seconds. The results of this analysis are repeated in
Table 1.5:

Table 1.5 Algorithmic Solution to


Cannonball Problem

In a spreadsheet solution, the calculations would be Page 15


performed in the cells of the spreadsheet, with the results
shown in a form similar to that of Table 1.5. In a spreadsheet, the
numerical value in a cell is a scalar—a single value that can be
represented on a numerical scale. However, in a computing language
like MATLAB, results of calculations are stored differently. It is
possible that we could have variables named t, tnew, h, and hnew. In
each calculation loop, we could write over the previous value of the
variable. In doing so, we would also be treating each variable as a
scalar, with a single value. But what if we wanted to keep the results
for each loop? We may want to plot height versus time. To do so, we
need to have those values stored in memory. It would be difficult to
give each value a unique name (for example, t1, t2, t3, etc. for time
values), and doing so would require making every calculation
sequentially, rather than in a repeating loop. Instead, we use arrays
to store data. An array is a single variable that has multiple values
associated with it. In our example, time t would be an array with
seven values. The values within an array are referenced by an index.
An index is an integer that refers to the position of the value within
the array. You can think of an index as being an address. Our
variable t has seven addresses, labeled 1–7. Into each address we
place the value of time (as in Table 1.6):

Table 1.6 Structure of Array t

We refer to an individual value of the array by including the index


number in parentheses following the array name, or as a subscript
to the variable name. For example, t (5) = 0.4 seconds, or t3 = 0.2
seconds.
It is very important to remember that index numbers must be
integers, beginning with one and progressing by one for subsequent
values. Some of the common errors that are made by beginning
programmers include:

▪ Trying to use zero as an index. In our example, the first value of


time is zero. Therefore, it is tempting to start an array with t (0)
= 0. This will result in the following error in MATLAB:
▪ Trying to use non-integer indices. For example, the statement “t
(.1) = 0.1” would result in the same error as above.

▪ Progressing index values by increments other than one. For


example, suppose that you are performing an experiment in
which you take temperature readings every 10 seconds. Your
first reading is 100°C, so you enter this as T(10) = 100. Page 16
In this case, there will not be an error, but rather an
array is created with T(1) through T(9) all having values of zero:

In all of these cases, the fundamental error is confusion between


independent variables and indices. Remember that indices are simply
counting values representing addresses within an array, and are not
variables themselves.
The arrays shown above are one-dimensional arrays. That is, a
single index number is used to establish the identity of a value in the
array. Arrays can also be multidimensional. In the example illustrated
in Table 1.5, note that there are two values of time for each loop: t
and tnew. Instead of storing these values in two one-dimensional
arrays, we can store them in a single two-dimensional array. If we
assign the first index a value of 1 or 2, representing t and tnew,
respectively, and assign the second index the value of the loop
number, then all 14 values will be stored in an array. As an example
of this scheme, t (1,5) = 0.4 and t (2,5) = 0.5.

1.3.3 Matrices and Vectors


One- and two-dimensional arrays are often referred to as matrices.
In addition to being an efficient method for storing data, many
mathematical operations can be performed directly with matrices. In
Other documents randomly have
different content
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back
back

You might also like