text
stringlengths 6
976k
| token_count
float64 677
677
| cluster_id
int64 1
1
|
---|---|---|
Light provides an important context for studying about the world in which we live. This topic can be researched in many disciplines, including biology, math, and physics. This module focuses on the seasonal characteristics of light and its affects on our earth and living systems. The lessons can be accomplished by direct hands-on field and laboratory investigations using graphing calculators, CBL, and other scientific equipment. Students will use Excel and Mathematica to investigate the physical properties of light. The students will model and analyze data collected during the investigations.
A pdf file that can be read using the free Abode Acrobat Reader or, for more functionality, with Acrobat Pro ($). The eBook's figures, equations, sections, chapters, index, table of contents, code listings, glossary, animations and executable codes (both Applets and Python programs) are linked, much like in a Web document. There are also links to video-based lectures covering most topics in the text, as well as to the slides used in the lectures. Section 1.2 of the text discusses how to use the various electronic features. Some movies are encapsulated into the text and some equations are linked to their xml forms (which can be imported into Maple or Mathematica for manipulation).
The Probability and Statistics EBook is an internet-based electronic textbook. The materials, tools, and demonstrations presented in this EBook would be very useful for advanced-placement (AP) statistics educational curriculum. The EBook was initially developed by the UCLA Statistics Online Computational Resource (SOCR). However, all statistics instructors, researchers, and educators are encouraged to contribute to this project and improve the content of these learning materials. There are four novel features of this specific Statistics EBook: it is community-built; completely open-access (in terms of use and contributions); blends information technology, scientific techniques, and modern pedagogical concepts; and is multilingual.
This module presents some of the general ideas behind and basics principles of high-performance computing (HPC) as performed on a supercomputer. These concepts should remain valid even as the technical specification of the latest machines continually change. Although this material is aimed at HPC supercomputers, if history be a guide, present HPC hardware and software become desktop machines in less than a decade.
| 677.169 | 1 |
More About
This Textbook
Overview
Introduction to MATLAB is intended for use in first-year or introductory Engineering courses. It also serves as an essential MATLAB introduction for engineers.
¿
Best-selling author Delores Etter provides an up-to-date introduction to MATLAB. Using a consistent five-step problem-solving methodology, Etter describes the computational and visualization capabilities of MATLAB and illustrates the problem solving process through a variety of engineering examples and applications.
¿
Teaching and Learning Experience
This program will provide a better teaching and learning experience–for you and your students. It will help:
¿
Customize your Course with ESource: Instructors can adopt this title as is, or use the ESource website to select the chapters they need, in the sequence they want.
Describe the Exceptional Computational and Visualization Capabilities of MATLAB: Students will gain a clear understanding of how to use MATLAB.
Illustrate the Problem-solving Process through a Variety of Engineering Examples and Applications: Numerous examples emphasize the creation of readable and simple solutions to develop and reinforce problem-solving skills.
Keep your Course Current with Discussion of the Latest Technologies: The discussions, screen captures, examples, and problem solutions have been updated to reflect MATLAB Version 8.2, R2013b.
Editorial Reviews
From the Publisher
"The best features of this test are the format, using chapter objectives, summaries keyed to the objectives, programming summaries, debugging and styles notes, and complete examples using the problem solving method."
-Virgil Thomason, UNIVERSITY OF TENNESSEE AT CHATTANOOGA
"Dr. Etter's strength is the straight forward way she presents the material. She motivates the topic with a well chosen example and then builds up to the solution in almost a menu driven way."
"The book does not assume an advanced math background which makes it appropriate for lower level students. It introduces the concepts in a concise and clear manner without overwhelming the student with huge amounts of detail that can be confusing to a beginner programmer."
-Mohammad Saed, TEXAS TECH UNIVERSITY
"The introduction of the Engineering Grand Challenges at the beginning of each chapter adds a sense of purpose to the material and greatly increases the value of the text. The inclusion of examples related to each Grand Challenge also adds value to the book and links together the chapters into one cohesive unit."
Meet the Author
Dr. Delores M. Etter, Assistant Secretary of the Navy for Research, Development and Acquisition, leads R&D and acquisition throughout the U.S. Navy. She is the first United States Naval Academy faculty member to hold the Office of Naval Research Distinguished Chair in Science and Technology. Dr. Etter is a member of the National Academy of Engineering, and a fellow of IEEE, AAAS, and ASEE
| 677.169 | 1 |
Course Objectives:† The student will be taught how to find the
values of the trig functions from right triangles and circles, the graphing of
trigonometric functions, the derivations of trigonometric identities, how to
use the sum, difference, double angle and half angle formulas, the inverse
trigonometric functions, solving problems involving right triangles, solving
trigonometric problems using the Law of Sines and Cosines, graphing polar
equations, and applications involving conics-the parabola, the ellipse, and the
hyperbola.† Applications of the
mathematics learned to solving real world problems will be addressed.
Evaluation Policy:† Students will be given four 100 point exams,
and a comprehensive final exam which will count 150 points.† The students will be assigned homework
problems and classroom problems which may be graded.† The students may also be given pop tests in class on homework
problems.† The total points from
homework, classroom problems and pop tests will be 100 points.† This is a total of 650 points for the
semester.†
Grading policy:† A studentís grade will be determined by
dividing the number of points earned by the total points possible.† If the student is absent on a test day and
contacts me before the scheduled exam and the absence is excusable(emergency
or illness), the test can be made-up on Thursday April 24 from 3:15-4:30 or
the final exam score will be substituted for the missed exam.† Do not schedule a doctorís
appointment on a test day as this is not excused. This applies to one
test only! No make-up test will be given for pop tests.† Homework points which are missed cannot
be made up.† If for any reason a student
has to leave the room during an exam, the exam has to be turned in and cannot
be completed.† Students are to turn off
cell phones during class.
Attendance Policy:† In this course each topic builds on the
previously learned material.† Therefore,
in order to be successful in this course, regular class attendance is very important.
| 677.169 | 1 |
The first five chapters treat topics important to economics, psychology, statistics, physics, and mathematics. Subjects include equivalence relations for ...
More About
This Book
The first five chapters treat topics important to economics, psychology, statistics, physics, and mathematics. Subjects include equivalence relations for matrixes, postulational approaches to determinants, and bilinear, quadratic, and Hermitian forms in their natural settings. The final chapters apply chiefly to students of engineering, physics, and advanced mathematics. They explore groups and rings, canonical forms for matrixes with respect to similarity via representations of linear transformations, and unitary and Euclidean vector spaces. Numerous examples appear throughout
| 677.169 | 1 |
textbook for upper division undergraduates and beginning graduate students. Its objective is that students learn to derive, test and analyze numerical methods for solving differential equations, and this includes both ordinary and partial differential equations. In this sense, the book is constructive rather than theoretical, with the intention that the students learn to solve differential equations numerically and understand the mathematical and computational issues that arise when this is done. An essential component of this is the exercises, which develop both the analytical and computational aspects of the material. The importance of the subject of the book is that most laws of physics involve differential equations, as do the modern theories on financial assets. Moreover many computer animation methods are now based on physics based rules and are heavily invested in differential equations. Consequently numerical methods for differential equations are important for multiple areas. (source: Nielsen Book Data)
| 677.169 | 1 |
Math Mammoth Algebra 1 comprises two worksheet collections, 1-A and 1-B, covering all typical topics of algebra 1 course. The worksheets have been created especially for teachers: each problem sheet is one page, concentrating on one topic.
Please note that these are worksheets collections and do not contain textbook
explanations. So if you are a student, you cannot use these alone to learn algebra.
These algebra worksheets have been "handicrafted" one by one. Each worksheet is
on one topic, but contains varying problems about that topic. The problems include
some that lead to a concept, basic practice problems about the topic on hand, and
most worksheet also include 1-2 challenging problems.
This collection contains a lot of word problems. In essence, the worksheets are like
the problem section of a math book, and far from the mechanical worksheets created
by a script.
Math Mammoth Algebra 1-A
The collection 1-A covers the first half of a typical algebra 1 course topics. The
first section of the book contains introductory problems about variables, expressions,
translating words into symbols, and building equations.
The second section covers basic properties of real numbers. Next follows a section
on solving linear equations, which also covers ratio, proportion, and percent
problems. I have also included lots of word problems here.
The next section, Graphing Linear Equations and Functions, starts with problems
about relations, then has worksheets for all the graphing-related concepts, such as
slope and parallel and perpendicular lines. Lastly in this section I have included three
worksheets about modeling with linear equations.
The next section concentrates on solving and graphing linear inequalities including
absolute value inequalities. Lastly in this collection we have systems of linear
equations and inequalities.
Math Mammoth Algebra 1-B
This collection covers the latter half of a typical algebra 1 course topics,
starting with exponents and powers, and introductory problems on exponential
functions. Next follows a section on polynomials and various factoring techniques.
The next section, Quadratic Equations, includes graphing quadratic functions,
solving quadratic equations, various applications (word problems), and using the
discriminant. Then comes a section called Rational Expressions and Equations, and
the last section covers radical expressions, radical equations, Pythagorean theorem
and its applications.
This collection also contains 8 review worksheets that cover the entire algebra
course.
After completing the order at Kagi, you will see the download links on the receipt page. You will also receive an email with download links for each book you bought, or for a zip file for the packages. You click on the links and download the books to your computer's hard drive.
In case of any problems with the download, you can always email me, and I can email the books to you directly. My contact info will be in the email you receive.
CurrClick.com carries all Blue, Golden, and Light Blue series books as downloads. They accept credit cards and Paypal. You will be able to download the products immediately upon the purchase, and also return to your account at CurrClick to redownload.
Lulu offers printed copies for the Blue, Golden, and Light Blue series books.
Rainbow Resource carries printed copies for the Light Blue series books, plus Light Blue CDs. You can also find links to Rainbow Resource on the individual product pages on this site.
By purchasing any of the books, permission IS granted for the teacher (or parent) to reproduce this material to be used with his/her students in a teaching situation; not for commercial resale. However, you are not permitted to share the material with another teacher.
In other words, you are permitted to make copies for the students/children you are teaching, but not for other teachers' usage.
Math Mammoth books are PDF files. You will need Adobe Reader to view them, including if you use a Mac or Linux. You can try other PDF viewers, but they seem to either omit or mess up some of the images.
| 677.169 | 1 |
Building on the foundations laid in the companion text Modern Engineering Mathematics, this book gives an extensive treatment of some of the advanced areas of mathematics that have applications in various fields of engineering, particularly as tools for computer-based system modelling, analysis and design. The philosophy of learning by doing helps students develop the ability to use mathematics with understanding to solve engineering problems. A wealth of engineering examples and the integration of MATLAB and MAPLE further support students.
Book details
Published 18/11/2010
Publisher Prentice-Hall
ISBN 9780273719236
Advanced Modern Engineering Mathematics
5
5
1
1
excellent book
This book is an excellent help for those who are studying or are planning to study somewhat about engeneering. There are really good explanations for complicated mathmatical tasks and the examples show you some good use of the formula. This book is recommendable to anyone who wants to learn more about higher mathmatics or who is studying some grade with higher mathmatics.
08 May 2011
| 677.169 | 1 |
This book is an ideal way to prepare for the Level 1 Maths Functional Skills test — whichever exam board you're studying. Each topic is clearly explained with straightforward notes, tips and worked examples. There are also practice questions throughout the book, plus plenty of test-style questions (with answers) to help you prepare for the real thing. Maths Books for Entry Level 3 (9781847628732) and Level 2 (9781847628725) are also available.
{"currencyCode":"GBP","itemData":[{"priceBreaksMAP":null,"buyingPrice":5.99,"ASIN":"1847628710","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":5.99,"ASIN":"1847628753","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":5.99,"ASIN":"1847628729","isPreorder":0}],"shippingId":"1847628710::tHorIo6HbdPlBQ9pIN%2F5zK3PYv61tLRs%2BjEps%2FeqBXLqmWCiQ4j46%2BX5L7ir7ZNvGrIX56478W2nbH5jU2EtyIcl1LOYYkfr,1847628753::8hYDv02yOln9NOvoxVjpK3Yi2ldGNr%2FIUtnRzVJxrZAip%2FZ1dpJYWV2HYYuidX3KDDg%2Fj6m74u2iqHl2Zq%2F7N%2F1KUDKKLztI,1847628729::1D1R1FuDsCTQRmlC4b73ufpTvyC18nxEm09o0juorQiOFR%2F3cEm0RR7pDUspP1brCewZOoTO6j6s%2FG1NqTp8J3i0vsQdedq Functional Skills Maths Level 1 - Study & Test Practice for an Amazon Gift Card of up to £1.12, which you can then spend on millions of items across the site. Trade-in values may vary (terms apply). Learn more
| 677.169 | 1 |
Essential Mathcad for Engineering, Science, and Math ISE
By
Brent Maxfield, Professional Engineer, Salt Lake City, UT, USA
Using the author's considerable experience of applying Mathcad to engineering problems, Essential Mathcad introduces the most powerful functions and features of the software and teaches how to apply these to create comprehensive calculations for any quantitative subject. The simple, step-by-step approach makes this book an ideal Mathcad text for professional engineers as well as engineering , science, and math students. Examples from a variety of fields demonstrate the power and utility of Mathcad's tools, while also demonstrating how other software, such as Excel spreadsheets, can be incorporated effectively.
Audience Engineering, math, and science students using Mathcad in their coursework. Engineers and scientists working in industry who need instruction on using Mathcad.
| 677.169 | 1 |
...
Customers Who Bought This Also Bought
More About
This Book
when we accept a tip on that "one in a thousand" sk, even when the tip comes from a successful day trader. With a wealth of entertaining and counterintuitive examples, The Math of Money delights as well as informs, and will help readers treat their financial resources more rationally.
Editorial Reviews
From the Publisher
From the reviews:
'Money is peculiar stuff'Or—and trenchantly and readably demystifies it. This is a clear and fascinating book, and anyone curious about the subject of money should read it.' —Plus Online Magazine, Cambridge University, U
"Davis offers a mathematician's view of certain areas of economics and finance. For instance, he helps readers understand how interest compounds, how the sk market works, and how anyone can save enough money for retirement. … Each chapter begins with a section called 'Test your intuition' that brings such matters to light. Many other scenarios and exercises in the text put money matters into the context of everyday life." (Science Now, March, 2002)
"This book is a very unusual and very entertaining introduction to financial mathematics to readers with a modest mathematical background. Each chapter begins with a section entitled Test Your Intuition. A few multiple choice questions are presented; the reader is invited to guess the answer. … Then the chapter goes on to present the related basic notions and ideas … . I warmly recommend the book to anyone who wants to learn the basic ideas of financial mathematics in a very enjoyable way." (László I. Szabó, Acta Scientiarum Mathematicarum, Vol. 68, 2002)
"This book presents, in the author's own words, a mathematician's point of view about basic issues of finance: mortgages, interest rates, investment futures, options and so on. … The main purpose of the book is to challenge (wrong) intuitions about some basic financial issues and to teach how to think mathematically … . This book is intended for the general reader. … The math of money is full with delightful explanations and insights and it is very lively ... ." (José Lúis Fernandez Perez, Zentralblatt MATH, Vol. 983, 2002)
"This book covers the range of topics that one would expect to find in an undergraduate course on financial mathematics … . the material is treated at a level that would be understood by anyone who has studied mathematics to the final year of high school. Most of the material is treated by means of concrete examples … . I quite enjoyed this book and I would have no hesitation in recommending it to students as preliminary reading for finance and derivative courses." (W. P. Wood, The Australian Mathematical Society Gazette, Vol. 29 (1), 2002)
"Each of the book's nine chapters takes a subject – 'Interest' or 'Statistics', for example – and trenchantly and readably demystifies it. ... Though the explanations are simple, they are not simplified, and indeed several examples are included ... . The examples are, though, are carefully chosen to help the story along, not merely stuck in for the sake of it. ... this is a clear and fascinating book, and anyone curious about the subject of money should read it." (Mark Wainwright, Issue 16, 2002)
Education Digest
For teachers of math and consumer science. . . . In clear and conversational prose The Math of Money shows students how to be smart about money by using real-life examples of investments their parents already make that they will soon have to make themselves.
Sci-Tech Book News
Certainly those who study this work will gain respect for the complexities and the nuances of money and investments, enhanced understanding of the logic behind why 'sure' things go wrong, and some new ideas about how to proceed through the uncertain terrain of financial decision making.
Booknews
Davis (emeritus, math City College of New York) does not offer a quick road to wealth. Although his discussion doesn't require a sophisticated math background, readers will need a strong interest in money and numbers and a willingness to examine some of the fallacies of "intuitive" understanding. In fact, each chapter begins with "test your intuition" questions (answers at the back of the book) with regard to investment strategies, interest, bonds, mortgages, retirement, the psychology of investing, statistics, and options. Certainly, those who study this work will gain respect for the complexities and the nuances of money and investments, enhanced understanding of the logic behind why "sure" things go wrong, and some new ideas about how to proceed through the uncertain terrain of financial decision making. Annotation c. Book News, Inc., Portland, OR (booknews.com)
Plus Online Magazine
Money is peculiar stuff. . . . Or . . . and trenchantly and readably demystifies it. . . . This is a clear and fascinating book, and anyone curious about the subject of money should read
| 677.169 | 1 |
On selecting a constituent part of MU the "Overview of publishing activities" page will be displayed with information relevant to the selected constituent part. The "Overview of publishing activities" page is not available for non-activated items.
The article was created as the result of the research oriented at the innovation of the content and forms of secondary school mathematics teaching. This article contains special and not very typical tasks and problems of elementary set theory, suitable for extending and completing student's knowledge in this field, especially for future teachers. It is possible to use these ideas at secondary schools while working with students gifted in mathematics. In the first part of the article there are introduced problems complementing and following the principle of inclusion and exclusion, in the second part there is shown the exploitation of set operations in the theory of metric spaces and in elementary geometry.
| 677.169 | 1 |
More About
This Textbook
Overview
This volume presents the Oxford Mathematical Institute notes for the enormously successful advanced undergraduate and first-year graduate student course on groups and geometry. The book's content closely follows the Oxford syllabus but covers a great deal more material than did the course itself. The book is divided into two parts: the first covers the fundamentals of groups, and the second covers geometry and its symbiotic relationship with groups. Both parts contain a number of useful examples and exercises. This book will be welcomed by student and teacher alike as a lucidly written text
| 677.169 | 1 |
978-0-17-438484-7 / 9780174384847
Shipping prices may be approximate. Please verify cost before checkout.
About the book:
The "MSM Mathematics" series offers an integrated and comprehensive assessment for GCSE mathematics. It provides a one-book-per-year mathematics course. There are worked examples and numerous graded exercises. The maths is set in the context of everyday life, involving investigations and project work, to provide approaches to all kinds of mathematical problem solving. The writing team has organized the mathematics covered by the National Curriculum into a series of topic-based sections within each book. Mathematical knowledge and skills are developed in line with current practice in maths teaching. The "MSM" series comprises course books at all levels. Books 1 and 2 provide maths for all abilities at Key Stage 3. Students of average ability can continue with the "x" series - books 3x, 4x and 5x. The "w" series provides support for students having difficulty with the maths covered in the books 1, 2, 3x-5x. The material in the "w" books is organized in the same sequence as the main course, but concentrates on the development of basic concepts for those students experiencing difficulties. The "y" series caters for more able students, providing maths for top grades of GCSE and preparation for Sixth-Form work leading up to Levels 9-10 at Key Stage 4Goldstone Books via United Kingdom
Softcover, ISBN 017438484X Publisher: Nelson Thornes Ltd7438484X Publisher: Nelson Thornes7438484X38484X Publisher: ., 1993 Used - Acceptable Usually dispatched within 1-2 Acceptable, Usually ships within 1 - 27438484X Publisher: Nelson Thornes Ltd, 1993 Like New, Usually dispatched within 1-2 business days, Post first class next post -1992 paper back Covers have slight marks The rest like new
Softcover, ISBN 017438484X Publisher: Nelson Thornes Ltd, 1993 Used - Good, Usually ships within 1 - 2 business days, We are certain you will be delighted with our high level of customer service. all our books are in 'Good' or better condition and we ship daily from our UK warehouse.
| 677.169 | 1 |
6.
v
Preface
MATLAB® is a very popular language for technical computing used by stu-
dents, engineers, and scientists in universities, research institutes, and industries
all over the world. The software is popular because it is powerful and easy to use.
For university freshmen in it can be thought of as the next tool to use after the
graphic calculator in high school.
This book was written following several years of teaching the software to
freshmen in an introductory engineering course. The objective was to write a book
that teaches the software in a friendly, non-intimidating fashion. Therefore, the
book is written in simple and direct language. In many places bullets, rather than
lengthy text, are used to list facts and details that are related to a specific topic.
The book includes numerous sample problems in mathematics, science, and engi-
neering that are similar to problems encountered by new users of MATLAB.
This fourth edition of the book is updated to MATLAB 7.11 (Release
2010b). Other modifications/changes to this edition are: programming (now
Chapter 6) is introduced before user-defined functions (now Chapter 7), applica-
tions in numerical analysis (now Chapter 9) follows polynomials, curve fitting
and interpolation that is covered in Chapter 8. The last two chapters are 3D plot-
ting (now Chapter 10) and symbolic math (Chapter 11). In addition, the end of
chapter problems have been revised. There are many more problems in every
chapter, and close to 80% are new of different than in previous editions. In addi-
tion, the problems cover a wider range of topics.
I would like to thank several of my colleagues at The Ohio State University.
Professors Richard Freuler, Mark Walter, and Walter Lampert, and Dr. Mike Parke
read sections of the book and suggested modifications. I also appreciate the
involvement and support of Professors Robert Gustafson and John Demel and Dr.
John Merrill from the First-Year Engineering Program at The Ohio State Univer-
sity. Special thanks go to Professor Mike Lichtensteiger (OSU), and my daughter
Tal Gilat (Marquette University), who carefully reviewed the first edition of the
book and provided valuable comments and criticisms. Professor Brian Harper
(OSU) has made a significant contribution to the new end of chapter problems in
the present edition.
I would like to express my appreciation to all those who have reviewed the
first edition of the text at its various stages of development, including Betty Barr,
University of Houston; Andrei G. Chakhovskoi, University of California, Davis;
Roger King, University of Toledo; Richard Kwor, University of Colorado at Colo-
rado Springs; Larry Lagerstrom, University of California, Davis; Yueh-Jaw Lin,
University of Akron; H. David Sheets, Canisius College; Geb Thomas, University
7.
vi Preface
of Iowa; Brian Vick, Virginia Polytechnic Institute and State University; Jay
Weitzen, University of Massachusetts, Lowell; and Jane Patterson Fife, The Ohio
State University. In addition, I would like to acknowledge Daniel Sayre, Ken San-
tor, and Katie Singleton, all from John Wiley & Sons, who supported the produc-
tion of the Fourth edition.
I hope that the book will be useful and will help the users of MATLAB to
enjoy the software.
Amos Gilat
Columbus, Ohio
November, 2010
gilat.1@osu.edu
To my parents Schoschana and Haim Gelbwacks
12.
1
Introduction
MATLAB is a powerful language for technical computing. The name MATLAB
stands for MATrix LABoratory, because its basic data element is a matrix (array).
MATLAB can be used for math computations, modeling and simulations, data
analysis and processing, visualization and graphics, and algorithm development.
MATLAB is widely used in universities and colleges in introductory and
advanced courses in mathematics, science, and especially engineering. In industry
the software is used in research, development, and design. The standard
MATLAB program has tools (functions) that can be used to solve common
problems. In addition, MATLAB has optional toolboxes that are collections of
specialized programs designed to solve specific types of problems. Examples
include toolboxes for signal processing, symbolic calculations, and control
systems.
Until recently, most of the users of MATLAB have been people with
previous knowledge of programming languages such as FORTRAN and C who
switched to MATLAB as the software became popular. Consequently, the
majority of the literature that has been written about MATLAB assumes that the
reader has knowledge of computer programming. Books about MATLAB often
address advanced topics or applications that are specialized to a particular field.
Today, however, MATLAB is being introduced to college students as the first (and
often the only) computer program they will learn. For these students there is a
need for a book that teaches MATLAB assuming no prior experience in computer
programming.. The book can also serve as a
reference in more advanced science and engineering courses where MATLAB is
used as a tool for solving problems. It also can be used for self-study of MATLAB
by students and practicing engineers. In addition, the book can be a supplement or
a secondary book in courses where MATLAB is used but the instructor does not
have the time to cover it extensively.
Topics Covered
MATLAB is a huge program, and therefore it is impossible to cover all of it in one
book. This book focuses primarily on the foundations of MATLAB. The
13.
2 Introduction
assumption is that once these foundations are well understood, the student will be
able to learn advanced topics easily by using the information in the Help menu.
The order in which the topics are presented in this book was chosen
carefully, based on several years of experience in teaching MATLAB in an
introductory engineering course. The topics are presented in an order that allows
the student to follow the book chapter after chapter. Every topic is presented
completely in one place and then used in the following chapters.
The first chapter describes the basic structure and features of MATLAB and
how to use the program for simple arithmetic operations with scalars as with a
calculator. Script files are introduced at the end of the chapter. They allow the
student to write, save, and execute simple MATLAB programs. The next two
chapters are devoted to the topic of arrays. MATLAB's basic data element is an
array that does not require dimensioning. This concept, which makes MATLAB a
very powerful program, can be a little difficult to grasp for students who have only
limited knowledge of and experience with linear algebra and vector analysis. The
concept of arrays is introduced gradually and then explained in extensive detail.
Chapter 2 describes how to create arrays, and Chapter 3 covers mathematical
operations with arrays.
Following the basics, more advanced topics that are related to script files
and input and output of data are presented in Chapter 4. This is followed by
coverage of two-dimensional plotting in Chapter 5. Programming with MATLAB
is introduced in Chapter 6. This includes flow control with conditional statements
and loops. User-defined functions, anonymous functions, and function functions
are covered next in Chapter 7. The coverage of function files (user-defined
functions) is intentionally separated from the subject of script files. This has
proven to be easier to understand by students who are not familiar with similar
concepts from other computer programs.
The next three chapters cover more advanced topics. Chapter 8 describes
how MATLAB can be used for carrying out calculations with polynomials, and
how to use MATLAB for curve fitting and interpolation. Chapter 9 covers
applications of MATLAB in numerical analysis. It includes solving nonlinear
equations, finding minimum or a maximum of a function, numerical integration,
and solution of first-order ordinary differential equations. Chapter 10 describes
how to produce three-dimensional plots, an extension of the chapter on two-
dimensional plots. Chapter 11 covers in great detail how to use MATLAB in
symbolic operations.
The Framework of a Typical Chapter
In every chapter the topics are introduced gradually in an order that makes the
concepts easy to understand. The use of MATLAB is demonstrated extensively
within the text and by examples. Some of the longer examples in Chapters 1–3 are
titled as tutorials. Every use of MATLAB is printed with a different font and with
a gray background. Additional explanations appear in boxed text with a white
background. The idea is that the reader will execute these demonstrations and
14.
Introduction 3
tutorials in order to gain experience in using MATLAB. In addition, every chapter
includes formal sample problems that are examples of applications of MATLAB
for solving problems in math, science, and engineering. Each example includes a
problem statement and a detailed solution. Some sample problems are presented
in the middle of the chapter. All of the chapters (except Chapter 2) have a section
at the end with several sample problems of applications. It should be pointed out
that problems with MATLAB can be solved in many different ways. The solutions
of the sample problems are written such that they are easy to follow. This means
that in many cases the problem can be solved by writing a shorter, or sometimes
"trickier," program. The students are encouraged to try to write their own solu-
tions and compare the end results. At the end of each chapter there is a set of
homework problems. They include general problems from math and science and
problems from different disciplines of engineering.
Symbolic Calculations
MATLAB is essentially a software for numerical calculations. Symbolic math
operations, however, can be executed if the Symbolic Math toolbox is installed.
The Symbolic Math toolbox is included in the student version of the software and
can be added to the standard program.
Software and Hardware
The MATLAB program, like most other software, is continually being developed
and new versions are released frequently. This book covers MATLAB Version
7.11, Release 2010b. It should be emphasized, however, that the book covers the
basics of MATLAB, which do not change much from version to version. The book
covers the use of MATLAB on computers that use the Windows operating system.
Everything is essentially the same when MATLAB is used on other machines. The
user is referred to the documentation of MATLAB for details on using MATLAB
on other operating systems. It is assumed that the software is installed on the
computer, and the user has basic knowledge of operating the computer.
The Order of Topics in the Book
It is probably impossible to write a textbook where all the subjects are presented
in an order that is suitable for everyone. The order of topics in this book is such
that the fundamentals of MATLAB are covered first (arrays and array operations),
and, as mentioned before, every topic is covered completely in one location,
which makes the book easy to use as a reference. The order of the topics in this
fourth edition of the book is a little bit different than in previous editions. Pro-
gramming is introduced before user-defined functions. This allows using pro-
gramming in user-defined functions. Also, applications of MATLAB in numerical
analysis (now Chapter 9, previously 10) follow Chapter 8 which covers polynomi-
als, curve fitting, and interpolation.
16.
5
Chapter 1
Starting with
MATLAB
This chapter begins by describing the characteristics and purposes of the different
windows in MATLAB. Next, the Command Window is introduced in detail. This
chapter shows how to use MATLAB for arithmetic operations with scalars in a
fashion similar to the way that a calculator is used. This includes the use of ele-
mentary math functions with scalars. The chapter then shows how to define scalar
variables (the assignment operator) and how to use these variables in arithmetic
calculations. The last section in the chapter introduces script files. It shows how to
write, save, and execute simple MATLAB programs.
1.1 STARTING MATLAB, MATLAB WINDOWS
It is assumed that the software is installed on the computer, and that the user can
start the program. Once the program starts, the MATLAB desktop window opens
(Figure 1-1). The window contains four smaller windows: the Command Window,
the Current Folder Window, the Workspace Window, and the Command History
Window. This is the default view that shows four of the various windows of MAT-
LAB. A list of several windows and their purpose is given in Table 1-1. The Start
button on the lower left side can be used to access MATLAB tools and features.
Four of the windows—the Command Window, the Figure Window, the Editor
Window, and the Help Window—are used extensively throughout the book and
are briefly described on the following pages. More detailed descriptions are
included in the chapters where they are used. The Command History Window,
Current Folder Window, and the Workspace Window are described in Sections
1.2, 1.8.4, and 4.1, respectively.
Command Window: The Command Window is MATLAB's main window and
opens when MATLAB is started. It is convenient to have the Command Window
as the only visible window, and this can be done by either closing all the other
windows (click on the x at the top right-hand side of the window you want to
close) or by first selecting the Desktop Layout in the Desktop menu, and then
17.
6 Chapter 1: Starting with MATLAB
selecting Command Window Only from the submenu that opens. Working in the
Command Window is described in detail in Section 1.2.
Figure Window: The Figure Window opens automatically when graphics com-
mands are executed, and contains graphs created by these commands. An example
of a Figure Window is shown in Figure 1-2. A more detailed description of this
window is given in Chapter 5.
Figure 1-1: The default view of MATLAB desktop.
Table 1-1: MATLAB windows
Window Purpose
Command Window Main window, enters variables, runs
programs.
Figure Window Contains output from graphic
commands.
Editor Window Creates and debugs script and
function files.
Help Window Provides help information.
Command History Window Logs commands entered in the
Command Window.
Workspace Window Provides information about the
variables that are used.
Current Folder Window Shows the files in the current folder.
18.
1.1 Starting MATLAB, MATLAB Windows 7
Editor Window: The Editor Window is used for writing and editing programs.
This window is opened from the File menu. An example of an Editor Window is
shown in Figure 1-3. More details on the Editor Window are given in Section
1.8.2, where it is used for writing script files, and in Chapter 7, where it is used to
write function files.
Help Window: The Help Window contains help information. This window can
be opened from the Help menu in the toolbar of any MATLAB window. The Help
Window is interactive and can be used to obtain information on any feature of
MATLAB. Figure 1-4 shows an open Help Window.
Figure 1-2: Example of a Figure Window.
Figure 1-3: Example of an Editor Window.
19.
8 Chapter 1: Starting with MATLAB
When MATLAB is started for the first time the screen looks like that shown in
Figure 1-1. For most beginners it is probably more convenient to close all the win-
dows except the Command Window. (Each of the windows can be closed by
clicking on the button.) The closed windows can be reopened by selecting
them from the Desktop menu. The windows shown in Figure 1-1 can be displayed
by selecting first Desktop Layout in the Desktop menu and then Default from
the submenu. The various windows in Figure 1-1 are docked to the desktop. A
window can be undocked (become a separate, independent window) by clicking
on the button on the upper right-hand corner. An independent window can be
redocked by clicking on the button.
Figure 1-4: The Help Window.
20.
1.2 Working in the Command Window 9
1.2 WORKING IN THE COMMAND WINDOW
The Command Window is MATLAB's main window and can be used for execut-
ing commands, opening other windows, running programs written by the user, and
managing the software. An example of the Command Window, with several sim-
ple commands that will be explained later in this chapter, is shown in Figure 1-5.
Notes for working in the Command Window:
• To type a command the cursor must be placed next to the command prompt ( >> ).
• Once a command is typed and the Enter key is pressed, the command is executed.
However, only the last command is executed. Everything executed previously
(that might be still displayed) is unchanged.
• Several commands can be typed in the same line. This is done by typing a comma
between the commands. When the Enter key is pressed the commands are exe-
cuted in order from left to right.
• It is not possible to go back to a previous line that is displayed in the Command
Window, make a correction, and then re-execute the command.
• A previously typed command can be recalled to the command prompt with the up-
arrow key ( ). When the command is displayed at the command prompt, it can
be modified if needed and then executed. The down-arrow key ( ) can be used to
move down the list of previously typed commands.
• If a command is too long to fit in one line, it can be continued to the next line by
typing three periods … (called an ellipsis) and pressing the Enter key. The con-
tinuation of the command is then typed in the new line. The command can con-
tinue line after line up to a total of 4,096 characters.
Figure 1-5: The Command Window.
To type a command the cursor is placed
next to the command prompt ( >> ).
21.
10 Chapter 1: Starting with MATLAB
The semicolon ( ; ):
When a command is typed in the Command Window and the Enter key is
pressed, the command is executed. Any output that the command generates is dis-
played in the Command Window. If a semicolon ( ; ) is typed at the end of a com-
mand the output of the command is not displayed. Typing a semicolon is useful
when the result is obvious or known, or when the output is very large.
If several commands are typed in the same line, the output from any of the
commands will not be displayed if a semicolon is typed between the commands
instead of a comma.
Typing %:
When the symbol % (percent) is typed at the beginning of a line, the line is desig-
nated as a comment. This means that when the Enter key is pressed the line is not
executed. The % character followed by text (comment) can also be typed after a
command (in the same line). This has no effect on the execution of the command.
Usually there is no need for comments in the Command Window. Comments,
however, are frequently used in a program to add descriptions or to explain the
program (see Chapters 4 and 6).
The clc command:
The clc command (type clc and press Enter) clears the Command Window.
After working in the Command Window for a while, the display may become very
long. Once the clc command is executed a clear window is displayed. The com-
mand does not change anything that was done before. For example, if some vari-
ables were defined previously (see Section 1.6), they still exist and can be used.
The up-arrow key can also be used to recall commands that were typed before.
The Command History Window:
The Command History Window lists the commands that have been entered in the
Command Window. This includes commands from previous sessions. A com-
mand in the Command History Window can be used again in the Command Win-
dow. By double-clicking on the command, the command is reentered in the
Command Window and executed. It is also possible to drag the command to the
Command Window, make changes if needed, and then execute it. The list in the
Command History Window can be cleared by selecting the lines to be deleted and
then selecting Delete Selection from the Edit menu (or right-click the mouse
when the lines are selected and then choose Delete Selection in the menu that
opens).
1.3 ARITHMETIC OPERATIONS WITH SCALARS
In this chapter we discuss only arithmetic operations with scalars, which are num-
bers. As will be explained later in the chapter, numbers can be used in arithmetic
calculations directly (as with a calculator) or they can be assigned to variables,
which can subsequently be used in calculations. The symbols of arithmetic opera-
22.
1.3 Arithmetic Operations with Scalars 11
tions are:
It should be pointed out here that all the symbols except the left division are
the same as in most calculators. For scalars, the left division is the inverse of the
right division. The left division, however, is mostly used for operations with
arrays, which are discussed in Chapter 3.
1.3.1 Order of Precedence
MATLAB executes the calculations according to the order of precedence dis-
played below. This order is the same as used in most calculators.
In an expression that has several operations, higher-precedence operations are
executed before lower-precedence operations. If two or more operations have the
same precedence, the expression is executed from left to right. As illustrated in the
next section, parentheses can be used to change the order of calculations.
1.3.2 Using MATLAB as a Calculator
The simplest way to use MATLAB is as a calculator. This is done in the Com-
mand Window by typing a mathematical expression and pressing the Enter key.
MATLAB calculates the expression and responds by displaying ans = and the
numerical result of the expression in the next line. This is demonstrated in Tutorial
1-1.
Operation Symbol Example
Addition + 5 + 3
Subtraction – 5 – 3
Multiplication * 5 * 3
Right division / 5 / 3
Left division 5 3 = 3 / 5
Exponentiation ^ 5 ^ 3 (means 53
= 125)
Precedence Mathematical Operation
First Parentheses. For nested parentheses, the innermost
are executed first.
Second Exponentiation.
Third Multiplication, division (equal precedence).
Fourth Addition and subtraction.
23.
12 Chapter 1: Starting with MATLAB
1.4 DISPLAY FORMATS
The user can control the format in which MATLAB displays output on the screen.
In Tutorial 1-1, the output format is fixed-point with four decimal digits (called
short), which is the default format for numerical values. The format can be
changed with the format command. Once the format command is entered, all
the output that follows is displayed in the specified format. Several of the avail-
able formats are listed and described in Table 1-2.
MATLAB has several other formats for displaying numbers. Details of these
formats can be obtained by typing help format in the Command Window. The
format in which numbers are displayed does not affect how MATLAB computes
and saves numbers.
Tutorial 1-1: Using MATLAB as a calculator.
>> 7+8/2
ans =
11
>> (7+8)/2
ans =
7.5000
>> 4+5/3+2
ans =
7.6667
>> 5^3/2
ans =
62.5000
>> 27^(1/3)+32^0.2
ans =
5
>> 27^1/3+32^0.2
ans =
11
>> 0.7854-(0.7854)^3/(1*2*3)+0.785^5/(1*2*3*4*5)...
-(0.785)^7/(1*2*3*4*5*6*7)
ans =
0.7071
>>
Type and press Enter.
8/2 is executed first.
Type and press Enter.
7+8 is executed first.
5/3 is executed first.
5^3 is executed first, /2 is executed next.
1/3 is executed first, 27^(1/3) and 32^0.2 are
executed next, and + is executed last.
27^1 and 32^0.2 are executed first, /3 is exe-
cuted next, and + is executed last.
Type three periods ... (and press Enter) to
continue the expression on the next line.
The last expression is the first four
terms of the Taylor series for sin( /4).
24.
1.5 Elementary Math Built-in Functions 13
1.5 ELEMENTARY MATH BUILT-IN FUNCTIONS
In addition to basic arithmetic operations, expressions in MATLAB can include
functions. MATLAB has a very large library of built-in functions. A function has
a name and an argument in parentheses. For example, the function that calculates
the square root of a number is sqrt(x). Its name is sqrt, and the argument is
x. When the function is used, the argument can be a number, a variable that has
been assigned a numerical value (explained in Section 1.6), or a computable
expression that can be made up of numbers and/or variables. Functions can also
be included in arguments, as well as in expressions. Tutorial 1-2 shows examples
Table 1-2: Display formats
Command Description Example
format short Fixed-point with 4 decimal
digits for:
Otherwise display format
short e.
>> 290/7
ans =
41.4286
format long Fixed-point with 15 decimal
digits for:
Otherwise display format
long e.
>> 290/7
ans =
41.428571428571431
format short e Scientific notation with 4
decimal digits.
>> 290/7
ans =
4.1429e+001
format long e Scientific notation with 15
decimal digits.
>> 290/7
ans =
4.142857142857143e+001
format short g Best of 5-digit fixed or
floating point.
>> 290/7
ans =
41.429
format long g Best of 15-digit fixed or
floating point.
>> 290/7
ans =
41.4285714285714
format bank Two decimal digits. >> 290/7
ans =
41.43
format compact Eliminates empty lines to allow more lines with
information displayed on the screen.
format loose Adds empty lines (opposite of compact).
0.001 number 1000
0.001 number 100
27.
16 Chapter 1: Starting with MATLAB
1.6 DEFINING SCALAR VARIABLES
A variable is a name made of a letter or a combination of several letters (and dig-
its) that is assigned a numerical value. Once a variable is assigned a numerical
value, it can be used in mathematical expressions, in functions, and in any MAT-
LAB statements and commands. A variable is actually a name of a memory loca-
tion. When a new variable is defined, MATLAB allocates an appropriate memory
space where the variable's assignment is stored. When the variable is used the
stored data is used. If the variable is assigned a new value the content of the
memory location is replaced. (In Chapter 1 we consider only variables that are
assigned numerical values that are scalars. Assigning and addressing variables
that are arrays is discussed in Chapter 2.)
1.6.1 The Assignment Operator
In MATLAB the = sign is called the assignment operator. The assignment opera-
tor assigns a value to a variable.
• The left-hand side of the assignment operator can include only one variable name.
The right-hand side can be a number, or a computable expression that can include
numbers and/or variables that were previously assigned numerical values. When
the Enter key is pressed the numerical value of the right-hand side is assigned to
the variable, and MATLAB displays the variable and its assigned value in the next
two lines.
The following shows how the assignment operator works.
sign(x) Signum function. Returns 1 if
, –1 if , and 0 if
.
>> sign(5)
ans =
1
>> x=15
x =
15
>> x=3*x-12
x =
33
>>
Table 1-5: Rounding functions (Continued)
Function Description Example
x 0 x 0
x 0=
Variable_name = A numerical value, or a computable expression
The number 15 is assigned to the variable x.
MATLAB displays the variable
and its assigned value.
A new value is assigned to x. The
new value is 3 times the previous
value of x minus 12.
28.
1.6 Defining Scalar Variables 17
The last statement ( ) illustrates the difference between the assignment
operator and the equal sign. If in this statement the = sign meant equal, the value
of x would be 6 (solving the equation for x).
The use of previously defined variables to define a new variable is demon-
strated next.
• If a semicolon is typed at the end of the command, then when the Enter key is
pressed, MATLAB does not display the variable with its assigned value (the vari-
able still exists and is stored in memory).
• If a variable already exists, typing the variable's name and pressing the Enter key
will display the variable and its value in the next two lines.
As an example, the last demonstration is repeated below using semicolons.
• Several assignments can be typed in the same line. The assignments must be sepa-
rated with a comma (spaces can be added after the comma). When the Enter key
is pressed, the assignments are executed from left to right and the variables and
their assignments are displayed. A variable is not displayed if a semicolon is typed
instead of a comma. For example, the assignments of the variables a, B, and C
above can all be done in the same line.
>> a=12
a =
12
>> B=4
B =
4
>> C=(a-B)+40-a/B*10
C =
18
>> a=12;
>> B=4;
>> C=(a-B)+40-a/B*10;
>> C
C =
18
>> a=12, B=4; C=(a-B)+40-a/B*10
a =
12
C =
18
x 3x 12–=
Assign 12 to a.
Assign 4 to B.
Assign the value of the expres-
sion on the right-hand side to
the variable C.
The variables a, B, and C are defined
but are not displayed since a semicolon
is typed at the end of each statement.
The value of the variable C is displayed
by typing the name of the variable.
The variable B is not displayed because a semi-
colon is typed at the end of the assignment.
29.
18 Chapter 1: Starting with MATLAB
• A variable that already exists can be reassigned a new value. For example:
• Once a variable is defined it can be used as an argument in functions. For exam-
ple:
1.6.2 Rules About Variable Names
A variable can be named according to the following rules:
• Must begin with a letter.
• Can be up to 63 characters long.
• Can contain letters, digits, and the underscore character.
• Cannot contain punctuation characters (e.g., period, comma, semicolon).
• MATLAB is case sensitive: it distinguishes between uppercase and lowercase let-
ters. For example, AA, Aa, aA, and aa are the names of four different variables.
• No spaces are allowed between characters (use the underscore where a space is
desired).
• Avoid using the name of a built-in function for a variable (i.e., avoid using cos,
sin, exp, sqrt, etc.). Once a function name is used to define a variable, the
function cannot be used.
1.6.3 Predefined Variables and Keywords
There are 20 words, called keywords, that are reserved by MATLAB for various
purposes and cannot be used as variable names. These words are:
break case catch classdef continue else elseif
end for function global if otherwise parfor
persistent return spmd switch try while
>> ABB=72;
>> ABB=9;
>> ABB
ABB =
9
>>
>> x=0.75;
>> E=sin(x)^2+cos(x)^2
E =
1
>>
A value of 72 is assigned to the variable ABB.
A new value of 9 is assigned to the variable ABB.
The current value of the variable is dis-
played when the name of the variable is
typed and the Enter key is pressed.
30.
1.7 Useful Commands for Managing Variables 19
When typed, these words appear in blue. An error message is displayed if the user
tries to use a keyword as a variable name. (The keywords can be displayed by typ-
ing the command iskeyword.)
A number of frequently used variables are already defined when MATLAB is
started. Some of the predefined variables are:
ans A variable that has the value of the last expression that was not assigned to a
specific variable (see Tutorial 1-1). If the user does not assign the value of
an expression to a variable, MATLAB automatically stores the result in
ans.
pi The number .
eps The smallest difference between two numbers. Equal to 2^(–52), which is
approximately 2.2204e–016.
inf Used for infinity.
i Defined as , which is: 0 + 1.0000i.
j Same as i.
NaN Stands for Not-a-Number. Used when MATLAB cannot determine a valid
numeric value. Example: 0/0.
The predefined variables can be redefined to have any other value. The vari-
ables pi, eps, and inf, are usually not redefined since they are frequently used
in many applications. Other predefined variables, such as i and j, are sometime
redefined (commonly in association with loops) when complex numbers are not
involved in the application.
1.7 USEFUL COMMANDS FOR MANAGING VARIABLES
The following are commands that can be used to eliminate variables or to obtain
information about variables that have been created. When these commands are
typed in the Command Window and the Enter key is pressed, either they provide
information, or they perform a task as specified below.
Command Outcome
clear Removes all variables from the memory.
clear x y z Removes only variables x, y, and z from the
memory.
who Displays a list of the variables currently in the
memory.
whos Displays a list of the variables currently in the
memory and their sizes together with informa-
tion about their bytes and class (see Section 4.1).
1–
31.
20 Chapter 1: Starting with MATLAB
1.8 SCRIPT FILES
So far all the commands were typed in the Command Window and were executed
when the Enter key was pressed. Although every MATLAB command can be
executed in this way, using the Command Window to execute a series of com-
mands—especially if they are related to each other (a program)—is not conve-
nient and may be difficult or even impossible. The commands in the Command
Window cannot be saved and executed again. In addition, the Command Window
is not interactive. This means that every time the Enter key is pressed only the
last command is executed, and everything executed before is unchanged. If a
change or a correction is needed in a command that was previously executed and
the results of this command are used in commands that follow, all the commands
have to be entered and executed again.
A different (better) way of executing commands with MATLAB is first to
create a file with a list of commands (program), save it, and then run (execute) the
file. When the file runs, the commands it contains are executed in the order that
they are listed. If needed, the commands in the file can be corrected or changed
and the file can be saved and run again. Files that are used for this purpose are
called script files.
IMPORTANT NOTE: This section covers only the minimum that is
required in order to run simple programs. This will allow the student to use
script files when practicing the material that is presented in this and the next
two chapters (instead of typing repeatedly in the Command Window). Script
files are considered again in Chapter 4 where many additional topics that are
essential for understanding MATLAB and writing programs in script file are
covered.
1.8.1 Notes About Script Files
• A script file is a sequence of MATLAB commands, also called a program.
• When a script file runs (is executed), MATLAB executes the commands in the
order they are written just as if they were typed in the Command Window.
• When a script file has a command that generates an output (e.g., assignment of
a value to a variable without a semicolon at the end), the output is displayed in
the Command Window.
• Using a script file is convenient because it can be edited (corrected or other-
wise changed) and executed many times.
• Script files can be typed and edited in any text editor and then pasted into the
MATLAB editor.
• Script files are also called M-files because the extension .m is used when they are
saved.
32.
1.8 Script Files 21
1.8.2 Creating and Saving a Script File
In MATLAB script files are created and edited in the Editor/Debugger Window.
This window is opened from the Command Window. In the File menu, select
New, and then select Script. An open Editor/Debugger Window is shown in Fig-
ure 1-6.
Once the window is open, the commands of the script file are typed line by
line. MATLAB automatically numbers a new line every time the Enter key is
pressed. The commands can also be typed in any text editor or word processor
program and then copied and pasted in the Editor/Debugger Window. An example
of a short program typed in the Editor/Debugger Window is shown in Figure 1-7.
The first few lines in a script file are typically comments (which are not executed
since the first character in the line is %) that describe the program written in the
script file.
Figure 1-6: The Editor/Debugger Window.
Figure 1-7: A program typed in the Editor/Debugger Window.
The commands in the script file are
typed line by line. The lines are num-
bered automatically. A new line
starts when the Enter key is pressed.
Line
number
Comments.
Define three
variables.
Calculating the two roots.
The Run icon.
33.
22 Chapter 1: Starting with MATLAB
Before a script file can be executed it has to be saved. This is done by
choosing Save As... from the File menu, selecting a location (many students save
to a flash drive, which appears in the directory as Drive(F:) or (G:)), and
entering a name for the file. When saved, MATLAB adds the extension .m to the
name. The rules for naming a script file follow the rules of naming a variable
(must begin with a letter, can include digits and underscore, no spaces, and up to
63 characters long). The names of user-defined variables, predefined variables,
and MATLAB commands or functions should not be used as names of script files.
1.8.3 Running (Executing) a Script File
A script file can be executed either directly from the Editor Window by clicking
on the Run icon (see Figure 1-7) or by typing the file name in the Command Win-
dow and then pressing the Enter key. For a file to be executed, MATLAB needs
to know where the file is saved. The file will be executed if the folder where the
file is saved is the current folder of MATLAB or if the folder is listed in the search
path, as explained next.
1.8.4 Current Folder
The current folder is shown in the "Current Folder" field in the desktop toolbar of
the Command Window, as shown in Figure 1-8. If an attempt is made to execute a
script file by clicking on the Run icon (in the Editor Window) when the current
folder is not the folder where the script file is saved, then the prompt shown in
Figure 1-9 will open. The user can then change the current folder to the folder
where the script file is saved, or add it to the search path. Once two or more differ-
ent current folders are used in a session, it is possible to switch from one to
another in the Current Folder field in the Command Window. The current folder
can also be changed in the Current Folder Window, shown in Figure 1-10, which
can be opened from the Desktop menu. The Current Folder can be changed by
choosing the drive and folder where the file is saved.
Figure 1-8: The Current folder field in the Command Window.
The current folder is shown here.
34.
1.8 Script Files 23
An alternative simple way to change the current folder is to use the cd com-
mand in the Command Window. To change the current folder to a different drive,
type cd, space, and then the name of the directory followed by a colon : and press
the Enter key. For example, to change the current folder to drive F (e.g., the flash
drive) type cd F:. If the script file is saved in a folder within a drive, the path to
that folder has to be specified. This is done by typing the path as a string in the cd
command. For example, cd('F:Chapter 1') sets the path to the folder
Chapter 1 in drive F. The following example shows how the current folder is
changed to be drive E. Then the script file from Figure 1-7, which was saved in
drive E as ProgramExample.m, is executed by typing the name of the file and
pressing the Enter key.
Figure 1-9: Changing the current directory.
Figure 1-10: The Current Folder Window.
>> cd E:
>> ProgramExample
x1 =
3.5000
x2 =
-1.2500
Current
folder
shown
here.
Click here
to change
the folder.
Click here
to browse
for a folder.
Click here to
go up one
level in the
file system.
The current directory is changed to drive E.
The script file is executed by typing the
name of the file and pressing the Enter key.
The output generated by the script file (the roots x1
and x2) is displayed in the Command Window.
35.
24 Chapter 1: Starting with MATLAB
1.9 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 1-1: Trigonometric identity
A trigonometric identity is given by:
Verify that the identity is correct by calculating each side of the equation, substi-
tuting .
Solution
The problem is solved by typing the following commands in the Command Win-
dow.
Sample Problem 1-2: Geometry and trigonometry
Four circles are placed as shown in the figure.
At each point where two circles are in contact
they are tangent to each other. Determine the
distance between the centers C2 and C4.
The radii of the circles are:
mm, mm, mm, and
mm.
Solution
The lines that connect the centers of the cir-
cles create four triangles. In two of the trian-
gles, C1C2C3 and C1C3C4, the lengths of all
the sides are known. This information is used to
calculate the angles 1 and 2 in these triangles by
using the law of cosines. For example, 1 is cal-
culated from:
>> x=pi/5;
>> LHS=cos(x/2)^2
LHS =
0.9045
>> RHS=(tan(x)+sin(x))/(2*tan(x))
RHS =
0.9045
x
2
---cos2 xtan xsin+
2 xtan
---------------------------=
x
5
---=
Define x.
Calculate the left-hand side.
Calculate the right-hand side.
R1 16= R2 6.5= R3 12=
R4 9.5=
36.
1.9 Examples of MATLAB Applications 25
Next, the length of the side C2C4 is calculated by considering the triangle
C1C2C4. This is done, again, by using the law of cosines (the lengths C1C2 and
C1C4 are known and the angle 3 is the sum of the angles 1 and 2).
The problem is solved by writing the following program in a script file:
When the script file is executed, the following (the value of the variable C2C4) is
displayed in the Command Window:
Sample Problem 1-3: Heat transfer
An object with an initial temperature of that is placed at time t = 0 inside a
chamber that has a constant temperature of will experience a temperature
change according to the equation
where T is the temperature of the object at time t, and k is a constant. A soda can at
a temperature of F (after being left in the car) is placed inside a refrigerator
where the temperature is F. Determine, to the nearest degree, the temperature
of the can after three hours. Assume k = 0.45. First define all of the variables and
then calculate the temperature using one MATLAB command.
Solution
The problem is solved by typing the following commands in the Command Win-
dow.
% Solution of Sample Problem 1-2
R1=16; R2=6.5; R3=12; R4=9.5;
C1C2=R1+R2; C1C3=R1+R3; C1C4=R1+R4;
C2C3=R2+R3; C3C4=R3+R4;
Gama1=acos((C1C2^2+C1C3^2-C2C3^2)/(2*C1C2*C1C3));
Gama2=acos((C1C3^2+C1C4^2-C3C4^2)/(2*C1C3*C1C4));
Gama3=Gama1+Gama2;
C2C4=sqrt(C1C2^2+C1C4^2-2*C1C2*C1C4*cos(Gama3))
C2C4 =
33.5051
C2C3
2 C1C2
2 C1C3
2 2 C1C2 C1C3 1cos–+=
Define the R's.
Calculate the
lengths of the sides.
Calculate 1, 2, and 3.
Calculate the length of
side C2C4.
T0
Ts
T Ts T0 Ts– e
kt–
+=
120
38
37.
26 Chapter 1: Starting with MATLAB
Sample Problem 1-4: Compounded interest
The balance B of a savings account after t years when a principal P is invested at
an annual interest rate r and the interest is compounded n times a year is given by:
(1)
If the interest is compounded yearly, the balance is given by:
(2)
Suppose $5,000 is invested for 17 years in one account where the interest is com-
pounded yearly. In addition, $5,000 is invested in a second account in which the
interest is compounded monthly. In both accounts the interest rate is 8.5%. Use
MATLAB to determine how long (in years and months) it would take for the bal-
ance in the second account to be the same as the balance of the first account after
17 years.
Solution
Follow these steps:
(a) Calculate B for $5,000 invested in a yearly compounded interest account after
17 years using Equation (2).
(b) Calculate t for the B calculated in part (a), from the monthly compounded
interest formula, Equation (1).
(c) Determine the number of years and months that correspond to t.
The problem is solved by writing the following program in a script file:
>> Ts=38; T0=120; k=0.45; t=3;
>> T=round(Ts+(T0-Ts)*exp(-k*t))
T =
59
% Solution of Sample Problem 1-4
P=5000; r=0.085; ta=17; n=12;
B=P*(1+r)^ta
t=log(B/P)/(n*log(1+r/n))
years=fix(t)
months=ceil((t-years)*12)
Round to the nearest integer.
B P 1
r
n
---+
nt
=
B P 1 r+ t=
Step (a): Calculate B from Eq. (2).
Step (b): Solve Eq. (1)
for t, and calculate t.
Step (c): Determine the number of years.
Determine the number of months.
40.
1.10 Problems 29
13. Two trigonometric identities are given by:
(a) (b)
For each part, verify that the identity is correct by calculating the values of the
left and right sides of the equation, substituting .
14. Define two variables: alpha = 5 /8, and beta = /8. Using these variables, show
that the following trigonometric identity is correct by calculating the values of
the left and right sides of the equation.
15. Given: . Use MATLAB to calculate the following
definite integral: .
16. In the triangle shown cm, cm, and
cm. Define a, b, and c as variables, and
then:
(a) Calculate the angle (in degrees) by substi-
tuting the variables in the Law of Cosines.
(Law of Cosines: )
(b) Calculate the angles and (in degrees)
using the Law of Sines.
(c) Check that the sum of the angles is .
17. In the triangle shown in., in., and .
Define a, b, and as variables, and then:
(a) Calculate the length of c by substituting the variables in
the Law of Cosines.
(Law of Cosines: )
(b) Calculate the angles and (in degrees) using the Law
of Sines.
(c) Verify the Law of Tangents by substituting the results
from part (b) into the right and left sides of the equation.
(Law of Tangents:
4xtan
4 xtan 4 xtan3–
1 6 xtan2– xtan4+
--------------------------------------------= xsin3 1
4
--- 3 xsin 3xsin–=
x 12=
cossin
1
2
--- –sin +sin+=
ax xdcos2 1
2
---x
2axsin
4a
-----------------–=
0.5x xdcos2
9
---
3
5
------
A
B
Ca
b
c
α
β
γ
a 9= b 18=
c 25=
c2 a2 b2 2abcos–+=
180
α
β
γ
a
b
c
A
B
Ca 5= b 7= 25=
c2 a2 b2 2abcos–+=
a b–
a b+
------------
1
2
--- –tan
1
2
--- +tan
-----------------------------------=
41.
30 Chapter 1: Starting with MATLAB
18. For the triangle shown, mm, mm,
and mm. Define a, b, and c as variables,
and then:
(a) Calculate the angle (in degrees) by substituting
the variables in the Law of Cosines.
(Law of Cosines: )
(b) Calculate the radius r of the circle inscribed in
the triangle using the formula .
(c) Calculate the radius r of the circle inscribed in the triangle using the for-
mula , where .
19. In the right triangle shown cm and cm.
Define a and c as variables, and then:
(a) Using the Pythagorean Theorem, calculate b by
typing one line in the Command Window.
(b) Using b from part (a) and the acosd function,
calculate the angle in degrees by typing one line
in the Command Window.
20. The distance d from a point to a plane is
given by:
Determine the distance of the point from the plane
. First define the variables A, B, C, D, x0, y0, and z0,
and then calculate d. (Use the abs and sqrt functions.)
21. The arc length s of the parabolic segment BOC is given
by:
Calculate the arc length of a parabola with in.
and in.
22. Oranges are packed such that 52 are placed in each box. Determine how many
boxes are needed to pack 4,000 oranges. Use MATLAB built-in function
ceil.
α
β
γ a
b
c
r
a 200= b 250=
c 300=
c2 a2 b2 2abcos–+=
r
1
2
--- a b c–+
1
2
---tan=
r
s s a– s b– s c–
s
-------------------------------------------------------= s
1
2
--- a b c+ +=
a
b
c
a 16= c 50=
x0 y0 z0 Ax By Cz D+ + + 0=
d
Ax0 By0 Cz0 D+ + +
A2 B2 C2+ +
-----------------------------------------------------=
8 3 10–
2x 23y 13z 24–+ + 0=
b
a
B
O
C
s
1
2
--- b2 16a2+
b2
8a
------
4a b2 16a2++
b
----------------------------------------ln+=
a 12=
b 8=
42.
1.10 Problems 31
23. The voltage difference between points a
and b in the Wheatstone bridge circuit is:
Calculate the voltage difference when
volts, ohms, ohms,
ohms, and ohms.
24. The prices of an oak tree and a pine tree are $54.95 and $39.95, respectively.
Assign the prices to variables named oak and pine, change the display format
to bank, and calculate the following by typing one command:
(a) The total cost of 16 oak trees and 20 pine trees.
(b) The same as part (a), and add 6.25% sale tax.
(c) The same as part (b) and round the total cost to the nearest dollar.
25. The resonant frequency f (in Hz) for the circuit
shown is given by:
Calculate the resonant frequency when
henrys, ohms, ohms,
and farads.
26. The number of combinations of taking r objects out of n objects is given
by:
A deck of poker cards has 52 different cards. Determine how many different
combinations are possible for selecting 5 cards from the deck. (Use the built-
in function factorial.)
27. The formula for changing the base of a logarithm is:
(a) Use MATLAB's function log(x) to calculate .
(b) Use MATLAB's function log10(x) to calculate .
+V
R1
R3
R4R2
a b
Vab
Vab V
R2
R1 R2+
------------------
R4
R3 R4+
------------------–=
V 12=
R1 120= R2 100=
R3 220= R4 120=
V
R1 R2
L C
f
1
2
------ LC
R1
2C L–
R2
2C L–
--------------------=
L 0.2= R1 1500= R2 1500=
C 2 10 6–=
Cn r
Cn r
n!
r! n r– !
----------------------=
aNlog bNlog
balog
---------------=
4 0.085log
6
1500log
43.
32 Chapter 1: Starting with MATLAB
28. The current I (in amps) t seconds after closing the
switch in the circuit shown is:
Given volts, ohms, and
henrys, calculate the current 0.003 seconds
after the switch is closed.
29. Radioactive decay of carbon-14 is used for estimating the age of organic
material. The decay is modeled with the exponential function ,
where t is time, is the amount of material at , is the amount of
material at time t, and k is a constant. Carbon-14 has a half-life of approxi-
mately 5,730 years. A sample of paper taken from the Dead Sea Scrolls shows
that 78.8% of the initial ( ) carbon-14 is present. Determine the esti-
mated age of the scrolls. Solve the problem by writing a program in a script
file. The program first determines the constant k, then calculates t for
, and finally rounds the answer to the nearest year.
30. Fractions can be added by using the smallest common denominator. For
example, the smallest common denominator of 1/4 and 1/10 is 20. Use the
MATLAB Help Window to find a MATLAB built-in function that determines
the least common multiple of two numbers. Then use the function to show
that the least common multiple of:
(a) 6 and 26 is 78.
(b) 6 and 34 is 102.
31. The Moment Magnitude Scale (MMS), denoted , which is used to mea-
sure the size of an earthquake, is given by:
where is the magnitude of the seismic moment in dyne-cm (measure of
the energy released during an earthquake). Determine how many times more
energy was released from the earthquake in Sumatra, Indonesia ( ),
in 2007 than the earthquake in San Francisco, California ( ), in 1906.
32. According to special relativity, a rod of length L moving at velocity v will
shorten by an amount , given by:
where c is the speed of light (about m/s). Calculate how much a rod
2 meter long will contract when traveling at 5,000 m/s.
V +
L
R
I
V
R
--- 1 e R L t––=
V 120= R 240=
L 0.5=
f t f 0 ekt=
f 0 t 0= f t
t 0=
f t 0.788f 0=
MW
MW
2
3
--- 10
M0log 10.7–=
M0
MW 8.5=
MW 7.9=
L 1 1
v2
c2
-----––=
300 106
44.
1.10 Problems 33
33. The monthly payment M of a loan amount P for y years and interest rate r can
be calculated by the formula:
(a) Calculate the monthly payment of a $85,000 loan for 15 years and interest
rate of 5.75% ( ). Define the variables P, r, and y and use them
to calculate M.
(b) Calculate the total amount needed for paying back the loan.
34. The balance B of a savings account after t years when a principal P is invested
at an annual interest rate r and the interest is compounded yearly is given by
. If the interest is compounded continuously, the balance is
given by . An amount of $40,000 is invested for 20 years in an
account that pays 5.5% interest and the interest is compounded yearly. Use
MATLAB to determine how many fewer days it will take to earn the same if
the money is invested in an account where the interest is compounded contin-
uously.
35. The temperature dependence of vapor pressure p can be estimated by the
Anteing equation:
where ln is the natural logarithm, p is in mm Hg, T is in kelvins, and A, B, and
C are material constants. For toluene (C6H5CH3) in the temperature range
from 280 to 410 K the material constants are , , and
. Calculate the vapor pressure of toluene at 315 and 405 K.
36. Sound level in units of decibels (dB) is determined by:
where p is the sound pressure of the sound, and Pa is a refer-
ence sound pressure (the sound pressure when dB).
(a) The sound pressure of a passing car is Pa. Determine its sound
level in decibels.
(b) The sound level of a jet engine is 110 decibels. By how many times is the
sound pressure of the jet engine larger (louder) than the sound of the pass-
ing car?
M
P r 12
1 1 r 12+ 12y––
--------------------------------------------=
r 0.0575=
B P 1 r+ t=
B Pert=
pln A B
C T+
-------------–=
A 16.0137= B 3096.52=
C 53.67–=
LP
LP 20
10
p
p
0
-----log=
p0
20 10 6–=
LP 0=
80 10 2–
46.
35
Chapter 2
Creating Arrays
The array is a fundamental form that MATLAB uses to store and manipulate data.
An array is a list of numbers arranged in rows and/or columns. The simplest array
(one-dimensional) is a row or a column of numbers. A more complex array (two-
dimensional) is a collection of numbers arranged in rows and columns. One use of
arrays is to store information and data, as in a table. In science and engineering,
one-dimensional arrays frequently represent vectors, and two-dimensional arrays
often represent matrices. This chapter shows how to create and address arrays, and
Chapter 3 shows how to use arrays in mathematical operations. In addition to
arrays made of numbers, arrays in MATLAB can also be a list of characters,
which are called strings. Strings are discussed in Section 2.10.
2.1 CREATING A ONE-DIMENSIONAL ARRAY (VECTOR)
A one-dimensional array is a list of numbers arranged in a row or a column. One
example is the representation of the position of a point in space in a three-dimen-
sional Cartesian coordinate system. As shown in Figure 2-1, the position of point
A is defined by a list of the three numbers 2, 4, and 5, which are the coordinates of
the point.
The position of point A can be
expressed in terms of a position vector:
rA = 2i + 4j +5k
where i, j, and k are unit vectors in the
direction of the x, y, and z axes, respec-
tively. The numbers 2, 4, and 5 can be
used to define a row or a column vector.
Any list of numbers can be set up
as a vector. For example, Table 2-1 con-
tains population growth data that can be
used to create two lists of numbers—one
of the years and the other of the popula-
tion values. Each list can be entered as elements in a vector with the numbers
placed in a row or in a column.
x
y
z
A (2, 4, 5)
2
4
5
Figure 2-1: Position of a point.
47.
36 Chapter 2: Creating Arrays
In MATLAB, a vector is created by assigning the elements of the vector to a
variable. This can be done in several ways depending on the source of the infor-
mation that is used for the elements of the vector. When a vector contains specific
numbers that are known (like the coordinates of point A), the value of each ele-
ment is entered directly. Each element can also be a mathematical expression that
can include predefined variables, numbers, and functions. Often, the elements of a
row vector are a series of numbers with constant spacing. In such cases the vector
can be created with MATLAB commands. A vector can also be created as the
result of mathematical operations as explained in Chapter 3.
Creating a vector from a known list of numbers:
The vector is created by typing the elements (numbers) inside square brackets [ ].
Row vector: To create a row vector type the elements with a space or a comma
between the elements inside the square brackets.
Column vector: To create a column vector type the left square bracket [ and then
enter the elements with a semicolon between them, or press the Enter key after
each element. Type the right square bracket ] after the last element.
Tutorial 2-1 shows how the data from Table 2-1 and the coordinates of point
A are used to create row and column vectors.
Table 2-1: Population data
Year 1984 1986 1988 1990 1992 1994 1996
Population
(millions)
127 130 136 145 158 178 211
Tutorial 2-1: Creating vectors from given data.
>> yr=[1984 1986 1988 1990 1992 1994 1996]
yr =
1984 1986 1988 1990 1992 1994 1996
>> pop=[127; 130; 136; 145; 158; 178; 211]
pop =
127
130
136
145
158
variable_name = [ type vector elements ]
The list of years is assigned to a row vector named yr.
The population data is assigned
to a column vector named pop.
48.
2.1 Creating a One-Dimensional Array (Vector) 37
Creating a vector with constant spacing by specifying the first term, the spac-
ing, and the last term:
In a vector with constant spacing the difference between the elements is the same.
For example, in the vector v = 2 4 6 8 10, the spacing between the elements is
2. A vector in which the first term is m, the spacing is q, and the last term is n is
created by typing:
Some examples are:
178
211
>> pntAH=[2, 4, 5]
pntAH =
2 4 5
>> pntAV=[2
4
5]
pntAV =
2
4
5
>>
>> x=[1:2:13]
x =
1 3 5 7 9 11 13
>> y=[1.5:0.1:2.1]
y =
1.5000 1.6000 1.7000 1.8000 1.9000 2.0000 2.1000
>> z=[-3:7]
z =
-3 -2 -1 0 1 2 3 4 5 6
7
>> xa=[21:-3:6]
Tutorial 2-1: Creating vectors from given data. (Continued)
The coordinates of point A
are assigned to a row vector
called pntAH.
The coordinates of point A are assigned
to a column vector called pntAV.
(The Enter key is pressed after each
element is typed.)
variable_name = [m:q:n] variable_name = m:q:nor
(The brackets are optional.)
First element 1, spacing 2, last element 13.
First element 1.5, spacing 0.1, last element 2.1.
First element –3, last term 7.
If spacing is omitted, the default is 1.
First element 21, spacing –3, last term 6.
49.
38 Chapter 2: Creating Arrays
• If the numbers m, q, and n are such that the value of n cannot be obtained by
adding q's to m, then (for positive n) the last element in the vector will be the
last number that does not exceed n.
• If only two numbers (the first and the last terms) are typed (the spacing is omit-
ted), then the default for the spacing is 1.
Creating a vector with linear (equal) spacing by specifying the first and last
terms, and the number of terms:
A vector with n elements that are linearly (equally) spaced in which the first ele-
ment is xi and the last element is xf can be created by typing the linspace com-
mand (MATLAB determines the correct spacing):
When the number of elements is omitted, the default is 100. Some examples are:
xa =
21 18 15 12 9 6
>>
>> va=linspace(0,8,6)
va =
0 1.6000 3.2000 4.8000 6.4000 8.0000
>> vb=linspace(30,10,11)
vb =
30 28 26 24 22 20 18 16 14 12 10
>> u=linspace(49.5,0.5)
u =
Columns 1 through 10
49.5000 49.0051 48.5101 48.0152 47.5202 47.0253
46.5303 46.0354 45.5404 45.0455
............
Columns 91 through 100
4.9545 4.4596 3.9646 3.4697 2.9747 2.4798
1.9848 1.4899 0.9949 0.5000
>>
variable_name = linspace(xi,xf,n)
First
element
Last
element
Number of
elements
6 elements, first element 0, last element 8.
11 elements, first element 30, last element 10.
When the number of elements is
omitted, the default is 100.
First element 49.5, last element 0.5.
100 elements are displayed.
50.
2.2 Creating a Two-Dimensional Array (Matrix) 39
2.2 CREATING A TWO-DIMENSIONAL ARRAY (MATRIX)
A two-dimensional array, also called a matrix, has numbers in rows and columns.
Matrices can be used to store information like the arrangement in a table. Matrices
play an important role in linear algebra and are used in science and engineering to
describe many physical quantities.
In a square matrix the number of rows and the number of columns is equal.
For example, the matrix
7 4 9
3 8 1 matrix
6 5 3
is square, with three rows and three columns. In general, the number of rows and
columns can be different. For example, the matrix:
31 26 14 18 5 30
3 51 20 11 43 65 matrix
28 6 15 61 34 22
14 58 6 36 93 7
has four rows and six columns. A matrix has m rows and n columns, and m
by n is called the size of the matrix.
A matrix is created by assigning the elements of the matrix to a variable.
This is done by typing the elements, row by row, inside square brackets [ ]. First
type the left bracket [ then type the first row, separating the elements with spaces
or commas. To type the next row type a semicolon or press Enter. Type the right
bracket ] at the end of the last row.
The elements that are entered can be numbers or mathematical expressions that
may include numbers, predefined variables, and functions. All the rows must have
the same number of elements. If an element is zero, it has to be entered as such.
MATLAB displays an error message if an attempt is made to define an incomplete
matrix. Examples of matrices defined in different ways are shown in Tutorial 2-2.
Tutorial 2-2: Creating matrices.
>> a=[5 35 43; 4 76 81; 21 32 40]
a =
5 35 43
4 76 81
21 32 40
>> b = [7 2 76 33 8
1 98 6 25 6
5 54 68 9 0]
3 3
4 6
m n
variable_name=[1st row elements; 2nd row elements; 3rd
row elements; ... ; last row elements]
A semicolon is typed before
a new line is entered.
The Enter key is pressed
before a new line is entered.
51.
40 Chapter 2: Creating Arrays
Rows of a matrix can also be entered as vectors using the notation for creat-
ing vectors with constant spacing, or the linspace command. For example:
In this example the first two rows were entered as vectors using the notation of
constant spacing, the third row was entered using the linspace command, and
in the last row the elements were entered individually.
2.2.1 The zeros, ones and, eye Commands
The zeros(m,n), ones(m,n), and eye(n) commands can be used to create
matrices that have elements with special values. The zeros(m,n) and the
ones(m,n) commands create a matrix with m rows and n columns in which all
elements are the numbers 0 and 1, respectively. The eye(n) command creates a
square matrix with n rows and n columns in which the diagonal elements are equal
to 1 and the rest of the elements are 0. This matrix is called the identity matrix.
Examples are:
b =
7 2 76 33 8
1 98 6 25 6
5 54 68 9 0
>> cd=6; e=3; h=4;
>> Mat=[e, cd*h, cos(pi/3); h^2, sqrt(h*h/cd), 14]
Mat =
3.0000 24.0000 0.5000
16.0000 1.6330 14.0000
>>
>> A=[1:2:11; 0:5:25; linspace(10,60,6); 67 2 43 68 4 13]
A =
1 3 5 7 9 11
0 5 10 15 20 25
10 20 30 40 50 60
67 2 43 68 4 13
>>
>> zr=zeros(3,4)
zr =
0 0 0 0
0 0 0 0
0 0 0 0
>> ne=ones(4,3)
Tutorial 2-2: Creating matrices. (Continued)
Three variables are defined.
Elements are defined
by mathematical
expressions.
52.
2.3 Notes About Variables in MATLAB 41
Matrices can also be created as a result of mathematical operations with
vectors and matrices. This topic is covered in Chapter 3.
2.3 NOTES ABOUT VARIABLES IN MATLAB
• All variables in MATLAB are arrays. A scalar is an array with one element, a
vector is an array with one row or one column of elements, and a matrix is an
array with elements in rows and columns.
• The variable (scalar, vector, or matrix) is defined by the input when the vari-
able is assigned. There is no need to define the size of the array (single element
for a scalar, a row or a column of elements for a vector, or a two-dimensional
array of elements for a matrix) before the elements are assigned.
• Once a variable exists—as a scalar, vector, or matrix—it can be changed to any
other size, or type, of variable. For example, a scalar can be changed to a vec-
tor or a matrix; a vector can be changed to a scalar, a vector of different length,
or a matrix; and a matrix can be changed to have a different size, or be reduced
to a vector or a scalar. These changes are made by adding or deleting elements.
This subject is covered in Sections 2.7 and 2.8.
2.4 THE TRANSPOSE OPERATOR
The transpose operator, when applied to a vector, switches a row (column) vector
to a column (row) vector. When applied to a matrix, it switches the rows (col-
umns) to columns (rows). The transpose operator is applied by typing a single
quote ' following the variable to be transposed. Examples are:
ne =
1 1 1
1 1 1
1 1 1
1 1 1
>> idn=eye(5)
idn =
1 0 0 0 0
0 1 0 0 0
0 0 1 0 0
0 0 0 1 0
0 0 0 0 1
>>
>> aa=[3 8 1]
aa =
3 8 1
>> bb=aa'
Define a row vector aa.
Define a column vector bb as
the transpose of vector aa.
53.
42 Chapter 2: Creating Arrays
2.5 ARRAY ADDRESSING
Elements in an array (either vector or matrix) can be addressed individually or in
subgroups. This is useful when there is a need to redefine only some of the ele-
ments, when specific elements are to be used in calculations, or when a subgroup
of the elements is used to define a new variable.
2.5.1 Vector
The address of an element in a vector is its position in the row (or column). For a
vector named ve, ve(k) refers to the element in position k. The first position is
1. For example, if the vector ve has nine elements:
ve = 35 46 78 23 5 14 81 3 55
then
ve(4) = 23, ve(7) = 81, and ve(1) = 35.
A single vector element, v(k), can be used just as a variable. For example, it
is possible to change the value of only one element of a vector by assigning a new
value to a specific address. This is done by typing: v(k) = value. A single element
can also be used as a variable in a mathematical expression. Examples are:
bb =
3
8
1
>> C=[2 55 14 8; 21 5 32 11; 41 64 9 1]
C =
2 55 14 8
21 5 32 11
41 64 9 1
>> D=C'
D =
2 21 41
55 5 64
14 32 9
8 11 1
>>
>> VCT=[35 46 78 23 5 14 81 3 55]
VCT =
35 46 78 23 5 14 81 3 55
>> VCT(4)
Define a matrix C
with 3 rows and 4
columns.
Define a matrix D as the
transpose of matrix C. (D has
4 rows and 3 columns.)
Define a vector.
Display the fourth element.
54.
2.5 Array Addressing 43
2.5.2 Matrix
The address of an element in a matrix is its position, defined by the row number
and the column number where it is located. For a matrix assigned to a variable ma,
ma(k,p) refers to the element in row k and column p.
For example, if the matrix is:
then ma(1,1) = 3 and ma(2,3) = 10.
As with vectors, it is possible to change the value of just one element of a
matrix by assigning a new value to that element. Also, single elements can be used
like variables in mathematical expressions and functions. Some examples are:
ans =
23
>> VCT(6)=273
VCT =
35 46 78 23 5 273 81 3 55
>> VCT(2)+VCT(8)
ans =
49
>> VCT(5)^VCT(8)+sqrt(VCT(7))
ans =
134
>>
>> MAT=[3 11 6 5; 4 7 10 2; 13 9 0 8]
MAT =
3 11 6 5
4 7 10 2
13 9 0 8
>> MAT(3,1)=20
MAT =
3 11 6 5
4 7 10 2
20 9 0 8
>> MAT(2,4)-MAT(1,2)
ans =
-9
Assign a new value to
the sixth element.
The whole vector is displayed.
Use the vector elements in
mathematical expressions.
ma
3 11 6 5
4 7 10 2
13 9 0 8
=
Create a matrix.3 4
Assign a new value to the (3,1) element.
Use elements in a mathematical expression.
55.
44 Chapter 2: Creating Arrays
2.6 USING A COLON : IN ADDRESSING ARRAYS
A colon can be used to address a range of elements in a vector or a matrix.
For a vector:
va(:) Refers to all the elements of the vector va (either a row or a column vector).
va(m:n) Refers to elements m through n of the vector va.
Example:
For a matrix:
A(:,n) Refers to the elements in all the rows of column n of the matrix A.
A(n,:) Refers to the elements in all the columns of row n of the matrix A.
A(:,m:n) Refers to the elements in all the rows between columns m and n of the
matrix A.
A(m:n,:) Refers to the elements in all the columns between rows m and n of the
matrix A.
A(m:n,p:q) Refers to the elements in rows m through n and columns p through
q of the matrix A.
The use of the colon symbol in addressing elements of matrices is demon-
strated in Tutorial 2-3.
>> v=[4 15 8 12 34 2 50 23 11]
v =
4 15 8 12 34 2 50 23 11
>> u=v(3:7)
u =
8 12 34 2 50
>>
Tutorial 2-3: Using a colon in addressing arrays.
>> A=[1 3 5 7 9 11; 2 4 6 8 10 12; 3 6 9 12 15 18; 4 8 12 16
20 24; 5 10 15 20 25 30]
A =
1 3 5 7 9 11
2 4 6 8 10 12
3 6 9 12 15 18
4 8 12 16 20 24
5 10 15 20 25 30
>> B=A(:,3)
A vector v is created.
A vector u is created from the ele-
ments 3 through 7 of vector v.
Define a matrix A with
5 rows and 6 columns.
Define a column
vector B from the
elements in all of the
rows of column 3 in
matrix A.
57.
46 Chapter 2: Creating Arrays
2.7 ADDING ELEMENTS TO EXISTING VARIABLES
A variable that exists as a vector, or a matrix, can be changed by adding elements
to it (remember that a scalar is a vector with one element). A vector (a matrix with
a single row or column) can be changed to have more elements, or it can be
changed to be a two-dimensional matrix. Rows and/or columns can also be added
to an existing matrix to obtain a matrix of different size. The addition of elements
can be done by simply assigning values to the additional elements, or by append-
ing existing variables.
Adding elements to a vector:
Elements can be added to an existing vector by assigning values to the new ele-
ments. For example, if a vector has 4 elements, the vector can be made longer by
assigning values to elements 5, 6, and so on. If a vector has n elements and a new
value is assigned to an element with an address of or larger, MATLAB
assigns zeros to the elements that are between the last original element and the
new element. Examples:
Elements can also be added to a vector by appending existing vectors. Two exam-
ples are:
B =
10 8 6 5 4
2 6 10 12 14
>> DF=1:4
DF =
1 2 3 4
>> DF(5:10)=10:5:35
DF =
1 2 3 4 10 15 20 25 30 35
>> AD=[5 7 2]
AD =
5 7 2
>> AD(8)=4
AD =
5 7 2 0 0 0 0 4
>> AR(5)=24
AR =
0 0 0 0 24
>>
>> RE=[3 8 1 24];
n 2+
Define vector DF with 4 elements.
Adding 6 elements starting with the 5th.
Define vector AD with 3 elements.
Assign a value to the 8th element.
MATLAB assigns zeros to
the 4th through 7th elements.
Assign a value to the 5th element of a new vector.
MATLAB assigns zeros to the
1st through 4th elements.
Define vector RE with 4 elements.
64.
2.10 Strings and Strings as Variables 53
2.10 STRINGS AND STRINGS AS VARIABLES
• A string is an array of characters. It is created by typing the characters within
single quotes.
• Strings can include letters, digits, other symbols, and spaces.
• Examples of strings: 'ad ef ', '3%fr2', '{edcba:21!', 'MATLAB'.
• A string that contains a single quote is created by typing two single quotes
within the string.
• When a string is being typed in, the color of the text on the screen changes to
maroon when the first single quote is typed. When the single quote at the end
of the string is typed, the color of the string changes to purple.
Strings have several different uses in MATLAB. They are used in output
commands to display text messages (Chapter 4), in formatting commands of plots
(Chapter 5), and as input arguments of some functions (Chapter 7). More details
are given in these chapters when strings are used for these purposes.
• When strings are being used in formatting plots (labels to axes, title, and text
notes), characters within the string can be formatted to have a specified font,
size, position (uppercase, lowercase), color, etc. See Chapter 5 for details.
Strings can also be assigned to variables by simply typing the string on the
right side of the assignment operator, as shown in the examples below:
When a variable is defined as a string, the characters of the string are stored
in an array just as numbers are. Each character, including a space, is an element in
the array. This means that a one-line string is a row vector in which the number of
elements is equal to the number of characters. The elements of the vectors are
A =
2 5 5 10 15 20
3 6 9 12 15 18
4 7 30 35 40 45
5 8 95 94 93 92
6 9 60 65 70 75
>> a='FRty 8'
a =
FRty 8
>> B='My name is John Smith'
B =
My name is John Smith
>>
65.
54 Chapter 2: Creating Arrays
addressed by position. For example, in the vector B that was defined above the 4th
element is the letter n, the 12th element is J, and so on.
As with a vector that contains numbers, it is also possible to change specific
elements by addressing them directly. For example, in the vector B above the
name John can be changed to Bill by:
Strings can also be placed in a matrix. As with numbers, this is done by typ-
ing a semicolon ; (or pressing the Enter key) at the end of each row. Each row
must be typed as a string, which means that it must be enclosed in single quotes.
In addition, as with a numerical matrix, all rows must have the same number of
elements. This requirement can cause problems when the intention is to create
rows with specific wording. Rows can be made to have the same number of ele-
ments by adding spaces.
MATLAB has a built-in function named char that creates an array with
rows having the same number of characters from an input of rows not all of the
same length. MATLAB makes the length of all the rows equal to that of the long-
est row by adding spaces at the end of the short lines. In the char function, the
rows are entered as strings separated by a comma according to the following for-
mat:
For example:
>> B(4)
ans =
n
>> B(12)
ans =
J
>> B(12:15)='Bill'
B =
My name is Bill Smith
>>
>> Info=char('Student Name:','John Smith','Grade:','A+')
Info =
Student Name:
John Smith
Grade:
A+
>>
Using a colon to assign new char-
acters to elements 12 through 15 in
the vector B.
variable_name = char('string 1','string 2','string 3')
A variable named Info is assigned four rows
of strings, each with different length.
The function char creates an array with four rows
with the same length as the longest row by adding
empty spaces to the shorter lines.
66.
2.11 Problems 55
A variable can be defined as either a number or a string made up of the
same digits. For example, as shown below, x is defined to be the number 536, and
y is defined to be a string made up of the digits 536.
The two variables are not the same even though they appear identical on the
screen. Note that the characters 536 in the line below the x= are indented, while
the characters 536 in the line below the y= are not indented. The variable x can be
used in mathematical expressions, while the variable y cannot.
2.11 PROBLEMS
1. Create a row vector that has the following elements: 3, , , 45,
, , and 0.05.
2. Create a row vector that has the following elements: , 32, ,
54, , and .
3. Create a column vector that has the following elements: 25.5, ,
, , 0.0375, and .
4. Create a column vector that has the following elements: , , 6.1,
, 0.00552, , and 133.
5. Define the variables , , and then use them to create a col-
umn vector that has the following elements: , , , , and .
6. Define the variables , , and then use them to create a row
vector that has the following elements: , , , , and .
7. Create a row vector in which the first element is 2 and the last element is 37,
with an increment of 5 between the elements (2, 7, 12, … , 37).
>> x=536
x =
536
>> y='536'
y =
536
>>
4 2.55 68 16
1103 25cos
54
3 4.22+
------------------- 6.32 7.22–
e3.7 66sin
3
8
------cos+
14 58tan
2.12 11+
----------------------------
6! 2.74 5
32
3.22
--------- 35sin2
292ln 29ln2
x 0.85= y 12.5=
y yx y xln y x x y+
a 3.5= b 6.4–=
a a2 a b a b a
67.
56 Chapter 2: Creating Arrays
8. Create a row vector with 9 equally spaced elements in which the first element
is 81 and the last element is 12.
9. Create a column vector in which the first element is 22.5, the elements
decrease with increments of –2.5, and the last element is 0. (A column vector
can be created by the transpose of a row vector.)
10. Create a column vector with 15 equally spaced elements in which the first ele-
ment is –21 and the last element is 12.
11. Using the colon symbol, create a row vector (assign it to a variable named
same) with seven elements that are all –3.
12. Use a single command to create a row vector (assign it to a variable named a)
with 9 elements such that the last element is 7.5 and the rest of the elements
are 0s. Do not type the vector explicitly.
13. Use a single command to create a row vector (assign it to a variable named b)
with 19 elements such that
b = 1 2 3 4 5 6 7 8 9 10 9 8 7 6 5 4 3 2 1
Do not type the vector explicitly.
14. Create a vector (name it vecA) that has 14 elements of which the first is 49,
the increment is –3, and the last element is 10. Then, using the colon symbol,
create a new vector (call it vecB) that has 8 elements. The first 4 elements are
the first 4 elements of the vector vecA, and the last 4 are the last 4 elements
of the vector vecA.
15. Create a vector (name it vecC) that has 16 elements of which the first is 13,
the increment is 4 and the last element is 73. Then create the following two
vectors:
(a) A vector (name it Codd) that contains all the elements with odd index of
vecCodd (vecCodd(1), vecCodd(3), etc; i.e., Codd = 13 21 29 ...
69).
(b) A vector (name it Ceven) that contains all the elements with even index
of vecCodd (vecCodd(2), vecCodd(4), etc; i.e., Codd = 17 25 33
... 73).
In both parts use vectors of odd and even numbers for the index of Codd and
Ceven, respectively. Do not type the vectors explicitly.
69.
58 Chapter 2: Creating Arrays
22. Create the following matrix by typing one command. Do not type individual
elements explicitly.
23. Create three row vectors:
, ,
(a) Use the three vectors in a MATLAB command to create a matrix in
which the rows are the vectors a, b, and c.
(b) Use the three vectors in a MATLAB command to create a matrix in
which the columns are the vectors a, b, and c.
24. Create three row vectors:
, ,
(a) Use the three vectors in a MATLAB command to create a matrix
such that the first, second, and third rows consist of the first three ele-
ments of the vectors a, b, and c, respectively.
(b) Use the three vectors in a MATLAB command to create a matrix
such that the first, second, and third columns consist of the last three ele-
ments of the vectors a, b, and c, respectively.
25. Create two row vectors:
,
(a) Use the two vectors in a MATLAB command to create a matrix
such that the first row consists of elements 2 through 5 of vector a, and the
second row consists of elements 3 through 6 of vector b.
(b) Use the two vectors in a MATLAB command to create a matrix
such that the first column consists of elements 2 through 4 of vector a, the
second column consists of elements 4 through 6 of vector a, the third col-
umn consists of elements 1 through 3 of vector b, and the fourth column
consists of elements 3 through 5 of vector b.
26. By hand (pencil and paper) write what will be displayed if the following com-
mands are executed by MATLAB. Check your answers by executing the com-
mands with MATLAB. (Parts (b), (c), and (d) use the vector that was defined
in part (a).)
(a) a=9:-3:0 (b) b=[a a] or b=[a,a] (c) c=[a;a]
(d) d=[a' a'] or d=[a',a'] (e) e=[[a; a; a; a] a']
F
0 0 0 0 0
0 0 1 10 20
0 0 2 8 26
0 0 3 6 32
=
a 7 2 3– 1 0= b 3– 10 0 7 2–= c 1 0 4 6– 5=
3 5
5 3
a 7 2 3– 1 0= b 3– 10 0 7 2–= c 1 0 4 6– 5=
3 3
3 3
a 4– 10 0.5 1.8 2.3– 7= b 0.7 9 5– 3 0.6– 12=
2 4
3 4
70.
2.11 Problems 59
27=v(2:5) (b) b=v([1,3:7,11]) (c) c=v([10,2,9,4])
28=[v([2 7:10]);v([3,5:7,2])]
(b) b=[v([3:5,8])' v([10 6 4 1])' v(7:-1:4)']
29. Create the following matrix A.
Use the matrix A to:
(a) Create a six-element row vector named ha that contains the elements of
the first row of A.
(b) Create a three-element row vector named hb that contains the elements of
the sixth column of A.
(c) Create a six-element row vector named hc that contains the first three
elements of the second row of A and the last three element of the third row
of A.
30. Create the following matrix B.
Use the matrix B to:
(a) Create a six-element column vector named va that contains the elements
of the second and fifth columns of B.
(b) Create a seven-element column vector named vb that contains elements 3
through 6 of the third row of B and the elements of the second column of B.
(c) Create a nine-element column vector named vc that contains the ele-
ments of the second, fourth, and sixth columns of B.
v 15 0 6 2– 3 5– 4 9 1.8 0.35– 7=
v 15 0 6 2– 3 5– 4 9 1.8 0.35– 7=
A
1 2 3 4 5 6
7 8 9 10 11 12
13 14 15 16 17 18
=
B
18 17 16 15 14 13
12 11 10 9 8 7
6 5 4 3 2 1
=
71.
60 Chapter 2: Creating Arrays
31. Create the following vector C.
Then use MATLAB's built-in reshape function and the transpose operation
to create the following matrix D from the vector C:
Use the matrix D to:
(a) Create a nine-element column vector named ua that contains the ele-
ments of the first, third, and fourth columns of D.
(b) Create an eight-element raw vector named ub that contains the elements
of the second row of D and the third column of D.
(c) Create a six-element row vector named uc that contains the first three ele-
ments of the first row of D and the last three elements of the last row of D.
32. Create the following matrix E.
(a) Create a matrix F from the second and fourth rows, and the third
through the seventh columns of matrix E.
(b) Create a matrix G from all rows and the third through fifth columns
of matrix E.
33. Create the following matrix H.
(a) Create a matrix G such that its first row includes the first two ele-
ments and the last two elements of the first row of H, and the second row
of G includes the second through the fifth elements of the third row of H.
(b) Create a matrix K such that the first, second, and third rows are the
first, fourth, and sixth columns of matrix H.
C 0.7 1.9 3.1 4.3 5.5 6.7 7.9 9.1 10.3 11.5 12.7 13.9 15.1 16.3 17.5=
D
0.7 1.9 3.1 4.3 5.5
6.7 7.9 9.1 10.3 11.5
12.7 13.9 15.1 16.3 17.5
=
E
0 0 0 0 2 2 2
0.7 0.6 0.5 0.4 0.3 0.2 0.1
2 4 6 8 10 12 14
22 19 16 13 10 7 4
=
2 5
4 3
H
1.7 1.6 1.5 1.4 1.3 1.2
22 24 26 28 30 32
9 8 7 6 5 4
=
2 4
3 3
74.
63
Chapter 3
Mathematical
Operations with Arrays
Once variables are created in MATLAB they can be used in a wide variety of
mathematical operations. In Chapter 1 the variables that were used in mathemati-
cal operations were all defined as scalars. This means that they were all
arrays (arrays with one row and one column that have only one element) and the
mathematical operations were done with single numbers. Arrays, however, can be
one-dimensional (arrays with one row, or with one column), two-dimensional
(arrays with multiple rows and columns), and even of higher dimensions. In these
cases the mathematical operations are more complex. MATLAB, as its name indi-
cates, is designed to carry out advanced array operations that have many applica-
tions in science and engineering. This chapter presents the basic, most common
mathematical operations that MATLAB performs using arrays.
Addition and subtraction are relatively simple operations and are covered
first, in Section 3.1. The other basic operations—multiplication, division, and
exponentiation—can be done in MATLAB in two different ways. One way, which
uses the standard symbols (*, /, and ^), follows the rules of linear algebra and is
presented in Sections 3.2 and 3.3. The second way, which is called element-by-
element operations, is covered in Section 3.4. These operations use the symbols
.*, ./, and .^ (a period is typed in front of the standard operation symbol). In addi-
tion, in both types of calculations, MATLAB has left division operators ( . or ),
which are also explained in Sections 3.3 and 3.4.
A Note to First-Time Users of MATLAB:
Although matrix operations are presented first and element-by-element operations
next, the order can be reversed since the two are independent of each other. It is
expected that almost every MATLAB user has some knowledge of matrix opera-
tions and linear algebra, and thus will be able to follow the material covered in
Sections 3.2 and 3.3 without any difficulty. Some readers, however, might prefer
to read Section 3.4 first. MATLAB can be used with element-by-element opera-
tions in numerous applications that do not require linear algebra multiplication (or
division) operations.
1 1
77.
66 Chapter 3: Mathematical Operations with Arrays
The product of the multiplication of two square matrices (they must be of the
same size) is a square matrix of the same size. However, the multiplication of
matrices is not commutative. This means that if A and B are both , then
A* *A. Also, the power operation can be executed only with a square matrix
(since A*A can be carried out only if the number of columns in the first matrix is
equal to the number of rows in the second matrix).
Two vectors can be multiplied only if they have the same number of elements,
and one is a row vector and the other is a column vector. The multiplication of a
row vector by a column vector gives a matrix, which is a scalar. This is the
dot product of two vectors. (MATLAB also has a built-in function, dot(a,b),
that computes the dot product of two vectors.) When using the dot function, the
vectors a and b can each be a row vector or a column vector (see Table 3-1). The
multiplication of a column vector by a row vector, each with n elements, gives an
matrix. Multiplication of array is demonstrated in Tutorial 3-1,
Tutorial 3-1: Multiplication of arrays.
>> A=[1 4 2; 5 7 3; 9 1 6; 4 2 8]
A =
1 4 2
5 7 3
9 1 6
4 2 8
>> B=[6 1; 2 5; 7 3]
B =
6 1
2 5
7 3
>> C=A*B
C =
28 27
65 49
98 32
84 38
>> D=B*A
??? Error using ==> *
Inner matrix dimensions must agree.
>> F=[1 3; 5 7]
F =
1 3
5 7
>> G=[4 2; 1 6]
n n
B B
1 1
n n
Define a matrix A.4 3
Define a matrix B.3 2
Multiply matrix A by matrix B and assign
the result to variable C.
Trying to multiply B by A,
B*A, gives an error since
the number of columns in
B is 2 and the number of
rows in A is 4.
Define two matrices F and G.2 2
79.
68 Chapter 3: Mathematical Operations with Arrays
Linear algebra rules of array multiplication provide a convenient way for
writing a system of linear equations. For example, the system of three equations
with three unknowns
can be written in a matrix form as
and in matrix notation as
where , , and .
3.3 ARRAY DIVISION
The division operation is also associated with the rules of linear algebra. This
operation is more complex and only a brief explanation is given below. A full
explanation can be found in books on linear algebra.
The division operation can be explained with the help of the identity matrix
and the inverse operation.
Identity matrix:
The identity matrix is a square matrix in which the diagonal elements are 1s, and
the rest of the elements are 0s. As was shown in Section 2.2.1, an identity matrix
can be created in MATLAB with the eye command. When the identity matrix
multiplies another matrix (or vector), that matrix (or vector) is unchanged (the
>> b*A
ans =
6 15 21 0
30 3 9 12
18 6 33 15
>> C=A*5
C =
10 25 35 0
50 5 15 20
30 10 55 25
Multiply the matrix A by b. This can be
done by either typing b*A or A*b.
Multiply the matrix A by 5 and assign
the result to a new variable C. (Typ-
ing C = 5*A gives the same result.)
A11x1 A12x2 A13x3+ + B1=
A21x1 A22x2 A23x3+ + B2=
A31x1 A32x2 A33x3+ + B3=
A11 A12 A13
A21 A22 A23
A31 A32 A33
x1
x2
x3
B1
B2
B3
=
AX B= A
A11 A12 A13
A21 A22 A23
A31 A32 A33
= X
x1
x2
x3
= B
B1
B2
B3
=
81.
70 Chapter 3: Mathematical Operations with Arrays
Not every matrix has an inverse. A matrix has an inverse only if it is square and its
determinant is not equal to zero.
Determinants:
A determinant is a function associated with square matrices. A short review on
determinants is given below. For a more detailed coverage refer to books on linear
algebra.
The determinant is a function that associates with each square matrix A a
number, called the determinant of the matrix. The determinant is typically denoted
by det(A) or |A|. The determinant is calculated according to specific rules. For a
second-order matrix the rule is:
, for example,
The determinant of a square matrix can be calculated with the det command (see
Table 3-1).
Array division:
MATLAB has two types of array division, right division and left division.
Left division, :
Left division is used to solve the matrix equation . In this equation X and
B are column vectors. This equation can be solved by multiplying, on the left, both
sides by the inverse of A:
The left-hand side of this equation is X since
So the solution of is:
In MATLAB the last equation can be written by using the left division character:
X = AB
It should be pointed out here that although the last two operations appear to give
the same result, the method by which MATLAB calculates X is different. In the
first, MATLAB calculates and then uses it to multiply B. In the second (left
division), the solution X is obtained numerically with a method that is based on
Gauss elimination. The left division method is recommended for solving a set of
>> A*A^-1
ans =
1 0 0
0 1 0
0 0 1
Use the power –1 to find the inverse of A.
Multiplying it by A gives the identity matrix.
2 2
A
a11 a12
a21 a22
a11a22 a12a21–= = 6 5
3 9
6 9 5– 3 39= =
AX B=
A
1–
AX A
1–
B=
A
1–
AX IX X= =
AX B=
X A
1–
B=
A
1–
82.
3.3 Array Division 71
linear equations because the calculation of the inverse may be less accurate than
the Gauss elimination method when large matrices are involved.
Right division, / :
The right division is used to solve the matrix equation . In this equation X
and D are row vectors. This equation can be solved by multiplying, on the right,
both sides by the inverse of C:
which gives
In MATLAB the last equation can be written using the right division character:
X = D/C
The following example demonstrates the use of the left and right division, and
the inv function to solve a set of linear equations.
Sample Problem 3-1: Solving three linear equations (array division)
Use matrix operations to solve the following system of linear equations.
Solution
Using the rules of linear algebra demonstrated earlier, the above system of equa-
tions can be written in the matrix form or in the form :
or
Solutions for both forms are shown below:
>> A=[4 -2 6; 2 8 2; 6 10 3];
>> B=[8; 4; 0];
>> X=AB
X =
-1.8049
0.2927
2.6341
>> Xb=inv(A)*B
Xb =
-1.8049
0.2927
2.6341
XC D=
X CC
1–
D C
1–
=
X D C
1–
=
4x 2y– 6z+ 8=
2x 8y 2z+ + 4=
6x 10y 3z+ + 0=
AX B= XC D=
4 2– 6
2 8 2
6 10 3
x
y
z
8
4
0
= x y z
4 2 6
2– 8 10
6 2 3
8 4 0=
Solving the form AX = B.
Solving by using left division: X = A B.
Solving by using the inverse of A: .X A
1–
B=
83.
72 Chapter 3: Mathematical Operations with Arrays
3.4 ELEMENT-BY-ELEMENT OPERATIONS
In Sections 3.2 and 3.3 it was shown that when the regular symbols for multiplica-
tion and division (* and /) are used with arrays, the mathematical operations fol-
low the rules of linear algebra. There are, however, many situations that require
element-by-element operations. These operations are carried out on each of the
elements of the array (or arrays). Addition and subtraction are by definition
already element-by-element operations since when two arrays are added (or sub-
tracted) the operation is executed with the elements that are in the same position in
the arrays. Element-by-element operations can be done only with arrays of the
same size.
Element-by-element multiplication, division, or exponentiation of two vectors
or matrices is entered in MATLAB by typing a period in front of the arithmetic
operator.
If two vectors a and b are and , then
element-by-element multiplication, division, and exponentiation of the two vec-
tors gives:
a .* b =
a ./ b =
a .^ b =
>> C=[4 2 6; -2 8 10; 6 2 3];
>> D=[8 4 0];
>> Xc=D/C
Xc =
-1.8049 0.2927 2.6341
>> Xd=D*inv(C)
Xd =
-1.8049 0.2927 2.6341
Symbol Description Symbol Description
.* Multiplication ./ Right division
.^ Exponentiation . Left Division
Solving the form XC = D.
Solving by using right division: X = D/C.
Solving by using the inverse of C: .X D C
1–
=
a a1 a2 a3 a4= b b1 b2 b3 b4=
a1b1 a2b2 a3b3 a4b4
a1 b1 a2 b2 a3 b3 a4 b4
a1
b1 a2
b2 a3
b3 a4
b4
85.
74 Chapter 3: Mathematical Operations with Arrays
Element-by-element calculations are very useful for calculating the value of a
function at many values of its argument. This is done by first defining a vector
that contains values of the independent variable, and then using this vector in ele-
ment-by-element computations to create a vector in which each element is the cor-
responding value of the function. One example is:
In the example above . Element-by-element operation is needed when
x is squared. Each element in the vector y is the value of y that is obtained when
the value of the corresponding element of the vector x is substituted in the equa-
tion. Another example is:
In the last example . Element-by-element operations are used in this
example three times: to calculate and , and to divide the numerator by the
denominator.
>> B.^3
ans =
1 64 1000
27 8 343
>> A*B
??? Error using ==> *
Inner matrix dimensions must agree.
>> x=[1:8]
x =
1 2 3 4 5 6 7 8
>> y=x.^2-4*x
y =
-3 -4 -3 0 5 12 21 32
>>
>> z=[1:2:11]
z =
1 3 5 7 9 11
>> y=(z.^3 + 5*z)./(4*z.^2 - 10)
y =
-1.0000 1.6154 1.6667 2.0323 2.4650 2.9241
Tutorial 3-2: Element-by-element operations. (Continued)
Element-by-element exponen-
tiation of array B. The result is
an array in which each term is
the corresponding term in B
raised to the power of 3.
Trying to multiply A*B gives
an error since A and B cannot
be multiplied according to lin-
ear algebra rules. (The number
of columns in A is not equal to
the number of rows in B.)
Create a vector x with eight elements.
Vector x is used in element-
by-element calculations of
the elements of vector y.
y x2 4x–=
Create a vector z with six elements.
Vector z is used in element-
by-element calculations of
the elements of vector y.
y
z
3
5z+
4z
2
10–
--------------------=
z
3
z
2
86.
3.5 Using Arrays in MATLAB Built-in Math Functions 75
3.5 USING ARRAYS IN MATLAB BUILT-IN MATH FUNCTIONS
The built-in functions in MATLAB are written such that when the argument
(input) is an array, the operation that is defined by the function is executed on each
element of the array. (One can think of the operation as element-by-element appli-
cation of the function.) The result (output) from such an operation is an array in
which each element is calculated by entering the corresponding element of the
argument (input) array into the function. For example, if a vector with seven ele-
ments is substituted in the function cos(x), the result is a vector with seven ele-
ments in which each element is the cosine of the corresponding element in x. This
is shown below.
An example in which the argument variable is a matrix is:
The feature of MATLAB in which arrays can be used as arguments in functions is
called vectorization.
3.6 BUILT-IN FUNCTIONS FOR ANALYZING ARRAYS
MATLAB has many built-in functions for analyzing arrays. Table 3-1 lists some
of these functions.
>> x=[0:pi/6:pi]
x =
0 0.5236 1.0472 1.5708 2.0944 2.6180 3.1416
>>y=cos(x)
y =
1.0000 0.8660 0.5000 0.0000 -0.5000 -0.8660 -1.0000
>>
>> d=[1 4 9; 16 25 36; 49 64 81]
d =
1 4 9
16 25 36
49 64 81
>> h=sqrt(d)
h =
1 2 3
4 5 6
7 8 9
Creating a array.3 3
h is a array in which each
element is the square root of the
corresponding element in array d.
3 3
87.
76 Chapter 3: Mathematical Operations with Arrays
Table 3-1: Built-in array functions
Function Description Example
mean(A) If A is a vector, returns the
mean value of the elements
of the vector.
>> A=[5 9 2 4];
>> mean(A)
ans =
5
C=max(A)
[d,n]=max(A)
If A is a vector, C is the larg-
est element in A. If A is a
matrix, C is a row vector
containing the largest ele-
ment of each column of A.
If A is a vector, d is the larg-
est element in A, and n is the
position of the element (the
first if several have the max
value).
>> A=[5 9 2 4 11 6 11 1];
>> C=max(A)
C =
11
>> [d,n]=max(A)
d =
11
n =
5
min(A)
[d,n]=min(A)
The same as max(A), but
for the smallest element.
The same as [d,n]=
max(A), but for the smallest
element.
>> A=[5 9 2 4];
>> min(A)
ans =
2
sum(A) If A is a vector, returns the
sum of the elements of the
vector.
>> A=[5 9 2 4];
>> sum(A)
ans =
20
sort(A) If A is a vector, arranges the
elements of the vector in
ascending order.
>> A=[5 9 2 4];
>> sort(A)
ans =
2 4 5 9
median(A) If A is a vector, returns the
median value of the elements
of the vector.
>> A=[5 9 2 4];
>> median(A)
ans =
4.5000
88.
3.7 Generation of Random Numbers 77
3.7 GENERATION OF RANDOM NUMBERS
Simulations of many physical processes and engineering applications frequently
require using a number (or a set of numbers) with a random value. MATLAB has
three commands—rand, randn, and randi—that can be used to assign ran-
dom numbers to variables.
The rand command:
The rand command generates uniformly distributed random numbers with val-
ues between 0 and 1. The command can be used to assign these numbers to a sca-
lar, a vector, or a matrix, as shown in Table 3-2.
std(A) If A is a vector, returns the
standard deviation of the ele-
ments of the vector.
>> A=[5 9 2 4];
>> std(A)
ans =
2.9439
det(A) Returns the determinant of a
square matrix A.
>> A=[2 4; 3 5];
>> det(A)
ans =
-2
dot(a,b) Calculates the scalar (dot)
product of two vectors a and
b. The vectors can each be
row or column vectors.
>> a=[1 2 3];
>> b=[3 4 5];
>> dot(a,b)
ans =
26
cross(a,b) Calculates the cross product
of two vectors a and b,
(axb). The two vectors must
have each three elements.
>> a=[1 3 2];
>> b=[2 4 1];
>> cross(a,b)
ans =
-5 3 -2
inv(A) Returns the inverse of a
square matrix A.
>> A=[2 -2 1; 3 2 -1; 2 -3 2];
>> inv(A)
ans =
0.2000 0.2000 0
-1.6000 0.4000 1.0000
-2.6000 0.4000 2.0000
Table 3-1: Built-in array functions (Continued)
Function Description Example
89.
78 Chapter 3: Mathematical Operations with Arrays
Sometimes there is a need for random numbers that are distributed in an inter-
val other than (0,1), or for numbers that are integers only. This can be done using
mathematical operations with the rand function. Random numbers that are dis-
tributed in a range (a,b) can be obtained by multiplying rand by (b – a) and add-
ing the product to a:
(b – a)*rand + a
For example, a vector of 10 elements with random values between –5 and 10 can
be created by (a = –5, b = 10):
The randi command:
The randi command generates uniformly distributed random integer. The com-
mand can be used to assign these numbers to a scalar, a vector, or a matrix, as
shown in Table 3-3.
Table 3-2: The rand command
Command Description Example
rand Generates a single random
number between 0 and 1.
>> rand
ans =
0.2311
rand(1,n) Generates an n-element
row vector of random
numbers between 0 and 1.
>> a=rand(1,4)
a =
0.6068 0.4860 0.8913 0.7621
rand(n) Generates an matrix
with random numbers
between 0 and 1.
>> b=rand(3)
b =
0.4565 0.4447 0.9218
0.0185 0.6154 0.7382
0.8214 0.7919 0.1763
rand(m,n) Generates an matrix
with random numbers
between 0 and 1.
>> c=rand(2,4)
c =
0.4057 0.9169 0.8936 0.3529
0.9355 0.4103 0.0579 0.8132
randperm(n) Generates a row vector
with n elements that are
random permutation of
integers 1 through n.
>> randperm(8)
ans =
8 2 7 4 3 6 5 1
>> v=15*rand(1,10)-5
v =
-1.8640 0.6973 6.7499 5.2127 1.9164 3.5174
6.9132 -4.1123 4.0430 -4.2460
n n
m n
90.
3.7 Generation of Random Numbers 79
The range of the random integers can be set to be between any two integers by
typing [imin imax] instead of imax. For example, a matrix with ran-
dom integers between 50 and 90 is created by:
The randn command:
The randn command generates normally distributed numbers with mean 0 and
standard deviation of 1. The command can be used to generate a single number, a
vector, or a matrix in the same way as the rand command. For example, a
matrix is created by:
The mean and standard deviation of the numbers can be changed by mathematical
operations to have any values. This is done by multiplying the number generated
by the randn function by the desired standard deviation, and adding the desired
mean. For example, a vector of six numbers with a mean of 50 and standard devi-
Table 3-3: The randi command
Command Description Example
randi(imax)
(imax is an inte-
ger)
Generates a single random
number between 1 and
imax.
>> a=randi(15)
a =
9
randi(imax,
n)
Generates an matrix
with random integers
between 1 and imax.
>> b=randi(15,3)
b =
4 8 11
14 3 8
1 15 8
randi(imax,
m,n)
Generates an matrix
with random integers
between 1 and imax.
>> c=randi(15,2,4)
c =
1 1 8 13
11 2 2 13
>> d=randi([50 90],3,4)
d =
57 82 71 75
66 52 67 61
84 66 76 67
>> d=randn(3,4)
d =
-0.4326 0.2877 1.1892 0.1746
-1.6656 -1.1465 -0.0376 -0.1867
0.1253 1.1909 0.3273 0.7258
n n
m n
3 4
3 4
91.
80 Chapter 3: Mathematical Operations with Arrays
ation of 6 is generated by:
Integers of normally distributed numbers can be obtained by using the round
function.
3.8 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 3-2: Equivalent force system (addition of vectors)
Three forces are applied to a bracket as
shown. Determine the total (equivalent)
force applied to the bracket.
Solution
A force is a vector (a physical quantity
that has a magnitude and direction). In a
Cartesian coordinate system a two-
dimensional vector F can be written as:
where F is the magnitude of the force and is its angle relative to the x axis, Fx
and Fy are the components of F in the directions of the x and y axes, respectively,
and i and j are unit vectors in these directions. If Fx and Fy are known, then F and
can be determined by:
and
The total (equivalent) force applied on the bracket is obtained by adding the forces
that are acting on the bracket. The MATLAB solution below follows three steps:
• Write each force as a vector with two elements, where the first element is the x
component of the vector and the second element is the y component.
• Determine the vector form of the equivalent force by adding the vectors.
• Determine the magnitude and direction of the equivalent force.
The problem is solved in the following script file.
>> v=4*randn(1,6)+50
v =
42.7785 57.4344 47.5819 50.4134 52.2527 50.4544
>> w=round(4*randn(1,6)+50)
w =
51 49 46 49 50 44
30o
20o
143o
F2 = 500 N
F3 = 700 N
F1 = 400 N
x
y
F Fxi Fyj+ F icos F j F icos jsin+=sin+= =
F Fx
2
Fy
2
+= tan
Fy
Fx
-----=
92.
3.8 Examples of MATLAB Applications 81
When the program is executed, the following is displayed in the Command Win-
dow:
The equivalent force has a magnitude of 589.98 N, and is directed (ccw)
relative to the x axis. In vector notation the force is N.
% Sample Problem 3-2 solution (script file)
clear
F1M=400; F2M=500; F3M=700;
Th1=-20; Th2=30; Th3=143;
F1=F1M*[cosd(Th1) sind(Th1)]
F2=F2M*[cosd(Th2) sind(Th2)]
F3=F3M*[cosd(Th3) sind(Th3)]
Ftot=F1+F2+F3
FtotM=sqrt(Ftot(1)^2+Ftot(2)^2)
Th=atand(Ftot(2)/Ftot(1))
F1 =
375.8770 -136.8081
F2 =
433.0127 250.0000
F3 =
-559.0449 421.2705
Ftot =
249.8449 534.4625
FtotM =
589.9768
Th =
64.9453
Define variables with the
magnitude of each vector.
Define variables with the angle of each vector.
Define the three vectors.
Calculate the total force vector.
Calculate the magnitude of
the total force vector.
Calculate the angle of the total force vector.
The components of F1.
The components of F2.
The components of F3.
The components of the total force.
The magnitude of the total force.
The direction of the total force in degrees.
64.95
F 249.84i 534.46j+=
93.
82 Chapter 3: Mathematical Operations with Arrays
Sample Problem 3-3: Friction experiment (element-by-element
calculations)
The coefficient of friction, can be determined in
an experiment by measuring the force F required to
move a mass m. When F is measured and m is
known, the coefficient of friction can be calculated
by:
(g = 9.81 m/s2
).
Results from measuring F in six tests are given in the table below. Determine the
coefficient of friction in each test, and the average from all tests.
Solution
A solution using MATLAB commands in the Command Window is shown below.
Test 1 2 3 4 5 6
Mass m (kg) 2 4 5 10 20 50
Force F (N) 12.5 23.5 30 61 117 294
>> m=[2 4 5 10 20 50];
>> F=[12.5 23.5 30 61 117 294];
>> mu=F./(m*9.81)
mu =
0.6371 0.5989 0.6116 0.6218 0.5963 0.5994
>> mu_ave=mean(mu)
mu_ave =
0.6109
m
F
friction
m
F
frictionF mg=
Enter the values of m in a vector.
Enter the values of F in a vector.
A value for mu is calculated for each test,
using element-by-element calculations.
The average of the elements in the vector mu
is determined by using the function mean.
94.
3.8 Examples of MATLAB Applications 83
Sample Problem 3-4: Electrical resistive network analysis (solving a
system of linear equations)
The electrical circuit shown consists of
resistors and voltage sources. Determine
the current in each resistor using the mesh
current method, which is based on Kirch-
hoff's voltage law.
V, V, V
, ,
, ,
,
Solution
Kirchhoff's voltage law states that the sum
of the voltage around a closed circuit is
zero. In the mesh current method a current
is first assigned for each mesh (i1, i2, i3, i4
in the figure). Then Kirchhoff's voltage
law is applied for each mesh. This results
in a system of linear equations for the currents (in this case four equations). The
solution gives the values of the mesh currents. The current in a resistor that
belongs to two meshes is the sum of the currents in the corresponding meshes. It is
convenient to assume that all the currents are in the same direction (clockwise in
this case). In the equation for each mesh, the voltage source is positive if the cur-
rent flows to the – pole, and the voltage of a resistor is negative for current in the
direction of the mesh current.
The equations for the four meshes in the current problem are:
The four equations can be rewritten in matrix form [A][x] = [B]:
_
+
+
_
+
_
i1
i2
i3
i4
R1
R2 R3
R5
R4
R6
R7
R8
V1
V2
V3
V1 20= V2 12= V3 40=
R1 18= R2 10= R3 16=
R4 6= R5 15= R6 8=
R7 12= R8 14=
V1 R1i1– R3 i1 i3–– R2 i1 i2–– 0=
R– 5i2 R2 i2 i1–– R4 i2 i3–– R7 i2 i4–– 0=
V– 2 R6 i3 i4–– R4 i3 i2–– R3 i3 i1–– 0=
V3 R8i4– R7 i4 i2–– R6 i4 i3–– 0=
R1 R2 R3+ +– R2 R3 0
R2 R2 R4 R5 R7+ + +– R4 R7
R3 R4 R3 R4 R6+ +– R6
0 R7 R6 R6 R7 R8+ +–
i1
i2
i3
i4
V– 1
0
V2
V– 3
=
95.
84 Chapter 3: Mathematical Operations with Arrays
The problem is solved in the following program, written in a script file:
When the script file is executed, the following is displayed in the Command Win-
dow:
The last column vector gives the current in each mesh. The currents in the resis-
tors R1, R5, and R8 are A, A, and A, respec-
tively. The other resistors belong to two meshes and their current is the sum of the
currents in the meshes.
The current in resistor R2 is A.
The current in resistor R3 is A.
The current in resistor R4 is A.
The current in resistor R6 is A.
The current in resistor R7 is A.
V1=20; V2=12; V3=40;
R1=18; R2=10; R3=16; R4=6;
R5=15; R6=8; R7=12; R8=14;
A=[-(R1+R2+R3) R2 R3 0
R2 -(R2+R4+R5+R7) R4 R7
R3 R4 -(R3+R4+R6) R6
0 R7 R6 -(R6+R7+R8)]
>> B=[-V1; 0; V2; -V3]
>> I=AB
A =
-44 10 16 0
10 -43 6 12
16 6 -30 8
0 12 8 -34
B =
-20
0
12
-40
I =
0.8411
0.7206
0.6127
1.5750
>>
Define variables with the
values of the V's and R's.
Create the matrix A.
Create the vector B.
Solve for the currents by using left division.
The numerical value
of the matrix A.
The numerical value
of the vector B.
The solution.
i1
i2
i3
i4
i1 0.8411= i2 0.7206= i4 1.5750=
i1 i2– 0.1205=
i1 i3– 0.2284=
i2 i3– 0.1079=
i4 i3– 0.9623=
i4 i2– 0.8544=
96.
3.8 Examples of MATLAB Applications 85
Sample Problem 3-5: Motion of two particles
A train and a car are approaching a road crossing. At
time the train is 400 ft south of the crossing
traveling north at a constant speed of 54 mi/h. At the
same time the car is 200 ft west of the crossing trav-
eling east at a speed of 28 mi/h and accelerating at 4
ft/s2. Determine the positions of the train and the car,
the distance between them, and the speed of the train
relative to the car every second for the next 10 sec-
onds.
To show the results, create an matrix in
which each row has the time in the first column and
the train position, car position, distance between the
train and the car, car speed, and the speed of the train relative to the car, in the next
five columns, respectively.
Solution
The position of an object that moves along a straight line at a constant acceleration
is given by where and are the position and velocity at
, and a is the acceleration. Applying this equation to the train and the car
gives:
(train)
(car)
The distance between the car and the train is: .
The velocity of the train is constant and in vector notation is . The
car is accelerating and its velocity at time t is given by . The
velocity of the train relative to the car, , is given by
. The magnitude (speed) of this
velocity is the length of the vector.
The problem is solved in the following program, written in a script file. First a
vector t with 11 elements for the time from 0 to 10 s is created, then the positions
of the train and the car, the distance between them, and the speed of the train rela-
tive to the car at each time element are calculated.
v0train=54*5280/3600; v0car=28*5280/3600; acar=4;
t=0:10;
y=-400+v0train*t;
x=-200+v0car*t+0.5*acar*t.^2;
d=sqrt(x.^2+y.^2);
t 0=
11 6
s so vot
1
2
--at
2
+ += so vo
t 0=
y 400– votraint+=
x 200– vocart
1
2
--acart
2
+ +=
d x2 y2+=
vtrain votrainj=
vcar vocar acart+ i=
vt c
vt c vtrain vcar– vocar acart+ i– votrainj+= =
Create variables for the initial velocities (in ft/s) and the acceleration.
Create the vector t.
Calculate the train and
car positions.
Calculate the distance between the train and car.
98.
3.9 Problems 87
3. For the function , calculate the value of y for the following
values of x using element-by-element operations: .
4. For the function , calculate the value of y for the
following values of t using element-by-element operations:
.
5. A ball that is dropped on the floor bounces back up
many times, reaching a lower height after each bounce.
When the ball impacts the floor its rebound velocity is
0.85 times the impact velocity. The velocity v with
which a ball hits the floor after being dropped from a
height h is given by , where m/s2.
The time between successive bounces is given by
, where v is the upward velocity after the last
impact. Consider a ball that is dropped from a height of
2 m. Determine the times at which the ball hits the floor for the first eight
bounces. Set when the ball hits the floor for the first time. (Calculate
the velocity of the ball when it hits the floor for the first time. Derive a for-
mula for the time of the following hits as a function of the bounce number.
Then create a vector and use the formula (use element-by ele-
ment operations) to calculate a vector with the values of t for each n.) Display
the results in a two-column table where the values of n and t are displayed in
the first and second columns, respectively.
6. An aluminum sphere ( cm) is dropped in a glass cyl-
inder filled with glycerin. The velocity of the sphere as a
function of time can be modeled by the equation
where V is the volume of the sphere, m/s2 is the
gravitational acceleration, is a constant, and
kg/m3 and kg/m3 are the density of
aluminum and glycerin, respectively. Determine the velocity
of the sphere for t = 0, 0.05, 0.1, 0.15, 0.2, 0.25, 0.3, and
0.35 s. Note that initially the velocity increases rapidly, but
then, due to the resistance of the glycerin, the velocity
increases more gradually. Eventually the velocity approaches a limit that is
called the terminal velocity.
y
x 3– x2 3+
x2
------------------------------------=
1 2 3 4 5 6 7
y
20t 2 3
t 1+
---------------- t 1+ 2
e 0.3t 5+
-------------------–
2
t 1+
-----------+=
0 1 2 3 4 5 6 7 8
y
v 0.85v
v 2gh= g 9.81=
t v g=
t 0=
n 1 2 8=
v
r 0.2=
v t
v t
V al gl– g
k
--------------------------------
V al gl– gk
V al
--------------------------------------- ttanh=
g 9.81=
k 0.0018=
al 2700= gl 1260=
99.
88 Chapter 3: Mathematical Operations with Arrays
7. The current i (in amps) t seconds after closing
the switch in the circuit shown is given by:
Consider the case where volts,
ohms and henry.
(a) Find the time required for the current to
reach 1% of its initial value, then use linspace to create a vector t hav-
ing 10 elements with the first element 0 and maximum value .
(b) Calculate the current i for each value of t from part (a).
8. The length (magnitude) of a vector is given by
. Given the vector , determine its
length two ways:
(a) Define the vector in MATLAB, and then write a mathematical expression
that uses the components of the vector.
(b) Define the vector in MATLAB, then use element-by element operations
to create a new vector with elements that are the squares of the elements
of the original vector. Then use MATLAB built-in functions sum and
sqrt to calculate the length. All of these steps can be written in one com-
mand.
9. The unit vector in the direction of the vector is given by
. Determine the unit vector of the vector
by writing one MATLAB command.
10. The following two vectors are v.*u (b) v*u' (c) v'*u
11. Two vectors are given:
and
Use MATLAB to calculate the dot product of the vectors in three ways:
(a) Write an expression using element-by-element calculation and the MAT-
LAB built-in function sum.
(b) Define u as a row vector and v as a column vector, and then use matrix
multiplication.
(c) Use the MATLAB built-in function dot.
V L
R
+
_
i(t)
i t
V
R
--- 1 e R L t––=
V 120=
R 120= L 0.1=
tm
tm
u u xi yj zk+ +=
u x2 y2 z2+ += u 23.5i 17j– 6k+=
un u xi yj zk+ +=
un
xi yj zk+ +
x2 y2 z2+ +
-------------------------------=
u 8i– 14j– 25k+=
v 3 2– 4= u 5 3 1–=
u 3i– 8j 2k–+= v 6.5i 5j– 4k–=
u v
101.
90 Chapter 3: Mathematical Operations with Arrays
18. The dot product can be used for determining the
angle between two vectors:
Use MATLAB's built-in functions cosd, sqrt,
and dot to find the angle (in degrees) between
and .
Recall that .
19. The position as a function of time
of a projectile fired with a speed of at an
angle is given by
where m/s2
. The polar coordinates of
the projectile at time t are , where
and . Consider the case where m/s
and . Determine and for s.
20. Two projectiles, A and B, are shot at the same
instant from the same spot. Projectile A is shot at
a speed of 560 m/s at an angle of and pro-
jectile B is shot at a speed of 680 m/s at an angle
of . Determine which projectile will hit the
ground first. Then take the flying time tf of that
projectile and divide it into ten increments by
creating a vector t with 11 equally spaced elements (the first element is 0, the
last is ). At each time t calculate the position vector between the two
projectiles. Display the results in a three-column matrix where the first col-
umn is t and the second and third columns are the corresponding x and y com-
ponents of .
21. Show that .
Do this by first creating a vector x that has the elements 1.5, 1.0, 0.5, 0.1, 0.01,
0.001, and 0.00001. Then, create a new vector y in which each element is deter-
mined from the elements of x by . Compare the elements of y with the
value 1 (use format long to display the numbers).
x y
z
r1
r2
θr1 r2
r1 r2
----------------cos 1–=
r1 3i 2j– k+= r2 1i 2j 4k–+=
r r r=
v0
α
r
x
y
θ
x t y t
v0
x t v0 cos t= y t v0 sin t
1
2
---gt2–=
g 9.81=
r t t
r t x t 2 y t 2+= tan y t
x t
---------= v0 162=
70= r t t t 1 6 11 31=
rAB
x
y
A
B
43
50
tf rAB
rAB
xsin
x
----------
x 0
lim 1=
xsin
x
----------
102.
3.9 Problems 91
22. Show that .
Do this by first creating a vector x that has the elements: 5, 3, 2, 1.5, 1.1,
1.001, and 1.00001. Then, create a new vector y in which each element is deter-
mined from the elements of x by . Compare the elements of y with the
value 2 (use format long to display the numbers).
23. Use MATLAB to show that the sum of the infinite series
converges to 1. Do it by computing the sum for:
(a) n = 10 (b) n = 20
(c) n = 30 (c) n = 40
For each part create a vector n in which the first element is 1, the increment is
1, and the last term is 10, 20, 30, or 40. Then use element-by-element calcula-
tions to create a vector in which the elements are . Finally, use the MAT-
LAB built-in function sum to add the terms of the series. Compare the values
obtained in parts (a), (b), (c), and (d) with the value of 1. (Don't forget to type
semicolons at the end of commands that otherwise will display large vectors.)
24. Use MATLAB to show that the sum of the infinite series is
equal to . Do this by computing the sum for:
(a) n = 10 (b) n = 20 (c) n = 50
For each part create a vector n in which the first element is 0, the increment is
1 and the last term is 10, 50, or 100. Then, use element-by-element calculation
to create a vector in which the elements are . Finally, use the function
sum to add the terms of the series and multiply the result by . Compare
the values obtained in parts (a), (b), and (c) to the value of in MATLAB.
25. Fisheries commonly estimate the growth of a fish population using the von
Bertalanffy growth law:
where is the maximum length, K is a rate constant, and is a time con-
stant. These constants vary with the species of fish. Assuming cm,
years–1
, and years, calculate the length of a fish at 0, 1, 2,
3, 4, and 5 years of age.
x2 1–
x 1–
--------------
x 1
lim 2=
x2 1–
x 1–
--------------
1
2n
-----
1
2
---
1
22
-----
1
23
-----+ + +=
n 1=
1
2n
-----
12
3– n–
2n 1+
---------------
n 0=
3– n–
2n 1+
---------------
12
L Lmax 1 e
K t +–
–=
Lmax
Lmax 58=
K 0.45= 0.65=
103.
92 Chapter 3: Mathematical Operations with Arrays
26. The path of a projectile fired with an initial
speed at an angle is described by the
equation
where m/s2
. Consider the case where
and m/s. Write a MAT-
LAB script that does the following: calculates
the distance s traveled by the projectile, creates a vector x with 100 elements
such that the first element is 0 and the last is s, calculates the value of y for
each value of x, finds the maximum height that the projectile reaches (use
MATLAB built-in function max) and the distance where the maximum
height is reached. When the script is executed only the values of and
are displayed.
27. Create the following three matrices:
(a) Calculate and to show that addition of matrices is commuta-
tive.
(b) Calculate and to show that addition of matrices is
associative.
(c) Calculate and to show that, when matrices are multi-
plied by a scalar, the multiplication is distributive.
(d) Calculate and to show that matrix multiplication is
distributive.
28. Use the matrices A, B, and C from the previous problem to answer the follow-
ing:
(a) Does ? (b) Does A*(B*C) = (A*B)*C?
(c) Does (A*B)t = Bt*At? ( t means transpose) (d) Does (A + B)t = At + Bt?
29. Create a matrix having random integer values between 1 and 10. Call
the matrix A and using MATLAB perform the following operations. For each
part explain the operation.
(a) A * A (b) A .*A (c) A A
(d) A . A (e) det(A) (e) inv(A)
v0
x
y
hm
s
θ
xm
200 m
v0
y xtan
g
2v0
2 cos2
----------------------- x2–=
g 9.81=
75= v0 110=
hm
xhm
hm xhm
A
2 4 1–
3 1 5–
0 1 4
= B
2– 5 0
3– 2 7
1– 6 9
= C
0 3 5
2 1 0
4 6 3–
=
A B+ B A+
A B C++ A B+ C+
5 A C+ 5A 5C+
A B C+ A B A C+
A B B A=
4 4
106.
95
Chapter 4
Using Script Files and
Managing Data
A script file (see Section 1.8) is a list of MATLAB commands, called a program,
that is saved in a file. When the script file is executed (run), MATLAB executes
the commands. Section 1.8 describes how to create, save, and run a simple script
file in which the commands are executed in the order in which they are listed, and
in which all the variables are defined within the script file. The present chapter
gives more details of how to input data to a script file, how data is stored in MAT-
LAB, various ways to display and save data that is created in script files, and how
to exchange data between MATLAB and other applications. (How to write more
advanced programs where commands are not necessarily executed in a simple
order is covered in Chapter 6.)
In general, variables can be defined (created) in several ways. As shown in
Chapter 2, variables can be defined implicitly by assigning values to a variable
name. Variables can also be assigned values by the output of a function. In addi-
tion, variables can be defined with data that is imported from files outside MAT-
LAB. Once defined (either in the Command Window or when a script file is
executed) the variables are stored in MATLAB's Workspace.
Variables that reside in the workspace can be displayed in various ways,
saved, or exported to applications outside MATLAB. Similarly, data from files
outside MATLAB can be imported to the workspace and then used in MATLAB.
Section 4.1 explains how MATLAB stores data in the workspace and how
the user can see the data that is stored. Section 4.2 shows how variables that are
used in script files can be defined in the Command Window and/or in script files.
Section 4.3 shows how to output data that is generated when script files are exe-
cuted. Section 4.4 explains how the variables in the workspace can be saved and
then retrieved, and Section 4.5 shows how to import and export data from and to
applications outside MATLAB.
107.
96 Chapter 4: Using Script Files and Managing Data
4.1 THE MATLAB WORKSPACE AND THE WORKSPACE WINDOW
The MATLAB workspace consists of the set of variables (named arrays) that are
defined and stored during a MATLAB session. It includes variables that have
been defined in the Command Window and variables defined when script files are
executed. This means that the Command Window and script files share the same
memory zone within the computer. This implies that once a variable is in the
workspace, it is recognized and can be used, and it can be reassigned new values,
in both the Command Window and script files. As will be explained in Chapter 7
(Section 7.3), there is another type of file in MATLAB, called a function file,
where variables can also be defined. These variables, however, are normally not
shared with other parts of the program since they use a separate workspace.
Recall from Chapter 1 that the who command displays a list of the variables
currently in the workspace. The whos command displays a list of the variables
currently in the workspace and information about their size, bytes, and class. An
example is shown below.
>> 'Variables in memory'
ans =
Variables in memory
>> a = 7;
>> E = 3;
>> d = [5, a+E, 4, E^2]
d =
5 10 4 9
>> g = [a, a^2, 13; a*E, 1, a^E]
g =
7 49 13
21 1 343
>> who
Your variables are:
E a ans d g
>> whos
Name Size Bytes Class Attributes
E 1x1 8 double
a 1x1 8 double
ans 1x19 38 char
d 1x4 32 double
g 2x3 48 double
>>
Typing a string.
The string is assigned to ans.
Creating the variables a,
E, d, and g.
The who command displays the vari-
ables currently in the workspace.
The whos command
displays the variables
currently in the work-
space, and informa-
tion about their size
and other information.
108.
4.2 Input to a Script File 97
The variables currently in memory can also be viewed in the Workspace Win-
dow. If not open, this window can be opened by selecting Workspace in the
Desktop menu. Figure 4-1 shows the Workspace Window that corresponds to the
variables defined above. The variables that are displayed in the Workspace Win-
dow can also be edited (changed). Double-clicking on a variable opens the Vari-
able Editor Window, where the content of the variable is displayed in a table. For
example, Figure 4-2 shows the Variable Editor Window that opens when the vari-
able g in Figure 4-1 is double-clicked.
The elements in the Variable Editor Window can be edited. The variables in the
Workspace Window can be deleted by selecting them, and then either pressing the
delete key on the keyboard or selecting delete from the edit menu. This has the
same effect as entering the command clear variable_name in the Com-
mand Window.
4.2 INPUT TO A SCRIPT FILE
When a script file is executed, the variables that are used in the calculations within
the file must have assigned values. In other words, the variables must be in the
workspace. The assignment of a value to a variable can be done in three ways,
depending on where and how the variable is defined.
Figure 4-1: The Workspace Window.
Figure 4-2: The Variable Editor Window.
109.
98 Chapter 4: Using Script Files and Managing Data
1. The variable is defined and assigned a value in the script file.
In this case the assignment of a value to the variable is part of the script file. If the
user wants to run the file with a different variable value, the file must be edited
and the assignment of the variable changed. Then, after the file is saved, it can be
executed again.
The following is an example of such a case. The script file (saved as
Chapter4Example2) calculates the average points scored in three games.
The display in the Command Window when the script file is executed is:
2. The variable is defined and assigned a value in the Command Window.
In this case the assignment of a value to the variable is done in the Command
Window. (Recall that the variable is recognized in the script file.) If the user wants
to run the script file with a different value for the variable, the new value is
assigned in the Command Window and the file is executed again.
For the previous example in which the script file has a program that calcu-
lates the average of points scored in three games, the script file (saved as
Chapter4Example3) is:
The Command Window for running this file is:
% This script file calculates the average points scored in three games.
% The assignment of the values of the points is part of the script file.
game1=75;
game2=93;
game3=68;
ave_points=(game1+game2+game3)/3
>> Chapter4Example2
ave_points =
78.6667
>>
% This script file calculates the average points scored in three games.
% The assignment of the values of the points to the variables
% game1, game2, and game3 is done in the Command Window.
ave_points=(game1+game2+game3)/3
>> game1 = 67;
>> game2 = 90;
>> game3 = 81;
The variables are assigned
values within the script file.
The script file is executed by typing the name of the file.
The variable ave_points with its value
is displayed in the Command Window.
The variables are assigned values in
the Command Window.
110.
4.2 Input to a Script File 99
3. The variable is defined in the script file, but a specific value is entered
in the Command Window when the script file is executed.
In this case the variable is defined in the script file, and when the file is executed,
the user is prompted to assign a value to the variable in the Command Window.
This is done by using the input command for creating the variable.
The form of the input command is:
When the input command is executed as the script file runs, the string is dis-
played in the Command Window. The string is a message prompting the user to
enter a value that is assigned to the variable. The user types the value and presses
the Enter key. This assigns the value to the variable. As with any variable, the
variable and its assigned value will be displayed in the Command Window unless
a semicolon is typed at the very end of the input command. A script file that
uses the input command to enter the points scored in each game to the program
that calculates the average of the scores is shown below.
The following shows the Command Window when this script file (saved as
>> Chapter4Example3
ave_points =
79.3333
>> game1 = 87;
>> game2 = 70;
>> game3 = 50;
>> Chapter4Example3
ave_points =
69
>>
% This script file calculates the average of points scored in three games.
% The points from each game are assigned to the variables by
% using the input command
The script file is executed.
The output from the script file is displayed
in the Command Window.
New values are assigned to
the variables.
The script file is executed again.
The output from the script file is displayed
in the Command Window.
variable_name = input('string with a message that
is displayed in the Command Window')
111.
100 Chapter 4: Using Script Files and Managing Data
Chapter4Example4) is executed.
In this example scalars are assigned to the variables. In general, however,
vectors and arrays can also be assigned. This is done by typing the array in the
same way that it is usually assigned to a variable (left bracket, then typing row by
row, and a right bracket).
The input command can also be used to assign a string to a variable. This
can be done in one of two ways. One way is to use the command in the same form
as shown above, and when the prompt message appears the string is typed
between two single quotes in the same way that a string is assigned to a variable
without the input command. The second way is to use an option in the input
command that defines the characters that are entered as a string. The form of the
command is:
where the 's' inside the command defines the characters that will be entered as a
string. In this case when the prompt message appears, the text is typed in without
the single quotes, but it is assigned to the variable as a string. An example where
the input command is used with this option is included in Sample Problem 6-4.
4.3 OUTPUT COMMANDS
As discussed before, MATLAB automatically generates a display when some
commands are executed. For example, when a variable is assigned a value, or the
name of a previously assigned variable is typed and the Enter key is pressed,
MATLAB displays the variable and its value. This type of output is not displayed
if a semicolon is typed at the end of the command. In addition to this automatic
display, MATLAB has several commands that can be used to generate displays.
The displays can be messages that provide information, numerical data, and plots.
Two commands that are frequently used to generate output are disp and
fprintf. The disp command displays the output on the screen, while the
fprintf command can be used to display the output on the screen or to save the
output to a file. The commands can be used in the Command Window, in a script
file, and, as will be shown later, in a function file. When these commands are used
>> Chapter4Example4
Enter the points scored in the first game 67
Enter the points scored in the second game 91
Enter the points scored in the third game 70
ave_points =
76
>>
The computer displays
the message. Then the
value of the score is
typed by the user and
the Enter key is
pressed.
variable_name = input('prompt message','s')
112.
4.3 Output Commands 101
in a script file, the display output that they generate is displayed in the Command
Window.
4.3.1 The disp Command
The disp command is used to display the elements of a variable without display-
ing the name of the variable, and to display text. The format of the disp com-
mand is:
• Every time the disp command is executed, the display it generates appears in
a new line. One example is:
The next example shows the use of the disp command in the script file that cal-
culates the average points scored in three games.
When this file (saved as Chapter4Example5) is executed, the display in the
>> abc = [5 9 1; 7 2 4];
>> disp(abc)
5 9 1
7 2 4
>> disp('The problem has no solution.')
The problem has no solution.
>>
% This script file calculates the average points scored in three games.
% The points from each game are assigned to the variables by
% using the input command.
% The disp command is used to display the output;
disp(' ')
disp('The average of points scored in a game is:')
disp(' ')
disp(ave_points)
disp(name of a variable) or disp('text as string')
A array is assigned to variable abc.2 3
The disp command is used to display the abc array.
The array is displayed without its name.
The disp command is used
to display a message.
Display empty line.
Display text.
Display empty line.
Display the value of the variable ave_points.
113.
102 Chapter 4: Using Script Files and Managing Data
Command Window is:
• Only one variable can be displayed in a disp command. If elements of two
variables need to be displayed together, a new variable (that contains the ele-
ments to be displayed) must first be defined and then displayed.
In many situations it is nice to display output (numbers) in a table. This can
be done by first defining a variable that is an array with the numbers and then
using the disp command to display the array. Headings to the columns can also
be created with the disp command. Since in the disp command the user cannot
control the format (the width of the columns and the distance between the col-
umns) of the display of the array, the position of the headings has to be aligned
with the columns by adding spaces. As an example, the script file below shows
how to display the population data from Chapter 2 in a table.
When this script file (saved as PopTable) is executed, the display in the Command
Window is:
>> Chapter4Example5
Enter the points scored in the first game 89
Enter the points scored in the second game 60
Enter the points scored in the third game 82
The average of points scored in a game is:
77
yr=[1984 1986 1988 1990 1992 1994 1996];
pop=[127 130 136 145 158 178 211];
tableYP(:,1)=yr';
tableYP(:,2)=pop';
disp(' YEAR POPULATION')
disp(' (MILLIONS)')
disp(' ')
disp(tableYP)
>> PopTable
YEAR POPULATION
(MILLIONS)
1984 127
1986 130
An empty line is displayed.
The text line is displayed.
An empty line is displayed.
The value of the variable ave_points is displayed.
The population data is
entered in two row vectors.
yr is entered as the first column in the array tableYP.
pop is entered as the second column in the array tableYP.
Display heading (first line).
Display heading (second line).
Display an empty line.
Display the array tableYP.
Headings are displayed.
An empty line is displayed.
114.
4.3 Output Commands 103
Another example of displaying a table is shown in Sample Problem 4-3.
Tables can also be created and displayed with the fprintf command, which is
explained in the next section.
4.3.2 The fprintf Command
The fprintf command can be used to display output (text and data) on the
screen or to save it to a file. With this command (unlike with the disp command)
the output can be formatted. For example, text and numerical values of variables
can be intermixed and displayed in the same line. In addition, the format of the
numbers can be controlled.
With many available options, the fprintf command can be long and
complicated. To avoid confusion, the command is presented gradually. First, this
section shows how to use the command to display text messages, then how to mix
numerical data and text, next how to format the display of numbers, and finally
how to save the output to a file.
Using the fprintf command to display text:
To display text, the fprintf command has the form:
For example:
If this line is part of a script file, then when the line is executed, the following is
displayed in the Command Window:
With the fprintf command it is possible to start a new line in the middle of the
string. This is done by inserting n before the character that will start the new
line. For example, inserting n after the first sentence in the previous example
gives:
1988 136
1990 145
1992 158
1994 178
1996 211
fprintf('The problem, as entered, has no solution. Please check the
input data.')
The problem, as entered, has no solution. Please check the input data.
fprintf('The problem, as entered, has no solution.nPlease
check the input data.')
The tableYP array is displayed.
fprintf('text typed in as a string')
115.
104 Chapter 4: Using Script Files and Managing Data
When this line executes, the display in the Command Window is:
The n is called an escape character. It is used to control the display. Other escape
characters that can be inserted within the string are:
b Backspace.
t Horizontal tab.
When a program has more than one fprintf command, the display gener-
ated is continuous (the fprintf command does not automatically start a new
line). This is true even if there are other commands between the fprintf com-
mands. An example is the following script file:
When this file is executed the display in the Command Window is:
To start a new line with the fprintf command, n must be typed at the start of
the string.
Using the fprintf command to display a mix of text and numerical data:
To display a mix of text and a number (value of a variable), the fprintf com-
mand has the form:
The problem, as entered, has no solution.
Please check the input data.
fprintf('The problem, as entered, has no solution. Please check the
input data.')
x = 6; d = 19 + 5*x;
fprintf('Try to run the program later.')
y = d + x;
fprintf('Use different input values.')
The problem, as entered, has no solution. Please check the
input data.Try to run the program later.Use different input
values.
fprintf('text as string %-5.2f additional text',
variable_name)
The name of the
variable whose
value is displayed.
Formatting elements
(define the format of
the number).
The % sign marks the
spot where the number is
inserted within the text.
116.
4.3 Output Commands 105
The formatting elements are:
The flag, which is optional, can be one of the following three characters:
The field width and precision (5.2 in the previous example) are optional.
The first number (5 in the example) is the field width, which specifies the mini-
mum number of digits in the display. If the number to be displayed is shorter than
the field width, spaces or zeros are added in front of the number. The precision is
the second number (2 in the example). It specifies the number of digits to be dis-
played to the right of the decimal point.
The last element in the formatting elements, which is required, is the con-
version character, which specifies the notation in which the number is displayed.
Some of the common notations are:
e Exponential notation using lower-case e (e.g., 1.709098e+001).
E Exponential notation using upper-case E (e.g., 1.709098E+001).
f Fixed-point notation (e.g., 17.090980).
g The shorter of e or f notations.
G The shorter of E or f notations.
i Integer.
Information about additional notation is available in the help menu of MATLAB.
As an example, the fprintf command with a mix of text and a number is used
in the script file that calculates the average points scored in three games.
Character used
for flag
Description
– (minus sign) Left-justifies the number within the field.
+ (plus sign) Prints a sign character (+ or –) in front of the number.
0 (zero) Adds zeros if the number is shorter than the field.
% This script file calculates the average points scored in three games.
% The values are assigned to the variables by using the input command.
% The fprintf command is used to display the output.
game(1) = input('Enter the points scored in the first game ');
game(2) = input('Enter the points scored in the second game ');
game(3) = input('Enter the points scored in the third game ');
ave_points = mean(game);
–5.2f
Conversion character
(required).
Field width
and precision
(optional).
Flag
(optional).
117.
106 Chapter 4: Using Script Files and Managing Data
Notice that, besides using the fprintf command, this file differs from the ones
shown earlier in the chapter in that the scores are stored in the first three elements
of a vector named game, and the average of the scores is calculated by using the
mean function. The Command Window where the script file above (saved as
Chapter4Example6) was run is shown below.
With the fprintf command it is possible to insert more than one number
(value of a variable) within the text. This is done by typing %g (or % followed by
any formatting elements) at the places in the text where the numbers are to be
inserted. Then, after the string argument of the command (following the comma),
the names of the variables are typed in the order in which they are inserted in the
text. In general the command looks like:
An example is shown in the following script file:
fprintf('An average of %f points was scored in the three games.',ave_points)
>> Chapter4Example6
Enter the points scored in the first game 75
Enter the points scored in the second game 60
Enter the points scored in the third game 81
An average of 72.000000 points was scored in the three games.
>>
% This program calculates the distance a projectile flies,
% given its initial velocity and the angle at which it is shot.
% the fprintf command is used to display a mix of text and numbers.
v=1584; % Initial velocity (km/h)
theta=30; % Angle (degrees)
vms=v*1000/3600;
t=vms*sind(30)/9.81;
d=vms*cosd(30)*2*t/1000;
Text Additional
text.
% marks the
position of
the number.
The name of the
variable whose
value is displayed.
The display generated by the fprintf command
combines text and a number (value of a variable).
fprintf('..text...%g...%g...%f...',variable1,variable2,variable3)
Changing velocity units to m/s.
Calculating the time to highest point.
Calculating max distance.
118.
4.3 Output Commands 107
When this script file (saved as Chapter4Example7) is executed, the display in the
Command Window is:
Additional remarks about the fprintf command:
• To place a single quotation mark in the displayed text, type two single quota-
tion marks in the string inside the command.
• The fprintf command is vectorized. This means that when a variable that is
a vector or a matrix is included in the command, the command repeats itself
until all the elements are displayed. If the variable is a matrix, the data is used
column by column.
For example, the script file below creates a matrix T in which the first
row contains the numbers 1 through 5, and the second row shows the correspond-
ing square roots.
When this script file is executed, the display in the Command Window is:
fprintf('A projectile shot at %3.2f degrees with a velocity
of %4.2f km/h will travel a distance of %g km.n',theta,v,d)
>> Chapter4Example7
A projectile shot at 30.00 degrees with a velocity of
1584.00 km/h will travel a distance of 17.091 km.
>>
x=1:5;
y=sqrt(x);
T=[x; y]
fprintf('If the number is: %i, its square root is: %fn',T)
T =
1.0000 2.0000 3.0000 4.0000 5.0000
1.0000 1.4142 1.7321 2.0000 2.2361
If the number is: 1, its square root is: 1.000000
If the number is: 2, its square root is: 1.414214
If the number is: 3, its square root is: 1.732051
If the number is: 4, its square root is: 2.000000
If the number is: 5, its square root is: 2.236068
2 5
Create a vector x.
Create a vector y.
Create matrix T, first row is x, second row is y.2 5
The fprintf command displays two numbers from T in every line.
The matrix T.2 5
The fprintf
command repeats
five times, using
the numbers from
the matrix T col-
umn after column.
119.
108 Chapter 4: Using Script Files and Managing Data
Using the fprintf command to save output to a file:
In addition to displaying output in the Command Window, the fprintf com-
mand can be used for writing the output to a file when it is necessary to save the
output. The data that is saved can subsequently be displayed or used in MATLAB
and in other applications.
Writing output to a file requires three steps:
a) Opening a file using the fopen command.
b) Writing the output to the open file using the fprintf command.
c) Closing the file using the fclose command.
Step a:
Before data can be written to a file, the file must be opened. This is done with the
fopen command, which creates a new file or opens an existing file. The fopen
command has the form:
fid is a variable called the file identifier. A scalar value is assigned to fid when
fopen is executed. The file name is written (including its extension) within sin-
gle quotes as a string. The permission is a code (also written as a string) that tells
how the file is opened. Some of the more common permission codes are:
'r' Open file for reading (default).
'w' Open file for writing. If the file already exists, its content is deleted.
If the file does not exist, a new file is created.
'a' Same as 'w', except that if the file exists the written data is
appended to the end of the file.
'r+' Open file for reading and writing.
'w+' Open file for writing and writing. If the file already exists, its con-
tent is deleted. If the file does not exists, a new file is created.
'a+' Same as 'w+', except that if the file exists the written data is
appended to the end of the file.
If a permission code is not included in the command, the file opens with the
default code 'r'. Additional permission codes are described in the help menu.
Step b:
Once the file is open, the fprintf command can be used to write output to the
file. The fprintf command is used in exactly the same way as it is used to dis-
play output in the Command Window, except that the variable fid is inserted
inside the command. The fprintf command then has the form:
fid = fopen('file_name','permission')
fprintf(fid,'text %-5.2f additional text',vari
able_name)
fid is added to the fprintf command.
120.
4.3 Output Commands 109
Step c:
When the writing of data to the file is complete, the file is closed using the
fclose command. The fclose command has the form:
Additional notes on using the fprintf command for saving output to a file:
• The created file is saved in the current directory.
• It is possible to use the fprintf command to write to several different files.
This is done by first opening the files, assigning a different fid to each (e.g.
fid1, fid2, fid3, etc.), and then using the fid of a specific file in the
fprintf command to write to that file.
An example of using fprintf commands for saving output to two files is
shown in the following script file. The program in the file generates two unit con-
version tables. One table converts velocity units from miles per hour to kilometers
per hour, and the other table converts force units from pounds to newtons. Each
conversion table is saved to a different text file (extension .txt).
% Script file in which fprintf is used to write output to files.
% Two conversion tables are created and saved to two different files.
% One converts mi/h to km/h, the other converts lb to N.
clear all
Vmph=10:10:100;
Vkmh=Vmph.*1.609;
TBL1=[Vmph; Vkmh];
Flb=200:200:2000;
FN=Flb.*4.448;
TBL2=[Flb; FN];
fid1=fopen('VmphtoVkm.txt','w');
fid2=fopen('FlbtoFN.txt','w');
fprintf(fid1,'Velocity Conversion Tablen n');
fprintf(fid1,' mi/h km/h n');
fprintf(fid1,' %8.2f %8.2fn',TBL1);
fclose(fid)
Creating a vector of velocities in mi/h.
Converting mph to km/h.
Creating a table (matrix) with two rows.
Creating a vector of forces in lb.
Converting lb to N.
Creating a table (matrix) with two rows.
Open a .txt file named VmphtoVkm.
Open a .txt file named FlbtoFN.
Writing a title and an empty line to the file fid1.
Writing two column headings to the file fid1.
Writing the data from the variable TBL1 to the file fid1.
121.
110 Chapter 4: Using Script Files and Managing Data
When the script file above is executed two new .txt files, named
VmphtoVkm and FlbtoFN, are created and saved in the current directory. These
files can be opened with any application that can read .txt files. Figures 4-3 and 4-
4 show how the two files appear when they are opened with Microsoft Word.
fprintf(fid2,'Force Conversion Tablen n');
fprintf(fid2,' Pounds Newtons n');
fprintf(fid2,' %8.2f %8.2fn',TBL2);
fclose(fid1);
fclose(fid2);
Figure 4-3: The VmphtoVkm.txt file opened in Word.
Figure 4-4: The FlbtoFN.txt file opened in Word.
Writing the force con-
version table (data in
variable TBL2) to the
file fid2.
Closing the files fid1 and fid2.
122.
4.4 The save and load Commands 111
4.4 THE save AND load COMMANDS
The save and load commands are most useful for saving and retrieving data for
use in MATLAB. The save command can be used for saving the variables that
are currently in the workspace, and the load command is used for retrieving vari-
ables that have been previously saved, to the workspace. The workspace can be
saved when MATLAB is used in one type of platform (e.g., PC), and retrieved for
use in MATLAB in another platform (e.g., Mac). The save and load com-
mands can also be used for exchanging data with applications outside MATLAB.
Additional commands that can be used for this purpose are presented in Section
4.5.
4.4.1 The save Command
The save command is used for saving the variables (all or some of them) that are
stored in the workspace. The two simplest forms of the save command are:
When either one of these commands is executed, all of the variables currently in
the workspace are saved in a file named file_name.mat that is created in the
current directory. In mat files, which are written in a binary format, each variable
preserves its name, type, size, and value. These files cannot be read by other appli-
cations. The save command can also be used for saving only some of the vari-
ables that are in the workspace. For example, to save two variables named var1
and var2 the command is:
The save command can also be used for saving in ASCII format, which
can be read by applications outside MATLAB. Saving in ASCII format is done by
adding the argument -ascii in the command (for example, save file_name
-ascii). In the ASCII format the variable's name, type, and size are not pre-
served. The data is saved as characters separated by spaces but without the vari-
able names. For example, the following shows how two variables (a vector
and a matrix) are defined in the Command Window and then saved in
ASCII format to a file named DatSavAsci:
>> V=[3 16 -4 7.3];
>> A=[6 -2.1 15.5; -6.1 8 11];
>> save -ascii DatSavAsci
save file_name save('file_name')and
save file_name var1 var2
save('file_name','var1','var2')
or
1 4
2 3
Create a vector V.1 4
Create a matrix A.2 3
Save variables to a file named DatSavAsci.
123.
112 Chapter 4: Using Script Files and Managing Data
Once saved, the file can be opened by any application that can read ASCII files.
For example, Figure 4-5 shows the data when the file is opened with Notepad.
Note that the file does not include the names of the variables just the numerical
values of the variables (first A and then V) are listed.
4.4.2 The load Command
The load command can be used for retrieving variables that were saved with the
save command back to the workspace, and for importing data that was created
with other applications and saved in ASCII format or in text (.txt) files. Variables
that were saved with the save command in .mat files can be retrieved with the
command:
When the command is executed, all the variables in the file (with the name, type,
size, and values as were saved) are added (loaded back) to the workspace. If the
workspace already has a variable with the same name as a variable that is
retrieved with the load command, then the variable that is retrieved replaces the
existing variable. The load command can also be used for retrieving only some
of the variables that are in the saved .mat file. For example, to retrieve two vari-
ables named var1 and var2, the command is:
The load command can also be used to import data that is saved in ASCII
or text (.txt) to the workspace. This is possible, however, only if the data in the file
is in the form of a variable in MATLAB. Thus, the file can have one number (sca-
lar), a row or a column of numbers (vector), or rows with the same number of
numbers in each (matrix). For example, the data shown in Figure 4-5 cannot be
loaded with the load command (even though it was saved in ASCII format with
the save command) because the number of elements is not the same in all rows.
(Recall that this file was created by saving two different variables.)
Figure 4-5: Data saved in ASCII format.
load file_name load('file_name')or
load file_name var1 var2
load('file_name','var1','var2')
or
124.
4.4 The save and load Commands 113
When data is loaded from an ASCII or text file into the workspace it has to be
assigned to a variable name. Data in ASCII format can be loaded with either of the
following two forms of the load command:
If the data is in a text file, the extension .txt has to be added to the file name. The
form of the load command is then:
In the first form of the command the data is assigned to a variable that has the
name of the file. In the second form the data is assigned to a variable named
VarName.
For example, the data shown in Figure 4-6 (a matrix) is typed in
Notepad, and then saved as DataFromText.txt.
Next, two forms of the load command are used to import the data in the text
file to the Workspace of MATLAB. In the first command the data is assigned to a
variable named DfT. In the second command the data is automatically assigned to
a variable named DataFromText, which is the name of the text file where the
data was saved.
Importing data to (or exporting from) other applications can also be done, with
MATLAB commands that are presented in the next section.
Figure 4-6: Data saved as .txt file.
>> DfT=load('DataFromText.txt')
DfT =
56.0000 -4.2000
3.0000 7.5000
-1.6000 198.0000
>> load DataFromText.txt
>> DataFromText
DataFromText =
56.0000 -4.2000
3.0000 7.5000
-1.6000 198.0000
load file_name VarName=load('file_name')or
load file_name.txt VarName=load('file_name.txt')or
3 2
Load the file
DataFromText and
assign the loaded data to the
variable Dft.
Use the load command with
the file DataFromText.
The data is assigned to a vari-
able named DataFromText.
125.
114 Chapter 4: Using Script Files and Managing Data
4.5 IMPORTING AND EXPORTING DATA
MATLAB is often used for analyzing data that was recorded in experiments or
generated by other computer programs. This can be done by first importing the
data into MATLAB. Similarly, data that is produced by MATLAB sometimes
needs to be transferred to other computer applications. There are various types of
data (numerical, text, audio, graphics, and images). This section describes only
how to import and export numerical data, which is probably the most common
type of data that needs to be transferred by new users of MATLAB. For other
types of data transfer, look in the Help Window under File I/O.
Importing data can be done either by using commands or by using the
Import Wizard. Commands are useful when the format of the data being imported
is known. MATLAB has several commands that can be used for importing vari-
ous types of data. Importing commands can also be included in a script file such
that the data is imported when the script is executed. The Import Wizard is useful
when the format of the data (or the command that is applicable for importing the
data) is not known. The Import Wizard determines the format of the data and
automatically imports it.
4.5.1 Commands for Importing and Exporting Data
This section describes—in detail—how to transfer data into and out of Excel
spreadsheets. Microsoft Excel is commonly used for storing data, and Excel is
compatible with many data recording devices and computer applications. Many
people are also capable of importing and exporting various data formats into and
from Excel. MATLAB also has commands for transferring data directly to and
from formats such as csv and ASCII, and to the spreadsheet program Lotus 123.
Details of these and many other commands can be found in the Help Window
under File I/O
Importing and exporting data into and from Excel:
Importing data from Excel is done with the xlsread command. When the com-
mand is executed, the data from the spreadsheet is assigned as an array to a vari-
able. The simplest form of the xlsread command is:
• 'filename' (typed as a string) is the name of the Excel file. The directory
of the Excel file must be either the current directory or listed in the search path.
• If the Excel file has more than one sheet, the data will be imported from the
first sheet.
variable_name=xlsread('filename')
126.
4.5 Importing and Exporting Data 115
When an Excel file has several sheets, the xlsread command can be used to
import data from a specified sheet. The form of the command is then:
• The name of the sheet is typed as a string.
Another option is to import only a portion of the data that is in the spreadsheet.
This is done by typing an additional argument in the command:
• The 'range' (typed as a string) is a rectangular region of the spreadsheet
defined by the addresses (in Excel notation) of the cells at opposite corners of
the region. For example, 'C2:E5' is a region of rows 2, 3, 4, and 5 and
columns C, D, and E.
Exporting data from MATLAB to an Excel spreadsheet is done by using the
xlswrite command. The simplest form of the command is:
• 'filename' (typed as a string) is the name of the Excel file to which the
data is exported. The file must be in the current directory. If the file does not
exist, a new Excel file with the specified name will be created.
• variable_name is the name of the variable in MATLAB with the assigned
data that is being exported.
• The arguments 'sheet_name' and 'range' can be added to the
xlswrite command to export to a specified sheet and to a specified range of
cells, respectively.
As an example, the data from the Excel spreadsheet shown in Figure 4-7 is
imported into MATLAB by using the xlsread command.
Figure 4-7: Excel spreadsheet with data.
variable_name = xlsread('filename','sheet_name')
variable_name = xlsread('filename','sheet_name','range')
4 3
xlswrite('filename',variable_name)
127.
116 Chapter 4: Using Script Files and Managing Data
The spreadsheet is saved in a file named TestData1 in a disk in drive A.
After the Current Directory is changed to drive A, the data is imported into MAT-
LAB by assigning it to the variable DATA:
4.5.2 Using the Import Wizard
Using the Import Wizard is probably the easiest way to import data into MAT-
LAB since the user does not have to know, or to specify, the format of the data.
The Import Wizard is activated by selecting Import Data in the File menu of the
Command Window. (It can also be started by typing the command uiimport.)
The Import Wizard starts by displaying a file selection box that shows all the data
files recognized by the Wizard. The user then selects the file that contains the data
to be imported, and clicks Open. The Import Wizard opens the file and displays a
portion of the data in a preview box so that the user can verify that the data is the
correct choice. The Import Wizard tries to process the data, and if the wizard is
successful, it displays the variables it has created with a portion of the data. The
user clicks next and the wizard shows the Column Separator that was used. If the
variable has the correct data, the user can proceed with the wizard (click next);
otherwise the user can choose a different Column Separator. In the next window
the wizard shows the name and size of the variable to be created in MATLAB.
(When the data is all numerical, the variable in MATLAB has the same name as
the file from which the data was imported.) When the wizard ends (click finish),
the data is imported to MATLAB.
As an example, the Import Wizard is used to import numerical ASCII data
saved in a .txt file. The data saved with the file name TestData2 is shown in Figure
4-8.
>> DATA = xlsread('TestData1')
DATA =
11.0000 2.0000 34.0000 14.0000 -6.0000 0 8.0000
15.0000 6.0000 -20.0000 8.0000 0.5600 33.0000 5.0000
0.9000 10.0000 3.0000 12.0000 -25.0000 -0.1000 4.0000
55.0000 9.0000 1.0000 -0.5550 17.0000 6.0000 -30.0000
Figure 4-8: Numerical ASCII data.
128.
4.5 Importing and Exporting Data 117
The display of the Import Wizard during the import process for the TestData2 file
is shown in Figures 4-9 and 4-10. Figure 4-10 shows that the name of the variable
in MATLAB is TestData2 and its size is .
In the Command Window of MATLAB, the imported data can be displayed by
typing the name of the variable.
Figure 4-9: Import Wizard, first display.
Figure 4-10: Import Wizard, second display.
>> TestData2
TestData2 =
5.1200 33.0000 22.0000 13.0000 4.0000
4.0000 92.0000 0 1.0000 7.5000
12.0000 5.0000 6.5300 15.0000 3.0000
3 5
129.
118 Chapter 4: Using Script Files and Managing Data
4.6 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 4-1: Height and surface area of a silo
A cylindrical silo with radius r has a spher-
ical cap roof with radius R. The height of
the cylindrical portion is H. Write a pro-
gram in a script file that determines the
height H for given values of r, R, and the
volume V. In addition, the program calcu-
lates the surface area of the silo.
Use the program to calculate the height and
surface area of a silo with r = 30 ft, R = 45
ft, and a volume of 120,000 ft3. Assign val-
ues for r, R, and V in the Command Win-
dow.
Solution
The total volume of the silo is obtained by
adding the volume of the cylindrical part and the volume of the spherical cap. The
volume of the cylinder is given by
and the volume of the spherical cap is given
by:
where ,
and is calculated from .
Using the equations above, the height, H, of
the cylindrical part can be expressed by
The surface area of the silo is obtained by
adding the surface areas of the cylindrical part and the spherical cap.
A program in a script file that solves the problem is presented below:
theta=asin(r/R);
h=R*(1-cos(theta));
Vcap=pi*h^2*(3*R-h)/3;
Vcyl r2H=
Vcap
1
3
--- h
2
3R h–=
h R Rcos– R 1 cos–= =
sin
r
R
---=
H
V Vcap–
r2
--------------------=
S Scyl Scap+ 2 rH 2 Rh+= =
Calculating .
Calculating h.
Calculating the volume of the cap.
130.
4.6 Examples of MATLAB Applications 119
The Command Window where the script file, named silo, was executed is:
Sample Problem 4-2: Centroid of a composite area
Write a program in a script file that calcu-
lates the coordinates of the centroid of a
composite area. (A composite area can
easily be divided into sections whose
centroids are known.) The user needs to
divide the area into sections and know the
coordinates of the centroid (two num-
bers) and the area of each section (one
number). When the script file is executed,
it asks the user to enter the three numbers
as a row in a matrix. The user enters as
many rows as there are sections. A sec-
tion that represents a hole is taken to have
a negative area. For output, the program
displays the coordinates of the centroid of the composite area. Use the program to
calculate the centroid of the area shown in the figure.
Solution
The area is divided into six sections as shown in the following figure. The total
area is calculated by adding the three sections on the left and subtracting the three
sections on the right. The location and coordinates of the centroid of each section
are marked in the figure, as well as the area of each section.
The coordinates and of the centroid of the total area are given by
and , where , , and A are the coordinates of the centroid
and area of each section, respectively.
A script file with a program for calculating the coordinates of the centroid
of a composite area is provided below.
H=(V-Vcap)/(pi*r^2);
S=2*pi*(r*H + R*h);
fprintf('The height H is: %f ft.',H)
fprintf('nThe surface area of the silo is: %f square ft.',S)
>> r=30; R=45; V=200000;
>> silo
The height H is: 64.727400 ft.
The surface area of the silo is: 15440.777753 square ft.
Calculating H.
Calculating the surface area S.
Assigning values to r, R, and V.
Running the script file named silo.
200
3040
150
200
50
50
100
50
20
R 60
Dimensions in mm
X Y
X
Ax
A
----------= Y
Ay
A
----------= x y
131.
120 Chapter 4: Using Script Files and Managing Data
The script file was saved with the name Centroid. The following shows the Com-
mand Window where the script file was executed.
% The program calculates the coordinates of the centroid
% of a composite area.
clear C xs ys As
C=input('Enter a matrix in which each row has three ele-
ments.nIn each row enter the x and y coordinates of the
centroid and the area of a section.n');
xs=C(:,1)';
ys=C(:,2)';
As=C(:,3)';
A=sum(As);
x=sum(As.*xs)/A;
y=sum(As.*ys)/A;
fprintf('The coordinates of the centroid are: ( %f, %f )n',x,y)
>> Centroid
Enter a matrix in which each row has three elements.
In each row enter the x and y coordinates of the centroid
and the area of a section.
Units: coordinates mm, area mm2
(100, 100)
A = 200*200
(60 + , 220)
140
3
(60 - , )
A = π*602/4
80
π 200 +80
π ( , 100 )
A = π502/2
200
3π (150, 95)
A = 40*150
x x
y y
(105, 145)
A = 50*50A = 140*60/2
Creating a row vector for the x coordinate of
each section (first column of C).
Creating a row vector for the y coordinate of
each section (second column of C).
Creating a row vector for the area of each
section (third column of C).
Calculating the total area.
Calculating the coordinates of the
centroid of the composite area.
132.
4.6 Examples of MATLAB Applications 121
Sample Problem 4-3: Voltage divider
When several resistors are connected in an electrical circuit in series, the voltage
across each of them is given by the voltage divider rule:
where vn and Rn are the voltage across resistor n and its resistance, respectively,
is the equivalent resistance, and vs is the source voltage. The power
dissipated in each resistor is given by:
The figure below shows a circuit with seven resistors connected in series.
Write a program in a script file that calculates the voltage across each resistor, and
the power dissipated in each resistor, in a circuit that has resistors connected in
series. When the script file is executed it requests the user to first enter the source
voltage and then to enter the resistances of the resistors in a vector. The program
displays a table with the resistance listed in the first column, the voltage across the
resistor in the second column, and the power dissipated in the resistor in the third
column. Following the table, the program displays the current in the circuit and
the total power.
Execute the file and enter the following data for vs and the R's.
V, , , , , ,
, .
[100 100 200*200
60-80/pi 200+80/pi pi*60^2/4
60+140/3 220 140*60/2
200/(3*pi) 100 -pi*50^2/2
105 145 -50*50
150 95 -40*150]
The coordinates of the centroid are: ( 85.387547 , 131.211809 )
Entering the data for matrix C.
Each row has three elements: the
x, y, and A of a section.
vn
Rn
Req
--------vs=
Req Rn=
Pn
Rn
Req
2
--------vs
2=
+
_
R1 R2 R3
vs R4
R5R6R7
vs 24= R1 20= R2 14= R3 12= R4 18= R5 8=
R6 15= R7 10=
133.
122 Chapter 4: Using Script Files and Managing Data
Solution
A script file that solves the problem is shown below.
The Command Window where the script file was executed is:
% The program calculates the voltage across each resistor
% in a circuit that has resistors connected in series.
vs=input('Please enter the source voltage ');
Rn=input('Enter the values of the resistors as elements in a
row vectorn');
Req=sum(Rn);
vn=Rn*vs/Req;
Pn=Rn*vs^2/Req^2;
i = vs/Req;
Ptotal = vs*i;
Table = [Rn', vn', Pn'];
disp(' ')
disp(' Resistance Voltage Power')
disp(' (Ohms) (Volts) (Watts)')
disp(' ')
disp(Table)
disp(' ')
fprintf('The current in the circuit is %f Amps.',i)
fprintf('nThe total power dissipated in the circuit is %f
Watts.',Ptotal)
>> VoltageDivider
Please enter the source voltage 24
Enter the value of the resistors as elements in a row vector
[20 14 12 18 8 15 10]
Resistance Voltage Power
(Ohms) (Volts) (Watts)
20.0000 4.9485 1.2244
14.0000 3.4639 0.8571
12.0000 2.9691 0.7346
18.0000 4.4536 1.1019
8.0000 1.9794 0.4897
Calculate the equivalent resistance.
Apply the voltage divider rule.
Calculate the power in each resistor.
Calculate the current in the circuit.
Calculate the total power in the circuit.
Create a variable table with the
vectors Rn, vn, and Pn as columns.
Display headings for
the columns.
Display an empty line.
Display the variable Table.
Name of the script file.
Voltage entered by the user.
Resistor values entered as a vector.
134.
4.7 Problems 123
4.7 PROBLEMS
Solve the following problems by first writing a program in a script file and then
executing the program.
1. The wind chill temperature, , is the air temperature felt on exposed skin
due to wind. In U.S. customary units it is calculated by
where T is the temperature in degrees F and v is the wind speed in mi/h. Write
a MATLAB program in a script file that calculates . For input the program
asks the user to enter values for T and v. For output the program displays the
message: "The wind chill temperature is: XX," where XX is the value of the
wind chill temperature rounded to the nearest integer. Execute the program
entering and mi/h.
2. The monthly payment M of a loan amount P for y years and with interest rate r
can be calculated by the formula:
Calculate the monthly payment and the total payment for a $100,000 loan for
10, 11, 12, ... , 29, 30 years with an interest rate of 4.85%. Display the results
in a three-column table where the first column is the number of years, the sec-
ond is the monthly payment, and the third is the total payment.
3. A torus-shaped water tube is designed to have a
volume of 8,000 in.3
. The volume of the tube, V,
and its surface area, S, are given by:
and
If , determine S and a and b for K = 0.2, 0.3,
0.4, 0.6, and 0.7. Display the results in a table.
15.0000 3.7113 0.9183
10.0000 2.4742 0.6122
The current in the circuit is 0.247423 Amps.
The total power dissipated in the circuit is 5.938144 Watts.
Twc
Twc 35.74 0.6215T 35.75v0.16– 0.4275T v0.16+ +=
Twc
T 30 F= v 42=
M
P r 12
1 1 r 12+ 12y––
--------------------------------------------=
ab
V
1
4
--- 2 a b+ b a– 2= S 2 b2 a2–=
a Kb=
135.
124 Chapter 4: Using Script Files and Managing Data
4. An ice cream container shaped as a frustum of a cone
with is designed to have a volume of 1,000
cm3. Determine , , and the surface area, S, of the
paper for containers with heights h of 8, 10, 12, 14,
and 16 cm. Display the results in a table.
The volume of the container, V, and the surface area
of the paper are given by:
5. Write a MATLAB program in a script file that calculate the average, standard
deviation, and median of a list of grades as well as the number of grades on
the list. The program asks the user (input command) to enter the grades as
elements of a vector. The program then calculates the required quantities
using MATLAB's built-in functions length, mean, std, and median.
The results are displayed in the Command Window in the following format:
"There are XX grades." where XX is the numerical value.
"The average grade is XX." where XX is the numerical value.
"The standard deviation is XX." where XX is the numerical value.
"The median deviation is XX." where XX is the numerical value.
Execute the program and enter the following grades: 81, 65, 61, 78, 94, 80,
65, 76, 77, 95, 82, 49, and 75.
6. The growth of some bacteria populations can be described by
where N is the number of individuals at time t, is the number at time ,
and k is a constant. Assuming the number of bacteria doubles every hour,
determine the number of bacteria every hour for 24 hours starting from an ini-
tial single bacterium.
7. A rocket flying straight up measures the angle with
the horizon at different heights h. Write a MATLAB
program in a script file that calculates the radius of the
earth R (assuming the earth is a perfect sphere) at each
data point and then determines the average of all the val-
ues.
h (km) 4 8 12 16 20 24 28 32 36 40
(deg) 2.0 2.9 3.5 4.1 4.5 5.0 5.4 5.7 6.1 6.4
h
R2
R1
R2 1.2R1=
R1 R2
V
1
3
--- h R1
2
R2
2
R1R2+ +=
S R1 R2+ R2 R1–
2
h
2
+ R1
2
R2
2
++=
N N0ekt=
N0 t 0=
R
h
R
θ
136.
4.7 Problems 125
8. A railroad bumper is designed to slow down a
rapidly moving railroad car. After a 20,000 kg
railroad car traveling at 20 m/s engages the
bumper, its displacement x (in meters) and
velocity v (in m/s) as a function of time t (in
seconds) is given by:
and
Determine x and v for every two hundredth of a second for the first half sec-
ond after impact. Display the results in a three-column table in which the first
column is time (s), the second is displacement (m), and the third is velocity
(m/s).
9. Decay of radioactive materials can be modeled by the equation ,
where A is the amount at time t, is the amount at t = 0, and k is the decay
constant ( ). Iodine-132 is a radioisotope that is used in thyroid function
tests. Its half-life time is 13.3 hours. Calculate the relative amount of Iodine-
132 ( ) in a patient's body 48 hours after receiving a dose. After deter-
mining the value of k, define a vector and calculate the cor-
responding values of .
10. The value, B, of a savings account of an amount A that is deposited for n years
with a yearly interest rate of r is given by:
Write a MATLAB program in a script file that calculates the balance B after
10 years for an initial deposit of $10,000 for yearly interest rates ranging from
2% to 6% with increments of 0.5%. Display the results in a table. The table
should have two columns where the first column displays the interest rate and
the second displays the corresponding value of B.
11. A rectangular printed page with sides of lengths a
and b is designed to have a printed area of 60 in.2
and margins of 1.75 in. at the top and bottom and
1.2 in. at both sides. Write a MATLAB program
that determine the dimensions of a and b such that
the overall area of the page will be as small as pos-
sible. In the program define a vector a with values
ranging from 5 to 20 with increments of 0.05. Use
this vector for calculating the corresponding val-
ues of b and the overall area of the page. Then use
MATLAB's built-in function min to find the dimensions of the smallest
page.
x
m
v
x t 4.219 e 1.58t– e 6.32t––= v t 26.67e 6.32t– 6.67e 1.58t––=
A A0ekt=
A0
k 0
A A0
t 0 4 8 48=
A A0
B A 1
r
100
---------+
n
=
A = 60 in2
1.75 in.
1.2 in.
b
a
137.
126 Chapter 4: Using Script Files and Managing Data
12. A round billboard with radius in. is
designed to have a rectangular picture placed
inside a rectangle with sides a and b. The mar-
gins between the rectangle and the picture are
10 in. at the top and bottom and 4 in. at each
side. Write a MATLAB program that deter-
mines the dimensions a and b such that the
overall area of the picture will be as large as
possible. In the program define a vector a with
values ranging from 5 to 100 with increments
of 0.25. Use this vector for calculating the cor-
responding values of b and the overall area of the picture. Then use MAT-
LAB's built-in function max to find the dimensions of the largest rectangle.
13. The balance of a loan, B, after n monthly payments is given by
where A is the loan amount, P is the amount of a monthly payment, and r is the
yearly interest rate entered in % (e.g., 7.5% entered as 7.5). Consider a 5-year,
$20,000 car loan with 6.5% yearly interest that has a monthly payment of
$391.32. Calculate the balance of the loan after every 6 months (i.e., at n = 6,
12, 18, 24, ... , 54, 60). Each time calculate the percent of the loan that is
already paid. Display the results in a three-column table, where the first col-
umn displays the month, and the second and third columns display the corre-
sponding value of B and percentage of the loan that is already paid,
respectively.
14. A large TV screen of height ft is placed
on the side wall of a tall building. The height from
the street to the bottom of the screen is ft.
The best view of the screen is when is maxi-
mum. Write a MATLAB program that determines
the distance x at which is at maximum. Define a
vector x with elements ranging from 30 to 300
with spacing of 0.5. Use this vector to calculate the corresponding values of .
Then use MATLAB's built-in function min to find the value of x that corre-
sponds to the largest value of .
Picture
10 in
4 in
b
a
R
R 55=
B A 1 r
1200
------------–
n P
r 1200
------------------ 1 r
1200
------------+
n
1––=
h
x
H
θ
H 50=
h 130=
138.
4.7 Problems 127
15. A student has a summer job as a
lifeguard at the beach. After spotting a
swimmer in trouble, he tries to deduce
the path by which he can reach the
swimmer in the shortest time. The
path of shortest distance (path A) is
obviously not the best since it
maximizes the time spent swimming
(he can run faster than he can swim).
Path B minimizes the time spent swimming but is probably not the best since
it is the longest (reasonable) path. Clearly the optimal path is somewhere in
between paths A and B.
Consider an intermediate path C and determine the time required to reach
the swimmer in terms of the running speed m/s the swimming speed
m/s; the distances m, m, and m; and the
lateral distance y at which the lifeguard enters the water. Create a vector y that
ranges between path A and path B ( m) and compute a
time t for each y. Use MATLAB built-in function min to find the minimum
time and the entry point y for which it occurs. Determine the angles that
correspond to the calculated value of y and investigate whether your result sat-
isfies Snell's law of refraction:
16. The airplane shown is flying at a constant speed of
m/s in a circular path of radius m
and is being tracked by a radar station positioned a
distance m below the bottom of the plane
path (point A). The airplane is at point A at ,
and the angle as a function of time is given (in
radians) by . Write a MATLAB program
that calculates and r as functions of time. The
program should first determine the time at which . Then construct a
vector t having 15 elements over the interval , and calculate and r
at each time. The program should print the values of , h, and v, followed by a
table where the first column is t, the second is the angle in degrees,
and the third is the corresponding value of r.
φ
α
dw
ds
L
Lifeguard
swimmer
shoreline
A
C
B
y
vrun 3=
vswim 1= L 48= ds 30= dw 42=
y 20 21 22 48=
tmin
sin
sin
-----------
vrun
vswim
------------=
α
θ
ρ
r
v
h
A
v 50= 2000=
h 500=
t 0=
v
---t=
90=
0 t t90
15 3
139.
128 Chapter 4: Using Script Files and Managing Data
17. Early explorers often estimated altitude by measuring the temperature of boil-
ing water. Use the following two equations to make a table that modern-day
hikers could use for the same purpose.
,
where p is atmospheric pressure in inches of mercury, is boiling tempera-
ture in F, and h is altitude in feet. The table should have two columns, the
first altitude and the second boiling temperature. The altitude should range
between –500 ft and 10,000 ft at increments of 500 ft.
18. The variation of vapor pressure p (in units of mm Hg) of benzene with tem-
perature in the range of C can be modeled with the equation
(Handbook of Chemistry and Physics, CRC Press)
where and are material constants and T is absolute
temperature (K). Write a program in a script file that calculates the pressure
for various temperatures. The program should create a vector of temperatures
from C to o
C with increments of 2 degrees, and display a two-
column table p and T, where the first column temperatures in C, and the sec-
ond column the corresponding pressures in mm Hg.
19. For many gases the temperature dependence of the heat capacity of can be
described in terms of a cubic equation:
The following table gives the coefficients of the cubic equation for four gases.
is in joules/(g mol)( C) and T is in C.
Calculate the heat capacity for each gas at temperatures ranging between 200
and 400 C at 20 C increments. To present the results, create an
matrix where the first column is the temperature, and the second through fifth
columns are the heat capacities of SO2, SO3, O2, and N2, respectively.
Gas a b c d
SO2 38.91
SO3 48.50
O2 29.10
N2 29.00
p 29.921 1 6.8753 10 6– h–= Tb 49.161 pln 44.932+=
Tb
0 T 42
10
plog b
0.05223a
T
----------------------–=
a 34172= b 7.9622=
T 0= T 4211 5
140.
4.7 Problems 129
20. The heat capacity of an ideal mixture of four gases can be expressed in
terms of the heat capacity of the components by the mixture equation
where , and are the fractions of the components, and
, and are the corresponding heat capacities. A mixture of
unknown quantities of the four gases SO2, SO3, O2, and N2 is given. To deter-
mine the fractions of the components, the following values of the heat capac-
ity of the mixture were measured at three temperatures:
Use the equation and data in the Problem 19 to determine the heat capacity of
each of the four components at the three temperatures. Then use the mixture
equation to write three equations for the mixture at the three temperatures.
The fourth equation is . Determine , and by
solving the linear system of equations.
21. When several resistors are connected in an electrical circuit in parallel, the
current through each of them is given by where in and Rn are the cur-
rent through resistor n and its resistance, respectively, and vs is the source
voltage. The equivalent resistance, Req, can be determined from the equation
The source current is given by , and the power, Pn, dissipated in
each resistor is given by .
Write a program in a script file that calculates the current through each
resistor and the power dissipated in a circuit that has resistors connected in
parallel. When the script file runs, it asks the user first to enter the source volt-
age and then to enter the resistors' resistance in a vector. The program dis-
plays a table with the resistance shown in the first column, the current through
the resistor in the second column, and the power dissipated in the resistor in
the third column. Following the table, the program displays the source current
and the total power. Use the script file to solve the following circuit.
Temperature C 25 150 300
joules/(g mol)( C) 39.82 44.72 49.10
Cpmixture
Cpmixture
x1Cp1 x2Cp2 x3Cp3 x4Cp4+ + +=
x1 x2 x3 x4
Cp1 Cp2 Cp3 Cp4
Cpmixture
x1 x2 x3 x4+ + + 1= x1 x2 x3 x4
in
vs
Rn
-----=
1
Req
--------
1
R1
-----
1
R2
-----
1
Rn
-----+ + +=
is vs Req=
Pn vsin=
vs = 48 V
+
_
34Ω
26Ω
45Ω
60Ω
10Ω
20Ω
142.
4.7 Problems 131
25. The surface of many airfoils can be
described with an equation of the form
where t is the maximum thickness as a fraction of the chord length c (e.g.,
). Given that m and m, the following values for y have
been measured for a particular airfoil:
Determine the constants , and . (Write a system of five equa-
tions and five unknowns and use MATLAB to solve the equations.)
26. During a golf match, a certain number of points are awarded for each eagle
and a different number for each birdie. No points are awarded for par, and a
certain number of points are deducted for each bogey and a different number
deducted for each double bogey (or worse). The newspaper report of an
important match neglected to mention what these point values were, but did
provide the following table of the results:
From the information in the table write four equations in terms of four
unknowns. Solve the equations for the unknown points awarded for eagles
and birdies and points deducted for bogeys and double bogeys.
27. The dissolution of copper sulfide in aqueous nitric acid is described by the
following chemical equation:
where the coefficients a, b, c, d, e, f, and g are the numbers of the various mol-
ecule participating in the reaction and are unknown. The unknown coeffi-
cients are determined by balancing each atom on left and right and then
balancing the ionic charge. The resulting equations are:
, , , , ,
x (m) 0.15 0.35 0.5 0.7 0.85
y (m) 0.08909 0.09914 0.08823 0.06107 0.03421
Golfer Eagles Birdies Pars Bogeys Doubles Points
A 1 2 10 1 1 5
B 2 3 11 0 1 12
C 1 4 10 1 10 11
D 1 3 10 12 0 8
x
y
c
Thickness
tmax
y
tc
0.2
------- a0 x c a1 x c+ +=
a+ 2 x c 2 a3 x c 3 a4 x c 4+ +
tmax ct= c 1= t 0.2=
a0 a1 a2 a3 a4
aCuS bNO3
–
cH
+
+ + dCu
2 +
eSO4
2 –
f NO gH2O+ + +
a d= a e= b f= 3b 4e f g+ += c 2g= b– c+ 2d 2e–=
143.
132 Chapter 4: Using Script Files and Managing Data
There are seven unknowns and only six equations. A solution can still be
obtained, however, by taking advantage of the fact that all the coefficients
must be positive integers. Add a seventh equation by guessing and
solve the system of equations. The solution is valid if all the coefficients are
positive integers. If this is not the case, take and repeat the solution.
Continue the process until all the coefficients in the solution are positive inte-
gers.
28 Write
a MATLAB program in a script file that displays the following chart of wind
chill temperature for given air temperature and wind speed in the Command
Window:
Temperature (F)
40 30 20 10 0 -10 -20 -30 -40
Speed
(mi/h)
10 34 21 9 -4 -16 -28 -41 -53 -66
20 30 17 4 -9 -22 -35 -48 -61 -74
30 28 15 1 -12 -26 -39 -53 -67 -80
40 27 13 -1 -15 -29 -43 -57 -71 -84
50 26 12 -3 -17 -31 -45 -60 -74 -88
60 25 10 -4 -19 -33 -48 -62 -76 -91
29. The stress intensity factor due to the crack shown depends
upon a geometrical parameter given by:
where . Calculate for between 0.05 and 0.95
at 0.05 increments, and display the results in a two-column
table with the first column showing and the second .
a 1=
a 2=
Twc
Twc 35.74 0.6215T 35.75v0.16– 0.4275T v0.16+ +=
M
M
b
a
CI
CI
2
-------
2
-------tan
0.923 0.199 1
2
-------sin–+
2
-------cos
---------------------------------------------------------------=
a
b
---= CI
CI
144.
133
Chapter 5
Two-Dimensional
Plots
Plots are a very useful tool for presenting information. This is true in any field, but
especially in science and engineering, where MATLAB is mostly used. MATLAB
has many commands that can be used for creating different types of plots. These
include standard plots with linear axes, plots with logarithmic and semi-logarith-
mic axes, bar and stairs plots, polar plots, three-dimensional contour surface and
mesh plots, and many more. The plots can be formatted to have a desired appear-
ance. The line type (solid, dashed, etc.), color, and thickness can be prescribed,
line markers and grid lines can be added, as can titles and text comments. Several
graphs can be created in the same plot, and several plots can be placed on the
same page. When a plot contains several graphs and/or data points, a legend can
be added to the plot as well.
This chapter describes how MATLAB can be used to create and format
many types of two-dimensional plots. Three-dimensional plots are addressed sep-
arately in Chapter 9. An example of a simple two-dimensional plot that was cre-
ated with MATLAB is shown in Figure 5-1. The figure contains two curves that
show the variation of light intensity with distance. One curve is constructed from
data points measured in an experiment, and the other curve shows the variation of
light as predicted by a theoretical model. The axes in the figure are both linear,
and different types of lines (one solid and one dashed) are used for the curves. The
theoretical curve is shown with a solid line, while the experimental points are con-
nected with a dashed line. Each data point is marked with a circular marker. The
dashed line that connects the experimental points is actually red when the plot is
displayed in the Figure Window. As shown, the plot in Figure 5-1 is formatted to
have a title, axis titles, a legend, markers, and a boxed text label.
145.
134 Chapter 5: Two-Dimensional Plots
5.1 THE plot COMMAND
The plot command is used to create two-dimensional plots. The simplest form
of the command is:
The arguments x and y are each a vector (one-dimensional array). The two vec-
tors must have the same number of elements. When the plot command is exe-
cuted, a figure is created in the Figure Window. If not already open, the Figure
Window opens automatically when the command is executed. The figure has a
single curve with the x values on the abscissa (horizontal axis) and the y values
on the ordinate (vertical axis). The curve is constructed of straight-line segments
that connect the points whose coordinates are defined by the elements of the vec-
tors x and y. Each of the vectors, of course, can have any name. The vector that is
typed first in the plot command is used for the horizontal axis, and the vector
that is typed second is used for the vertical axis.
The figure that is created has axes with a linear scale and default range. For
example, if a vector x has the elements 1, 2, 3, 5, 7, 7.5, 8, 10, and a vector y has
the elements 2, 6.5, 7, 7, 5.5, 4, 6, 8, a simple plot of y versus x can be created by
typing the following in the Command Window:
Figure 5-1: Example of a formatted two-dimensional plot.
8 10 12 14 16 18 20 22 24
0
200
400
600
800
1000
1200
DISTANCE (cm)
INTENSITY(lux)
Light Intensity as a Function of Distance
Comparison between theory and experiment.
Theory
Experiment
X AXIS LABEL
LEGEND
TEXT
LABEL
PLOT TITLE
Y AXIS
LABEL
MARKER
plot(x,y)
Vector Vector
146.
5.1 The plot Command 135
Once the plot command is executed, the Figure Window opens and the plot is
displayed, as shown in Figure 5-2.
The plot appears on the screen in blue, which is the default line color.
The plot command has additional, optional arguments that can be used to
specify the color and style of the line and the color and type of markers, if any are
desired. With these options the command has the form:
Line Specifiers:
Line specifiers are optional and can be used to define the style and color of the
line and the type of markers (if markers are desired). The line style specifiers are:
>> x=[1 2 3 5 7 7.5 8 10];
>> y=[2 6.5 7 7 5.5 4 6 8];
>> plot(x,y)
Figure 5-2: The Figure Window with a simple plot.
Line Style Specifier Line Style Specifier
solid (default) - dotted :
dashed -- dash-dot -.
plot(x,y,'line specifiers','PropertyName',PropertyValue)
(Optional) Specifiers that
define the type and color
of the line and markers.
Vector Vector
(Optional) Properties with
values that can be used to
specify the line width, and a
marker's size and edge, and
fill colors.
147.
136 Chapter 5: Two-Dimensional Plots
The line color specifiers are:
The marker type specifiers are:
Notes about using the specifiers:
• The specifiers are typed inside the plot command as strings.
• Within the string the specifiers can be typed in any order.
• The specifiers are optional. This means that none, one, two, or all three types
can be included in a command.
Some examples:
plot(x,y) A blue solid line connects the points with no markers
(default).
plot(x,y,'r') A red solid line connects the points.
plot(x,y,'--y') A yellow dashed line connects the points.
plot(x,y,'*') The points are marked with * (no line between the
points).
plot(x,y,'g:d') A green dotted line connects the points that are marked
with diamond markers.
Property Name and Property Value:
Properties are optional and can be used to specify the thickness of the line, the size
of the marker, and the colors of the marker's edge line and fill. The Property
Name is typed as a string, followed by a comma and a value for the property, all
inside the plot command.
Line Color Specifier Line Color Specifier
red r magenta m
green g yellow y
blue b black k
cyan c white w
Marker Type Specifier Marker Type Specifier
plus sign + square s
circle o diamond d
asterisk * five-pointed star p
point . six-pointed star h
cross x triangle (pointed left) <
triangle (pointed up) ^ triangle (pointed right) >
triangle (pointed down) v
148.
5.1 The plot Command 137
Four properties and their possible values are:
For example, the command
plot(x,y,'-mo','LineWidth',2,'markersize',12,
'MarkerEdgeColor','g','markerfacecolor','y')
creates a plot that connects the points with a magenta solid line and circles as
markers at the points. The line width is 2 points and the size of the circle markers
is 12 points. The markers have a green edge line and yellow filling.
A note about line specifiers and properties:
The three line specifiers, which indicate the style and color of the line, and the
type of the marker can also be assigned with a PropertyName argument fol-
lowed by a PropertyValue argument. The Property Names for the line speci-
fiers are:
As with any command, the plot command can be typed in the Command
Window, or it can be included in a script file. It also can be used in a function file
(explained in Chapter 7). It should also be remembered that before the plot com-
mand can be executed the vectors x and y must have assigned elements. This can
Property name Description
Possible property
values
LineWidth
(or linewidth)
Specifies the width of the
line.
A number in units of
points (default 0.5).
MarkerSize
(or markersize)
Specifies the size of the
marker.
A number in units of
points.
MarkerEdgeColor
(or
markeredgecolor)
Specifies the color of the
marker, or the color of the
edge line for filled mark-
ers.
Color specifiers from
the table above, typed
as a string.
MarkerFaceColor
(or
markerfacecolor)
Specifies the color of the
filling for filled markers.
Color specifiers from
the table above, typed
as a string.
Specifier Property Name Possible property values
Line style linestyle
(or LineStyle)
Line style specifier from the
table above, typed as a string.
Line color color (or Color) Color specifier from the table
above, typed as a string.
Marker marker (or Marker) Marker specifier from the
table above, typed as a string.
149.
138 Chapter 5: Two-Dimensional Plots
be done, as was explained in Chapter 2, by entering values directly, by using com-
mands, or as the result of mathematical operations. The next two subsections
show examples of creating simple plots.
5.1.1 Plot of Given Data
In this case given data is used to create vectors that are then used in the plot
command. The following table contains sales data of a company from 1988 to
1994.
To plot this data, the list of years is assigned to one vector (named yr), and
the corresponding sales data is assigned to a second vector (named sle). The
Command Window where the vectors are created and the plot command is used
is shown below:
Once the plot command is executed, the Figure Window with the plot, as shown
in Figure 5-3, opens. The plot appears on the screen in red.
Year 1988 1989 1990 1991 1992 1993 1994
Sales
(millions)
8 12 20 22 18 24 27
>> yr=[1988:1:1994];
>> sle=[8 12 20 22 18 24 27];
>> plot(yr,sle,'--r*','linewidth',2,'markersize',12)
>>
Figure 5-3: The Figure Window with a plot of the sales data.
Line Specifiers:
dashed red line and
asterisk marker.
Property Name and Property Value:
the line width is 2 points and the marker
size is 12 points.
150.
5.1 The plot Command 139
5.1.2 Plot of a Function
In many situations there is a need to plot a given function. This can be done in
MATLAB by using the plot or the fplot command. The use of the plot com-
mand is explained below. The fplot command is explained in detail in the next
section.
In order to plot a function with the plot command, the user needs
to first create a vector of values of x for the domain over which the function will
be plotted. Then a vector y is created with the corresponding values of by
using element-by-element calculations (see Chapter 3). Once the two vectors are
defined, they can be used in the plot command.
As an example, the plot command is used to plot the function
for . A program that plots this function is shown in
the following script file.
Once the script file is executed, the plot is created in the Figure Window, as
shown in Figure 5-4. Since the plot is made up of segments of straight lines that
connect the points, to obtain an accurate plot of a function, the spacing between
the elements of the vector x must be appropriate. Smaller spacing is needed for a
% A script file that creates a plot of
% the function: 3.5.^(-0.5*x).*cos(6x)
x=[-2:0.01:4];
y=3.5.^(-0.5*x).*cos(6*x);
plot(x,y)
Figure 5-4: The Figure Window with a plot of the function .
y f x=
f x
y 3.5
0.5x–
6xcos= 2– x 4
Create vector x with the domain of the function.
Create vector y with the function
value at each x.
Plot y as a function of x.
y 3.5
0.5x–
6xcos=
151.
140 Chapter 5: Two-Dimensional Plots
function that changes rapidly. In the last example a small spacing of 0.01 pro-
duced the plot that is shown in Figure 5-4. However, if the same function in the
same domain is plotted with much larger spacing—for example, 0.3—the plot that
is obtained, shown in Figure 5-5, gives a distorted picture of the function. Note
also that in Figure 5-4 the plot is shown with the Figure Window, while in Figure
5-5 only the plot is shown. The plot can be copied from the Figure Window (in the
Edit menu, select Copy Figure) and then pasted into other applications.
5.2 THE fplot COMMAND
The fplot command plots a function with the form between specified
limits. The command has the form:
'function': The function can be typed directly as a string inside the com-
mand. For example, if the function that is being plotted is , it
is typed as: '8*x^2+5*cos(x)'. The functions can include MATLAB built-in
functions and functions that are created by the user (covered in Chapter 6).
• The function to be plotted can be typed as a function of any letter. For example,
the function in the previous paragraph can be typed as '8*z^2+5*cos(z)'
or '8*t^2+5*cos(t)'.
Figure 5-5: A plot of the function with large spacing.
x=[-2:0.3:4];
y=3.5.^(-0.5*x).*cos(6*x);
plot(x,y)
y 3.5
0.5x–
6xcos=
y f x=
fplot('function',limits,'line specifiers')
Specifiers that define the
type and color of the line
and markers (optional).
The function to
be plotted.
The domain of x and,
optionally, the limits
of the y axis.
f x 8x2 5 xcos+=
152.
5.2 The fplot Command 141
• The function cannot include previously defined variables. For example, in the
function above it is not possible to assign 8 to a variable, and then use the vari-
able when the function is typed in the fplot command.
limits: The limits argument is a vector with two elements that specify the
domain of x [xmin,xmax], or a vector with four elements that specifies the
domain of x and the limits of the y-axis [xmin,xmax,ymin,ymax].
line specifiers: The line specifiers are the same as in the plot com-
mand. For example, a plot of the function for can
be created with the fplot command by typing:
in the Command Window. The figure that is obtained in the Figure Window is
shown in Figure 5-6.
5.3 PLOTTING MULTIPLE GRAPHS IN THE SAME PLOT
In many situations there is a need to make several graphs in the same plot. This is
shown, for example, in Figure 5-1 where two graphs are plotted in the same fig-
ure. There are three methods to plot multiple graphs in one figure. One is by using
the plot command, the second is by using the hold on and hold off com-
mands, and the third is by using the line command.
5.3.1 Using the plot Command
Two or more graphs can be created in the same plot by typing pairs of vectors
inside the plot command. The command
plot(x,y,u,v,t,h)
creates three graphs—y vs. x, v vs. u, and h vs. t—all in the same plot. The vec-
tors of each pair must be of the same length. MATLAB automatically plots the
graphs in different colors so that they can be identified. It is also possible to add
line specifiers following each pair. For example the command
plot(x,y,'-b',u,v,'--r',t,h,'g:')
>> fplot('x^2+4*sin(2*x)-1',[-3 3])
Figure 5-6: A plot of the function .
y x2 4 2xsin 1–+= 3– x 3
-3 -2 -1 0 1 2 3
-5
0
5
10
y x2 4 2xsin 1–+=
153.
142 Chapter 5: Two-Dimensional Plots
plots y vs. x with a solid blue line, v vs.u with a dashed red line, and h vs. t with
a dotted green line.
Sample Problem 5-1: Plotting a function and its derivatives
Plot the function , and its first and second derivatives, for
, all in the same plot.
Solution
The first derivative of the function is: .
The second derivative of the function is: .
A script file that creates a vector x and calculates the values of y, , and is:
The plot that is created is shown in Figure 5-7.
5.3.2 Using the hold on and hold off Commands
To plot several graphs using the hold on and hold off commands, one graph
is plotted first with the plot command. Then the hold on command is typed.
This keeps the Figure Window with the first plot open, including the axis proper-',x,yd,'--r',x,ydd,':k')
Figure 5-7: A plot of the function and its first and second
derivatives.
y 3x3 26x– 10+=
2– x 4
y' 9x2 26–=
y'' 18x=
y y
Create vector x with the domain of the function.
Create vector y with the function value at each x.
Create vector yd with values of the first derivative.
Create vector ydd with values of the second derivative.
Create three graphs, y vs. x, yd vs. x, and ydd vs. x, in the same figure.
−2 −1 0 1 2 3 4
−50
0
50
100
150
y 3x
3
26x– 10+=
154.
5.3 Plotting Multiple Graphs in the Same Plot 143
ties and formatting (see Section 5.4) if any was done. Additional graphs can be
added with plot commands that are typed next. Each plot command creates a
graph that is added to that figure. The hold off command stops this process. It
returns MATLAB to the default mode, in which the plot command erases the
previous plot and resets the axis properties.
As an example, a solution of Sample Problem 5-1 using the hold on and
hold off commands is shown in the following script file:
5.3.3 Using the line Command
With the line command additional graphs (lines) can be added to a plot that
already exists. The form of the line command is:
The format of the line command is almost the same as the plot command (see
Section 5.1). The line command does not have the line specifiers, but the line
style, color, and marker can be specified with the Property Name and property
value features. The properties are optional and if none are entered MATLAB uses
default properties and values. For example, the command:
line(x,y,'linestyle','--','color','r','marker','o')
will add a dashed red line with circular markers to a plot that already exists.
The major difference between the plot and line commands is that the
plot command starts a new plot every time it is executed, while the line com-
mand adds lines to a plot that already exists. To make a plot that has several
graphs, a plot command is typed first and then line commands are typed for addi-
tional graphs. (If a line command is entered before a plot command an error mes-
sage is displayed.)')
hold on
plot(x,yd,'--r')
plot(x,ydd,':k')
hold off
The first graph is created.
Two more graphs are added to the figure.
line(x,y,'PropertyName',PropertyValue)
(Optional) Properties with values that can be
used to specify the line style, color, and width,
marker type, size, and edge and fill colors.
155.
144 Chapter 5: Two-Dimensional Plots
The solution to Sample Problem 5-1, which is the plot in Figure 5-7, can be
obtained by using the plot and line commands as shown in the following
script file:
5.4 FORMATTING A PLOT
The plot and fplot commands create bare plots. Usually, however, a figure
that contains a plot needs to be formatted to have a specific look and to display
information in addition to the graph itself. This can include specifying axis labels,
plot title, legend, grid, range of custom axis, and text labels.
Plots can be formatted by using MATLAB commands that follow the plot
or fplot command, or interactively by using the plot editor in the Figure Win-
dow. The first method is useful when a plot command is a part of a computer
program (script file). When the formatting commands are included in the pro-
gram, a formatted plot is created every time the program is executed. On the other
hand, formatting that is done in the Figure Window with the plot editor after a plot
has been created holds only for that specific plot, and will have to be repeated the
next time the plot is created.
5.4.1 Formatting a Plot Using Commands
The formatting commands are entered after the plot or the fplot command.
The various formatting commands are:
The xlabel and ylabel commands:
Labels can be placed next to the axes with the xlabel and ylabel command
which have the form:
The title command:
A title can be added to the plot with the command:LineStyle','-','color','b')
line(x,yd,'LineStyle','--','color','r')
line(x,ydd,'linestyle',':','color','k')
xlabel('text as string')
ylabel('text as string')
title('text as string')
156.
5.4 Formatting a Plot 145
The text is placed at the top of the figure as a title.
The text command:
A text label can be placed in the plot with the text or gtext commands:
The text command places the text in the figure such that the first character is
positioned at the point with the coordinates x, y (according to the axes of the fig-
ure). The gtext command places the text at a position specified by the user.
When the command is executed, the Figure Window opens and the user specifies
the position with the mouse.
The legend command:
The legend command places a legend on the plot. The legend shows a sample of
the line type of each graph that is plotted, and places a label, specified by the user,
beside the line sample. The form of the command is:
legend('string1','string2', ..... ,pos)
The strings are the labels that are placed next to the line sample. Their order corre-
sponds to the order in which the graphs were created. The pos is an optional
number that specifies where in the figure the legend is to be placed. The options
are:
pos = -1 Places the legend outside the axes boundaries on the right side.
pos = 0 Places the legend inside the axes boundaries in a location that inter-
feres the least with the graphs.
pos = 1 Places the legend at the upper-right corner of the plot (default).
pos = 2 Places the legend at the upper-left corner of the plot.
pos = 3 Places the legend at the lower-left corner of the plot.
pos = 4 Places the legend at the lower-right corner of the plot.
Formatting the text within the xlabel, ylabel, title, text
and legend commands:
The text in the string that is included in the command and is displayed when the
command is executed can be formatted. The formatting can be used to define the
font, size, position (superscript, subscript), style (italic, bold, etc.), and color of
the characters, the color of the background, and many other details of the display.
Some of the more common formatting possibilities are described below. A com-
plete explanation of all the formatting features can be found in the Help Window
under Text and Text Properties. The formatting can be done either by adding mod-
ifiers inside the string, or by adding to the command optional PropertyName
and PropertyValue arguments following the string.
text(x,y,'text as string')
gtext('text as string')
157.
146 Chapter 5: Two-Dimensional Plots
The modifiers are characters that are inserted within the string. Some of the
modifiers that can be added are:
These modifiers affect the text from the point at which they are inserted until the
end of the string. It is also possible to have the modifiers applied to only a section
of the string by typing the modifier and the text to be affected inside braces { }.
Subscript and superscript:
A single character can be displayed as a subscript or a superscript by typing _ (the
underscore character) or ^ in front of the character, respectively. Several consecu-
tive characters can be displayed as a subscript or a superscript by typing the char-
acters inside braces { } following the _ or the ^.
Greek characters:
Greek characters can be included in the text by typing name of the
letter within the string. To display a lowercase Greek letter the name of the
letter should be typed in all lowercase English characters, To display a capital
Greek letter the name of the letter should start with a capital letter. Some examples
are:
Formatting of the text that is displayed by the xlabel, ylabel, title,
and text commands can also be done by adding optional PropertyName and
PropertyValue arguments following the string inside the command. With this
Modifier Effect Modifier Effect
bf bold font fontname{fontname} specified font
is used
it italic style fontsize{fontsize} specified font
size is used
rm normal font
Characters
in the string
Greek
letter
Characters
in the string
Greek
letter
alpha Phi
beta Delta
gamma Gamma
theta Lambda
pi Omega
sigma Sigma
158.
5.4 Formatting a Plot 147
option the text command, for example, has the form:
In the other three commands the PropertyName and PropertyValue argu-
ments are added in the same way. The PropertyName is typed as a string, and
the PropertyValue is typed as a number if the property value is a number and
as a string if the property value is a word or a letter character. Some of the Prop-
erty Names and corresponding possible Property Values are:
The axis command:
When the plot(x,y) command is executed, MATLAB creates axes with limits
that are based on the minimum and maximum values of the elements of x and y.
The axis command can be used to change the range and the appearance of the
axes. In many situations a graph looks better if the range of the axes extend
beyond the range of the data. The following are some of the possible forms of the
axis command:
Property name Description
Possible property
values
Rotation Specifies the orientation
of the text.
Scalar (degrees)
Default: 0
FontAngle Specifies italic or normal
style characters.
normal, italic
Default: normal
FontName Specifies the font for the
text.
Font name that is
available in the system.
FontSize Specifies the size of the
font.
Scalar (points)
Default: 10
FontWeight Specifies the weight of
the characters.
light, normal,
bold
Default: normal
Color Specifies the color of the
text.
Color specifiers (see
Section 5.1).
Background-
Color
Specifies the background
color (rectangular area).
Color specifiers (see
Section 5.1).
EdgeColor Specifies the color of the
edge of a rectangular box
around the text.
Color specifiers (see
Section 5.1).
Default: none.
LineWidth Specifies the width of the
edge of a rectangular box
around the text.
Scalar (points)
Default: 0.5
text(x,y,'text as string',PropertyName,PropertyValue)
159.
148 Chapter 5: Two-Dimensional Plots
axis([xmin,xmax,ymin,ymax]) Sets the limits of both the x and y
axes (xmin, xmax, ymin, and
ymax are numbers).
axis equal Sets the same scale for both axes.
axis square Sets the axes region to be square.
axis tight Sets the axis limits to the range of the data.
The grid command:
grid on Adds grid lines to the plot.
grid off Removes grid lines from the plot.
An example of formatting a plot by using commands is given in the following
script file which was used to generate the formatted plot in Figure 5-1.
5.4.2 Formatting a Plot Using the Plot Editor
A plot can be formatted interactively in the Figure Window by clicking on the plot
and/or using the menus. Figure 5-8 shows the Figure Window with the plot of Fig-
ure 5-1. The Plot Editor can be used to introduce new formatting items or to mod-
ify formatting that was initially introduced with the formatting commands.
x=[10:0.1:22];
y=95000./x.^2;
xd=[10:2:22];
yd=[950 640 460 340 250 180 140];
plot(x,y,'-','LineWidth',1.0)
xlabel('DISTANCE (cm)')
ylabel('INTENSITY (lux)')
title('fontname{Arial}Light Intensity as a Function of Distance','FontSize',14)
axis([8 24 0 1200])
text(14,700,'Comparison between theory and experiment.','EdgeColor','r','LineWidth',2)
hold on
plot(xd,yd,'ro--','linewidth',1.0,'markersize',10)
legend('Theory','Experiment',0)
hold off
Formatting text inside the
title command.
Formatting text
inside the text
command.
160.
5.5 Plots with Logarithmic Axes 149
5.5 PLOTS WITH LOGARITHMIC AXES
Many science and engineering applications require plots in which one or both
axes have a logarithmic (log) scale. Log scales provide means for presenting data
over a wide range of values. It also provides a tool for identifying characteristics
of data and possible forms of mathematical relationships that can be appropriate
for modeling the data (see Section 8.2.2).
MATLAB commands for making plots with log axes are:
semilogy(x,y) Plots y versus x with a log (base 10) scale for the y
axis and linear scale for the x axis.
semilogx(x,y) Plots y versus x with a log (base 10) scale for the x
axis and linear scale for the y axis.
loglog(x,y) Plots y versus x with a log (base 10) scale for both axes.
Line specifiers and Property Name and Property Value arguments can be added to
the commands (optional) just as in the plot command. As an example, Figure 5-
9 shows a plot of the function for . The figure shows
four plots of the same function: one with linear axes, one with a log scale for the y
axis, one with a log scale for the x axis, and one with a log scale on both axes.
Figure 5-8: Formatting a plot using the Plot Editor.
Click the arrow button to start the plot edit mode. Then click
on an item. A window with formatting tool for the item opens.
Use the Edit
and Insert
menus to add
formatting
objects, or to
edit existing
objects.
Change posi-
tion of a label,
legend or
other object by
clicking on the
object and
dragging.
y 2
0.2x– 10+
= 0.1 x 60
161.
150 Chapter 5: Two-Dimensional Plots
Notes for plots with logarithmic axes:
• The number zero cannot be plotted on a log scale (since a log of zero is not
defined).
• Negative numbers cannot be plotted on log scales (since a log of a negative
number is not defined).
5.6 PLOTS WITH ERROR BARS
Experimental data that is measured and then displayed in plots frequently contains
error and scatter. Even data that is generated by computational models includes
error or uncertainty that depends on the accuracy of the input parameters and the
assumptions in the mathematical models that are used. One method of plotting
data that displays the error, or uncertainty, is by using error bars. An error bar is
typically a short vertical line that is attached to a data point in a plot. It shows the
magnitude of the error that is associated with the value that is displayed by the
data point. For example, Figure 5-10 shows a plot with error bars for the experi-
mental data from Figure 5-1.
Figure 5-9: Plots of with linear, semilog, and log-log scales.
x=linspace(0.1,60,1000);
y=2.^(-0.2*x+10);
plot(x,y)
Linear
x=linspace(0.1,60,1000);
y=2.^(-0.2*x+10);
semilogx(x,y)
x=linspace(0.1,60,1000);
y=2.^(-0.2*x+10);
loglog(x,y)
x=linspace(0.1,60,1000);
y=2.^(-0.2*x+10);
semilogy(x,y)
Linear
Log
LinearLinear
LogLog
Log
y 2
0.2x– 10+
=
162.
5.6 Plots with Error Bars 151
Plots with error bars can be done in MATLAB with the errorbar com-
mand. Two forms of the command, one for making plots with symmetric error
bars (with respect to the value of the data point) and the other for nonsymmetric
error bars at each point, are presented. When the error is symmetric, the error bar
extends the same length above and below the data point and the command has the
form:
• The lengths of the three vectors x, y, and e must be the same.
• The length of the error bar is twice the value of e. At each point the error bar
extends from y(i)-e(i) to y(i)+e(i).
The plot in Figure 5-10, which has symmetric error bars, was done by exe-
cuting the following code:
The command for making a plot with error bars that are not symmetric is:
Figure 5-10: A plot with error bars.
xd=[10:2:22];
yd=[950 640 460 340 250 180 140];
ydErr=[30 20 18 35 20 30 10]
errorbar(xd,yd,ydErr)
xlabel('DISTANCE (cm)')
ylabel('INTENSITY (lux)')
8 10 12 14 16 18 20 22 24
100
200
300
400
500
600
700
800
900
1000
DISTANCE (cm)
INTENSITY(lux)
errorbar(x,y,e)
Vector with the value of the
error at each point.
Vectors with horizontal and verti-
cal coordinates of each point.
errorbar(x,y,d,u)
Vector with the upper-
bound value of the
error at each point.
Vectors with horizontal and
vertical coordinates of each
point.
Vector with the lower-
bound value of the
error at each point.
163.
152 Chapter 5: Two-Dimensional Plots
• The lengths of the four vectors x, y, d, and u must be the same.
• At each point the error bar extends from y(i)-d(i) to y(i)+u(i).
5.7 PLOTS WITH SPECIAL GRAPHICS
All the plots that have been presented so far in this chapter are line plots in which
the data points are connected by lines. In many situations plots with different
graphics or geometry can present data more effectively. MATLAB has many
options for creating a wide variety of plots. These include bar, stairs, stem, and pie
plots and many more. Following are some of the special graphics plots that can be
created with MATLAB. A complete list of the plotting functions that MATLAB
offers and information on how to use them can be found in the Help Window. In
this window first choose "Functions by Category," then select "Graphics" and
then select "Basic Plots and Graphs" or "Specialized Plotting."
Bar (vertical and horizontal), stairs, and stem plots are presented in the fol-
lowing charts using the sales data from Section 5.1.1.
Vertical Bar
Plot
Function
format:
bar(x,y)
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
bar(yr,sle,'r')
xlabel('Year')
ylabel('Sales (Mil-
lions)')
Horizontal Bar
Plot
Function
format:
barh(x,y)
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
barh(yr,sle)
xlabel('Sales (Millions)')
ylabel('Year')
1988 1989 1990 1991 1992 1993 1994
0
5
10
15
20
25
30
Year
Sales(Millions)
The
bars are
in red.
0 5 10 15 20 25 30
1988
1989
1990
1991
1992
1993
1994
Year
Sales(Millions)
164.
5.8 Histograms 153
Pie charts are useful for visualizing the relative sizes of different but related
quantities. For example, the table below shows the grades that were assigned to a
class. The data is used to create the pie chart that follows.
5.8 HISTOGRAMS
Histograms are plots that show the distribution of data. The overall range of a
given set of data points is divided into subranges (bins), and the histogram shows
how many data points are in each bin. The histogram is a vertical bar plot in which
the width of each bar is equal to the range of the corresponding bin and the height
Stairs Plot
Function
format:
stairs(x,y)
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
stairs(yr,sle)
Stem Plot
Function
Format
stem(x,y)
yr=[1988:1994];
sle=[8 12 20 22 18 24 27];
stem(yr,sle)
Grade A B C D E
Number of students 11 18 26 9 5
Pie Plot
Function
format:
pie(x)
grd=[11 18 26 9 5];
pie(grd)
title('Class Grades')
1988 1989 1990 1991 1992 1993 1994
5
10
15
20
25
30
Year
Sales(Millions)
1988 1989 1990 1991 1992 1993 1994
0
5
10
15
20
25
30
Year
Sales(Millions)
MATLAB draws the
sections in different col-
ors. The letters (grades)
were added using the
Plot Editor.
165.
154 Chapter 5: Two-Dimensional Plots
of the bar corresponds to the number of data points in the bin. Histograms are cre-
ated in MATLAB with the hist command. The simplest form of the command
is:
y is a vector with the data points. MATLAB divides the range of the data
points into 10 equally spaced subranges (bins) and then plots the num-
ber of data points in each bin.
For example, the following data points are the daily maximum temperature
(in F) in Washington, DC, during the month of April 2002: 58 73 73 53 50 48 56
73 73 66 69 63 74 82 84 91 93 89 91 80 59 69 56 64 63 66 64 74 63 69 (data from
the U.S. National Oceanic and Atmospheric Administration). A histogram of this
data is obtained with the commands:
The plot that is generated is shown in Figure 5-11 (the axis titles were added using
the Plot Editor). The smallest value in the data set is 48 and the largest is 93,
which means that the range is 45 and the width of each bin is 4.5. The range of the
first bin is from 48 to 52.5 and contains two points. The range of the second bin is
from 52.5 to 57 and contains three points, and so on. Two of the bins (75 to 79.5
and 84 to 88.5) do not contain any points.
Since the division of the data range into 10 equally spaced bins might not be
the division that is preferred by the user, the number of bins can be defined to be
different than 10. This can be done either by specifying the number of bins, or by
specifying the center point of each bin as shown in the following two forms of the
>> y=[58 73 73 53 50 48 56 73 73 66 69 63 74 82 84 91 93 89
91 80 59 69 56 64 63 66 64 74 63 69];
>> hist(y)
Figure 5-11: Histogram of temperature data.
hist(y)
40 50 60 70 80 90 100
0
1
2
3
4
5
6
7
Temperature (F)
Numberofdays
166.
5.8 Histograms 155
hist command:
nbins is a scalar that defines the number of bins. MATLAB divides the range
in equally spaced subranges.
x is a vector that specifies the location of the center of each bin (the dis-
tance between the centers does not have to be the same for all the bins).
The edges of the bins are at the middle point between the centers.
In the example above the user
might prefer to divide the temperature
range into three bins. This can be done
with the command:
As shown in the top graph, the histo-
gram that is generated has three equally
spaced bins.
The number and width of the bins
can also be specified by a vector x
whose elements define the centers of
the bins. For example, shown in the
lower graph is a histogram that displays
the temperature data from above in six
bins with an equal width of 10 degrees.
The elements of the vector x for this
plot are 45, 55, 65, 75, 85, and 95. The
plot was obtained with the following commands:
The hist command can be used with options that provide numerical out-
put in addition to plotting a histogram. An output of the number of data points in
each bin can be obtained with one of the following commands:
The output n is a vector. The number of elements in n is equal to the number of
bins, and the value of each element of n is the number of data points (frequency
count) in the corresponding bin. For example, the histogram in Figure 5-11 can
>> hist(y,3)
>> x=[45:10:95]
x =
45 55 65 75 85 95
>> hist(y,x)
hist(y,nbins) hist(y,x)or
40 50 60 70 80 90 100
0
2
4
6
8
10
12
14
Temperature (F)
Numberofdays
45 55 65 75 85 95
0
2
4
6
8
10
Temperature (F)
Numberofdays
n=hist(y,nbins) n=hist(y,x)n=hist(y)
167.
156 Chapter 5: Two-Dimensional Plots
also be created with the following command:
The vector n shows that the first bin has two data points, the second bin has three
data points, and so on.
An additional, optional numerical output is the location of the bins. This
output can be obtained with one of the following commands:
xout is a vector in which the value of each element is the location of the center of
the corresponding bin. For example, for the histogram in Figure 5-11:
The vector xout shows that the center of the first bin is at 50.25, the center of the
second bin is at 54.75, and so on.
5.9 POLAR PLOTS
Polar coordinates, in which the position of a point in a
plane is defined by the angle and the radius (distance) to
the point, are frequently used in the solution of science and
engineering problems. The polar command is used to
plot functions in polar coordinates. The command has the
form:
where theta and radius are vectors whose elements define the coordinates of
the points to be plotted. The polar command plots the points and draws the
polar grid. The line specifiers are the same as in the plot command. To plot a
function in a certain domain, a vector for values of is created first, and
then a vector r with the corresponding values of is created using element-by-
>> n = hist(y)
n =
2 3 2 7 3 6 0 3 0 4
>> [n xout]=hist(y)
n =
2 3 2 7 3 6 0 3 0 4
xout =
50.2500 54.7500 59.2500 63.7500 68.2500 72.7500
77.2500 81.7500 86.2500 90.7500
The vector n shows how many
elements are in each bin.
[n xout]=hist(y,nbins)[n xout]=hist(y)
x
y
r
polar(theta,radius,'line specifiers')
(Optional) Specifiers that
define the type and color of
the line and markers.
Vector Vector
r f=
f
168.
5.10 Putting Multiple Plots on the Same Page 157
element calculations. The two vectors are then used in the polar command.
For example, a plot of the function for is
shown below.
5.10 PUTTING MULTIPLE PLOTS ON THE SAME PAGE
Multiple plots can be created on the same page with the subplot command,
which has the form:
The command divides the Figure Window
(and the page when printed) into rectangu-
lar subplots. The subplots are arranged like ele-
ments in an matrix where each element is a
subplot. The subplots are numbered from 1
through . The upper left subplot is numbered
1 and the lower right subplot is numbered .
The numbers increase from left to right within a
row, from the first row to the last. The command
subplot(m,n,p) makes the subplot p current.
This means that the next plot command (and any
formatting commands) will create a plot (with the corresponding format) in this
subplot. For example, the command subplot(3,2,1) creates six areas
arranged in three rows and two columns as shown, and makes the upper left sub-
plot current. An example of using the subplot command is shown in the solu-
tion of Sample Problem 5-2.
5.11 MULTIPLE FIGURE WINDOWS
When plot or any other command that generates a plot is executed, the Figure
Window opens (if not already open) and displays the plot. MATLAB labels the
Figure Window as Figure 1 (see the top left corner of the Figure Window that is
displayed in Figure 5-4). If the Figure Window is already open when the plot or
any other command that generates a plot is executed, a new plot is displayed in the
r 3 0.5cos2 += 0 2
t=linspace(0,2*pi,200);
r=3*cos(0.5*t).^2+t;
polar(t,r)
subplot(m,n,p)
(3,2,1) (3,2,2)
(3,2,3)
(3,2,5)
(3,2,4)
(3,2,6)
m n
m n
m n
m n
169.
158 Chapter 5: Two-Dimensional Plots
Figure Window (replacing the existing plot). Commands that format plots are
applied to the plot in the Figure Window that is open.
It is possible, however, to open additional Figure Windows and have several
of them open (with plots) at the same time. This is done by typing the command
figure. Every time the command figure is entered, MATLAB opens a new
Figure Window. If a command that creates a plot is entered after a figure com-
mand, MATLAB generates and displays the new plot in the last Figure Window
that was opened, which is called the active or current window. MATLAB labels
the new Figure Windows successively; i.e., Figure 2, Figure 3, and so on. For
example, after the following three commands are entered, the two Figure Win-
dows that are shown in Figure 5-12 are displayed.
The figure command can also have an input argument that is a number
(integer), of the form figure(n). The number corresponds to the number of the
corresponding Figure Window. When the command is executed, window number
n becomes the active Figure Window (if a Figure Window with this number does
not exist, a new window with this number opens). When commands that create
new plots are executed, the plots that they generate are displayed in the active Fig-
ure Window. In the same way, commands that format plots are applied to the plot
in the active window. The figure(n) command provides means for having a
program in a script file that opens and makes plots in a few defined Figure Win-
dows. (If several figure commands are used in a program instead, new Figure
Windows will open every time the script file is executed.)
Figure Windows can be closed with the close command. Several forms of
the command are:
close closes the active Figure Window.
close(n) closes the nth Figure Window.
close all closes all Figure Windows that are open.
>> fplot('x*cos(x)',[0,10])
>> figure
>> fplot('exp(-0.2*x)*cos(x)',[0,10])
Figure 5-12: Two open Figure Windows.
Plot displayed in Figure 1 window.
Figure 2 window opens.
Plot displayed in Figure 2 window.
170.
5.12 Examples of MATLAB Applications 159
5.12 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 5-2: Piston-crank mechanism
The piston-rod-crank mechanism is used in many engineering applications. In the
mechanism shown in the following figure, the crank is rotating at a constant speed
of 500 rpm.
Calculate and plot the position, velocity, and acceleration of the piston for one
revolution of the crank. Make the three plots on the same page. Set when
t = 0.
Solution
The crank is rotating with a constant angular velocity . This means that if we set
= 0o when t = 0, then at time t the angle is given by , and that at
all times.
The distances d1 and h are
given by:
and
With h known, the distance d2 can be
calculated using the Pythagorean
Theorem:
The position x of the piston is then given by:
The derivative of x with respect to time gives the velocity of the piston:
The second derivative of x with respect to time gives the acceleration of the pis-
ton:
0=
·
·
t=
··
0=
θ
cr
h
d1
x
d2
d1 rcos= h rsin=
d2 c2 h2– 1 2/ c2 r2 sin2– 1 2/= =
x d1 d2 rcos= c2 r2 sin2– 1 2/+ +=
x· r
·
sin–
r2 ·
2sin
2 c2 r2 sin2– 1 2/
--------------------------------------------–=
x·· r
· 2
cos–
4r2 · 2
2cos c2 r2 sin2– r2 ·
2sin 2
+
4 c2 r2 sin2– 3 2/
-----------------------------------------------------------------------------------------------------–=
171.
160 Chapter 5: Two-Dimensional Plots
In the equation above, was taken to be zero.
A MATLAB program (script file) that calculates and plots the position,
velocity, and acceleration of the piston for one revolution of the crank is shown
below.
When the script file runs it generates the three plots on the same page as
shown in Figure 5-13. The figure nicely shows that the velocity of the piston is
zero at the end points of the travel range where the piston changes the direction of
the motion. The acceleration is maximum (directed to the left) when the piston is
at the right end.
THDrpm=500; r=0.12; c=0.25;
THD=THDrpm*2*pi/60;
tf=2*pi/THD;
t=linspace(0,tf,200);
TH=THD*t;
d2s=c^2-r^2*sin(TH).^2;
x=r*cos(TH)+sqrt(d2s);
xd=-r*THD*sin(TH)-(r^2*THD*sin(2*TH))./(2*sqrt(d2s));
xdd=-r*THD^2*cos(TH)-(4*r^2*THD^2*cos(2*TH).*d2s+
(r^2*sin(2*TH)*THD).^2)./(4*d2s.^(3/2));
subplot(3,1,1)
plot(t,x)
grid
xlabel('Time (s)')
ylabel('Position (m)')
subplot(3,1,2)
plot(t,xd)
grid
xlabel('Time (s)')
ylabel('Velocity (m/s)')
subplot(3,1,3)
plot(t,xdd)
grid
xlabel('Time (s)')
ylabel('Acceleration (m/s^2)')
··
Define , r, and c.·
Change the units of from rpm to rad/s.·
Calculate the time for one revolution of the crank.
Create a vector for the time with 200 elements.
Calculate for each t.
Calculate d2 squared for each .
Calculate x for each .
Calculate and for each .x· x··
Plot x vs. t.
Format the first plot.
Plot vs. t.x·
Format the second plot.
Plot vs. t.x··
Format the third plot.
172.
5.12 Examples of MATLAB Applications 161
Sample Problem 5-3: Electric Dipole
The electric field at a point due to a charge is a vector E
with magnitude E given by Coulomb's law:
where is the permittivity
constant, q is the magnitude of the charge, and r is the
distance between the charge and the point. The direction
of E is along the line that connects the charge with the
point. E points outward from q if q is positive, and toward q if q is negative. An
electric dipole is created when a positive charge and a negative charge of equal
magnitude are placed some distance apart. The electric field, E, at any point is
obtained by superposition of the electric field of each charge.
An electric dipole with
C is created, as shown in
the figure. Determine and plot the
magnitude of the electric field along
the x axis from cm to
cm.
Figure 5-13: Position, velocity, and acceleration of the piston vs. time.
0 0.02 0.04 0.06 0.08 0.1 0.12
0
0.2
0.4
Time (s)
Position(m)
0 0.02 0.04 0.06 0.08 0.1 0.12
-10
0
10
Time (s)
Velocity(m/s)
0 0.02 0.04 0.06 0.08 0.1 0.12
-500
0
500
Time (s)
Acceleration(m/s2
)
E
1
4 0
-----------
q
r2
----=
0 8.8541878 10 12– C
2
N m2
---------------=
+q
x
y
q
(2 cm, 2 cm)( 2 cm, 2 cm)
q 12 10 9–=
x 5–=
x 5=
173.
162 Chapter 5: Two-Dimensional Plots
Solution
The electric field E at any point (x, 0)
along the x axis is obtained by adding
the electric field vectors due to each of
the charges.
E = E–+ E+
The magnitude of the electric field is
the length of the vector E.
The problem is solved by following these steps:
Step 1: Create a vector x for points along the x axis.
Step 2: Calculate the distance (and distance squared) from each charge to the
points on the x axis.
Step 3: Write unit vectors in the direction from each charge to the points on the
x axis.
Step 4: Calculate the magnitude of the vector E– and E+ at each point by using
Coulomb's law.
Step 5: Create the vectors E– and E+ by multiplying the unit vectors by the
magnitudes.
Step 6: Create the vector E by adding the vectors E– and E+.
Step 7: Calculate E, the magnitude (length) of E.
Step 8: Plot E as a function of x.
A program in a script file that solves the problem is:
q=12e-9;
epsilon0=8.8541878e-12;
x=[-0.05:0.001:0.05]';
rminusS=(0.02-x).^2+0.02^2;
rminus=sqrt(rminusS);
rplusS=(x+0.02).^2+0.02^2;
rplus=sqrt(rplusS);
rminus 0.02 x– 2 0.022+= rplus x 0.02x+ 2 0.022+=
EminusUV
1
rminus
------------- 0.02 x– i 0.02j–=
EplusUV
1
rplus
---------- x 0.02+ i 0.02j+=
EminusMAG
1
4 0
-----------
q
rminus
2
--------------= EplusMAG
1
4 0
-----------
q
rplus
2
----------=
Create a column vector x.
Step 2. Each variable
is a column vector.
175.
164 Chapter 5: Two-Dimensional Plots
5. Use the fplot command to plot the function
in the domain .
6. A parametric equation is given by
,
Plot the function for . Format the plot such that the both axes will
range from –2 to 2.
7. Plot the function for . Notice that the function
has a vertical asymptote at . Plot the function by creating two vectors
for the domain of x. The first vector (name it x1) includes elements from –4 to
–1.1, and the second vector (name it x2) includes elements from –0.9 to 3. For
each x vector create a y vector (mane them y1 and y2) with the corresponding
values of y according to the function. To plot the function make two curves in
the same plot (y1 vs. x1, and y2 vs. x2).
8. A parametric equation is given by
,
(Note that the denominator approaches 0 when t approaches –1) Plot the func-
tion (the plot is called the Folium of Descartes) by plotting two curves in the
same plot—one for and the other for .
9. Plot the function for . Notice that the function
has two vertical asymptotes. Plot the function by dividing the domain of x into
three parts: one from –6 to near the left asymptote, one between the two
asymptotes, and one from near the right asymptote to 6. Set the range of the y
axis from –20 to 20.
10. A cycloid is a curve (shown in the fig-
ure) traced by a point on a circle that
rolls along a line. The parametric equa-
tion of a cycloid is given by
and
Plot a cycloid with and .
11. Plot the function and its derivative, both on the same
plot, for . Plot the function with a solid line, and the derivative with
a dashed line. Add a legend and label the axes.
f x e2 0.4xsin 5 4xcos= 20– x 30
x 1.5 5tsin= y 1.5 3tcos=
0 t 2
f x
x2 3x 3+ +
0.8 x 1+
--------------------------= 4– x 3
x 1–=
x 3t
1 t3+
-------------= y 3t2
1 t3+
-------------=
30– t 1.6– 0.6– t 40
f x x2 4x– 7–
x
2
x– 6–
--------------------------= 6– x 6
x
y
x r t tsin–= y r t tcos–=
r 1.5= 0 t 4
f x xcos 2xsin=
x
176.
5.13 Problems 165
12. The Gateway Arch in St. Louis is shaped according to the equation
ft
Make a plot of the arch.
13. An electrical circuit that includes a voltage source
with an internal resistance and a load resis-
tance is shown in the figure. The power P dissi-
pated in the load is given by
Plot the power P as a function of for
, given that V and ..
14. Two ship, A and B, travel at a speed of
mi/h and mi/h, respectively.
The directions they are moving and their loca-
tion at 8 A.M. are shown in the figure. Plot the
distance between the ships as a function of
time for the next 4 hours. The horizontal axis
should show the actual time of day starting at 8
A.M., while the vertical axis should show the
distance. Label the axes.
15. The plasma concentration of orally delivered drugs is a function of the
rate of absorption, , and the rate of elimination, :
where A is a constant (associated with the specific drag) and t is time. Con-
sider a case where mg/L, h–1
, and h–1
. Make a
plot that displays vs. time for .
16. The position as a function of time of a squirrel
running on a grass field is given in polar coor-
dinates by:
m
(a) Plot the trajectory (position) of the squirrel for s.
(b) Create a (second) plot for the speed of the squirrel, given by , as
a function of time for s.
y 693.8 68.8
x
99.7
----------cosh–=
rS
RL
vS Battery
vS rS
RL
P
vS
2
RL
RL rS+
2
------------------------=
RL
1 RL 10 vS 12= rS 2.5=
x
y
A 36 mi
12 mi
45 mi
18 mi
vA
vB
70
o
30o
vA 27= vB 14=
CP
Kab Kel
CP A
Kab
Kab Kel–
---------------------- e Kelt–
e Kabt–
–=
A 140= Kab 1.6= Kab 0.45=
CP 0 t 10
x
y
r(t)
θ(t)r t 20 30 1 e 0.1t––+=
t 1 e 0.2t––=
0 t 20
v r
d
dt
------=
0 t 20
177.
166 Chapter 5: Two-Dimensional Plots
17. In astronomy, the relationship between the relative luminosity
(brightness relative to the sun), the relative radius , and the relative
temperature of a star is modeled by:
The HR (Hertzsprung-Russell) diagram is a plot of versus the temper-
ature. The following data is given:
To compare the data with the model, use MATLAB to plot an HR diagram.
The diagram should have two sets of points. One uses the values of
from the table (use asterisk markers), and the other uses values of that
are calculated from the equation by using from the table (use circle
markers). In the HR diagram both axes are logarithmic. In addition, the values
of temperature on the horizontal axis are decreasing from left to right. This is
done with the command set(gca,'XDir','reverse'). Label the axes
and use a legend.
18. The position x as a function of time of a particle that moves along a straight
line is given by
ft
The velocity v(t) of the particle is determined by the derivative of x(t) with
respect to t, and the acceleration a(t) is determined by the derivative of v(t)
with respect to t.
Derive the expressions for the velocity and acceleration of the particle,
and make plots of the position, velocity, and acceleration as functions of time
for s. Use the subplot command to make the three plots on the
same page with the plot of the position on the top, the velocity in the middle,
and the acceleration at the bottom. Label the axes appropriately with the cor-
rect units.
Sun Spica Regulus Alioth Barnard's
Star
Epsilon
Indi
Beta
Crucis
Temp (K) 5,840 22,400 13,260 9,400 3,130 4,280 28,200
L/LSun 1 13,400 150 108 0.0004 0.15 34,000
R/RSun 1 7.8 3.5 3.7 0.18 0.76 8
L LSun
R RSun
T TSun
L
LSun
----------
R
RSun
----------
2 T
TSun
----------
4
=
L LSun
L LSun
L LSun
R RSun
x t 0.41t4 10.8t3– 64t2 8.2t– 4.4+ +=
0 t 8
178.
5.13 Problems 167
19. In a typical tension test a dog bone
shaped specimen is pulled in a
machine. During the test, the force F
needed to pull the specimen and the
length L of a gauge section are measured. This data is used for plotting a
stress-strain diagram of the material. Two definitions, engineering and true,
exist for stress and strain. The engineering stress and strain are defined
by
and , where and are the initial gauge length and the
initial cross-sectional area of the specimen, respectively. The true stress
and strain are defined by and .
The following are measurements of force and gauge length from a tension
test with an aluminum specimen. The specimen has a round cross section with
radius 6.4 mm (before the test). The initial gauge length is mm. Use
the data to calculate and generate the engineering and true stress-strain curves,
both on the same plot. Label the axes and label the curves.
Units: When the force is measured in newtons (N), and the area is calculated
in m2, the unit of the stress is pascals (Pa).
20. The area of the aortic valve, in cm2, can be estimated by the equation
(Hakki Formula)
where is the cardiac output in L/min, and PG is the difference between the
left ventricular systolic pressure and the aortic systolic pressure (in mm Hg).
Make one plot with two curves of versus PG, for mm Hg—
one curve for L/min and the other for L/min. Label the axes and
use a legend.
F (N) 0 13,345 26,689 40,479 42,703 43,592 44,482 44,927
L (mm) 25 25.037 25.073 25.113 25.122 25.125 25.132 25.144
F (N) 45,372 46,276 47,908 49,035 50,265 53,213 56,161
L (mm) 25.164 25.208 25.409 25.646 26.084 27.398 29.150
e e
e
F
A0
-----= e
L L0–
L0
---------------= L0 A0
t
t t
F
A0
-----
L
L0
-----= t
L
L0
-----ln=
L0 25=
AV
AV
Q
PG
------------=
Q
AV 2 PG 60
Q 4= Q 5=
179.
168 Chapter 5: Two-Dimensional Plots
21. A series RLC circuit with an AC voltage source
is shown. The amplitude of the current, I, in this
circuit is given by
where in which is the driving fre-
quency; R and C are the resistance of the resistor and capacitance of the
capacitor, respectively; and is the amplitude of V. For the circuit in the fig-
ure , F, H, and V.
Make a plot of I as a function of for Hz. Use a linear
scale for I and a log scale for .
22. The speed distribution, , of gas molecules can be modeled by Maxwell's
speed distribution law:
where m (kg) is the mass of each molecule, v (m/s) is the speed, T (K) is the
temperature, and J/K is Boltzmann's constant. Make a plot of
versus v for m/s for oxygen molecules ( kg).
Make two graphs in the same plot, one for K and the other for
K. Label the axes and display a legend.
23. A resistor, R = 4 , and an inductor, L = 1.3 H, are connected in a circuit to a
voltage source as shown in Figure (a) (an RL circuit). When the voltage
source applies a rectangular voltage pulse with an amplitude of V = 12 V and a
duration of 0.5 s, as shown in Figure (b), the current i(t) in the circuit as a
function of time is given by:
for s
for s
Make a plot of the current as a function of time for s.
C
L
R
V
I
vm
R
2
dL 1 dC–
2
+
--------------------------------------------------------------=
d 2 fd= fd
vm
R 80= C 18 10
6–
= L 260 10
3–
= vm 10=
fd 10 f 10000
fd
N v
N v 4
m
2 kT
-------------
3 2
v2e
mv2–
2kT
-------------
=
k 1.38 10 23–=
N v 0 v 1200 m 5.3 10 26–=
T 80=
T 300=
(a) (b)
i t
V
R
--- 1 e
Rt– L
–= 0 t 0.5
i t e
Rt L– V
R
--- e
0.5R L
1–= 0.5 t
0 t 2
180.
5.13 Problems 169
24. The shape of a symmetrical four digit NACA airfoil is described by the equa-
tion
where c is the cord length and t is the max-
imum thickness as a fraction of the cord
length ( maximum thickness). Sym-
metrical four digit NACA airfoils are des-
ignated NACA 00XX, where XX is
(i.e., NACA 0012 has ). Plot the
shape of a NACA 0020 airfoil with a cord
length of 1.5 m.
25. The dynamic storage modulus and loss modulus are measures of a
material mechanical response to harmonic loading. For many biological mate-
rials these moduli can be described by Fung's model:
and
where is the frequency of the harmonic loading, and , c, , and are
material constants. Plot and versus (two separate plots on the same
page) for ksi, , s, and s. Let vary
between 0.0001 and 1000 s–1. Use a log scale for the axis.
26. The vibrations of the body of a helicopter due
to the periodic force applied by the rotation of
the rotor can be modeled by a frictionless
spring-mass-damper system subjected to an
external periodic force. The position of
the mass is given by the equation:
where , and , is the frequency of the applied
force, and is the natural frequency of the helicopter. When the value of
is close to the value of , the vibration consists of fast oscillation with
slowly changing amplitude called beat. Use N/kg, rad/s,
and rad/s to plot as a function of t for s.
y
tc
0.2
------- 0.2969
x
c
-- 0.1260
x
c
--– 0.3516
x
c
--
2
– 0.2843
x
c
--
3
0.1015
x
c
--
4
–+=
0 0.5 1 1.5
-0.2
-0.1
0
0.1
0.2
tc =
100t
t 0.12=
G G
G G 1
c
2
---
1 2
2
+
1 1
2
+
--------------------------ln+= G cG 2tan 1–
1tan 1––=
G 1 2
G G
G 5= c 0.05= 1 0.05= 2 500=
x
k
m
c
F(t)
x t
x t
2f0
n
2 2–
------------------- n –
2
----------------tsin n –
2
----------------tsin=
F t F0 tsin= f0 F0 m=
n
n
F0 m 12= n 10=
12= x t 0 t 10
181.
170 Chapter 5: Two-Dimensional Plots
27. Consider the diode circuit shown in the fig-
ure. The current and the voltage can be
determined from the solution of the following
system of equations:
,
The system can be solved numerically or
graphically. The graphical solution is found by plotting as a function of
from both equations. The solution is the intersection of the two curves. Make
the plots and estimate the solution for the case where A,
V, , and mV.
28. The ideal gas equation states that , where P is the pressure, V is the
volume, T is the temperature, (L atm)/(mol K) is the gas con-
stant, and n is the number of moles. For one mole ( ) the quantity is
a constant equal to 1 at all pressures. Real gases, especially at high pressures,
deviate from this behavior. Their response can be modeled with the van der
Waals equation
where a and b are material constants. Consider 1 mole ( ) of nitrogen
gas at K. (For nitrogen gas (L2
atm)/mol2
, and
L/mol.) Use the van der Waals equation to calculate P as a function of V for
L, using increments of 0.02 L. At each value of V calculate the
value of and make a plot of versus P. Does the response of nitrogen
agree with the ideal gas equation?
29. When monochromatic light passes through a
narrow slit it produces on a screen a diffraction
pattern consisting of bright and dark fringes.
The intensity of the bright fringes, I, as a func-
tion of can be calculated by
, where
where is the light wave length and a is the
width of the slit. Plot the relative intensity
as a function of for . Make one plot that contains three
graphs for the cases , , and . Label the axes, and dis-
play a legend.
R
iD
vS
Diode
vD
iD vD
iD I0 e
qvD
kT
---------
1–= iD
vS vD–
R
----------------=
iD vD
I0 10 14–=
vS 1.5= R 1200=
kT
q
------ 30=
PV
RT
------- n=
R 0.08206=
n 1=
PV
RT
-------
P
nRT
V nb–
----------------
n2a
V2
--------–=
n 1=
T 300= a 1.39= b 0.0391=
0.08 V 6
PV
RT
-------
PV
RT
-------
θ
Incident
light
I Imax
sin
-----------
2
=
a
------sin=
I Imax 20– 20
a 10= a 5= a =
182.
5.13 Problems 171
30. In order to supply fluid to point D, a new pipe
CD with diameter of is connected to an
existing pipe with diameter of at point C
between points A and B. The resistance, R, to
fluid flow along the path ACD is given by
where K is a constant. Determine the location of point C (the distance s) that
minimizes the flow resistance R. Define a vector with elements ranging
from to with spacing of . Calculate for each value of ,
and make a plot of versus . Use MATLAB's built-in function min to
find the minimum value of and the corresponding , and then calculate
the value of s. Use in., in., ft, ft.
31. A simply supported beam is sub-
jected to a constant distributed load w
over half of its length and a moment
M, as shown in the figure. The deflec-
tion y, as a function of x, is given by
the equations
for
for
where E is the elastic modulus, I is the moment of inertia, and L is the length
of the beam. For the beam shown in the figure m, Pa
(steel), m4, N/m, and N m. Make
a plot of the deflection of the beam y as a function of x.
32 The ideal gas law relates the pressure P, volume V, and temperature T of an
ideal gas:
where n is the number of moles and J/(K mol). Plots of pressure
versus volume at constant temperature are called isotherms. Plot the isotherms
for one mole of an ideal gas for volume ranging from 1 to 10 m3
, at tempera-
tures of K (four curves in one plot). Label the
axes and display a legend. The units for pressure are Pa.
θ
A BC
D
L1
L2
s
d2
d1
d2
d1
R
L1 L2 cot–
r1
4
-----------------------------K
L2
r2
4 sin
----------------K+=
30 85 0.5 R K
R K
R K
d1 1.75= d2 1.5= L1 50= L2 40=
x
y
w
L
2
L
2
M
y
wx–
384EI
--------------- 16x3 24Lx2– 9L2+
Mx
6EIL
------------- x2 3Lx– 2L2++= 0 x
1
2
---L
y
wL–
384EI
--------------- 8x3 24Lx2– 17L2x L3–+
Mx
6EIL
------------- x2 3Lx– 2L2++=
1
2
---L x L
L 20= E 200 10
9
=
I 348 10
6–
= w 5.4 10
3
= M 200 10
3
=
PV nRT=
R 8.3145=
T 100 200 300 and 400,,,=
184.
173
Chapter 6
Programming in
MATLAB
A computer program is a sequence of computer commands. In a simple program
the commands are executed one after the other in the order they are typed. In this
book, for example, all the programs that have been presented so far in script files
are simple programs. Many situations, however, require more sophisticated pro-
grams in which commands are not necessarily executed in the order they are
typed, or different commands (or groups of commands) are executed when the
program runs with different input variables. For example, a computer program
that calculates the cost of mailing a package uses different mathematical expres-
sions to calculate the cost depending on the weight and size of the package, the
content (books are less expensive to mail), and the type of service (airmail,
ground, etc.). In other situations there might be a need to repeat a sequence of
commands several times within a program. For example, programs that solve
equations numerically repeat a sequence of calculations until the error in the
answer is smaller than some measure.
MATLAB provides several tools that can be used to control the flow of a
program. Conditional statements (Section 6.2) and the switch structure (Section
6.3) make it possible to skip commands or to execute specific groups of com-
mands in different situations. For loops and while loops (Section 6.4) make it
possible to repeat a sequence of commands several times.
It is obvious that changing the flow of a program requires some kind of
decision-making process within the program. The computer must decide whether
to execute the next command or to skip one or more commands and continue at a
different line in the program. The program makes these decisions by comparing
values of variables. This is done by using relational and logical operators, which
are explained in Section 6.1.
It should also be noted that user-defined functions (introduced in Chapter 7)
can be used in programming. A user-defined function can be used as a subpro-
gram. When the main program reaches the command line that has the user-defined
function, it provides input to the function and "waits" for the results. The user-
185.
174 Chapter 6: Programming in MATLAB
defined function carries out the calculations and transfers the results back to the
main program, which then continues to the next command.
6.1 RELATIONAL AND LOGICAL OPERATORS
A relational operator compares two numbers by determining whether a compari-
son statement (e.g., 5 < 8) is true or false. If the statement is true, it is assigned a
value of 1. If the statement is false, it is assigned a value of 0. A logical operator
examines true/false statements and produces a result that is true (1) or false (0)
according to the specific operator. For example, the logical AND operator gives 1
only if both statements are true. Relational and logical operators can be used in
mathematical expressions and, as will be shown in this chapter, are frequently
used in combination with other commands, to make decisions that control the
flow of a computer program.
Relational operators:
Relational operators in MATLAB are:
Note that the "equal to" relational operator consists of two = signs (with no space
between them), since one = sign is the assignment operator. In other relational
operators that consist of two characters there also is no space between the charac-
ters (<=, >=, ~=).
• Relational operators are used as arithmetic operators within a mathematical
expression. The result can be used in other mathematical operations, in
addressing arrays, and together with other MATLAB commands (e.g., if) to
control the flow of a program.
• When two numbers are compared, the result is 1 (logical true) if the compari-
son, according to the relational operator, is true, and 0 (logical false) if the
comparison is false.
• If two scalars are compared, the result is a scalar 1 or 0. If two arrays are com-
pared (only arrays of the same size can be compared), the comparison is done
element-by-element, and the result is a logical array of the same size with 1s
and 0s according to the outcome of the comparison at each address.
Relational operator Description
< Less than
> Greater than
<= Less than or equal to
>= Greater than or equal to
== Equal to
~= Not Equal to
186.
6.1 Relational and Logical Operators 175
• If a scalar is compared with an array, the scalar is compared with every element
of the array, and the result is a logical array with 1s and 0s according to the out-
come of the comparison of each element.
Some examples are:
>> 5>8
ans =
0
>> a=5<10
a =
1
>> y=(6<10)+(7>8)+(5*3= =60/4)
y =
2
>> b=[15 6 9 4 11 7 14]; c=[8 20 9 2 19 7 10];
>> d=c>=b
d =
0 1 1 0 1 1 0
>> b == c
ans =
0 0 1 0 0 1 0
>> b~=c
ans =
1 1 0 1 1 0 1
>> f=b-c>0
f =
1 0 0 1 0 0 1
>> A=[2 9 4; -3 5 2; 6 7 -1]
A =
2 9 4
-3 5 2
6 7 -1
>> B=A<=2
Checks if 5 is larger than 8.
Since the comparison is false (5 is
not larger than 8) the answer is 0.
Checks if 5 is smaller than 10, and assigns the answer to a.
Since the comparison is true (5 is smaller
than 10) the number 1 is assigned to a.
Using relational operators
in math expression.
Equal to 1 since
6 is smaller than 10.
Equal to 0 since 7 is
not larger than 8.
Equal to 1 since 5*3
is equal to 60/4.
Define vec-
tors b and c.
Checks which c elements are larger than or equal to b elements.
Assigns 1 where an element of c is larger than or equal to an element of b.
Checks which b elements are equal to c elements.
Checks which b elements are not equal to c elements.
Subtracts c from b and then checks
which elements are larger than zero.
Define a matrix A.3 3
Checks which elements in A are smaller than
or equal to 2. Assigns the results to matrix B.
187.
176 Chapter 6: Programming in MATLAB
• The results of a relational operation with vectors, which are vectors with 0s and
1s, are called logical vectors and can be used for addressing vectors. When a
logical vector is used for addressing another vector, it extracts from that vector
the elements in the positions where the logical vector has 1s. For example:
• Numerical vectors and arrays with the numbers 0s and 1s are not the same as
logical vectors and arrays with 0s and 1s. Numerical vectors and arrays can not
be used for addressing. Logical vectors and arrays, however, can be used in
arithmetic operations. The first time a logical vector or an array is used in arith-
metic operations it is changed to a numerical vector or array.
• Order of precedence: In a mathematical expression that includes relational and
arithmetic operations, the arithmetic operations (+, –, *, /, ) have precedence
over relational operations. The relational operators themselves have equal pre-
cedence and are evaluated from left to right. Parentheses can be used to alter
the order of precedence. Examples are:
B =
1 0 0
1 0 1
0 0 1
>> r = [8 12 9 4 23 19 10]
r =
8 12 9 4 23 19 10
>> s=r<=10
s =
1 0 1 1 0 0 1
>> t=r(s)
t =
8 9 4 10
>> w=r(r<=10)
w =
8 9 4 10
>> 3+4<16/2
ans =
1
>> 3+(4<16)/2
ans =
3.5000
Define a vector r.
Checks which r elements are smaller than or equal to 10.
A logical vector s with 1s at positions where
elements of r are smaller than or equal to 10.
Use s for addresses in vector r to create vector t.
Vector t consists of elements of
r in positions where s has 1s.
The same procedure can be done in one step.
+ and / are executed first.
The answer is 1 since 7 < 8 is true.
4 < 16 is executed first, and is equal to 1, since it is true.
3.5 is obtained from 3 + 1/2.
188.
6.1 Relational and Logical Operators 177
Logical operators:
Logical operators in MATLAB are:
• Logical operators have numbers as operands. A nonzero number is true, and a
zero number is false.
• Logical operators (like relational operators) are used as arithmetic operators
within a mathematical expression. The result can be used in other mathemati-
cal operations, in addressing arrays, and together with other MATLAB com-
mands (e.g., if) to control the flow of a program.
• Logical operators (like relational operators) can be used with scalars and
arrays.
• The logical operations AND and OR can have both operands as scalars, arrays,
or one array and one scalar. If both are scalars, the result is a scalar 0 or 1. If
both are arrays, they must be of the same size and the logical operation is done
element-by-element. The result is an array of the same size with 1s and 0s
according to the outcome of the operation at each position. If one operand is a
scalar and the other is an array, the logical operation is done between the scalar
and each of the elements in the array and the outcome is an array of the same
size with 1s and 0s.
• The logical operation NOT has one operand. When it is used with a scalar the
outcome is a scalar 0 or 1. When it is used with an array, the outcome is an
array of the same size with 1s in positions where the array has nonzero num-
bers and 0s in positions where the array has 0s.
Following are some examples:
Logical operator Name Description
&
Example: A&B
AND Operates on two operands (A and B). If both
are true, the result is true (1); otherwise the
result is false (0).
|
Example: A|B
OR Operates on two operands (A and B). If
either one, or both, are true, the result is true
(1); otherwise (both are false) the result is
false (0).
~
Example: ~A
NOT Operates on one operand (A). Gives the
opposite of the operand; true (1) if the oper-
and is false, and false (0) if the operand is
true.
>> 3&7 3 AND 7.
189.
178 Chapter 6: Programming in MATLAB
Order of precedence:
Arithmetic, relational, and logical operators can be combined in mathematical
expressions. When an expression has such a combination, the result depends on
the order in which the operations are carried out. The following is the order used
by MATLAB:
ans =
1
>> a=5|0
a =
1
>> ~25
ans =
0
>> t=25*((12&0)+(~0)+(0|5))
t =
50
>> x=[9 3 0 11 0 15]; y=[2 0 13 -11 0 4];
>> x&y
ans =
1 0 0 1 0 1
>> z=x|y
z =
1 1 1 1 0 1
>> ~(x+y)
ans =
0 0 0 1 1 0
Precedence Operation
1 (highest) Parentheses (if nested parentheses exist, inner ones have
precedence)
2 Exponentiation
3 Logical NOT (~)
4 Multiplication, division
5 Addition, subtraction
6 Relational operators (>, <, >=, <=, ==, ~=)
7 Logical AND (&)
8 (lowest) Logical OR ( | )
3 and 7 are both true (nonzero), so the outcome is 1.
5 OR 0 (assign to variable a).
1 is assigned to a since at least one number is true (nonzero).
NOT 25.
The outcome is 0 since 25 is true
(nonzero) and the opposite is false.
Using logical operators in a math expression.
Define two vec-
tors x and y.
The outcome is a vector with 1 in every position where
both x and y are true (nonzero elements), and 0s otherwise.
The outcome is a vector with 1 in every position where either
or both x and y are true (nonzero elements), and 0s otherwise.
The outcome is a vector with 0 in every position where
the vector x + y is true (nonzero elements), and 1 in
every position where x + y is false (zero elements).
190.
6.1 Relational and Logical Operators 179
If two or more operations have the same precedence, the expression is executed in
order from left to right.
It should be pointed out here that the order shown above is the one used
since MATLAB 6. Previous versions of MATLAB used a slightly different order
(& did not have precedence over |), so the user must be careful. Compatibility
problems between different versions of MATLAB can be avoided by using paren-
theses even when they are not required.
The following are examples of expressions that include arithmetic, rela-
tional, and logical operators:
Built-in logical functions:
MATLAB has built-in functions that are equivalent to the logical operators. These
functions are:
and(A,B) equivalent to A&B
or(A,B) equivalent to A|B
not(A) equivalent to ~A
>> x=-2; y=5;
>> -5<x<-1
ans =
0
>> -5<x & x<-1
ans =
1
>> ~(y<7)
ans =
0
>> ~y<7
ans =
1
>> ~((y>=8)|(x<-1))
ans =
0
>> ~(y>=8)|(x<-1)
ans =
1
Define variables x and y.
This inequality is correct mathematically. The answer,
however, is false since MATLAB executes from left to
right. –5 < x is true (=1) and then 1 < –1 is false (0).
The mathematically correct statement is obtained by
using the logical operator &. The inequalities are exe-
cuted first. Since both are true (1), the answer is 1.
y < 7 is executed first, it is true (1), and ~1 is 0.
~y is executed first. y is true (1) (since y
is nonzero), ~1 is 0, and 0 < 7 is true (1).
y >= 8 (false), and x < –1 (true) are exe-
cuted first. OR is executed next (true). ~
is executed last, and gives false (0).
y >= 8 (false), and x < –1 (true) are executed
first. NOT of (y >= 8) is executed next (true).
OR is executed last, and gives true (1).
191.
180 Chapter 6: Programming in MATLAB
In addition, MATLAB has other logical built-in functions, some of which are
described in the following table:
Function Description Example
xor(a,b) Exclusive or. Returns true (1) if
one operand is true and the
other is false.
>> xor(7,0)
ans =
1
>> xor(7,-5)
ans =
0
all(A) Returns 1 (true) if all elements
in a vector A are true (nonzero).
Returns 0 (false) if one or more
elements are false (zero).
If A is a matrix, treats columns
of A as vectors, and returns a
vector with 1s and 0s.
>> A=[6 2 15 9 7 11];
>> all(A)
ans =
1
>> B=[6 2 15 9 0 11];
>> all(B)
ans =
0
any(A) Returns 1 (true) if any element
in a vector A is true (nonzero).
Returns 0 (false) if all elements
are false (zero).
If A is a matrix, treats columns
of A as vectors, and returns a
vector with 1s and 0s.
>> A=[6 0 15 0 0 11];
>> any(A)
ans =
1
>> B = [0 0 0 0 0 0];
>> any(B)
ans =
0
find(A)
find(A>d)
If A is a vector, returns the indi-
ces of the nonzero elements.
If A is a vector, returns the
address of the elements that are
larger than d (any relational
operator can be used).
>> A=[0 9 4 3 7 0 0 1
8];
>> find(A)
ans =
2 3 4
5 8 9
>> find(A>4)
ans =
2 5 9
192.
6.1 Relational and Logical Operators 181
The operations of the four logical operators, and, or, xor, and not can be
summarized in a truth table:
Sample Problem 6-1: Analysis of temperature data
The following were the daily maximum temperatures (in F) in Washington, DC,
during the month of April 2002: 58 73 73 53 50 48 56 73 73 66 69 63 74 82 84 91
93 89 91 80 59 69 56 64 63 66 64 74 63 69 (data from the U.S. National Oceanic
and Atmospheric Administration). Use relational and logical operations to deter-
mine the following:
(a) The number of days the temperature was above 75 .
(b) The number of days the temperature was between 65 and 80 .
(c) The days of the month when the temperature was between 50 and 60 .
Solution
In the script file below the temperatures are entered in a vector. Relational and
logical expressions are then used to analyze the data.
INPUT OUTPUT
A B
AND
A&B
OR
A|B
XOR
(A,B)
NOT
~A
NOT
~B
false false false false false true true
false true false true true true false
true false false true true false true
true true true true false false false
T=[58 73 73 53 50 48 56 73 73 66 69 63 74 82 84 ...
91 93 89 91 80 59 69 56 64 63 66 64 74 63 69];
Tabove75=T>=75;
NdaysTabove75=sum(Tabove75)
Tbetween65and80=(T>=65)&(T<=80);
NdaysTbetween65and80=sum(Tbetween65and80)
datesTbetween50and60=find((T>=50)&(T<=60))
A vector with 1s at addresses where T >= 75.
Add all the 1s in the vector Tabove75.
A vector with 1s at addresses
where T >= 65 and T <= 80.
Add all the 1s in the vector Tbetween65and80.
The function find returns the address of the ele-
ments in T that have values between 50 and 60.
193.
182 Chapter 6: Programming in MATLAB
The script file (saved as Exp6_1) is executed in the Command Window:
6.2 CONDITIONAL STATEMENTS
A conditional statement is a command that allows MATLAB to make a decision
of whether to execute a group of commands that follow the conditional statement,
or to skip these commands. In a conditional statement a conditional expression is
stated. If the expression is true, a group of commands that follow the statement are
executed. If the expression is false, the computer skips the group. The basic form
of a conditional statement is:
Examples:
if a < b
if c >= 5
if a == b
if a ~= 0
if (d<h)&(x>7)
if (x~=13)|(y<0)
• Conditional statements can be a part of a program written in a script file or a
user-defined function (Chapter 7).
• As shown below, for every if statement there is an end statement.
The if statement is commonly used in three structures, if-end,
if-else-end, and if-elseif-else-end, which are described next.
6.2.1 The if-end Structure
The if-end conditional statement is shown schematically in Figure 6-1. The fig-
ure shows how the commands are typed in the program, and a flowchart that sym-
bolically shows the flow, or the sequence, in which the commands are executed.
As the program executes, it reaches the if statement. If the conditional expres-
>> Exp6_1
NdaysTabove75 =
7
NdaysTbetween65and80 =
12
datesTbetween50and60 =
1 4 5 7 21 23
For 7 days the temp was above 75.
For 12 days the temp was between 65 and 80.
Dates of the month with
temp between 50 and 60.
if conditional expression consisting of relational and/or logical operators.
All the variables must
have assigned values.
194.
6.2 Conditional Statements 183
sion in the if statement is true (1), the program continues to execute the com-
mands that follow the if statement all the way down to the end statement. If the
conditional expression is false (0), the program skips the group of commands
between the if and the end, and continues with the commands that follow the
end.
The words if and end appear on the screen in blue, and the commands
between the if statement and the end statement are automatically indented (they
don't have to be), which makes the program easier to read. An example where the
if-end statement is used in a script file is shown in Sample Problem 6-2.
Sample Problem 6-2: Calculating worker's pay
A worker is paid according to his hourly wage up to 40 hours, and 50% more for
overtime. Write a program in a script file that calculates the pay to a worker. The
program asks the user to enter the number of hours and the hourly wage. The pro-
gram then displays the pay.
Solution
The program in a script file is shown below. The program first calculates the pay
by multiplying the number of hours by the hourly wage. Then an if statement
checks whether the number of hours is greater than 40. If so, the next line is exe-
cuted and the extra pay for the hours above 40 is added. If not, the program skips
to the end.
Figure 6-1: The structure of the if-end conditional statement.
t=input('Please enter the number of hours worked ');
h=input('Please enter the hourly wage in $ ');
Pay=t*h;
if t>40
......
......
......
if conditional expression
........
........
........
end
......
......
......
A group of
MATLAB commands.
MATLAB program.
MATLAB program.
Flowchart
195.
184 Chapter 6: Programming in MATLAB
Application of the program (in the Command Window) for two cases is shown
below (the file was saved as Workerpay):
6.2.2 The if-else-end Structure
The if-else-end structure provides a means for choosing one group of com-
mands, out of a possible two groups, for execution. The if-else-end struc-
ture is shown in Figure 6-2. The figure shows how the commands are typed in the
program, and a flowchart that illustrates the flow, or the sequence, in which the
Pay=Pay+(t-40)*0.5*h;
end
fprintf('The worker''s pay is $ %5.2f',Pay)
>> Workerpay
Please enter the number of hours worked 35
Please enter the hourly wage in $ 8
The worker's pay is $ 280.00
>> Workerpay
Please enter the number of hours worked 50
Please enter the hourly wage in $ 10
The worker's pay is $ 550.00
Figure 6-2: The structure of the if-else-end conditional statement.
if
statement
True
Commands
group 1
False
end
Commands
group 2
......
......
196.
6.2 Conditional Statements 185
commands are executed. The first line is an if statement with a conditional
expression. If the conditional expression is true, the program executes group 1 of
commands between the if and the else statements and then skips to the end. If
the conditional expression is false, the program skips to the else and then exe-
cutes group 2 of commands between the else and the end.
6.2.3 The if-elseif-else-end Structure
The if-elseif-else-end structure is shown in Figure 6-3. The figure
shows how the commands are typed in the program, and gives a flowchart that
illustrates the flow, or the sequence, in which the commands are executed. This
structure includes two conditional statements (if and elseif) that make it
possible to select one out of three groups of commands for execution. The first
line is an if statement with a conditional expression. If the conditional expression
is true, the program executes group 1 of commands between the if and the
elseif statements and then skips to the end. If the conditional expression in the
if statement is false, the program skips to the elseif statement. If the condi-
tional expression in the elseif statement is true, the program executes group 2
of commands between the elseif and the else and then skips to the end. If
the conditional expression in the elseif statement is false, the program skips to
the else and executes group 3 of commands between the else and the end.
It should be pointed out here that several elseif statements and associ-
Figure 6-3: The structure of the if-elseif-else-end conditional statement.
if
statement
True
Commands
group 1
False
end
Commands
group 2
Commands
group 3
elseif
statement
True
False
......
......
if conditional expression
........
........
........
elseGroup 3 of
MATLAB commands.
197.
186 Chapter 6: Programming in MATLAB
ated groups of commands can be added. In this way more conditions can be
included. Also, the else statement is optional. This means that in the case of sev-
eral elseif statements and no else statement, if any of the conditional state-
ments is true the associated commands are executed; otherwise nothing is
executed.
The following example uses the if-elseif-else-end structure in a
program.
Sample Problem 6-3: Water level in water tower
The tank in a water tower has the geometry
shown in the figure (the lower part is a cylinder
and the upper part is an inverted frustum of a
cone). Inside the tank there is a float that indi-
cates the level of the water. Write a MATLAB
program that determines the volume of the
water in the tank from the position (height h) of
the float. The program asks the user to enter a
value of h in m, and as output displays the vol-
ume of the water in m3.
Solution
For m the volume of the water is given by the volume of a cylinder with
height h: .
For m the volume of the water is given by adding the volume of a cyl-
inder with m, and the volume of the water in the cone:
where .
The program is:
% The program calculates the volume of the water in the
water tower.
h=input('Please enter the height of the float in meter ');
if h > 33
disp('ERROR. The height cannot be larger than 33 m.')
elseif h < 0
disp('ERROR. The height cannot be a negative number.')
elseif h <= 19
v = pi*12.5^2*h;
fprintf('The volume of the water is %7.3f cubic meter.n',v)
0 h 19
V 12.52h=
19 h 33
h 19=
V 12.52 19
1
3
--- h 19– 12.52 12.5 rh rh
2+ ++=
rh 12.5
10.5
14
---------- h 19–+=
198.
6.3 The switch-case Statement 187
The following is the display in the Command Window when the program is used
with three different values of water height.
6.3 THE switch-case STATEMENT
The switch-case statement is another method that can be used to direct the
flow of a program. It provides a means for choosing one group of commands for
execution out of several possible groups. The structure of the statement is shown
in Figure 6-4.
• The first line is the switch command, which has the form:
The switch expression can be a scalar or a string. Usually it is a variable that has
an assigned scalar or a string. It can also be, however, a mathematical expression
that includes pre-assigned variables and can be evaluated.
• Following the switch command are one or several case commands. Each
has a value (can be a scalar or a string) next to it (value1, value2, etc.) and an
associated group of commands below it.
• After the last case command there is an optional otherwise command fol-
lowed by a group of commands.
• The last line must be an end statement.
How does the switch-case statement work?
The value of the switch expression in the switch command is compared with the
values that are next to each of the case statements. If a match is found, the group
of commands that follow the case statement with the match are executed. (Only
one group of commands—the one between the case that matches and either the
else
rh=12.5+10.5*(h-19)/14;
v=pi*12.5^2*19+pi*(h-19)*(12.5^2+12.5*rh+rh^2)/3;
fprintf('The volume of the water is %7.3f cubic meter.n',v)
end
Please enter the height of the float in meter 8
The volume of the water is 3926.991 cubic meter.
Please enter the height of the float in meter 25.7
The volume of the water is 14114.742 cubic meter.
Please enter the height of the float in meter 35
ERROR. The height cannot be larger than 33 m.
switch switch expression
199.
188 Chapter 6: Programming in MATLAB
case, otherwise, or end statement that is next—is executed).
• If there is more than one match, only the first matching case is executed.
• If no match is found and the otherwise statement (which is optional) is
present, the group of commands between otherwise and end is executed.
• If no match is found and the otherwise statement is not present, none of the
command groups is executed.
• A case statement can have more than one value. This is done by typing the
values in the form: {value1, value2, value3, ...}. (This form,
which is not covered in this book, is called a cell array.) The case is executed if
at least one of the values matches the value of switch expression.
A Note: In MATLAB only the first matching case is executed. After the group of
commands associated with the first matching case are executed, the program skips
to the end statement. This is different from the C language, where break state-
ments are required.
Sample Problem 6-4: Converting units of energy
Write a program in a script file that converts a quantity of energy (work) given in
units of either joule, ft-lb, cal, or eV to the equivalent quantity in different units
specified by the user. The program asks the user to enter the quantity of energy, its
Figure 6-4: The structure of a switch-case statement.
......
......
switch switch expression
case value1
........
........
case value2
........
........
case value3
........
........
otherwise
........
........
end
......
......
Group 1 of commands.
MATLAB program.
MATLAB program.
Group 2 of commands.
Group 3 of commands.
Group 4 of commands.
200.
6.3 The switch-case Statement 189
current units, and the desired new units. The output is the quantity of energy in the
new units.
The conversion factors are: 1 ft-lb cal eV.
Use the program to:
(a) Convert 150 J to ft-lb.
(b) Convert 2,800 cal to J.
(c) Convert 2.7 eV to cal.
Solution
The program includes two sets of switch-case statements and one if-
else-end statement. The first switch-case statement is used to convert the
input quantity from its initial units to units of joules. The second is used to
convert the quantity from joules to the specified new units. The if-else-end
statement is used to generate an error message if units are entered incorrectly.
Ein=input('Enter the value of the energy (work) to be converted: ');
EinUnits=input('Enter the current units (J, ft-lb, cal, or eV): ','s');
EoutUnits=input('Enter the new units (J, ft-lb, cal, or eV): ','s');
error=0;
switch EinUnits
case 'J'
EJ=Ein;
case 'ft-lb'
EJ=Ein/0.738;
case 'cal'
EJ=Ein/0.239;
case 'eV'
EJ=Ein/6.24e18;
otherwise
error=1;
end
switch EoutUnits
case 'J'
Eout=EJ;
case 'ft-lb'
Eout=EJ*0.738;
case 'cal'
Eout=EJ*0.239;
case 'eV'
Eout=EJ*6.24e18;
J 0.738= 0.239= 6.24 1018=
Assign 0 to variable error.
First switch statement. Switch expres-
sion is a string with initial units.
Each of the four case statements has
a value (string) that corresponds to
one of the initial units, and a com-
mand that converts Ein to units of J.
(Assign the value to EJ.)
Assign 1 to error if no match is found. Possi-
ble only if initial units were typed incorrectly.
Second switch statement. Switch
expression is a string with new units.
Each of the four case statements has
a value (string) that corresponds to
one of the new units, and a command
that converts EJ to the new units.
(Assign the value to Eout.)
201.
190 Chapter 6: Programming in MATLAB
As an example, the script file (saved as EnergyConversion) is used next in the
Command Window to make the conversion in part (b) of the problem statement.
6.4 LOOPS
A loop is another method to alter the flow of a computer program. In a loop, the
execution of a command, or a group of commands, is repeated several times con-
secutively. Each round of execution is called a pass. In each pass at least one vari-
able, but usually more than one, or even all the variables that are defined within
the loop, are assigned new values. MATLAB has two kinds of loops. In for-end
loops (Section 6.4.1) the number of passes is specified when the loop starts. In
while-end loops (Section 6.4.2) the number of passes is not known ahead of
time, and the looping process continues until a specified condition is satisfied.
Both kinds of loops can be terminated at any time with the break command (see
Section 6.6).
6.4.1 for-end Loops
In for-end loops the execution of a command, or a group of commands, is
repeated a predetermined number of times. The form of a loop is shown in Figure
6-5.
• The loop index variable can have any variable name (usually i, j, k, m, and n
are used, however, i and j should not be used if MATLAB is used with com-
plex numbers).
otherwise
error=1;
end
if error
disp('ERROR current or new units are typed incorrectly.')
else
fprintf('E = %g %s',Eout,EoutUnits)
end
>> EnergyConversion
Enter the value of the energy (work) to be converted: 2800
Enter the current units (J, ft-lb, cal, or eV): cal
Enter the new units (J, ft-lb, cal, or eV): J
E = 11715.5 J
Assign 1 to error if no match is found. Pos-
sible only if new units were typed incorrectly.
If-else-end statement.
If error is true (nonzero),
display an error message.
If error is false (zero), display converted energy.
202.
6.4 Loops 191
• In the first pass k = f and the computer executes the commands between the
for and end commands. Then, the program goes back to the for command
for the second pass. k obtains a new value equal to k = f + s, and the com-
mands between the for and end commands are executed with the new value
of k. The process repeats itself until the last pass, where k = t. Then the pro-
gram does not go back to the for, but continues with the commands that fol-
low the end command. For example, if k = 1:2:9, there are five loops, and the
corresponding values of k are 1, 3, 5, 7, and 9.
• The increment s can be negative (i.e.; k = 25:–5:10 produces four passes with
k = 25, 20, 15, 10).
• If the increment value s is omitted, the value is 1 (default) (i.e.; k = 3:7 pro-
duces five passes with k = 3, 4, 5, 6, 7).
• If f = t, the loop is executed once.
• If f > t and s > 0, or if f < t and s < 0, the loop is not executed.
• If the values of k, s, and t are such that k cannot be equal to t, then if s is
positive, the last pass is the one where k has the largest value that is smaller
than t (i.e., k = 8:10:50 produces five passes with k = 8, 18, 28, 38, 48). If s is
negative, the last pass is the one where k has the smallest value that is larger
than t.
• In the for command k can also be assigned a specific value (typed as a vec-
tor). Example: for k = [7 9 –1 3 3 5].
• The value of k should not be redefined within the loop.
• Each for command in a program must have an end command.
• The value of the loop index variable (k) is not displayed automatically. It is
possible to display the value in each pass (which is sometimes useful for
debugging) by typing k as one of the commands in the loop.
Figure 6-5: The structure of a for-end loop.
for k = f:s:t
........
........
........
end
A group of
MATLAB commands.
Loop index
variable.
The value of k
in the first pass.
The increment in k
after each pass.
The value of k
in the last pass.
203.
192 Chapter 6: Programming in MATLAB
• When the loop ends, the loop index variable (k) has the value that was last
assigned to it.
A simple example of a for-end loop (in a script file) is:
When this program is executed, the loop is executed four times. The value of k in
the four passes is k = 1, 4, 7, and 10, which means that the values that are assigned
to x in the passes are x = 1, 16, 49, and 100, respectively. Since a semicolon is not
typed at the end of the second line, the value of x is displayed in the Command
Window at each pass. When the script file is executed, the display in the Com-
mand Window is:
Sample Problem 6-5: Sum of a series
(a) Use a for-end loop in a script file to calculate the sum of the first n terms of
the series: . Execute the script file for n = 4 and n = 20.
(b) The function sin(x) can be written as a Taylor series by:
Write a user-defined function file that calculates sin(x) by using the Taylor series.
For the function name and arguments use y = Tsin(x,n). The input arguments
are the angle x in degrees and n the number of terms in the series. Use the func-
tion to calculate sin( ) using three and seven terms.
Solution
(a) A script file that calculates the sum of the first n terms of the series is shown
below.
The summation is done with a loop. In each pass one term of the series is calcu-
for k=1:3:10
x = k^2
end
>> x =
1
x =
16
x =
49
x =
100
1–
k
k
2
k
----------------
k 1=
n
xsin
1–
k
x
2k 1+
2k 1+ !
---------------------------
k 0=
=
204.
6.4 Loops 193
lated (in the first pass the first term, in the second pass the second term, and so on)
and is added to the sum of the previous elements. The file is saved as Exp6_5a and
then executed twice in the Command Window:
(b) A user-defined function file that calculates sin(x) by adding n terms of a
Taylor series is shown below.
The first element corresponds to k = 0, which means that in order to add n terms of
the series, in the last loop k = n – 1. The function is used in the Command Window
to calculate sin( ) using three and seven terms:
n=input('Enter the number of terms ' );
S=0;
for k=1:n
S=S+(-1)^k*k/2^k;
end
fprintf('The sum of the series is: %f',S)
>> Exp6_5a
Enter the number of terms 4
The sum of the series is: -0.125000
>> Exp7_5a
Enter the number of terms 20
The sum of the series is: -0.222216
function y = Tsin(x,n)
% Tsin calculates the sin using Taylor formula.
% Input arguments:
% x The angle in degrees, n number of terms.
xr=x*pi/180;
y=0;
for k=0:n-1
y=y+(-1)^k*xr^(2*k+1)/factorial(2*k+1);
end
>> Tsin(150,3)
ans =
0.6523
Setting the sum to zero.
In each pass one element of the
series is calculated and is added
to the sum of the elements from
the previous passes.
for-end
loop.
Converting the angle from degrees to radians.
for-end
loop.
Calculating sin(150o) with three terms of Taylor series.
205.
194 Chapter 6: Programming in MATLAB
A note about for-end loops and element-by-element operations:
In some situations the same end result can be obtained by either using for-end
loops or using element-by-element operations. Sample Problem 6-5 illustrates
how the for-end loop works, but the problem can also be solved by using ele-
ment-by-element operations (see Problems 7 and 8 in Section 3.9). Element-by-
element operations with arrays are one of the superior features of MATLAB that
provide the means for computing in circumstances that otherwise require loops. In
general, element-by-element operations are faster than loops and are recom-
mended when either method can be used.
Sample Problem 6-6: Modify vector elements
A vector is given by V = [5, 17, –3, 8, 0, –7, 12, 15, 20, –6, 6, 4, –7, 16]. Write a
program as a script file that doubles the elements that are positive and are divisible
by 3 or 5, and, raises to the power of 3 the elements that are negative but greater
than –5.
Solution
The problem is solved by using a for-end loop that has an if-elseif-end
conditional statement inside. The number of passes is equal to the number of ele-
ments in the vector. In each pass one element is checked by the conditional state-
ment. The element is changed if it satisfies the conditions in the problem
statement. A program in a script file that carries out the required operations is:
>> Tsin(150,7)
ans =
0.5000
V=[5, 17, -3, 8, 0, -7, 12, 15, 20 -6, 6, 4, -2, 16];
n=length(V);
for k=1:n
if V(k)>0 & (rem(V(k),3) = = 0| rem(V(k),5)= = 0)
V(k)=2*V(k);
elseif V(k) < 0 & V(k) > -5
V(k)=V(k)^3;
end
end
V
Calculating sin(150 ) with seven terms of Taylor series.
The exact value is 0.5.
Setting n to be equal to the number of elements in V.
if-
elseif-
end
statement.
for-end
loop.
206.
6.4 Loops 195
The file is saved as Exp7_6 and then executed in the Command Window:
6.4.2 while-end Loops
while-end loops are used in situations when looping is needed but the number
of passes is not known in advance. In while-end loops the number of passes is
not specified when the looping process starts. Instead, the looping process contin-
ues until a stated condition is satisfied. The structure of a while-end loop is
shown in Figure 6-6.
The first line is a while statement that includes a conditional expression.
When the program reaches this line the conditional expression is checked. If it is
false (0), MATLAB skips to the end statement and continues with the program. If
the conditional expression is true (1), MATLAB executes the group of commands
that follow between the while and end commands. Then MATLAB jumps back
to the while command and checks the conditional expression. This looping pro-
cess continues until the conditional expression is false.
For a while-end loop to execute properly:
• The conditional expression in the while command must include at least one
variable.
• The variables in the conditional expression must have assigned values when
MATLAB executes the while command for the first time.
• At least one of the variables in the conditional expression must be assigned a
new value in the commands that are between the while and the end. Other-
wise, once the looping starts it will never stop since the conditional expression
will remain true.
An example of a simple while-end loop is shown in the following program. In
>> Exp7_6
V =
10 17 -27 8 0 -7 24 30 40 -6 12 4
-8 16
Figure 6-6: The structure of a while-end loop.
while conditional expression
........
........
........
end
A group of
MATLAB commands.
207.
196 Chapter 6: Programming in MATLAB
this program a variable x with an initial value of 1 is doubled in each pass as long
as its value is equal to or smaller than 15.
When this program is executed the display in the Command Window is:
Important note:
When writing a while-end loop, the programmer has to be sure that the variable
(or variables) that are in the conditional expression and are assigned new values
during the looping process will eventually be assigned values that make the condi-
tional expression in the while command false. Otherwise the looping will con-
tinue indefinitely (indefinite loop). In the example above if the conditional
expression is changed to x >= 0.5, the looping will continue indefinitely. Such a
situation can be avoided by counting the passes and stopping the looping if the
number of passes exceeds some large value. This can be done by adding the max-
imum number of passes to the conditional expression, or by using the break
command (Section 6.6).
Since no one is free from making mistakes, a situation of indefinite looping
can occur in spite of careful programming. If this happens, the user can stop the
execution of an indefinite loop by pressing the Ctrl + C or Ctrl + Break keys.
Sample Problem 6-7: Taylor series representation of a function
The function can be represented in a Taylor series by .
Write a program in a script file that determines by using the Taylor series rep-
resentation. The program calculates by adding terms of the series and stopping
x=1
while x<=15
x=2*x
end
x =
1
x =
2
x =
4
x =
8
x =
16
Initial value of x is 1.
The next command is executed only if x <= 15.
In each pass x doubles.
Initial value of x.
In each pass x doubles.
When x = 16, the conditional expression in the
while command is false and the looping stops.
f x ex= ex x
n
n!
-----
n 0=
=
ex
ex
208.
6.4 Loops 197
when the absolute value of the term that was added last is smaller than 0.0001.
Use a while-end loop, but limit the number of passes to 30. If in the 30th pass
the value of the term that is added is not smaller than 0.0001, the program stops
and displays a message that more than 30 terms are needed.
Use the program to calculate , , and .
Solution
The first few terms of the Taylor series are:
A program that uses the series to calculate the function is shown next. The
program asks the user to enter the value of x. Then the first term, an, is assigned
the number 1, and an is assigned to the sum S. Then, from the second term on, the
program uses a while loop to calculate the nth term of the series and add it to the
sum. The program also counts the number of terms n. The conditional expression
in the while command is true as long as the absolute value of the nth an term is
larger than 0.0001, and the number of passes n is smaller than 30. This means that
if the 30th term is not smaller than 0.0001, the looping stops.
The program uses an if-else-end statement to display the results. If the loop-
ing stopped because the 30th term is not smaller than 0.0001, it displays a mes-
sage indicating this. If the value of the function is calculated successfully, it
displays the value of the function and the number of terms used. When the pro-
gram executes, the number of passes depends on the value of x. The program
(saved as expox) is used to calculate , , and :
x=input('Enter x ' );
n=1; an=1; S=an;
while abs(an) >= 0.0001 & n <= 30
an=x^n/factorial(n);
S=S+an;
n=n+1;
end
if n >= 30
disp('More than 30 terms are needed')
else
fprintf('exp(%f) = %f',x,S)
fprintf('nThe number of terms used is: %i',n)
end
>> expox
e2 e 4– e21
ex 1 x
x2
2!
-----
x3
3!
-----+ + + +=
Start of the while loop.
Calculating the nth term.
Adding the nth term to the sum.
Counting the number of passes.
End of the while loop.
if-else-end loop.
e2 e 4– e21
209.
198 Chapter 6: Programming in MATLAB
6.5 NESTED LOOPS AND NESTED CONDITIONAL STATEMENTS
Loops and conditional statements can be nested within other loops or conditional
statements. This means that a loop and/or a conditional statement can start (and
end) within another loop or conditional statement. There is no limit to the number
of loops and conditional statements that can be nested. It must be remembered,
however, that each if, case, for, and while statement must have a corre-
sponding end statement. Figure 6-7 shows the structure of a nested for-end
loop within another for-end loop. In the loops shown in this figure, if, for
example, n = 3 and m = 4, then first k = 1 and the nested loop executes four times
with h = 1, 2, 3, 4. Next k = 2 and the nested loop executes again four times with
h = 1, 2, 3, 4. Finally k = 3 and the nested loop executes again four times. Every
time a nested loop is typed, MATLAB automatically indents the new loop relative
to the outside loop. Nested loops and conditional statements are demonstrated in
the following sample problem.
Enter x 2
exp(2.000000) = 7.389046
The number of terms used is: 12
>> expox
Enter x -4
exp(-4.000000) = 0.018307
The number of terms used is: 18
>> expox
Enter x 21
More than 30 terms are needed
Figure 6-7: Structure of nested loops.
Calculating exp(2).
12 terms used.
Calculating exp(–4).
18 terms used.
Trying to calculate exp(21).
for k = 1:n
for h = 1:m
........
........
........
end
end
A group of
commands.
Nested
loop
Loop
Every time k
increases by 1, the
nested loop executes
m times. Overall, the
group of commands
are executed
times.
n m
210.
6.5 Nested Loops and Nested Conditional Statements 199
Sample Problem 6-8: Creating a matrix with a loop
Write a program in a script file that creates an matrix with elements that
have the following values. The value of each element in the first row is the num-
ber of the column. The value of each element in the first column is the number of
the row. The rest of the elements each has a value equal to the sum of the element
above it and the element to the left. When executed, the program asks the user to
enter values for n and m.
Solution
The program, shown below, has two loops (one nested) and a nested if-
elseif-else-end structure. The elements in the matrix are assigned values
row by row. The loop index variable of the first loop, k, is the address of the row,
and the loop index variable of the second loop, h, is the address of the column.
The program is executed in the Command Window to create a matrix.
n=input('Enter the number of rows ');
m=input('Enter the number of columns ');
A=[];
for k=1:n
for h=1:m
if k==1
A(k,h)=h;
elseif h==1
A(k,h)=k;
else
A(k,h)=A(k,h-1)+A(k-1,h);
end
end
end
A
>> Chap6_exp8
Enter the number of rows 4
Enter the number of columns 5
n m
Define an empty matrix A
Start of the first for-end loop.
Start of the second for-end loop.
Start of the conditional statement.
Assign values to the elements of the first row.
Assign values to the elements of the first column.
Assign values to other elements.
end of the if statement.
end of the nested for-end loop.
end of the first for-end loop.
4 5
211.
200 Chapter 6: Programming in MATLAB
6.6 THE break AND continue COMMANDS
The break command:
• When inside a loop (for or while), the break command terminates the
execution of the loop (the whole loop, not just the last pass). When the break
command appears in a loop, MATLAB jumps to the end command of the loop
and continues with the next command (it does not go back to the for com-
mand of that loop).
• If the break command is inside a nested loop, only the nested loop is termi-
nated.
• When a break command appears outside a loop in a script or function file, it
terminates the execution of the file.
• The break command is usually used within a conditional statement. In loops
it provides a method to terminate the looping process if some condition is met
—for example, if the number of loops exceeds a predetermined value, or an
error in some numerical procedure is smaller than a predetermined value.
When typed outside a loop, the break command provides a means to termi-
nate the execution of a file, such as when data transferred into a function file is
not consistent with what is expected.
The continue command:
• The continue command can be used inside a loop (for or while) to stop
the present pass and start the next pass in the looping process.
• The continue command is usually a part of a conditional statement. When
MATLAB reaches the continue command, it does not execute the remain-
ing commands in the loop, but skips to the end command of the loop and then
starts a new pass.
A =
1 2 3 4 5
2 4 7 11 16
3 7 14 25 41
4 11 25 50 91
212.
6.7 Examples of MATLAB Applications 201
6.7 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 6-9: Withdrawing from a retirement account.
A person in retirement is depositing $300,000 in a saving account that pays 5%
interest per year. The person plans to withdraw money from the account once a
year. He starts by withdrawing $25,000 after the first year, and in future years he
increases the amount he withdraws according to the inflation rate. For example, if
the inflation rate is 3%, he withdraws $25,750 after the second year. Calculate the
number of years the money in the account will last assuming a constant yearly
inflation rate of 2%. Make a plot that shows the yearly withdrawals and the bal-
ance of the account over the years.
Solution
The problem is solved by using a loop (a while loop since the number of passes
is not known before the loop starts). In each pass the amount to be withdrawn and
the account balance are calculated. The looping continues as long as the account
balance is larger than or equal to the amount to be withdrawn. The following is a
program in a script file that solves the problem. In the program, year is a vector
in which each element is a year number, W is a vector with the amount withdrawn
each year, and AB is a vector with the account balance each year.
rate=0.05; inf=0.02;
clear W AB year
year(1)=0;
W(1)=0;
AB(1)=300000;
Wnext=25000;
ABnext=300000*(1 + rate);
n=2;
while ABnext >= Wnext
year(n)=n-1;
W(n)=Wnext;
AB(n)=ABnext-W(n);
ABnext=AB(n)*(1+rate);
Wnext=W(n)*(1+inf);
n=n+1;
end
fprintf('The money will last for %f years',year(n-1))
bar(year,[AB' W'],2.0)
First element is year 0.
Initial withdrawal amount.
Initial account balance.
The amount to be withdrawn after a year.
The account balance after a year.
while checks if the next balance
is larger than the next withdrawal.
Amount withdrawn in year n – 1.
Account balance in year n – 1 after withdrawal.
The account balance after additional year.
The amount to be withdrawn
after an additional year.
213.
202 Chapter 6: Programming in MATLAB
The program is executed in the following Command Window:
The program also generates the following figure (axis labels and legend were
added to the plot by using the Plot Editor).
Sample Problem 6-10: Creating a random list
Six singers—John, Mary, Tracy, Mike, Katie, and David—are performing in a
competition. Write a MATLAB program that generates a list of a random order in
which the singers will perform.
Solution
An integer (1 through 6) is assigned to each name (1 to John, 2 to Mary, 3 to
Tracy, 4 to Mike, 5 to Katie, and 6 to David). The program, shown below, first cre-
ates a list of the integers 1 through 6 in a random order. The integers are made the
elements of six-element vector. This is done by using MATLAB's built-in func-
tion randi (see Section 3.7) for assigning integers to the elements of the vector.
To make sure that all the integers of the elements are different from each other, the
integers are assigned one by one. Each integer that is suggested by the randi
function is compared with all the integers that have been assigned to previous ele-
ments. If a match is found, the integer is not assigned, and randi is used for sug-
gesting a new integer. Since each singer name is associated with an integer, once
the integer list is complete the switch-case statement is used to create the cor-
responding name list.
>> Chap6_exp9
The money will last for 15 years.
clear, clc
n=6;
214.
6.7 Examples of MATLAB Applications 203
The while loop checks that every new integer (element) that is to be added to the
vector L is not equal any of the integers in elements already in the vector L. If a
match is found, it keeps generating new integers until the new integer is different
from all the integers that are already in x.
When the program is executed, the following is displayed in the Command
Window. Obviously, a list in a different order will be displayed every time the pro-
gram is executed.
L(1)=randi(n);
for p=2:n
L(p)=randi(n);
r=0;
while r==0
r=1;
for k=1:p-1
if L(k)==L(p)
L(p)=randi(n);
r=0;
break
end
end
end
end
for i=1:n
switch L(i)
case 1
disp('John')
case 2
disp('Mary')
case 3
disp('Tracy')
case 4
disp('Mike')
case 5
disp('Katie')
case 6
disp('David')
end
end
The performing order is:
Assign the first integer to L(1).
Assign the next integer to L(p).
Set r to zero.
See explanation below.
Set r to 1.
for loop compares the integer assigned to L(p)to the
integers that have been assigned to previous elements.
If a match if found, a
new integer is
assigned to L(p) and
r is set to zero.
The nested for loop is stopped. The pro-
gram goes back to the while loop. Since
r = 0 the nested loop inside the while
loop starts again and checks if the new
integer that is assigned to L(p) is equal to
an integer that is already in the vector L.
The switch-case state-
ment lists the names
according to the values of
the integers in the elements
of L.
215.
204 Chapter 6: Programming in MATLAB
Sample Problem 6-11: Flight of a model rocket
The flight of a model rocket can be modeled as follows.
During the first 0.15s the rocket is propelled upward by the
rocket engine with a force of 16 N. The rocket then flies up
while slowing down under the force of gravity. After it
reaches the apex, the rocket starts to fall back down. When
its downward velocity reaches 20 m/s a parachute opens
(assumed to open instantly), and the rocket continues to
drop at a constant speed of 20 m/s until it hits the ground.
Write a program that calculates and plots the speed and alti-
tude of the rocket as a function of time during the flight.
Solution
The rocket is assumed to be a particle that moves along a
straight line in the vertical plane. For motion with constant acceleration along a
straight line, the velocity and position as a function of time are given by:
and
where and are the initial velocity and position, respectively. In the computer
program the flight of the rocket is divided into three segments. Each segment is
calculated in a while loop. In every pass the time increases by an increment.
Segment 1: The first 0.15s when the rocket engine is on.
During this period, the rocket moves up with a constant
acceleration. The acceleration is determined by drawing a
free body and a mass acceleration diagram (shown on the
right). From Newton's second law, the sum of the forces
in the vertical direction is equal to the mass times the
acceleration (equilibrium equation):
+
Solving the equation for the acceleration gives:
Katie
Tracy
David
Mary
John
Mike
v t v0 at+= s t s0 v0t
1
2
---at2+ +=
v0 s0
F FE mg– ma= =
a
FE mg–
m
--------------------=
216.
6.7 Examples of MATLAB Applications 205
The velocity and height as a function of time are:
and
where the initial velocity and initial position are both zero. In the computer pro-
gram this segment starts at t = 0, and the looping continues as long as s.
The time, velocity, and height at the end of this segment are , , and .
Segment 2: The motion from when the engine stops until the parachute opens. In
this segment the rocket moves with a constant deceleration g. The speed and
height of the rocket as functions of time are given by:
and
In this segment the looping continues until the velocity of the rocket is –20m/s
(negative since the rocket moves down). The time and height at the end of this
segment are and .
Segment 3: The motion from when the parachute opens until the rocket hits the
ground. In this segment the rocket moves with constant velocity (zero accelera-
tion). The height as a function of time is given by , where
is the constant velocity after the parachute opens. In this segment the loop-
ing continues as long as the height is greater than zero.
A program in a script file that carries out the calculations is shown below.
m=0.05; g=9.81; tEngine=0.15; Force=16; vChute=-20; Dt=0.01;
clear t v h
n=1;
t(n)=0; v(n)=0; h(n)=0;
% Segment 1
a1=(Force-m*g)/m;
while t(n) < tEngine & n < 50000
n=n+1;
t(n)=t(n-1)+Dt;
v(n)=a1*t(n);
h(n)=0.5*a1*t(n)^2;
end
v1=v(n); h1=h(n); t1=t(n);
% Segment 2
while v(n) >= vChute & n < 50000
n=n+1;
t(n)=t(n-1)+Dt;
v(n)=v1-g*(t(n)-t1);
v t 0 at+= h t 0 0
1
2
---at2+ +=
t 0.15
t1 v1 h1
v t v1 g t t1––= h t h1 v1 t t1–
1
2
---g t t1– 2–+=
t2 h2
h t h2 vchute t t2––=
vchute
The first while loop.
The second while loop.
217.
206 Chapter 6: Programming in MATLAB
The accuracy of the results depends on the magnitude of the time increment
Dt. An increment of 0.01 s appears to give good results. The conditional expres-
sion in the while commands also includes a condition for n (if n is larger than
50,000 the loop stops). This is done as a precaution to avoid an infinite loop in
case there is an error in an of the statements inside the loop. The plots generated
by the program are shown below (axis labels and text were added to the plots
using the Plot Editor).
Note: The problem can be solved and programmed in different ways. The solu-
tion shown here is one option. For example, instead of using while loops, the
times when the parachute opens and when the rocket hits the ground can be calcu-
lated first, and then for-end loops can be used instead of the while loop. If the
times are determined first, it is possible also to use element-by-element calcula-
tions instead of loops.
h(n)=h1+v1*(t(n)-t1)-0.5*g*(t(n)-t1)^2;
end
v2=v(n); h2=h(n); t2=t(n);
% Segment 3
while h(n) > 0 & n < 50000
n=n+1;
t(n)=t(n-1)+Dt;
v(n)=vChute;
h(n)=h2+vChute*(t(n)-t2);
end
subplot(1,2,1)
plot(t,h,t2,h2,'o')
subplot(1,2,2)
plot(t,v,t2,v2,'o')
The third while loop.
0 2 4 6 8 10 12
-20
0
20
40
60
80
100
120
Time (s)
Height(m)
0 2 4 6 8 10 12
-30
-20
-10
0
10
20
30
40
50
Time (s)
Velocity(m/s)
Parachute
opens
Parachute
opens
218.
6.7 Examples of MATLAB Applications 207
Sample Problem 6-12: AC to DC converter
A half-wave diode rectifier is an elec-
trical circuit that converts AC voltage
to DC voltage. A rectifier circuit that
consists of an AC voltage source, a
diode, a capacitor, and a load (resis-
tor) is shown in the figure. The volt-
age of the source is ,
where , in which f is the fre-
quency. The operation of the circuit is
illustrated in the lower diagram where
the dashed line shows the source volt-
age and the solid line shows the volt-
age across the resistor. In the first
cycle, the diode is on (conducting
current) from until . At
this time the diode turns off and the
power to the resistor is supplied by the discharging capacitor. At the diode
turns on again and continues to conduct current until . The cycle continues
as long as the voltage source is on. In this simplified analysis of this circuit, the
diode is assumed to be ideal and the capacitor is assumed to have no charge ini-
tially (at ). When the diode is on, the resistor's voltage and current are given
by:
and
The current in the capacitor is:
When the diode is off, the voltage across the resistor is given by:
The times when the diode switches off ( , , and so on) are calculated from the
condition . The diode switches on again when the voltage of the source
reaches the voltage across the resistor (time in the figure).
Write a MATLAB program that plots the voltage across the resistor and
the voltage of the source as a function of time for ms. The resistance
of the load is 1,800 , the voltage source V, and Hz. To examine
the effect of capacitor size on the voltage across the load, execute the program
twice, once with F and once with F.
vR v0 t e
t tA–– RC
sin=
vs v0 tsin=
2 f=
t 0= t tA=
t tB=
t tD=
t 0=
vR v0 tsin= iR v0 t Rsin=
iC Cv0 tcos=
vR v0 tA e
t tA–– RC
sin=
tA tD
iR iC–=
tB
vR
vs 0 t 70
v0 12= f 60=
C 45= C 10=
219.
208 Chapter 6: Programming in MATLAB
Solution
A program that solves the problem is presented below. The program has two
parts—one that calculates the voltage when the diode is on, and the other when
the diode is off. The switch command is used for switching between the two
parts. The calculations start with the diode on (the variable state='on'), and
when the value of state is changed to 'off', and the program
switches to the commands that calculate for this state. These calculations con-
tinue until , when the program switches back to the equations that are valid
when the diode is on.
V0=12; C=45e-6; R=1800; f=60;
Tf=70e-3; w=2*pi*f;
clear t VR Vs
t=0:0.05e-3:Tf;
n=length(t);
state='on'
for i=1:n
Vs(i)=V0*sin(w*t(i));
switch state
case 'on'
VR(i)=Vs(i);
iR=Vs(i)/R;
iC=w*C*V0*cos(w*t(i));
sumI=iR+iC;
if sumI <= 0
state='off ';
tA=t(i);
end
case 'off '
VR(i)=V0*sin(w*tA)*exp(-(t(i)-tA)/(R*C));
if Vs(i) >= VR(i)
state='on';
end
end
end
plot(t,Vs,':',t,VR,'k','linewidth',1)
xlabel('Time (s)'); ylabel('Voltage (V)')
vR
iR iC– 0
vR
vs vR
Assign 'on' to the variable state.
Calculate the voltage of the source at time t.
Diode is on.
Check if .iR iC– 0
If true, assign 'off' to state.
Assign a value to .tA
Diode is off.
Check if .vs vR
If true, assign
'on' to the
variable state.
221.
210 Chapter 6: Programming in MATLAB
4. Use the vectors v and w from Problem 3. Use relational operators to create a
vector y that is made up of the elements of w that are larger than or equal to the
elements of v.
5. Evaluate the following expressions without using MATLAB. Check the
answer with MATLAB.
(a) 0&21 (b) ~–2>–1&11>=~0
(c) 4–7/2&6<5|-3 (d) 3|–1&~2*–3|0
6. The maximum daily temperature (in F) for Chicago and San Francisco dur-
ing the month of August 2009 are given in the vectors below (data from the
U.S. National Oceanic and Atmospheric Administration).
TCH = [75 79 86 86 79 81 73 89 91 86 81 82 86 88 89 90 82 84 81
79 73 69 73 79 82 72 66 71 69 66 66]
TSF = [69 68 70 73 72 71 69 76 85 87 74 84 76 68 79 75 68 68 73
72 79 68 68 69 71 70 89 95 90 66 69]
Write a program in a script file to answer the following:
(a) Calculate the average temperature for the month in each city.
(b) How many days was the temperature above the average in each city?
(c) How many days, and on which dates in the month, was the temperature in
San Francisco lower than the temperature in Chicago?
(d) How many days, and on which dates in the month, was the temperature
the same in both cities?
7. Fibonacci numbers are the numbers in a sequence in which the first two ele-
ments are 0 and 1, and the value of each subsequent element is the sum of the
previous two elements:
0, 1, 1, 2, 3, 5, 8, 13, ...
Write a MATLAB program in a script file that determines and displays the
first 20 Fibonacci numbers.
8. Use loops to create a matrix in which the value of each element is the
sum of its row number and its column number divided by the square of its col-
umn number. For example, the value of element (2,3) is .
9. The elements of the symmetric Pascal matrix are obtained from:
Write a MATLAB program that creates an symmetric Pascal matrix.
Use the program to create and Pascal matrices.
4 3
2 3+ 32 0.5555=
Pij
i j 2–+ !
i 1– ! j 1– !
-----------------------------------=
n n
4 4 7 7
222.
6.8 Problems 211
10. A Fibonacci sequence is a sequence of numbers beginning with 0 and 1,
where the value of each subsequent element is the sum of the previous two
elements:
, i.e. 0, 1, 1, 2, 3, 5, 8, 13, ...
Related sequences can be constructed with other beginning numbers. Write a
MATLAB program in a script file that construct an matrix such that the
first row contains the first n elements of a sequence, the second row contains
the through th elements and so on. The first line of the script should
show the order n of the matrix followed by the values of the first two ele-
ments. These two elements can be any two integers, except they cannot both
be zero. A property of matrices thus constructed is that their determinants are
always zero. Run the program for and and for different values
of the first two elements. Verify that the determinant is zero in each case (use
MATLAB's built-in function det).
11. Write a program in a script file that determines the real roots of a quadratic
equation . Name the file quadroots. When the file runs, it
asks the user to enter the values of the constants a, b, and c. To calculate the
roots of the equation the program calculates the discriminant D, given by:
If D > 0, the program displays message "The equation has two roots," and the
roots are displayed in the next line.
If D = 0, the program displays message "The equation has one root," and the
root is displayed in the next line.
If D < 0, the program displays message "The equation has no real roots."
Run the script file in the Command Window three times to obtain solutions to
the following three equations:
(a)
(b)
(c)
12. Write a program in a script file that finds the smallest odd integer that is divis-
ible by 11 and whose square root is greater than 132. Use a loop in the pro-
gram. The loop should start from 1 and stop when the number is found. The
program prints the message "The required number is:" and then prints the
number.
13. Write a program (using a loop) that determines the expression:
Run the program with m = 5, m = 10, and m = 20. Compare the result with .
(Use format long.)
ai 1+ ai ai 1–+=
n n
n 1+ 2n
n 4= n 6=
ax2 bx c+ + 0=
D b2 4ac–=
2x2 8x 8+ + 0=
5x2– 3x 4–+ 0=
2x2– 7x 4+ + 0=
12
1 3– n
2n 1+
--------------------
n 0=
m
223.
212 Chapter 6: Programming in MATLAB
14. Write a program (using a loop) that determines the expression:
Run the program with m = 100, m = 100,000, and m = 1,0000,000. Compare the
result with . (Use format long.)
15. A vector is given by x = [–3.5 –5 6.2 11 0 8.1 –9 0 3 –1 3 2.5]. Using
conditional statements and loops, write a program that creates two vectors
from x—one (call it P) that contains the positive elements of x, and a second
(call it N) that contains the negative elements of x. In both P and N, the ele-
ments are in the same order as in x.
16. A vector is given by x = [–3.5 5 –6.2 11.1 0 7 –9.5 2 15 –1 3 2.5]. Using
conditional statements and loops, write a program that rearranges the ele-
ments of x in order from the smallest to the largest. Do not use MATLAB's
built-in function sort.
17. The following is a list of 20 exam scores. Write a computer program that cal-
culates the average of the top 8 scores.
Exam scores: 73, 91, 37, 81, 63, 66, 50, 90, 75, 43, 88, 80, 79, 69, 26, 82, 89,
99, 71, 59
18. The Taylor series expansion for is
where x is in radians. Write a MATLAB program that determines using
the Taylor series expansion. The program asks the user to type a value for an
angle in degrees. Then the program uses a loop for adding the terms of the
Taylor series. If is the nth term in the series, then the sum of the n terms
is . In each pass calculate the estimated error E given by
. Stop adding terms when . The program displays
the value of . Use the program for calculating:
(a) (b) .
Compare the values with those obtained by using a calculator.
19. Write a MATLAB program in a script file that finds a positive integer n such
that the sum of all the integers is a number between 100 and
1000 whose three digits are identical. As output the program displays the inte-
ger n and the corresponding sum.
2
2n 2
2n 2 1–
----------------------
n 1=
m
2
4
3
---
16
15
------
36
35
------=
xsin
xsin x
x3
3!
-----–
x5
5!
-----
x7
7!
-----–+ +
1–
n
2n 1+ !
----------------------x
2n 1+
n 0=
= =
xsin
an Sn
Sn Sn 1– an+=
E
Sn Sn 1––
Sn 1–
----------------------= E 0.000001
xsin
45sin 195sin
1 2 3 n+ + + +
224.
6.8 Problems 213
20. The following are formulas for calculating the training heart rate (THR) for
men and women
For men (Karvonen formula):
For women:
where AGE is the person's age, RHR the resting heart rate, and INTEN the fit-
ness level (0.55 for low, 0.65 for medium, and 0.8 for high fitness). Write a
program in a script file that determines the THR. The program asks users to
enter their gender (male or female), age (number), resting heart rate (number),
and fitness level (low, medium, or high). The program then displays the train-
ing heart rate. Use the program for determining the training heart rate for the
following two individuals:
(a) A 21-years-old male, resting heart rate of 62, and low fitness level.
(b) A 19-years-old female, resting heart rate of 67, and high fitness level.
21. Write a program that determines the center and the radius of a circle that
passes through three given points. The program asks the user to enter the
coordinates of the points one at a time. The program displays the coordinate
of the center and the radius, and makes a plot of the circle and the three points
displayed on the plot with asterisk markers. Execute the program to find the
circle that passes through the points (13, 15), (4, 18), and (19, 3).
22. Body Mass Index (BMI) is a measure of obesity. In standard units it is calcu-
lated by the formula
where W is weight in pounds, and H is height in inches. The obesity classifica-
tion is:
Write a program in a script file that calculates the BMI of a person. The pro-
gram asks the person to enter his or her weight (lb) and height (in.). The pro-
gram displays the result in a sentence that reads: "Your BMI value is XXX,
which classifies you as SSSS," where XXX is the BMI value rounded to the
nearest tenth, and SSSS is the corresponding classification. Use the program
for determining the obesity of the following two individuals:
(a) A person 6 ft 2 in. tall with a weight of 180 lb.
(b) A person 5 ft 1 in. tall with a weight of 150 lb.
BMI Classification
Below 18.5 Underweight
18.5 to 24.9 Normal
25 to 29.9 Overweight
30 and above Obese
THR 220 AGE– RHR– INTEN RHR+=
THR 206 0.88 AGE– RHR– INTEN RHR+=
BMI 703
W
H 2
-------=
225.
214 Chapter 6: Programming in MATLAB
23. Write a program in a script file that calculates the cost of a telephone call
according to the following price schedule:
The program asks the user to enter the time the call is made (day, evening, or
night) and the duration of the call (a number that can have one digit to the
right of the decimal point). If the duration of the call is not an integer, the pro-
gram rounds up the duration to the next integer. The program then displays the
cost of the call.
Run the program three times for the following calls:
(a) 8.3 min at 1:32 P.M. (b) 34.5 min at 8:00 P.M. (c) 29.6 min at 1:00 A.M.
24. Write a program that determines the change given back to a customer in a
self-service checkout machine of a supermarket for purchases of up to $20.
The program generates a random number between 0.01 and 20.00 and dis-
plays the number as the amount to be paid. The program then asks the user to
enter payment, which can be one $1 bill, one $5 bill, one $10 bill, or one $20
bill. If the payment is less than the amount to be paid, an error message is dis-
played. If the payment is sufficient, the program calculates the change and
lists the bills and/or the coins that make up the change, which has to be com-
posed of the least number each of bills and coins. For example, if the amount
to be paid is $2.33 and a $10 bill is entered as payment, then the change is one
$5 bill, two $1 bills, two quarters, one dime, one nickel, and two pennies.
25. The concentration of a drug in the body can be modeled by the equation
where is the dosage administered (mg), is the volume of distribution
(L), is the absorption rate constant (h–1
), is the elimination rate con-
stant (h–1
), and t is the time (h) since the drug was administered. For a cer-
tain drug, the following quantities are given: mg, L,
h–1
, and h–1
.
(a) A single dose is administered at . Calculate and plot versus t
for 10 hours.
Time the call
made
Duration of call
1–10 min 10–30 min More than 30 min
Day:
8 A.M. to 6 P.M.
$0.10/min $1.00 + $0.08/min for
additional min above 10.
$2.60 + $0.06/min for
additional min above 30.
Evening:
6 P.M. to 12 A.M.
$0.07/min $0.70 + $0.05/min for
additional min above 10.
$1.70 + $0.04/min for
additional min above 30.
Night:
12 A.M. to 8 A.M.
$0.04/min $0.40 + $0.03/min for
additional min above 10.
$1.00 + $0.02/min for
additional min above 13.
CP
Cp
DG
Vd
-------
ka
ka ke–
-------------------- e
ket–
e
kat–
–=
DG Vd
ka ke
DG 150= Vd 50=
ka 1.6= ke 0.4=
t 0= CP
226.
6.8 Problems 215
(b) A first dose is administered at , and subsequently four more doses
are administered at intervals of 4 hours (i.e., at ). Calculate
and plot versus t for 24 hours.
26. One numerical method for calculating the square root of a number is the Babylo-
nian method. In this method is calculated in iterations. The solution process
starts by choosing a value as a first estimate of the solution. Using this value, a
second, more accurate solution can be calculated with ,
which is then used for calculating a third, still more accurate solution , and so
on. The general equation for calculating the value of the solution from the
solution is . Write a MATLAB program that calculates
the square root of a number. In the program use for the first estimate of the
solution. Then, by using the general equation in a loop, calculate new, more accu-
rate solutions. Stop the looping when the estimated relative error E defined by
is smaller than 0.00001. Use the program to calculate:
(a) (b) (c)
27. A twin primes is a pair of prime numbers such that the difference between them
is 2 (for example, 17 and 19). Write a computer program that finds all the twin
primes between 10 and 500. The program displays the results in a two-column
matrix in which each row is a twin prime.
28. Write a program in a script file that converts a measure of volume given in
units of either m3, L, ft3, or gat (U.S. gallons) to the equivalent quantity in
different units specified by the user. The program asks the user to enter the
amount of volume, its current units, and the desired new units. The output is
the specification of volume in the new units. Use the program to:
(a) Convert 3.5 m3
to gal.
(b) Convert 200 L to ft3
.
(c) Convert 480 ft3
to m3
.
29. In a one-dimensional random walk the position x of a walker is computed
by
where s is a random number. Write a program that calculates the number of
steps required for the walker to reach a boundary . Use MATLAB's
built-in function randn(1,1) to calculate s. Run the program 100 times
(by using a loop) and calculate the average number of steps when .
t 0=
t 4 8 12 16=
CP
P
x1
x2 x2 x1 P x1+ 2=
x3
xi 1+
xi xi 1+ xi P xi+ 2=
x P=
E
xi 1+ xi–
xi
--------------------=
110 93 443 23.25
xj xj s+=
x B=
B 10=
227.
216 Chapter 6: Programming in MATLAB
30. The Sierpinski triangle can be implemented in MATLAB by plotting points
iteratively according to one of the following three rules which are selected
randomly with equal probability.
Rule 1: ,
Rule 2: ,
Rule 3: ,
Write a program in a script file that calculates the x and y vectors and then
plots y versus x as individual points (use plot(x,y,'^')). Start with
and . Run the program four times with 10, 100, 1,000, and
10,000 iterations.
31. There are 12 teams in a league, numbered 1 through 12. Six games are
planned for the weekend. Write a MATLAB program that randomly assign the
teams for each game. Display the results in a two-column table where each
row contains the two teams that play each other.
32. The temperature dependence of the heat capacity of many gases can be
described in terms of a cubic equation:
The following table gives the coefficients of the cubic equation for four gases.
is in J/(g mol)( C) and T is in C.
Write a program that does the following:
• Prints the four gases on the screen and asks the user to select which gas to
find the heat capacity for.
• Asks the user for a temperature.
• Asks the user if another temperature is needed (enter yes or no). If the
answer is yes, the user is asked to enter another temperature. This process
continues until the user enters no.
• Display a table containing the temperatures entered and the corresponding
heat capacities.
Gas a b c d
SO2 38.91
SO3 48.50
O2 29.10
N2 29.00
xn 1+ 0.5xn= yn 1+ 0.5yn=
xn 1+ 0.5xn 0.25+= yn 1+ 0.5yn
3
4
-------+=
xn 1+ 0.5xn 0.5+= yn 1+ 0.5yn=
x1 0= y1 0
228.
6.8 Problems 217
(a) Use the program for determining the heat capacity of SO3 at 100 and
180 .
(b) Use the program for finding the heat capacity of N2 at 220 and 300 .
33. The overall grade in a course is determined from the grades of 5 quizzes, 3
midterms, and a final, using the following scheme:
Quizzes: Quizzes are graded on a scale from 0 to 10. The grade of the lowest
quiz is dropped and the average of the 4 quizzes with the higher grades consti-
tutes 25% of the course grade.
Midterms: Midterms are graded on a scale from 0 to 100. If the average of the
midterm scores is higher than the score on the final, the average of the mid-
terms is 35% of the course grade. If the final grade is higher than the average
of the midterms, then the lowest midterm is dropped and the average of the
two midterms with the higher grades is 35% of the course grade.
Final: Finals are graded on a scale from 0 to 10. The final is 40% of the course
grade.
Write a computer program in a script file that determines the course
grade for a student. The program first asks the user to enter the five quiz
grades (in a vector), the three midterm grades (in a vector), and the grade of
the final. Then the program calculates a numerical course grade (a number
between 0 and 100). Finally, the program assigns a letter grade according to
the following key: A for , B for , C for
, D for , and E for a grade lower than 60. Exe-
cute the program for the following cases:
(a) Quiz grades: 7, 9, 4, 8 , 7. Midterm grades: 93, 83, 87. Final grade: 89.
(b) Quiz grades: 8, 6, 9, 6 , 9. Midterm grades: 81, 75, 79. Final grade: 72.
34. The handicap differential (HCD) for a round of golf is calculated from the for-
mula:
The course rating and the slope are measures of how difficult a particular
course is. A golfers handicap is calculated from a certain number N of their
best (lowest) handicap scores according to the following table.
# Rounds played N # Rounds played N
5-6 1 15-16 6
7-8 2 17 7
9-10 3 18 8
11-12 4 19 9
13-14 5 20 10
Grade 90 80 Grade 90
70 Grade 80 60 Grade 70
HCD
Score Course Rating–
Course Slope
------------------------------------------------------------------ 113=
229.
218 Chapter 6: Programming in MATLAB
For example, if 13 rounds have been played, only the best five handicaps are
used. A handicap cannot be computed for fewer than five rounds. If more than
20 rounds have been played, only the 20 most recent results are used.
Once the lowest N handicap differentials have been identified, they are
averaged and then rounded down to the nearest tenth. The result is the
player's handicap. Write a program in a script file that calculates a persons
handicap. The program asks the user to enter the golfers record in a three col-
umns matrix where the first column is the course rating, the second is the
course slope, and the third is the players score. Each row corresponds to one
round. The program displays the person's handicap. Execute the program for
players with the following records.
(a)
(b)
Rating Slope Score
71.6 122 85
72.8 118 87
69.7 103 83
70.3 115 81
70.9 116 79
72.3 117 91
71.6 122 89
70.3 115 83
72.8 118 92
70.9 109 80
73.1 132 94
68.2 115 78
74.2 135 103
71.9 121 84
Rating Slope Score
72.2 119 71
71.6 122 73
74.0 139 78
68.2 125 69
70.2 130 74
69.6 109 69
66.6 111 74
230.
219
Chapter 7
User-Defined Functions
and Function Files
A simple function in mathematics, , associates a unique number to each
value of x. The function can be expressed in the form , where is usu-
ally a mathematical expression in terms of x. A value of y (output) is obtained
when a value of x (input) is substituted in the expression. Many functions are pro-
grammed inside MATLAB as built-in functions, and can be used in mathematical
expressions simply by typing their name with an argument (see Section 1.5);
examples are sin(x), cos(x), sqrt(x), and exp(x). Frequently, in computer
programs, there is a need to calculate the value of functions that are not built-in.
When a function expression is simple and needs to be calculated only once, it can
be typed as part of the program. However, when a function needs to be evaluated
many times for different values of arguments, it is convenient to create a "user-
defined" function. Once a user-defined function is created (saved) it can be used
just like the built-in functions.
A user-defined function is a MATLAB program that is created by the user,
saved as a function file, and then can be used like a built-in function. The function
can be a simple, single mathematical expression or a complicated and involved
series of calculations. In many cases it is actually a subprogram within a computer
program. The main feature of a function file is that it has an input and an output.
This means that the calculations in the function file are carried out using the input
data, and the results of the calculations are transferred out of the function file by
the output. The input and the output can be one or several variables, and each can
be a scalar, vector, or an array of any size. Schematically, a function file can be
illustrated by:
f x
y f x= f x
Function
File
Input data Output data
231.
220 Chapter 7: User-Defined Functions and Function Files
A very simple example of a user-defined function is a function that calcu-
lates the maximum height that a ball reaches when thrown upward with a certain
velocity. For a velocity , the maximum height is given by ,
where g is the gravitational acceleration. In function form this can be written as
. In this case the input to the function is the velocity (a number),
and the output is the maximum height (a number). For example, in SI units (g =
9.81 m/s2) if the input is 15 m/s, the output is 11.47 m.
In addition to being used as math functions, user-defined functions can be
used as subprograms in large programs. In this way large computer programs can
be made up of smaller "building blocks" that can be tested independently. Func-
tion files are similar to subroutines in Basic and Fortran, procedures in Pascal, and
functions in C.
The fundamentals of user-defined functions are explained in Sections 7.1
through 7.7. In addition to user-defined functions that are saved in separate func-
tion files and called for use in a computer program, MATLAB provides an option
to define and use a user-defined math function within a computer program (not in
a separate file). This can be done by using anonymous and/or inline functions,
which are presented in Section 7.8. There are built-in and user-defined functions
that have to be supplied with other functions when they are called. These func-
tions, which in MATLAB are called function functions, are introduced in Section
7.9. The last two sections cover subfunctions and nested functions. Both are meth-
ods for incorporating two or more user-defined functions in a single function file.
7.1 CREATING A FUNCTION FILE
Function files are created and edited, like script files, in the Editor/Debugger Win-
dow. This window is opened from the Command Window. In the File menu, select
New, and then select Function. Once the Editor/Debugger Window opens, it
looks like that shown in Figure 7-1. The editor contains several pre-typed lines
that outline the structure of a function file. The first line is the function definition
line, which is followed by comments the describe the function. Next comes the
program (the empty lines 4 and 5 in Figure 7-1), and the last line is an end state-
ment, which is optional. The structure of a function file is described in detail in the
next section.
Note: The Editor/Debugger Window can also be opened (as was described
in Chapter 1) by selecting Script after New. The window that opens is empty,
without any pre-typed lines. The window can be used for writing a script file or a
v0 hmax hmax
v0
2
2g
------=
hmax v0
v0
2
2g
------=
Function File
15 m/s 11.47 m
232.
7.2 Structure of a Function File 221
function file. If the Editor/Debugger Window is opened by selecting Function
after New, it can also be used for writing a script file or a function file.
7.2 STRUCTURE OF A FUNCTION FILE
The structure of a typical complete function file is shown in Figure 7-2. This par-
ticular function calculates the monthly payment and the total payment of a loan.
The inputs to the function are the amount of the loan, the annual interest rate, and
the duration of the loan (number of years). The output from the function is the
monthly payment and the total payment.
Figure 7-1: The Editor/Debugger Window.
Figure 7-2: Structure of a typical function file.
The first line in a function file must
be the function definition line.
Function definition line.
The H1 line.
Help text.
Assignment of values to output arguments.
Function body
(computer program).
233.
222 Chapter 7: User-Defined Functions and Function Files
The various parts of the function file are described in detail in the following sec-
tions.
7.2.1 Function Definition Line
The first executable line in a function file must be the function definition line.
Otherwise the file is considered a script file. The function definition line:
• Defines the file as a function file.
• Defines the name of the function.
• Defines the number and order of the input and output arguments.
The form of the function definition line is:
The word "function," typed in lowercase letters, must be the first word in
the function definition line. On the screen the word function appears in blue. The
function name is typed following the equal sign. The name can be made up of let-
ters, digits, and the underscore character (the name cannot include a space). The
rules for the name are the same as the rules for naming variables described in Sec-
tion 1.6.2. It is good practice to avoid names of built-in functions and names of
variables already defined by the user or predefined by MATLAB.
7.2.2 Input and Output Arguments
The input and output arguments are used to transfer data into and out of the func-
tion. The input arguments are listed inside parentheses following the function
name. Usually, there is at least one input argument, although it is possible to have
a function that has no input arguments. If there are more than one, the input argu-
ments are separated with commas. The computer code that performs the calcula-
tions within the function file is written in terms of the input arguments and
assumes that the arguments have assigned numerical values. This means that the
mathematical expressions in the function file must be written according to the
dimensions of the arguments, since the arguments can be scalars, vectors, or
arrays. In the example shown in Figure 7-2 there are three input arguments
(amount,rate,years), and in the mathematical expressions they are
assumed to be scalars. The actual values of the input arguments are assigned when
the function is used (called). Similarly, if the input arguments are vectors or
function [output arguments]=function_name(input arguments)
The word "function"
must be the first word,
and must be typed in
lowercase letters.
The name of
the function.
A list of output
arguments typed
inside brackets.
A list of input
arguments typed
inside parentheses.
234.
7.2 Structure of a Function File 223
arrays, the mathematical expressions in the function body must be written to fol-
low linear algebra or element-by-element calculations.
The output arguments, which are listed inside brackets on the left side of the
assignment operator in the function definition line, transfer the output from the
function file. Function files can have zero, one, or several output arguments. If
there are more than one, the output arguments are separated with commas. If there
is only one output argument, it can be typed without brackets. In order for the
function file to work, the output arguments must be assigned values in the
computer program that is in the function body. In the example in Figure 7-2
there are two output arguments, mpay and tpay. When a function does not have
an output argument, the assignment operator in the function definition line can be
omitted. A function without an output argument can, for example, generate a plot
or write data to a file.
It is also possible to transfer strings into a function file. This is done by typ-
ing the string as part of the input variables (text enclosed in single quotes). Strings
can be used to transfer names of other functions into the function file.
Usually, all the input to, and the output from, a function file transferred
through the input and output arguments. In addition, however, all the input and
output features of script files are valid and can be used in function files. This
means that any variable that is assigned a value in the code of the function file will
be displayed on the screen unless a semicolon is typed at the end of the command.
In addition, the input command can be used to input data interactively, and the
disp, fprintf, and plot commands can be used to display information on the
screen, save to a file, or plot figures just as in a script file. The following are
examples of function definition lines with different combinations of input and out-
put arguments.
Function definition line Comments
function [mpay,tpay] = loan(amount,rate,years) Three input arguments, two
output arguments.
function [A] = RectArea(a,b) Two input arguments, one out-
put argument.
function A = RectArea(a,b) Same as above; one output
argument can be typed without
the brackets.
function [V, S] = SphereVolArea(r) One input variable, two output
variables.
function trajectory(v,h,g) Three input arguments, no out-
put arguments.
235.
224 Chapter 7: User-Defined Functions and Function Files
7.2.3 The H1 Line and Help Text Lines
The H1 line and help text lines are comment lines (lines that begin with the per-
cent, %, sign) following the function definition line. They are optional but are fre-
quently used to provide information about the function. The H1 line is the first
comment line and usually contains the name and a short definition of the function.
When a user types (in the Command Window) lookfor a_word, MATLAB
searches for a_word in the H1 lines of all the functions, and if a match is found,
the H1 line that contains the match is displayed.
The help text lines are comment lines that follow the H1 line. These lines
contain an explanation of the function and any instructions related to the input and
output arguments. The comment lines that are typed between the function defini-
tion line and the first non-comment line (the H1 line and the help text) are
displayed when the user types help function_name in the Command Win-
dow. This is true for MATLAB built-in functions as well as the user-defined func-
tions. For example, for the function loan in Figure 7-2, if help loan is typed
in the Command Window (make sure the current directory or the search path
includes the directory where the file is saved), the display on the screen is:
A function file can include additional comment lines in the function body. These
lines are ignored by the help command.
7.2.4 Function Body
The function body contains the computer program (code) that actually performs
the computations. The code can use all MATLAB programming features. This
includes calculations, assignments, any built-in or user-defined functions, flow
control (conditional statements and loops) as explained in Chapter 6, comments,
blank lines, and interactive input and output.
7.3 LOCAL AND GLOBAL VARIABLES
All the variables in a function file are local (the input and output arguments and
any variables that are assigned values within the function file). This means that
the variables are defined and recognized only inside the function file. When a
>> help loan
loan calculates monthly and total payment of loan.
Input arguments:
amount=loan amount in $.
rate=annual interest rate in percent.
years=number of years.
Output arguments:
mpay=monthly payment, tpay=total payment.
236.
7.4 Saving a Function File 225
function file is executed, MATLAB uses an area of memory that is separate from
the workspace (the memory space of the Command Window and the script files).
In a function file the input variables are assigned values each time the function is
called. These variables are then used in the calculations within the function file.
When the function file finishes its execution the values of the output arguments
are transferred to the variables that were used when the function was called. All of
this means that a function file can have variables with the same names as variables
in the Command Window or in script files. The function file does not recognize
variables with the same names as have been assigned values outside the function.
The assignment of values to these variables in the function file will not change
their assignment elsewhere.
Each function file has its own local variables, which are not shared with
other functions or with the workspace of the Command Window and the script
files. It is possible, however, to make a variable common (recognized) in several
different function files, and perhaps in the workspace too. This is done by declar-
ing the variable global with the global command, which has the form:
Several variables can be declared global by listing them, separated with spaces, in
the global command. For example:
global GRAVITY_CONST FrictionCoefficient
• The variable has to be declared global in every function file that the user wants
it to be recognized in. The variable is then common only to these files.
• The global command must appear before the variable is used. It is recom-
mended to enter the global command at the top of the file.
• The global command has to be entered in the Command Window, or in a
script file, for the variable to be recognized in the workspace.
• The variable can be assigned, or reassigned, a value in any of the locations in
which it is declared common.
• The use of long descriptive names (or all capital letters) is recommended for
global variables in order to distinguish them from regular variables.
7.4 SAVING A FUNCTION FILE
A function file must be saved before it can be used. This is done, as with a script
file, by choosing Save as . . . from the File menu, selecting a location (many stu-
dents save to a flash drive), and entering the file name. It is highly recommended
that the file be saved with a name that is identical to the function name in the func-
tion definition line. In this way the function is called (used) by using the function
name. (If a function file is saved with a different name, the name it is saved under
must be used when the function is called.) Function files are saved with the exten-
global variable_name
237.
226 Chapter 7: User-Defined Functions and Function Files
sion .m. Examples:
7.5 USING A USER-DEFINED FUNCTION
A user-defined function is used in the same way as a built-in function. The func-
tion can be called from the Command Window, from a script file, or from another
function. To use the function file, the folder where it is saved must either be in the
current folder or be in the search path (see Sections 1.8.3 and 1.8.4).
A function can be used by assigning its output to a variable (or variables), as
a part of a mathematical expression, as an argument in another function, or just by
typing its name in the Command Window or in a script file. In all cases the user
must know exactly what the input and output arguments are. An input argument
can be a number, a computable expression, or a variable that has an assigned
value. The arguments are assigned according to their position in the input and out-
put argument lists in the function definition line.
Two of the ways that a function can be used are illustrated below with the
user-defined loan function in Figure 7-2, which calculates the monthly and total
payments (two output arguments) of a loan. The input arguments are the loan
amount, annual interest rate, and the length (number of years) of the loan. In the
first illustration the loan function is used with numbers as input arguments:
In the second illustration the loan function is used with two pre-assigned
variables and a number as the input arguments:
Function definition line File name
function [mpay,tpay] = loan(amount,rate,years) loan.m
function [A] = RectArea(a,b) RectArea.m
function [V, S] = SphereVolArea(r) SphereVolArea.m
function trajectory(v,h,g) trajectory.m
>> [month total]=loan(25000,7.5,4)
month =
600.72
total =
28834.47
>> a=70000; b=6.5;
>> [x y]=loan(a,b,30)
First argument is loan amount, second is
interest rate, and third is number of years.
Define variables a and b.
Use a, b, and the number 30 for input
arguments and x (monthly pay) and y
(total pay) for output arguments.
238.
7.6 Examples of Simple User-Defined Functions 227
7.6 EXAMPLES OF SIMPLE USER-DEFINED FUNCTIONS
Sample Problem 7-1: User-defined function for a math function
Write a function file (name it chp7one) for the function . The
input to the function is x and the output is . Write the function such that x can
be a vector. Use the function to calculate:
(a) for x = 6.
(b) for x = 1, 3, 5, 7, 9, and 11.
Solution
The function file for the function is:
Note that the mathematical expression in the function file is written for element-
by-element calculations. In this way if x is a vector, y will also be a vector. The
function is saved and then the search path is modified to include the directory
where the file was saved. As shown below, the function is used in the Command
Window.
(a) Calculating the function for can be done by typing chp7one(6) in
the Command Window, or by assigning the value of the function to a new vari-
able:
(b) To calculate the function for several values of x, a vector with the values of x
is created and then used for the argument of the function.
x =
440.06
y =
158423.02
function y=chp7one(x)
y=(x.^4.*sqrt(3*x+5))./(x.^2+1).^2;
>> chp7one(6)
ans =
4.5401
>> F=chp7one(6)
F =
4.5401
>> x=1:2:11
x =
1 3 5 7 9 11
f x
x4 3x 5+
x2 1+ 2
-------------------------=
f x
f x
f x
f x
Function definition line.
Assignment to output argument.
x 6=
239.
228 Chapter 7: User-Defined Functions and Function Files
Another way is to type the vector x directly in the argument of the function.
Sample Problem 7-2: Converting temperature units
Write a user-defined function (name it FtoC) that converts temperature in degrees
F to temperature in degrees C. Use the function to solve the following problem.
The change in the length of an object, , due to a change in the temperature, ,
is given by: , where is the coefficient of thermal expansion. Deter-
mine the change in the area of a rectangular (4.5 m by 2.25 m) aluminum
( 1/ C) plate if the temperature changes from 40 F to 92 F.
Solution
A user-defined function that converts degrees F to degrees C is:
A script file (named Chapter7Example2) that calculates the change of the area of
the plate due to the temperature is:
Executing the script file in the Command Window gives the solution:
>> chp7one(x)
ans =
0.7071 3.0307 4.1347 4.8971 5.5197 6.0638
>> H=chp7one([1:2:11])
H =
0.7071 3.0307 4.1347 4.8971 5.5197 6.0638
function C=FtoC(F)
%FtoC converts degrees F to degrees C
C=5*(F-32)./9;
a1=4.5; b1=2.25; T1=40; T2=92; alpha=23e-6;
deltaT=FtoC(T2)-FtoC(T1);
a2=a1+alpha*a1*deltaT;
b2=b1+alpha*b1*deltaT;
AreaChange=a2*b2-a1*b1;
fprintf('The change in the area is %6.5f meters
square.',AreaChange)
>> Chapter7Example2
The change in the area is 0.01346 meters square.
L T
L L T=
23 10 6–=
Function definition line.
Assignment to output argument.
Using the FtoC function to calculate the
temperature difference in degrees C.
Calculating the new length.
Calculating the new width.
Calculating the change in the area.
240.
7.7 Comparison between Script Files and Function Files 229
7.7 COMPARISON BETWEEN SCRIPT FILES AND FUNCTION FILES
Students who are studying MATLAB for the first time sometimes have difficulty
understanding exactly the differences between script and function files since, for
many of the problems that they are asked to solve using MATLAB, either type of
file can be used. The similarities and differences between script and function files
are summarized below.
• Both script and function files are saved with the extension .m (that is why they
are sometimes called M-files).
• The first executable line in a function file is (must be) the function definition
line.
• The variables in a function file are local. The variables in a script file are rec-
ognized in the Command Window.
• Script files can use variables that have been defined in the workspace.
• Script files contain a sequence of MATLAB commands (statements).
• Function files can accept data through input arguments and can return data
through output arguments.
• When a function file is saved, the name of the file should be the same as the
name of the function.
7.8 ANONYMOUS AND INLINE FUNCTIONS
User-defined functions written in function files can be used for simple mathemati-
cal functions, for large and complicated math functions that require extensive pro-
gramming, and as subprograms in large computer programs. In cases when the
value of a relatively simple mathematical expression has to be determined many
times within a program, MATLAB provides the option of using anonymous func-
tions. An anonymous function is a user-defined function that is defined and writ-
ten within the computer code (not in a separate function file) and is then used in
the code. Anonymous functions can be defined in any part of MATLAB (in the
Command Window, in script files, and inside regular user-defined functions).
Anonymous functions were introduced in MATLAB 7. They replace inline
functions that were used for the same purpose in previous versions of MATLAB.
Both anonymous and inline functions can be used in MATLAB R2010b). Anony-
mous functions, however, have several advantages over inline functions, and it is
expected that inline functions will gradually be phased out. Anonymous functions
are covered in detail in Section 7.8.1, and inline functions are described in the sec-
tion that follows.
241.
230 Chapter 7: User-Defined Functions and Function Files
7.8.1 Anonymous Functions
An anonymous function is a simple (one-line) user-defined function that is
defined without creating a separate function file (M-file). Anonymous functions
can be constructed in the Command Window, within a script file, or inside a regu-
lar user-defined function.
An anonymous function is created by typing the following command:
A simple example is: cube = @ (x) x^3, which calculates the cube of the input
argument.
• The command creates the anonymous function and assigns a handle for the
function to the variable name on the left-hand side of the = sign. (Function
handles provide means for using the function and passing it to other functions;
see Section 7.9.1.)
• The expr consists of a single valid mathematical MATLAB expression.
• The mathematical expression can have one or several independent variables.
The independent variable(s) is (are) entered in the (arglist). Multiple
independent variables are separated with commas. An example of an anony-
mous function that has two independent variables is: circle = @ (x,y)
16*x^2+9*y^2
• The mathematical expression can include any built-in or user-defined func-
tions.
• The expression must be written according to the dimensions of the arguments
(element-by-element or linear algebra calculations).
• The expression can include variables that are already defined when the anony-
mous function is defined. For example, if three variables a, b, and c are
defined (have assigned numerical values), then they can be used in the expres-
sion of the anonymous function parabola = @ (x) a*x^2+b*x+c.
Important note: MATLAB captures the values of the predefined variables
when the anonymous function is defined. This means that if new values are subse-
quently assigned to the predefined variables, the anonymous function is not
changed. The anonymous function has to be redefined in order for the new values
of the predefined variables to be used in the expression.
name = @ (arglist) expr
The name of the anony-
mous function.
The @
symbol.
A list of input argu-
ments (independent
variables).
Mathematical
expression.
242.
7.8 Anonymous and Inline Functions 231
Using an anonymous function:
• Once an anonymous function is defined, it can be used by typing its name and
a value for the argument (or arguments) in parentheses (see examples that fol-
low).
• Anonymous functions can also be used as arguments in other functions (see
Section 7.9.1).
Example of an anonymous function with one independent variable:
The function can be defined (in the Command Window) as an
anonymous function for x as a scalar by:
If a semicolon is not typed at the end, MATLAB responds by displaying the func-
tion. The function can then be used for different values of x, as shown below.
If x is expected to be an array, with the function calculated for each element, then
the function must be modified for element-by-element calculations.
Example of an anonymous function with several independent variables:
The function can be defined as an anonymous function
by:
>> FA = @ (x) exp(x^2)/sqrt(x^2+5)
FA =
@(x)exp(x^2)/sqrt(x^2+5)
>> FA(2)
ans =
18.1994
>> z = FA(3)
z =
2.1656e+003
>> FA = @ (x) exp(x.^2)./sqrt(x.^2+5)
FA =
@(x)exp(x.^2)./sqrt(x.^2+5)
>> FA([1 0.5 2])
ans =
1.1097 0.5604 18.1994
>> HA = @ (x,y) 2*x^2 - 4*x*y + y^2
HA =
@(x,y)2*x^2-4*x*y+y^2
f x
ex2
x2 5+
------------------=
Using a vector as input argument.
f x y 2x2 4xy– y2+=
243.
232 Chapter 7: User-Defined Functions and Function Files
Then the anonymous function can be used for different values of x and y. For
example, typing HA(2,3) gives:
Another example of using an anonymous function with several arguments is
shown in Sample Problem 6-3.
Sample Problem 7-3: Distance between points in polar coordinates
Write an anonymous function that calculates the
distance between two points in a plane when the
position of the points is given in polar coordinates.
Use the anonymous function to calculate the dis-
tance between point A (2, /6) and point B (5, 3 /4).
Solution
The distance between two points in polar coordi-
nates can be calculated by using the Law of
Cosines:
The formula for the distance is entered as an anonymous function with four input
arguments . Then the function is used for calculating the distance
between points A and B.
>> HA(2,3)
ans =
-7
>> d= @ (rA,thetA,rB,thetB) sqrt(rA^2+rB^2-2*rA*rB*cos(thetB-thetA))
d =
@(rA,thetA,rB,thetB)sqrt(rA^2+rB^2-2*rA*rB*cos(thetB-
thetA))
>> DistAtoB = d(2,pi/6,5,3*pi/4)
DistAtoB =
5.8461
A(rA ,θA)
θA
θB
d
rA
rB
B(rB ,θB)
d rA
2 rB
2 2rArB A B–cos–+=
rA A rB B
List of input arguments.
The arguments are typed in the order defined in the function.
244.
7.8 Anonymous and Inline Functions 233
7.8.2 Inline Functions
Similar to an anonymous function, an inline function is a simple user-defined
function that is defined without creating a separate function file (M-file). As
already mentioned, anonymous functions replace the inline functions used in ear-
lier versions of MATLAB. Inline functions are created with the inline com-
mand according to the following format:
A simple example is cube = inline('x^3'), which calculates the cube of
the input argument.
• The mathematical expression can have one or several independent variables.
• Any letter except i and j can be used for the independent variables in the
expression.
• The mathematical expression can include any built-in or user-defined func-
tions.
• The expression must be written according to the dimension of the argument
(element-by-element or linear algebra calculations).
• The expression cannot include pre assigned variables.
• Once the function is defined it can be used by typing its name and a value for
the argument (or arguments) in parentheses (see example below).
• The inline function can be used as an argument in other functions.
For example, the function: can be defined as an inline function for
x by:
>> FA=inline('exp(x.^2)./sqrt(x.^2+5)')
FA =
Inline function:
FA(x) = exp(x.^2)./sqrt(x.^2+5)
>> FA(2)
ans =
18.1994
>> FA([1 0.5 2])
ans =
1.1097 0.5604 18.1994
name = inline('math expression typed as a string')
f x
ex2
x2 5+
------------------=
Expression written
with element-by-
element operations.
Using a scalar as the argument.
Using a vector as the argument.
245.
234 Chapter 7: User-Defined Functions and Function Files
An inline function that has two or more independent variables can be writ-
ten by using the following format:
In the format shown here the order of the arguments to be used when calling the
function is defined. If the independent variables are not listed in the command,
MATLAB arranges the arguments in alphabetical order. For example, the function
can be defined as an inline function by:
Once defined, the function can be used with any values of x and y. For example,
HA(2,3) gives:
7.9 FUNCTION FUNCTIONS
There are many situations where a function (Function A) works on (uses) another
function (Function B). This means that when Function A is executed it has to be
provided with Function B. A function that accepts another function is called in
MATLAB a function function. For example, MATLAB has a built-in function
called fzero (Function A) that finds the zero of a math function (Function
B), i.e., the value of x where . The program in the function fzero is
written such that it can find the zero of any . When fzero is called, the spe-
cific function to be solved is passed into fzero, which finds the zero of the .
(The function fzero is described in detail in Chapter 9.)
A function function, which accepts another function (imported function),
includes in its input arguments a name that represents the imported function. The
imported function name is used for the operations in the program (code) of the
function function. When the function function is used (called), the specific func-
tion that is imported is listed in its input argument. In this way different functions
can be imported (passed) into the function function. There are two methods for
listing the name of an imported function in the argument list of a function func-
tion. One is by using a function handle (Section 7.9.1), and the other is by typing
the name of the function that is being passed in as a string expression (Section
7.9.2). The method that is used affects the way that the operations in the function
>> HA=inline('2*x^2-4*x*y+y^2')
HA =
Inline function:
HA(x,y) = 2*x^2-4*x*y+y^2
>> HA(2,3)
ans =
-7
name = inline('mathematical expression','arg1',
'arg2','arg3')
f x y 2x2 4xy– y2+=
f x
f x 0=
f x
f x
246.
7.9 Function Functions 235
function are written (this is explained in more detail in the next two sections).
Using function handles is easier and more efficient, and should be the preferred
method.
7.9.1 Using Function Handles for Passing a Function into a Function
Function
Function handles are used for passing (importing) user-defined functions, built-in
functions, and anonymous functions into function functions that can accept them.
This section first explains what a function handle is, then shows how to write a
user-defined function function that accepts function handles, and finally shows
how to use function handles for passing functions into function functions.
Function handle:
A function handle is a MATLAB value that is associated with a function. It is a
MATLAB data type and can be passed as an argument into another function. Once
passed, the function handle provides means for calling (using) the function it is
associated with. Function handles can be used with any kind of MATLAB func-
tion. This includes built-in functions, user-defined functions (written in function
files), and anonymous functions.
• For built-in and user-defined functions, a function handle is created by typing
the symbol @ in front of the function name. For example, @cos is the function
handle of the built-in function cos, and @FtoC is the function handle of the
user-defined function FtoC that was created in Sample Problem 7-2.
• The function handle can also be assigned to a variable name. For example,
cosHandle=@cos assigns the handle @cos to cosHandle. Then the name
cosHandle can be used for passing the handle.
• As anonymous functions (see Section 7.8.1), their name is already a function
handle.
Writing a function function that accepts a function handle as an input argument:
As already mentioned, the input arguments of a function function (which accepts
another function) includes a name (dummy function name) that represents the
imported function. This dummy function (including a list of input arguments
enclosed in parentheses) is used for the operations of the program inside the func-
tion function.
• The function that is actually being imported must be in a form consistent with
the way that the dummy function is being used in the program. This means that
both must have the same number and type of input and output arguments.
The following is an example of a user-defined function function, named
funplot, that makes a plot of a function (any function that is imported into
it) between the points and . The input arguments are (Fun,a,b),
f x
x a= x b=
247.
236 Chapter 7: User-Defined Functions and Function Files
where Fun is a dummy name that represents the imported function, and a and b
are the end points of the domain. The function funplot also has a numerical
output xyout, which is a matrix with the values of x and at the three
points , , and . Note that in the program, the dummy
function Fun has one input argument (x) and one output argument y, which are
both vectors.
As an example, the function over the
domain is passed into the user-defined function funplot. This is done in
two ways: first, by writing a user-defined function for , and then by writing
as an anonymous function.
Passing a user-defined function into a function function:
First, a user-defined function is written for . The function, named Fdemo,
calculates for a given value of x and is written using element-by-element
operations.
Next, the function Fdemo is passed into the user-defined function function
function xyout=funplot(Fun,a,b)
% funplot makes a plot of the function Fun which is passed in
% when funplot is called in the domain [a, b].
% Input arguments are:
% Fun: Function handle of the function to be plottedFun(Fun((a+b)/2);
xyout(3,2)=y(100);
plot(x,y)
xlabel('x'), ylabel('y')
function y=Fdemo(x)
y=exp(-0.17*x).*x.^3-2*x.^2+0.8*x-3;
3 2 f x
x a= x a b+ 2= x b=
A name for the function that is passed in.
Using the imported function to calculate f(x) at 100 points.
Using the imported function to
calculate f(x) at the midpoint.
f x e 0.17x– x3 2x2– 0.8x 3–+=
0.5 4
f x
f x
f x
f x
248.
7.9 Function Functions 237
funplot, which is called in the Command Window. Note that a handle of the
user-defined function Fdemo is entered (the handle is @Fdemo) for the input
argument Fun in the user-defined function funplot.
In addition to the display of the numerical output, when the command is
executed, the plot shown in Figure 7-3 is displayed in the Figure Window.
Passing an anonymous function into a function function:
To use an anonymous function, the function first
has to be written as an anonymous function, and then passed into the user-defined
function funplot. The following shows how both of these steps are done in the
Command Window. Note that the name of the anonymous function
FdemoAnony is entered without the @ sign for the input argument Fun in the
user-defined function funplot (since the name is already the handle of the
anonymous function).
>> ydemo=funplot(@Fdemo,0.5,4)
ydemo =
0.5000 -2.9852
2.2500 -3.5548
4.0000 0.6235
Figure 7-3: A plot of the function .
>> FdemoAnony=@(x) exp(-0.17*x).*x.^3-2*x.^2+0.8*x-3
FdemoAnony =
@(x) exp(-0.17*x).*x.^3-2*x.^2+0.8*x-3
>> ydemo=funplot(FdemoAnony,0.5,4)
ydemo =
0.5000 -2.9852
2.2500 -3.5548
4.0000 0.6235
Enter a handle of the user-defined
function Fdemo.
0.5 1 1.5 2 2.5 3 3.5 4
-4
-3
-2
-1
0
1
x
f(x)
f x e 0.17x– x3 2x2– 0.8x 3–+=
f x e 0.17x– x3 2x2– 0.8x 3–+=
Create an anonymous
function for .f x
Enter the name of the anonymous
function (FdemoAnony).
249.
238 Chapter 7: User-Defined Functions and Function Files
In addition to the display of the numerical output in the Command Window, the
plot shown in Figure 7-3 is displayed in the Figure Window.
7.9.2 Using a Function Name for Passing a Function into a Function
Function
A second method for passing a function into a function function is by typing the
name of the function that is being imported as a string in the input argument of the
function function. The method which was used before the introduction of function
handles, can be used for importing user-defined functions. As mentioned, function
handles are easier to use and more efficient and should be the preferred method.
Importing user-defined functions by using their name is covered in the present
edition of the book for the benefit of readers who need to understand programs
written before MATLAB 7. New programs should use function handles.
When a user-defined function is imported by using its name, the value of
the imported function inside the function function has to be calculated with the
feval command. This is different from the case where a function handle is used,
which means that there is a difference in the way that the code in the function
function is written that depends on how the imported function is passed in.
The feval command:
The feval (short for "function evaluate") command evaluates the value of a
function for a given value (or values) of the function's argument (or arguments).
The format of the command is:
The value that is determined by feval can be assigned to a variable, or if the
command is typed without an assignment, MATLAB displays ans = and the
value of the function.
• The function name is typed as string.
• The function can be a built-in or a user-defined function.
• If there is more than one input argument, the arguments are separated with
commas.
• If there is more than one output argument, the variables on the left-hand side of
the assignment operator are typed inside brackets and separated with commas.
Two examples using the feval command with built-in functions follow.
>> feval('sqrt',64)
ans =
8
>> x=feval('sin',pi/6)
variable = feval('function name', argument value)
250.
7.9 Function Functions 239
The following shows the use of the feval command with the user-defined
function loan which was created earlier in the chapter (Figure 7-2). This func-
tion has three input arguments and two output arguments.
Writing a function function that accepts a function by typing its name as an
input argument:
As already mentioned, when a user-defined function is imported by using its
name, the value of the function inside the function function has to be calculated
with the feval command. This is demonstrated in the following user-defined
function function that is called funplotS. The function is the same as the func-
tion funplot from Section 7.9.1, except that the command feval is used for
the calculations with the imported function.
x =
0.5000
>> [M,T]=feval('loan',50000,3.9,10)
M =
502.22
T =
60266.47
function xyout=funplotS(Fun,a,b)
% funplotS makes a plot of the function Fun which is passed in
% when funplotS is called in the domain [a, b].
% Input arguments are:
% Fun: The function to be plotted. Its name is entered as
string expressionfeval(Fun,feval(Fun,(a+b)/2);
xyout(3,2)=y(100);
A $50,000 loan, 3.9% interest, 10 years.
Monthly payment.
Total payment.
A name for the function that is passed in.
Using the imported function to calculate f(x) at 100 points.
Using the imported function to
calculate f(x) at the midpoint.
251.
240 Chapter 7: User-Defined Functions and Function Files
Passing a user-defined function into another function by using a string expression:
The following demonstrates how to pass a user-defined function into a function
function by typing the name of the imported function as a string in the input argu-
ment. The function from Section 7.9.1, created as
a user-defined function named Fdemo, is passed into the user-defined function
funplotS. Note that the name Fdemo is typed in a string for the input argument
Fun in the user-defined function funplotS.
In addition to the display of the numerical output in the Command Window, the
plot shown in Figure 7-3 is displayed in the Figure Window.
7.10 SUBFUNCTIONS
A function file can contain more than one user-defined function. The functions are
typed one after the other. Each function begins with a function definition line. The
first function is called the primary function and the rest of the functions are called
subfunctions. The subfunctions can be typed in any order. The name of the func-
tion file that is saved should correspond to the name of the primary function. Each
of the functions in the file can call any of the other functions in the file. Outside
functions, or programs (script files), can call only the primary function. Each of
the functions in the file has its own workspace, which means that in each the vari-
ables are local. In other words, the primary function and the subfunctions cannot
access each other's variables (unless variables are declared to be global).
Subfunctions can help in writing user-defined functions in an organized
manner. The program in the primary function can be divided into smaller tasks,
each of which is carried out in a subfunction. This is demonstrated in Sample
Problem 7-4.
Sample Problem 7-4: Average and standard deviation
Write a user-defined function that calculates the average and the standard devia-
tion of a list of numbers. Use the function to calculate the average and the stan-
dard deviation of the following list of grades:
80 75 91 60 79 89 65 80 95 50 81
plot(x,y)
xlabel('x'), ylabel('y')
>> ydemoS=funplotS('Fdemo',0.5,4)
ydemoS =
0.5000 -2.9852
2.2500 -3.5548
4.0000 0.6235
f x e 0.17x– x3 2x2– 0.8x 3–+=
The name of the imported
function is typed as a string.
252.
7.10 Subfunctions 241
Solution
The average (mean) of a given set of n numbers is given by:
The standard deviation is given by:
A user-defined function, named stat, is written for solving the problem. To
demonstrate the use of subfunctions, the function file includes stat as a primary
function, and two subfunctions called AVG and StandDiv. The function AVG
calculates , and the function StandDiv calculates . The subfunctions are
called by the primary function.The following listing is saved as one function file
called stat.
The user-defined function stat is then used in the Command Window for calcu-
lating the average and the standard deviation of the grades:
function [me SD] = stat(v)
n=length(v);
me=AVG(v,n);
SD=StandDiv(v,me,n);
function av=AVG(x,num)
av=sum(x)/num;
function Sdiv=StandDiv(x,xAve,num)
xdif=x-xAve;
xdif2=xdif.^2;
Sdiv= sqrt(sum(xdif2)/(num-1));
>> Grades=[80 75 91 60 79 89 65 80 95 50 81];
>> [AveGrade StanDeviation] = stat(Grades)
AveGrade =
76.8182
StanDeviation =
13.6661
xave x1 x2 xn
xave x1 x2 xn+ + + n=
xi xave– 2
i 1=
i n=
n 1–
------------------------------------=
xave
The primary function.
Subfunction.
Subfunction.
253.
242 Chapter 7: User-Defined Functions and Function Files
7.11 NESTED FUNCTIONS
A nested function is a user-defined function that is written inside another user-
defined function. The portion of the code that corresponds to the nested function
starts with a function definition line and ends with an end statement. An end
statement must also be entered at the end of the function that contains the nested
function. (Normally, a user-defined function does not require a terminating end
statement. However, an end statement is required if the function contains one or
more nested functions.) Nested functions can also contain nested functions. Obvi-
ously, having many levels of nested functions can be confusing. This section con-
siders only two levels of nested functions.
One nested function:
The format of a user-defined function A (called the primary function) that contains
one nested function B is:
function y=A(a1,a2)
.......
function z=B(b1,b2)
.......
end
.......
end
• Note the end statements at the ends of functions B and A.
• The nested function B can access the workspace of the primary function A, and
the primary function A can access the workspace of the function B. This means
that a variable defined in the primary function A can be read and redefined in
nested function B and vice versa.
• Function A can call function B, and function B can call function A.
Two (or more) nested functions at the same level:
The format of a user-defined function A (called the primary function) that contains
two nested functions B and C at the same level is:
function y=A(a1,a2)
.......
function z=B(b1,b2)
.......
end
.......
function w=C(c1,c2)
.......
end
.......
end
254.
7.11 Nested Functions 243
• The three functions can access the workspace of each other.
• The three functions can call each other.
As an example, the following user-defined function (named statNest),
with two nested functions at the same level, solves Sample Problem 7-4. Note that
the nested functions are using variables (n and me) that are defined in the primary
function.
Using the user-defined function statNest in the Command Window for calcu-
lating the average of the grade data gives:
function [me SD]=statNest(v)
n=length(v);
me=AVG(v);
function av=AVG(x)
av=sum(x)/n;
end
function Sdiv=StandDiv(x)
xdif=x-me;
xdif2=xdif.^2;
Sdiv= sqrt(sum(xdif2)/(n-1));
end
SD=StandDiv(v);
end
>> Grades=[80 75 91 60 79 89 65 80 95 50 81];
>> [AveGrade StanDeviation] = statNest(Grades)
AveGrade =
76.8182
StanDeviation =
13.6661
The primary function.
Nested function.
Nested function.
255.
244 Chapter 7: User-Defined Functions and Function Files
Two levels of nested functions:
Two levels of nested functions are created when nested functions are written
inside nested functions. The following shows an example for the format of a user-
defined function with four nested functions in two levels.
function y=A(a1,a2) (Primary function A.)
.......
function z=B(b1,b2) (B is nested function in A.)
.......
function w=C(c1,c2) (C is nested function in B.)
.......
end
end
function u=D(d1,d2) (D is nested function in A.)
.......
function h=E(e1,e2) (E is nested function in D.)
.......
end
end
.......
end
The following rules apply to nested functions:
• A nested function can be called from a level above it. (In the preceding exam-
ple, function A can call B or D, but not C or E.)
• A nested function can be called from a nested function at the same level within
the primary function. (In the preceding example, function B can call D, and D
can call B.)
• A nested function can be called from a nested function at any lower level.
• A variable defined in the primary function is recognized and can be redefined
by a function that is nested at any level within the primary function.
• A variable defined in a nested function is recognized and can be redefined by
any of the functions that contain the nested function.
256.
7.12 Examples of MATLAB Applications 245
7.12 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 7-5: Exponential growth and decay
A model for exponential growth or decay of a quantity is given by
where and are the quantity at time t and time 0, respectively, and k is a
constant unique to the specific application.
Write a user-defined function that uses this model to predict the quantity
at time t from knowledge of and at some other time . For function
name and arguments use At = expGD(A0,At1,t1,t), where the output argu-
ment At corresponds to , and for input arguments use A0,At1,t1,t, cor-
responding to , , , and t, respectively.
Use the function file in the Command Window for the following two cases:
(a) The population of Mexico was 67 million in the year 1980 and 79 million in
1986. Estimate the population in 2000.
(b) The half-life of a radioactive material is 5.8 years. How much of a 7-gram
sample will be left after 30 years?
Solution
To use the exponential growth model, the value of the constant k has to be deter-
mined first by solving for k in terms of , , and :
Once k is known, the model can be used to estimate the population at any time.
The user-defined function that solves the problem is:
function At=expGD(A0,At1,t1,t)
% expGD calculates exponential growth and decay
% Input arguments are:
% A0: Quantity at time zero.
% At1: Quantity at time t1.
% t1: The time t1.
% t: time t.
% Output argument is:
% At: Quantity at time t.
k=log(At1/A0)/t1;
At=A0*exp(k*t);
A t A0ekt=
A t A0
A t A0 A t1 t1
A t
A0 A t1 t1
A0 A t1 t1
k
1
t1
---
A t1
A0
------------ln=
Function definition line.
Determination of k.
Determination of A(t).
(Assignment of value to output variable.)
257.
246 Chapter 7: User-Defined Functions and Function Files
Once the function is saved, it is used in the Command Window to solve the two
cases. For case a) , , , and :
For case b) , (since corresponds to the half-life, which is
the time required for the material to decay to half of its initial quantity), ,
and .
Sample Problem 7-6: Motion of a projectile
Create a function file that calculates the tra-
jectory of a projectile. The inputs to the
function are the initial velocity and the angle
at which the projectile is fired. The outputs
from the function are the maximum height
and distance. In addition, the function gener-
ates a plot of the trajectory. Use the function
to calculate the trajectory of a projectile that is fired at a velocity of 230 m/s at an
angle of 39 .
Solution
The motion of a projectile can be analyzed by considering the horizontal and ver-
tical components. The initial velocity can be resolved into horizontal and verti-
cal components
and
In the vertical direction the velocity and position of the projectile are given by:
and
The time it takes the projectile to reach the highest point and the corre-
sponding height are given by:
and
The total flying time is twice the time it takes the projectile to reach the highest
point, . In the horizontal direction the velocity is constant, and the
position of the projectile is given by:
>> expGD(67,79,6,20)
ans =
116.03
>> expGD(7,3.5,5.8,30)
ans =
0.19
A0 67= A t1 79= t1 6= t 20=
Estimation of the population in the year 2000.
A0 7= A t1 3.5= t1
t1 5.8=
t 30=
The amount of material after 30 years.
v0
v0x v0 cos= v0y v0 sin=
vy v0y gt–= y v0yt
1
2
---gt2–=
vy 0=
thmax
v0y
g
-------= hmax
v0y
2
2g
-------=
ttot 2thmax=
x v0xt=
258.
7.12 Examples of MATLAB Applications 247
In MATLAB notation the function name and arguments are entered as
[hmax,dmax] = trajectory(v0,theta). The function file is:
After the function is saved, it is used in the Command Window for a projec-
tile that is fired at a velocity of 230 m/s and an angle of 39o.
function [hmax,dmax]=trajectory(v0,theta)
% trajectory calculates the max height and distance of a
projectile, and makes a plot of the trajectory.
% Input arguments are:
% v0: initial velocity in (m/s).
% theta: angle in degrees.
% Output arguments are:
% hmax: maximum height in (m).
% dmax: maximum distance in (m).
% The function creates also a plot of the trajectory.
g=9.81;
v0x=v0*cos(theta*pi/180);
v0y=v0*sin(theta*pi/180);
thmax=v0y/g;
hmax=v0y^2/(2*g);
ttot=2*thmax;
dmax=v0x*ttot;
% Creating a trajectory plot
tplot=linspace(0,ttot,200);
x=v0x*tplot;
y=v0y*tplot-0.5*g*tplot.^2;
plot(x,y)
xlabel('DISTANCE (m)')
ylabel('HEIGHT (m)')
title('PROJECTILE''S TRAJECTORY')
>> [h d]=trajectory(230,39)
h =
1.0678e+003
d =
5.2746e+003
Function definition line.
Creating a time vector with 200 elements.
Calculating the x and y coordi-
nates of the projectile at each time.
Note the element-by-element multiplication.
259.
248 Chapter 7: User-Defined Functions and Function Files
In addition, the following figure is created in the Figure Window:
7.13 PROBLEMS
1. The fuel efficiency of an automobile is measured in mi/gal (miles per U.S.
gallon) or in km/L (kilometers per liter). Write a MATLAB user-defined func-
tion that converts fuel efficiency values from km/L to mi/gal. For the function
name and arguments use mpg=kmlTOmpg(kml). The input argument kml
is the efficiency in km/L, and the output argument mpg is the efficiency in mi/
gal. Use the function in the Command Window to:
(a) Determine the fuel efficiency in mi/gal of a car that consumes 9 km/L.
(b) Determine the fuel efficiency in mi/gal of a car that consumes 14 km/L.
2. Write a user-defined MATLAB function for the following math function:
The input to the function is x and the output is y. Write the function such that x
can be a vector (use element-by-element operations).
(a) Use the function to calculate y(–2.5), and y(3).
(b) Use the function to make a plot of the function for .
3. Write a user-defined MATLAB function, with two input and two output argu-
ments, that determines the height in centimeters and mass in kilograms of a
person from his height in inches and weight in pounds. For the function name
and arguments use [cm,kg] = STtoSI(in,lb). The input arguments are
the height in inches and weight in pounds, and the output arguments are the
height in centimeters and mass in kilograms. Use the function in the Com-
mand Window to:
(a) Determine in SI units the height and mass of a 5 ft 8 in. person who
weighs 175 lb.
(b) Determine your own height and weight in SI units.
0 1000 2000 3000 4000 5000 6000
0
200
400
600
800
1000
1200
DISTANCE (m)
HEIGHT(m)
PROJECTILE'S TRAJECTORY
y x 0.2x4– e 0.5x– x3 7x2+ +=
y x 3– x 4
260.
7.13 Problems 249
4. Write a user-defined MATLAB function that converts speed given in units of
miles per hour to speed in units of meters per second. For the function name
and arguments use mps = mphTOmets(mph). The input argument is the
speed in mi/h, and the output argument is the speed in m/s. Use the function to
convert 55 mi/h to units of m/s.
5. Write a user-defined MATLAB function for the following math function:
The input to the function is (in radians) and the output is r. Write the func-
tion such that can be a vector.
(a) Use the function to calculate r(3 /4) and r(7 /4).
(b) Use the function to plot (polar plot) for .
6. Write a user-defined MATLAB function that determines the area of a triangle
when the lengths of the sides are given. For the function name and arguments
use [Area] = triangle(a,b,c). Use the function to determine the areas
of triangles with the following sides:
(a) a = 3, b = 8, c = 10. (b) a = 7, b = 7, c = 5.
7. A cylindrical vertical fuel tank has hemispheric end caps
as shown. The radius of the cylinder and the caps is
in., and the height of the cylindrical middle sec-
tion is 40 in.
Write a user-defined function (for the function
name and arguments use V = Volfuel(h)) that gives
the volume of fuel in the tank (in gallons) as a function of
the height h (measured from the bottom). Use the func-
tion to make a plot of the volume as a function of h for
in.
8. The surface area S of a ring in shape of a torus with an
inner radius r and a diameter d is given by:
The ring is to be plated with a thin layer of coating. The
weight of the coating W can be calculated approxi-
mately as , where is the specific weight of
the coating material and t is its thickness. Write an
anonymous function that calculates the weight of the coating. The function
should have four input arguments, r, d, t, and . Use the anonymous function
to calculate the weight of a gold coating ( lb/in.3
) of a ring with
in., in., and in.
r 2 4sinsincos=
r 0 2
h r
r 15=
0 h 70
r
d
S 2 2r d+ d=
W S t=
0.696=
r 0.35= d 0.12= t 0.002=
261.
250 Chapter 7: User-Defined Functions and Function Files
9. The monthly deposit into a savings account S needed to reach an investment
goal B can be calculated by the formula
where M is the monthly deposit, S is the saving goal, N is the number of years,
and r is the annual interest rate (%). Write a MATLAB user-defined function
that calculates the monthly deposit into a savings account. For the function
name and arguments use M = invest(S,r,N). The input arguments are S
(the investment goal), r (the annual interest rate, %), and N (duration of the
savings in years). The output M is the amount of the monthly deposit. Use the
function to calculate the monthly deposit for a 10-year investment if the
investment goal is $25,000 and the annual interest rate is 4.25%.
10. The heat index, HI (in degrees F), is an apparent temperature. For tempera-
tures higher than 80 F and humidity higher than 40% it is calculated by:
where T is temperature in degrees F, R is the relative humidity in percent,
, , , ,
, , ,
, and . Write a user-defined function for
calculating HI for given T and R. For the function name and arguments use
HI=HeatIn(T,R). The input arguments are T in F and, R in %, and the
output argument is HI in F (rounded to the nearest integer). Use the function
to determine the heat index for the following conditions:
(a) F, %.
(b) F, % (condition in a sauna).
11. The body fat percentage (BFP) of a person can be estimated by the formula
where BMI is the body mass index, given by , in which W is
the weight in pounds and H is the height in inches, Age is the person's age, and
for a male and for a female.
Write a MATLAB user-defined function that calculates the body fat per-
centage. For the function name and arguments use BFP = Body-
Fat(w,h,age,gen). The input arguments are the weight, height, age, and
gender (1 for male, 0 for female), respectively. The output argument is the
BEF value. Use the function to calculate the body fat percentage of:
a) A 35-years-old, 6 ft 2 in. tall, 220 lb male.
b) A 22-years-old, 5 ft 7 in. tall, 135 lb female.
M S
r
1200
------------
1
r
1200
------------+
12N
1–
--------------------------------------------=
HI C1 C2T C3R C4TR C5T2 C6R2 C7T2R C8TR2 C9R2T2+ + + + + + + +=
C1 42.379–= C2 2.04901523= C3 10.14333127= C4 0.22475541–=
C5 6.83783– 10 3–= C6 5.481717– 10 2–= C7 1.22874 10 3–=
C8 8.5282 10 4–= C9 1.99– 10 6–=
T 95= R 80=
T 100= R 100=
BFP 1.2 BMI 0.23 Age 10.8 Gender 0.54––+=
BMI 703
W
H 2
-------=
Gender 1= Gender 0=
262.
7.13 Problems 251
12. Write a user-defined function that calculates grade point average (GPA) on a
scale of 0 to 4, where , , , , and . For the
function name and arguments use av = GPA(g,h). The input argument g is a
vector whose elements are letter grades A, B, C, D, or E entered as strings. The
input argument h is a vector with the corresponding credit hours. The output
argument av is the calculated GPA. Use the function to calculate the GPA for
a student with the following record:
For this case the input arguments are:
g=['BACEABDB'] and h=[3 4 3 4 3 4 3 2].
13. The factorial n! of a positive number (integer) is defined by
, where . Write a user-defined
function that calculates the factorial n! of a number. For function name and
arguments use y=fact(x), where the input argument x is the number
whose factorial is to be calculated, and the output argument y is the value .
The function displays an error message if a negative or non-integer number is
entered when the function is called. Use fact with the following numbers:
(a) 12! (b) 0! (c) –7! (d) 6.7!
14. Write a user-defined MATLAB function that determines the vector connecting
two points (A and B). For the function name and arguments use V=vec-
tor(A,B). The input arguments to the function are vectors A and B, each
with the Cartesian coordinates of points A and B. The output V is the vector
from point A to point B. If points A and B have two coordinates each (they are
in the x y plane), then V is a two-element vector. If points A and B have three
coordinates each (general points in space), then V is a three-element vector.
Use the function vector for determining the following vectors.
(a) The vector from point (0.5, 1.8) to point (–3, 16).
(b) The vector from point (–8.4, 3.5, –2.2) to point (5, –4.6, 15).
15. Write a user-defined MATLAB function that determines the dot product of
two vectors. For the function name and arguments use D=dotpro(u,v).
The input arguments to the function are two vectors, which can be two- or
three-dimensional. The output D is the result (a scalar). Use the function
dotpro for determining the dot product of:
(a) Vectors and .
(b) Vectors and .
Grade B A C E A B D B
Credit Hours 3 4 3 4 3 4 3 2
A 4= B 3= C 3= D 1= E 0=
n! n n 1– n 2– 3 2 1= 0! 1=
x!
a 3i 11j+= b 14i 7.3j–=
c 6i– 14.2j 3k+ += d 6.3i 8j– 5.6k–=
263.
252 Chapter 7: User-Defined Functions and Function Files
16. Write a user-defined MATLAB function that determines the unit vector in the
direction of the line that connects two points (A and B) in space. For the func-
tion name and arguments use n = unitvec(A,B). The input to the function
are two vectors A and B, each with the Cartesian coordinates of the corre-
sponding point. The output is a vector with the components of the unit vector
in the direction from A to B. If points A and B have two coordinates each (they
are in the x y plane), then n is a two-element vector. If points A and B have
three coordinate each (general points in space), then n is a three-element vec-
tor. Use the function to determine the following unit vectors:
(a) In the direction from point (1.2, 3.5) to point (12, 15).
(b) In the direction from point (–10, –4, 2.5) to point (–13, 6, –5).
17. Write a user-defined MATLAB function that determines the cross product of
two vectors. For the function name and arguments use w=crosspro(u,v).
The input arguments to the function are the two vectors, which can be two- or
three-dimensional. The output w is the result (a vector). Use the function
crisper for determining the cross product of:
(a) Vectors and .
(b) Vectors and .
18. The area of a triangle ABC can be calculated by:
where AB is the vector from point A to point B and AC is the vector from point
A to point C. Write a user-defined MATLAB function that determines the area
of a triangle given its vertices' coordinates. For the function name and argu-
ments use [Area] = TriArea(A,B,C). The input arguments A, B, and C,
are vectors, each with the coordinates of the corresponding vertex. Write the code
of TriArea such that it has two subfunctions—one that determines the vec-
tors AB and AC and an other that executes the cross product. (If available, use
the user-defined functions from Problems 15 and 17. The function should
work for a triangle in the x y plane (each vertex is defined by two coordinates)
or for a triangle in space (each vertex is defined by three coordinates). Use the
function to determine the areas of triangles with the following vertices:
(a) , , .
(b) , , .
19. Write a user-defined function that plots a circle given the coordinates of the
center and the radius. For the function name and arguments use
circleplot(x,y,R). The input arguments are the x and y coordinates of
the center and the radius. This function has no output arguments. Use the
function to plot the following circles:
(a) , , . (b) , , .
a 3i 11j+= b 14i 7.3j–=
c 6i– 14.2j 3k+ += d 6.3i 8j– 5.6k–=
A
1
2
--- AB AC=
A 1 2= B 10 3= C 6 11=
A 1.5– 4.2– 3–= B 5.1– 6.3 2= C 12.1 0 0.5–=
x 3.5= y 2.0= R 8.5= x 4.0–= y 1.5–= R 10=
264.
7.13 Problems 253
20. Write a user-defined function that plots a circle that passes through three
given points. For the function name and arguments use cirpnts(P). The
input arguments is a matrix in which the two elements of a row are the x
and y coordinates of one point. This function has no output arguments. The
figure that is created by the function displays the circle and the three points
marked with asterisks. Use the function to plot a circle that passes through the
points (6, 1.5), (2, 4), (–3, –1.8).
21. In polar coordinates a two-dimensional vector is
given by its radius and angle . Write a user-
defined MATLAB function that adds two vectors
that are given in polar coordinates. For the func-
tion name and arguments use
[r th]= AddVecPol(r1,th1,r2,th2),
where the input arguments are and
, and the output arguments are the radius and angle of the result. Use
the function to carry out the following additions:
(a) , . (b) , .
22. Write a user-defined function that plots an
ellipse with axes that are parallel to the x and y
axes, given the coordinates of its center and the
length of the axes. For the function name and
arguments use ellipse-
plot(xc,yc,a,b). The input arguments xc
and yc are the coordinates of the center, and a
and b are half the lengths of the horizontal and vertical axes (see figure),
respectively. This function has no output arguments. Use the function to plot
the following ellipses:
(a) , , , .
(b) , , , .
23. Write a user-defined function that finds all the prime numbers between two
numbers m and n. Name the function pr=prime(m,n), where the input
arguments m and n are positive integers, and the output argument pr is a vec-
tor with the prime numbers. If is entered when the function is called,
the error message "The value of n must be larger than the value of m." is dis-
played. If a negative number or a number that is not an integer is entered when
the function is called, the error message "The input argument must be a posi-
tive integer." is displayed. Use the function with:
(a) prime(12,80) (b) prime(21,63.5)
(c) prime(100,200) (d) prime(90,50)
3 2
x
y
θ2
r2
θ1
r1
r
θ
r
r1 1
r2 2
r1 5 23= r2 12 40= r1 6 80= r2 15 125=
x
y
ab
xc
yc
xc 3.5= yc 2.0= a 8.5= b 3=
xc 5–= yc 1.5= a 4= b 8=
m n
265.
254 Chapter 7: User-Defined Functions and Function Files
24. The geometric mean GM of a set of n positive numbers is defined
by:
Write a user-defined function that calculates the geometric mean of a set of
numbers. For function name and arguments use GM=Geomean(x), where
the input argument x is a vector of numbers (any length) and the output argu-
ment GM is their geometric mean. The geometric mean is useful for calculat-
ing the average return of a stock. The following table gives the returns for
IBM stock over the last ten years (a return of 16% means 1.16). Use the user-
defined function Geomean to calculate the average return of the stock.
25. Write a user-defined function that determines the polar
coordinates of a point from the Cartesian coordinates in
a two-dimensional plane. For the function name and
arguments use [th rad]=CartToPolar(x,y).
The input arguments are the x and y coordinates of the
point, and the output arguments are the angle and the
radial distance to the point. The angle is in degrees
and is measured relative to the positive x axis, such that
it is a positive number in quadrants I and II, and a negative number in quadrant III
and IV. Use the function to determine the polar coordinates of points (14, 9), (–11,
–20), (–15, 4), and (13.5, –23.5).
26. Write a user-defined function that sorts the elements of a vector from the
largest to the smallest. For the function name and arguments use
y=downsort(x). The input to the function is a vector x of any length, and
the output y is a vector in which the elements of x are arranged in a
descending order. Do not use the MATLAB built-in function sort, max, or
min. Test your function on a vector with 14 numbers (integers) randomly
distributed between –30 and 30. Use the MATLAB randi function to
generate the initial vector.
27. Write a user-defined function that sorts the elements of a matrix. For the func-
tion name and arguments use B = matrixsort(A), where A is any size
matrix and B is a matrix of the same size with the elements of A rearranged in
descending order row after row with the (1,1) element the largest and the
(m,n) element the smallest. If available, use the user-defined function down-
sort from Problem 26 as a subfunction within matrixsort.
Year 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006
Return 1.38 1.76 1.17 0.79 1.42 0.64 1.2 1.06 0.83 1.18
x1 x2 xn
GM x1 x2 xn
1 n=
266.
7.13 Problems 255
Test your function on a matrix with elements (integers) randomly
distributed between –30 and 30. Use MATLAB's randi function to generate
the initial matrix.
28. Write a user-defined MATLAB function that calculates the determinant of a
matrix by using the formula:
For the function name and arguments use d3 = det3by3(A), where the
input argument A is the matrix and the output argument d3 is the value of the
determinant. Write the code of det3by3 such that it has a subfunction that
calculates the determinant. Use det3by3 for calculating the determi-
nants of:
(a) (b)
29. A two-dimensional state of stress at a point in a
loaded material is defined by three components of
stress , , and . The maximum and mini-
mum normal stresses (principal stresses) at the point,
and , are calculated from the stress compo-
nents by:
Write a user-defined MATLAB function that determines the principal stresses
from the stress components. For the function name and arguments use
[Smax,Smin] = princstress(Sxx,Syy,Sxy). The input arguments
are the three stress components, and the output arguments are the maximum
and minimum stresses.
Use the function to determine the principal stresses for the following
states of stress:
(a) MPa, MPa, and MPa.
(b) ksi, ksi, and ksi.
30. The dew point temperature and the relative humidity RH can be calculated
(approximately) from the dry-bulb and wet-bulb temperatures by
(
4 7
3 3
det A11
A22 A23
A32 A33
A12
A21 A23
A31 A33
– A13
A21 A22
A31 A32
+=
2 2
1 3 2
6 5 4
7 8 9
2.5– 7 1
5 3– 2.6–
4 2 1–
xx yy xy
max min
max
min
xx yy+
2
----------------------
xx yy–
2
---------------------
2
xy
2
+=
xx 190–= yy 145= xy 110=
xx 14= yy 15–= xy 8=
Td
T Tw
es 6.112
17.67T
T 243.5+
-----------------------exp= ew 6.112
17.67Tw
Tw 243.5+
--------------------------exp=
267.
256 Chapter 7: User-Defined Functions and Function Files
where the temperatures are in degrees Celsius, RH is in %, and is the
barometric pressure in units of millibars.
Write a user-defined MATLAB function that calculates the dew point
temperature and relative humidity for given dry-bulb and wet-bulb tempera-
tures and barometric pressure. For the function name and arguments use
[Td,RH] = DewptRhum(T,Tw,BP), where the input arguments are ,
and , and the output arguments are and RH. The values of the output
arguments should be rounded to the nearest tenth. Use the user-defined func-
tion dewpoint for calculating the dew point temperature and relative
humidity for the following cases:
(a) C, C, mbar.
(b) C, C, mbar.
31. Write a user-defined MATLAB function that calculates a student's final grade
in a course using the scores from three midterm exams, a final exam, and six
homework assignments. The midterms are graded on a scale from 0 to 100
and each accounts for 15% of the course grade. The final exam is graded on a
scale from 0 to 100 and accounts for 40% of the course grade. The six home-
work assignments are each graded on a scale from 0 to 10. The homework
assignment with the lowest grade is dropped, and the average of the remaining
assignments accounts for 15% of the course grade. In addition, the following
adjustment is made when the grade is calculated. If the average grade for the
three midterms is higher than the grade for the final exam, then the grade of
the final exam is not used and the average grade of the three midterms
accounts for 85% of the course grade. The program calculates a course grade
that is a number between 0 and 100.
For the function name and arguments use g = fgrade(R). The input
argument R is a matrix in which the elements in each row are the grades of
one student. The first six columns are the homework grades (numbers
between 0 and 10), the next three columns are the midterm grades (numbers
between 0 and 100), and the last column is the final exam grade (a number
between 0 and 100). The output from the function, g, is a column vector with
the student grades for the course. Each row has the course grade of the student
with the grades in the corresponding row of the matrix R.
The function can be used to calculate the grades of any number of stu-
dents. For one student the matrix R has one row. Use the function for the fol-
lowing cases:
(a) Use the Command Window to calculate the course grade of one student
e ew psta T Tw– 0.00066 1 0.00115Tw+–=
RH 100
e
es
----= Td
243.5 e 6.112ln
17.67 e 6.112ln–
--------------------------------------------------=
psta
T Tw
psta Td
T 25= Tw 19= psta 985=
T 36= Tw 31= psta 1020=
268.
7.13 Problems 257
with the following grades: 8, 9, 6, 10, 9, 7, 76, 86, 91, 80.
(b) Write a program in a script file. The program asks the user to enter the
students' grades in an array (one student per row). The program then cal-
culates the course grades by using the function fgrade. Run the script
file in the Command Window to calculate the grades of the following four
students:
Student A: 7, 10, 6, 9, 10, 9, 91, 71, 81, 88.
Student B: 5, 5, 6, 1, 8, 6, 59, 72, 66, 59.
Student C: 6, 8, 10, 4, 5, 9, 72, 78, 84 78.
Student D: 7, 7, 8, 8, 9, 8, 83, 82, 81 84.
32. In a lottery the player has to select several numbers out of a list. Write a
MATLAB program that generates a list of n integers that are uniformly
distributed between the numbers a and b. All the selected numbers on the list
must be different.
(a) Use the function to generate a list of seven numbers from the numbers 1
through 59.
(b) Use the function to generate a list of eight numbers from the numbers 50
through 65.
(c) Use the function to generate a list of nine numbers from the numbers –25
through –2.
33. The solution of the nonlinear equation gives the fifth root of the num-
ber P. A numerical solution of the equation can be calculated with Newton's
method. The solution process starts by choosing a value as a first estimate of
the solution. Using this value, a second, more accurate solution can be calcu-
lated with , which is then used for calculating a third, still more
accurate solution , and so on. The general equation for calculating the value of
the solution from the solution is . Write a user-
defined function that calculates the fifth root of a number. For function name and
arguments use y=fifthroot(P), where the input argument P is the number
whose fifth root is to be determined, and the output argument y is the value .
In the program use for the first estimate of the solution. Then, by using the
general equation in a loop, calculate new, more accurate solutions. Stop the loop-
ing when the estimated relative error E defined by is smaller than
0.00001. Use the function cubic to calculate:
(a) (b) (c)
x5 P– 0=
x1
x2
x2 x1
x1
5 P–
5x1
4
--------------–=
x3
xi 1+ xi xi 1+ xi
xi
5 P–
5xi
4
--------------–=
P5
x P=
E
xi 1+ xi–
xi
--------------------=
1205 168075 15–5
269.
258 Chapter 7: User-Defined Functions and Function Files
34. Write a user-defined function that determines the
coordinate of the centroid of the T-shaped
cross-sectional area shown in the figure. For the
function name and arguments use yc = cen-
troidT(w,h,t,d), where the input argu-
ments w, h, t and d, are the dimensions shown in
the figure, and the output argument yc is the
coordinate .
Use the function to determine for an area
with w = 240 mm, h = 380 mm, d = 42 mm, and t =
60 mm.
35. The area moment of inertia of a rectangle about the
axis passing through its centroid is . The
moment of inertia about an axis x that is parallel to is
given by , where A is the area of the rect-
angle, and is the distance between the two axes.
Write a MATLAB user-defined function
that determines the area moment of inertia
of a " T " beam about the axis that passes
through its centroid (see drawing). For the func-
tion name and arguments use Ixc = IxcT-
Beam(w,h,t,d), where the input arguments
w, h, t, and d are the dimensions shown in the
figure, and the output argument Ixc is . For
finding the coordinate of the of the centroid
use the user-defined function centroidT
from Problem 34 as a subfunction inside IxcTBeam.
(The moment of inertia of a composite area is obtained by dividing the area
into parts and adding the moments of inertia of the parts.)
Use the function to determine the moment of inertia of a "T" beam with w
= 240 mm, h = 380 mm, d = 42 mm, and t = 60 mm.
36. In a low-pass RC filter (a filter that passes
signals with low frequencies), the ratio of
the magnitudes of the voltages is given by:
where is the frequency of the input signal.
w
h
t
d yc
yc
yc
yc
Ixo
xo Ixo
1
12
------bh
3
=
xo
Ix Ixo
Ad x
2
+=
dx
w
h
t
d yc
xc
Ixc
Ixc
yc
RV
Vo
Vi
-----
1
1 RC
2
+
---------------------------------= =
270.
7.13 Problems 259
Write a user-defined MATLAB function that calculates the magnitude
ratio. For the function name and arguments use RV = lowpass(R,C,w).
The input arguments are R, the size of the resistor in (ohms); C, the size of
the capacitor in F (farads); and w, the frequency of the input signal in rad/s.
Write the function such that w can be a vector.
Write a program in a script file that uses the lowpass function to gener-
ate a plot of RV as a function of for rad/s. The plot has a log-
arithmic scale on the horizontal axis ( ). When the script file is executed, it
asks the user to enter the values of R and C. Label the axes of the plot.
Run the script file with , and F.
37. A bandpass filter passes signals with fre-
quencies that are within a certain range. In
this filter the ratio of the magnitudes of the
voltages is given by
where is the frequency of the input signal.
Write a user-defined MATLAB function that calculates the magnitude
ratio. For the function name and arguments use RV = band-
pass(R,C,L,w). The input arguments are R the size of the resistor in
(ohms); C, the size of the capacitor in F (farads); L, the inductance of the coil
in H (henrys); and w, the frequency of the input signal in rad/s. Write the func-
tion such that w can be a vector.
Write a program in a script file that uses the bandpass function to gen-
erate a plot of RV as a function of for rad/s. The plot has a
logarithmic scale on the horizontal axis ( ). When the script file is executed,
it asks the user to enter the values of R, L, and C. Label the axes of the plot.
Run the script file for the following two cases:
(a) , F, mH.
(b) , F, mH.
38. The first derivative of a function at can be approximated
with the four-point central difference formula
where h is a small number relative to . Write a user-defined function func-
tion (see Section 7.9) that calculates the derivative of a math function by
using the four-point central difference formula. For the user-defined function
name use dfdx=Funder(Fun,x0), where Fun is a name for the function
that is passed into Funder, and x0 is the point where the derivative is calcu-
10
2–
10
6
R 1200= C 8=
RV
Vo
Vi
-----
RC
1 2LC– 2 RC 2+
-------------------------------------------------------------= =
10
2–
10
7
R 1100= C 9= L 7=
R 500= C 300= L 400=
df x
dx
------------ f x x x0=
df x
dx
------------
f x0 2h– f x0 h–– f x0 h+ f x0 2h+–+
12h
-------------------------------------------------------------------------------------------------------------=
x0
f x
271.
260 Chapter 7: User-Defined Functions and Function Files
lated. Use in the four-point central difference formula. Use the
user-defined function Funder to calculate the following:
(a) The derivative of at .
(b) The derivative of at .
In both cases compare the answer obtained from Funder with the analytical
solution (use format long).
39. The new coordinates of a point in the x y plane that is rotated about
the z axis at an angle (positive is clockwise) are given by
where are the coordinates of the point before the rotation. Write a
user-defined function that calculates given and . For func-
tion name and arguments use [xr,yr]=rotation(x,y,q), where the
input arguments are the initial coordinates and the rotation angle in degrees,
and the output arguments are the new coordinates.
(a) Use rotation to determine the new coordinates of a point originally at
that is rotated about the z-axis by .
(b) Consider the function for . Write a program in
a script file that makes a plot of the function. Then use rotation to rotate
all the points that make up the first plot and make a plot of the rotated func-
tion. Make both plots in the same figure and set the range of both axes at 0 to
10.
h x0 10=
f x x2ex= x0 0.25=
f x
2x
x
-----= x0 2=
Xr Yr
Xr X0 cos Y0 sin–=
Yr X0 sin Y0 cos+=
X0 Y0
Xr Yr X0 Y0
6.5 2.1 25
y x 7– 2 1.5+= 5 x 9
272.
261
Chapter 8
Polynomials,
Curve Fitting, and
Interpolation
Polynomials are mathematical expressions that are frequently used for problem
solving and modeling in science and engineering. In many cases an equation that
is written in the process of solving a problem is a polynomial, and the solution of
the problem is the zero of the polynomial. MATLAB has a wide selection of func-
tions that are specifically designed for handling polynomials. How to use polyno-
mials in MATLAB is described in Section 8.1.
Curve fitting is a process of finding a function that can be used to model
data. The function does not necessarily pass through any of the points, but models
the data with the smallest possible error. There are no limitations to the type of the
equations that can be used for curve fitting. Often, however, polynomial, exponen-
tial, and power functions are used. In MATLAB curve fitting can be done by writ-
ing a program, or by interactively analyzing data that is displayed in the Figure
Window. Section 8.2 describes how to use MATLAB programming for curve fit-
ting with polynomials and other functions. Section 8.4 describes the basic fitting
interface that is used for interactive curve fitting and interpolation.
Interpolation is the process of estimating values between data points. The
simplest kind of interpolation is done by drawing a straight line between the
points. In a more sophisticated interpolation, data from additional points is used.
How to interpolate with MATLAB is discussed in Sections 8.3 and 8.4.
8.1 POLYNOMIALS
Polynomials are functions that have the form:
The coefficients are real numbers, and n, which is a nonnega-
f x anxn an 1– xn 1– a1x a0+ + + +=
an an 1– a1 a0
273.
262 Chapter 8: Polynomials, Curve Fitting, and Interpolation
tive integer, is the degree, or order, of the polynomial.
Examples of polynomials are:
polynomial of degree 5.
polynomial of degree 2.
polynomial of degree 1.
A constant (e.g., ) is a polynomial of degree 0.
In MATLAB, polynomials are represented by a row vector in which the ele-
ments are the coefficients . The first element is the coefficient of
the x with the highest power. The vector has to include all the coefficients, includ-
ing the ones that are equal to 0. For example:
8.1.1 Value of a Polynomial
The value of a polynomial at a point x can be calculated with the function
polyval which has the form:
x can also be a vector or a matrix. In such a case the polynomial is calculated for
each element (element-by-element), and the answer is a vector, or a matrix, with
the corresponding values of the polynomial.
Sample Problem 8-1: Calculating polynomials with MATLAB
For the polynomial :
(a) Calculate .
(b) Plot the polynomial for .
Solution
The problem is solved in the Command Window.
(a) The coefficients of the polynomials are assigned to vector p. The function
Polynomial MATLAB representation
p = [8 5]
d = [2 –4 10]
, MATLAB form: h = [6 0 –150]
, MATLAB form: c = [5 0 0 6 –7 0]
f x 5x5 6x2 7x 3+ + +=
f x 2x2 4x– 10+=
f x 11x 5–=
f x 6=
an an 1– a1 a0
8x 5+
2x2 4x– 10+
6x2 150– 6x2 0x 150–+
5x5 6x2 7x–+
5x5 0x4 0x3 6x2 7x– 0+ + + +
polyval(p,x)
p is a vector with the coef-
ficients of the polynomial.
x is a number, or a variable that
has an assigned value, or a com-
putable expression.
f x x5 12.1x4– 40.59x3 17.015x2– 71.95x– 35.88+ +=
f 9
1.5– x 6.7
274.
8.1 Polynomials 263
polyval is then used to calculate the value at x = 9.
(b) To plot the polynomial, a vector x is first defined with elements ranging
from –1.5 to 6.7. Then a vector y is created with the values of the polynomial for
every element of x. Finally, a plot of y vs. x is made.
The plot created by MATLAB is presented below (axis labels were added with the
Plot Editor).
8.1.2 Roots of a Polynomial
The roots of a polynomial are the values of the argument for which the value of
the polynomial is equal to zero. For example, the roots of the polynomial
are the values of x for which , which are
and x = 3.
MATLAB has a function, called roots, that determines the root, or roots,
of a polynomial. The form of the function is:
For example, the roots of the polynomial in Sample Problem 8-1 can be deter-
mined by:
>> p = [1 -12.1 40.59 -17.015 -71.95 35.88];
>> polyval(p,9)
ans =
7.2611e+003
>> x=-1.5:0.1:6.7;
>> y=polyval(p,x);
>> plot(x,y)
Calculating the value of the polyno-
mial for each element of the vector x.
-2 -1 0 1 2 3 4 5 6 7
-200
-150
-100
-50
0
50
100
150
x
y
f x x2 2x– 3–= x2 2x– 3– 0= x 1–=
r = roots(p)
p is a row vector with the coef-
ficients of the polynomial.
r is a column vector with
the roots of the polynomial.
275.
264 Chapter 8: Polynomials, Curve Fitting, and Interpolation
The roots command is very useful for finding the roots of a quadratic equation.
For example, to find the roots of , type:
When the roots of a polynomial are known, the poly command can be used
for determining the coefficients of the polynomial. The form of the poly com-
mand is:
For example, the coefficients of the polynomial in Sample Problem 8-1 can be
obtained from the roots of the polynomial (see above) by:
8.1.3 Addition, Multiplication, and Division of Polynomials
Addition:
Two polynomials can be added (or subtracted) by adding (subtracting) the vectors
of the coefficients. If the polynomials are not of the same order (which means that
the vectors of the coefficients are not of the same length), the shorter vector has to
be modified to be of the same length as the longer vector by adding zeros (called
padding) in front. For example, the polynomials
and can be added
by:
>> p= 1 -12.1 40.59 -17.015 -71.95 35.88];
>> r=roots(p)
r =
6.5000
4.0000
2.3000
-1.2000
0.5000
>> roots([4 10 -8])
ans =
-3.1375
0.6375
>> r=6.5 4 2.3 -1.2 0.5];
>> p=poly(r)
p =
1.0000 -12.1000 40.5900 -17.0150 -71.9500 35.8800
When the roots are known, the polynomial can
actually be written as:
f x x 1.2+ x 0.5– x 2.3– x 4– x 6.5–=
f x 4x2 10x 8–+=
p = poly(r)
r is a vector (row or column)
with the roots of the polynomial.
p is a row vector with the
coefficients of the polynomial.
f1 x 3x6 15x5 10x3– 3x2– 15x 40–+ += f2 x 3x3 2x– 6–=
276.
8.1 Polynomials 265
Multiplication:
Two polynomials can be multiplied using the MATLAB built-in function conv,
which has the form:
• The two polynomials do not have to be of the same order.
• Multiplication of three or more polynomials is done by using the conv func-
tion repeatedly.
For example, multiplication of the polynomials and above gives:
which means that the answer is:
Division:
A polynomial can be divided by another polynomial with the MATLAB built-in
function deconv, which has the form:
For example, dividing by is done by:
>> p1=[3 15 0 -10 -3 15 -40];
>> p2=[3 0 -2 -6];
>> p=p1+[0 0 0 p2]
p =
3 15 0 -7 -3 13 -46
>> pm=conv(p1,p2)
pm =
9 45 -6 -78 -99 65 -54 -12 -10 240
>> u=[2 9 7 -6];
>> v=[1 3];
Three 0s are added in front
of p2, since the order of p1
is 6 and the order of p2 is 3.
c = conv(a,b)
a and b are the vectors of the
coefficients of the polynomials
that are being multiplied.
c is a vector of the coefficients
of the polynomial that is the
product of the multiplication.
f1 x f2 x
9x9 45x8 6x7– 78x6– 99x5– 65x4 54x3– 12x2– 10x– 240+ + +
[q,r] = deconv(u,v)
u is a vector with the coefficients of
the numerator polynomial.
v is a vector with the coefficients of
the denominator polynomial.
q is a vector with the coefficients
of the quotient polynomial.
r is a vector with the coefficients
of the remainder polynomial.
2x3 9x2 7x 6–+ + x 3+
277.
266 Chapter 8: Polynomials, Curve Fitting, and Interpolation
An example of division that gives a remainder is
divided by :
The answer is: .
8.1.4 Derivatives of Polynomials
The built-in function polyder can be used to calculate the derivative of a single
polynomial, a product of two polynomials, or a quotient of two polynomials, as
shown in the following three commands.
k = polyder(p) Derivative of a single polynomial. p is a vector with
the coefficients of the polynomial. k is a vector with
the coefficients of the polynomial that is the derivative.
k = polyder(a,b) Derivative of a product of two polynomials. a and b
are vectors with the coefficients of the polynomials that
are multiplied. k is a vector with the coefficients of the
polynomial that is the derivative of the product.
[n d] = polyder(u,v) Derivative of a quotient of two polynomials. u and v
are vectors with the coefficients of the numerator and
denominator polynomials. n and d are vectors with the
coefficients of the numerator and denominator polyno-
mials in the quotient that is the derivative.
The only difference between the last two commands is the number of output argu-
ments. With two output arguments MATLAB calculates the derivative of the quo-
tient of two polynomials. With one output argument the derivative is of the
product.
>> [a b]=deconv(u,v)
a =
2 3 -2
b =
0 0 0 0
>> w=[2 -13 0 75 2 0 -60];
>> z=[1 0 -5];
>> [g h]=deconv(w,z)
g =
2 -13 10 10 52
h =
0 0 0 0 0 50 200
The answer is: .2x2 3x 2–+
Remainder is zero.
2x6 13x5– 75x3 2x2 60–+ +
x2 5–
The quotient is: .2x4 13x3– 10x2 10x 52+ + +
The remainder is: .50x 200+
2x4 13x3– 10x2 10x 52
50x 200+
x2 5–
------------------------+ + + +
278.
8.2 Curve Fitting 267
For example, if , and , the derivatives of
, , and can be determined by:
8.2 CURVE FITTING
Curve fitting, also called regression analysis, is a process of fitting a function to a
set of data points. The function can then be used as a mathematical model of the
data. Since there are many types of functions (linear, polynomial, power, expo-
nential, etc.), curve fitting can be a complicated process. Many times one has
some idea of the type of function that might fit the given data and will need only
to determine the coefficients of the function. In other situations, where nothing is
known about the data, it is possible to make different types of plots that provide
information about possible forms of functions that might fit the data well. This
section describes some of the basic techniques for curve fitting and the tools that
MATLAB has for this purpose.
8.2.1 Curve Fitting with Polynomials; The polyfit Function
Polynomials can be used to fit data points in two ways. In one the polynomial
passes through all the data points, and in the other the polynomial does not neces-
sarily pass through any of the points, but overall gives a good approximation of
the data. The two options are described below.
Polynomials that pass through all the points:
When n points (xi, yi) are given, it is possible to write a polynomial of degree
that passes through all the points. For example, if two points are given it is possi-
ble to write a linear equation in the form of that passes through the
points. With three points the equation has the form of . With n
>> f1= 3 -2 4];
>> f2=[1 0 5];
>> k=polyder(f1)
k =
6 -2
>> d=polyder(f1,f2)
d =
12 -6 38 -10
>> [n d]=polyder(f1,f2)
n =
2 22 -10
d =
1 0 10 0 25
f1 x 3x2 2x– 4+= f2 x x2 5+=
3x2 2x– 4+ 3x2 2x– 4+ x2 5+
3x2 2x– 4+
x2 5+
-----------------------------
Creating the vectors of coefficients of f1 and f2.
The derivative of f1 is: .6x 2–
The derivative of f1*f2 is: .12x3 6x2– 38x 10–+
The derivative of is: .
3x2 2x– 4+
x2 5+
-----------------------------
2x2 22x 10–+
x4 10x2 25+ +
-----------------------------------
n 1–
y mx b+=
y ax2 bx c+ +=
279.
268 Chapter 8: Polynomials, Curve Fitting, and Interpolation
points the polynomial has the form . The coef-
ficients of the polynomial are determined by substituting each point in the polyno-
mial and then solving the n equations for the coefficients. As will be shown later
in this section, polynomials of high degree might give a large error if they are used
to estimate values between data points.
Polynomials that do not necessarily pass through any of the points:
When n points are given, it is possible to write a polynomial of degree less than
that does not necessarily pass through any of the points, but overall approxi-
mates the data. The most common method of finding the best fit to data points is
the method of least squares. In this method the coefficients of the polynomial are
determined by minimizing the sum of the squares of the residuals at all the data
points. The residual at each point is defined as the difference between the value of
the polynomial and the value of the data. For example, consider the case of find-
ing the equation of a straight line that best fits four data points as shown in Figure
8-1. The points are , , , and , and the polynomial of the
first degree can be written as . The residual, , at each point is
the difference between the value of the function at and , . An
equation for the sum of the squares of the residuals of all the points is given by
or, after substituting the equation of the polynomial at each point, by:
At this stage R is a function of and . The minimum of R can be determined
by taking the partial derivative of R with respect to and (two equations) and
equating them to zero.
and
Figure 8-1: Least squares fitting of first-degree polynomial to four points.
an 1– xn 1– an 2– xn 2– a1x a0+ + + +
n 1–
x1 y1, x2 y2, x3 y3, x4 y4,
(x1, y1)
R2
R1
R3
x
y
R4
f(x1)
f(x2)
f(x3)
f(x4)
(x2, y2)
(x3, y3)
(x4, y4)
f(x) = a1x + a0
f x a1x a0+= Ri
xi yi Ri f xi yi–=
Ri
R f x1 y1–
2
f x2 y2–
2
f x3 y3–
2
f x4 y4–
2
+ + +=
R a1x1 a0 y1–+
2
a1x2 a0 y2–+
2
a1x3 a0 y3–+
2
a1x4 a0 y4–+
2
+ + +=
a1 a0
a1 a0
R
a1
-------- 0=
R
a0
-------- 0=
280.
8.2 Curve Fitting 269
This results in a system of two equations with two unknowns, and . The
solution of these equations gives the values of the coefficients of the polynomial
that best fits the data. The same procedure can be followed with more points and
higher-order polynomials. More details on the least squares method can be found
in books on numerical analysis.
Curve fitting with polynomials is done in MATLAB with the polyfit
function, which uses the least squares method. The basic form of the polyfit
function is:
For the same set of m points, the polyfit function can be used to fit poly-
nomials of any order up to . If n = 1 the polynomial is a straight line, if n = 2
the polynomial is a parabola, and so on. The polynomial passes through all the
points if (the order of the polynomial is one less than the number of
points). It should be pointed out here that a polynomial that passes through all the
points, or polynomials with higher order, do not necessarily give a better fit over-
all. High-order polynomials can deviate significantly between the data points.
Figure 8-2 shows how polynomials of different degrees fit the same set of
data points. A set of seven points is given by (0.9, 0.9), (1.5, 1.5), (3, 2.5), (4, 5.1),
Figure 8-2: Fitting data with polynomials of different order.
a1 a0
p = polyfit(x,y,n)
x is a vector with the horizontal coordinates
of the data points (independent variable).
y is a vector with the vertical coordinates of
the data points (dependent variable).
n is the degree of the polynomial.
p is the vector of the coeffi-
cients of the polynomial
that fits the data.
m 1–
n m 1–=
0 2 4 6 8 10
0
1
2
3
4
5
6
7
x
y
n = 1
0 2 4 6 8 10
0
1
2
3
4
5
6
7
x
y
n = 2
281.
270 Chapter 8: Polynomials, Curve Fitting, and Interpolation
(6, 4.5), (8, 4.9), and (9.5, 6.3). The points are fitted using the polyfit function
with polynomials of degrees 1 through 6. Each plot in Figure 8-2 shows the same
data points, marked with circles, and a curve-fitted line that corresponds to a poly-
nomial of the specified degree. It can be seen that the polynomial with n = 1 is a
straight line, and with n = 2 is a slightly curved line. As the degree of the polyno-
mial increases, the line develops more bends such that it passes closer to more
points. When n = 6, which is one less than the number of points, the line passes
through all the points. However, between some of the points, the line deviates sig-
nificantly from the trend of the data.
The script file used to generate one of the plots in Figure 8-2 (the polyno-
mial with n = 3) is shown below. Note that in order to plot the polynomial (the
line) a new vector xp with small spacing is created. This vector is then used with
x=[0.9 1.5 3 4 6 8 9.5];
y=[0.9 1.5 2.5 5.1 4.5 4.9 6.3];
p=polyfit(x,y,3)
xp=0.9:0.1:9.5;
yp=polyval(p,xp);
plot(x,y,'o',xp,yp)
xlabel('x'); ylabel('y')
Figure 8-2: Fitting data with polynomials of different order. (Continued)
0 2 4 6 8 10
0
1
2
3
4
5
6
7
x
y
n = 3
0 2 4 6 8 10
0
1
2
3
4
5
6
7
x
y
n = 4
0 2 4 6 8 10
0
1
2
3
4
5
6
7
x
y
n = 5
0 2 4 6 8 10
0
2
4
6
8
10
x
y
n = 6
Create vectors x and y with the
coordinates of the data points.
Create a vector p using the polyfit function.
Create a vector xp to be used for plotting the polynomial.
Create a vector yp with values of the polynomial at each xp.
A plot of the seven points and the polynomial.
282.
8.2 Curve Fitting 271
the function polyval to create a vector yp with the value of the polynomial for
each element of xp.
When the script file is executed, the following vector p is displayed in the
Command Window.
This means that the polynomial of the third degree in Figure 8-2 has the form
.
8.2.2 Curve Fitting with Functions Other than Polynomials
Many situations in science and engineering require fitting functions that are not
polynomials to given data. Theoretically, any function can be used to model data
within some range. For a particular data set, however, some functions provide a
better fit than others. In addition, determining the best-fitting coefficients can be
more difficult for some functions than for others. This section covers curve fitting
with power, exponential, logarithmic, and reciprocal functions, which are com-
monly used. The forms of these functions are:
(power function)
or (exponential function)
or (logarithmic function)
(reciprocal function)
All of these functions can easily be fitted to given data with the polyfit func-
tion. This is done by rewriting the functions in a form that can be fitted with a lin-
ear polynomial (n = 1), which is
The logarithmic function is already in this form, and the power, exponential and
reciprocal equations can be rewritten as:
(power function)
or (exponential function)
(reciprocal function)
These equations describe a linear relationship between and for the
power function, between and x for the exponential function, between y and
or for the logarithmic function, and between 1/y and x for the recip-
rocal function. This means that the polyfit(x,y,1) function can be used to
determine the best-fit constants m and b for best fit if, instead of x and y, the
p =
0.0220 -0.4005 2.6138 -1.4158
0.022x3 0.4005x2– 2.6138x 1.4148–+
y bxm=
y bemx= y b10
mx
=
y m xln b+= y m xlog b+=
y
1
mx b+
----------------=
y mx b+=
yln m xln bln+=
yln mx bln+= ylog mx blog+=
1
y
--- mx b+=
yln xln
yln
xln xlog
283.
272 Chapter 8: Polynomials, Curve Fitting, and Interpolation
following arguments are used.
The result of the polyfit function is assigned to p, which is a two-element vec-
tor. The first element, p(1), is the constant m, and the second element, p(2), is b
for the logarithmic and reciprocal functions, or for the exponential
function, and for the power function ( or for the expo-
nential function, and for the power function).
For given data it is possible to estimate, to some extent, which of the func-
tions has the potential for providing a good fit. This is done by plotting the data
using different combinations of linear and logarithmic axes. If the data points in
one of the plots appear to fit a straight line, the corresponding function can pro-
vide a good fit according to the list below.
Other considerations in choosing a function:
• Exponential functions cannot pass through the origin.
• Exponential functions can fit only data with all positive y's or all negative y's.
• Logarithmic functions cannot model x = 0 or negative values of x.
• For the power function y = 0 when x = 0.
• The reciprocal equation cannot model y = 0.
Function polyfit function form
power p=polyfit(log(x),log(y),1)
exponential or p=polyfit(x,log(y),1) or
p=polyfit(x,log10(y),1)
logarithmic or p=polyfit(log(x),y,1) or
p=polyfit(log10(x),y,1)
reciprocal p=polyfit(x,1./y,1)
x axis y axis Function
linear linear linear
logarithmic logarithmic power
linear logarithmic exponential or
logarithmic linear logarithmic or
linear linear
(plot 1/y)
reciprocal
y bxm=
y bemx=
y b10
mx
=
y m xln b+=
y m xlog b+=
y
1
mx b+
----------------=
bln blog
bln b e
p 2
= b 10
p 2
=
b e
p 2
=
y mx b+=
y bxm=
y bemx= y b10
mx
=
y m xln b+= y m xlog b+=
y
1
mx b+
----------------=
284.
8.2 Curve Fitting 273
The following example illustrates the process of fitting a function to a set of data
points.
Sample Problem 8-2: Fitting an equation to data points
The following data points are given. Determine a function (t is the inde-
pendent variable, w is the dependent variable) with a form discussed in this sec-
tion that best fits the data.
Solution
The data is first plotted with linear scales
on both axes. The figure indicates that a
linear function will not give the best fit
since the points do not appear to line up
along a straight line. From the other possi-
ble functions, the logarithmic function is
excluded since for the first point ,
and the power function is excluded since at
, . To check if the other two
functions (exponential and reciprocal) might give a better fit, two additional plots,
shown below, are made. The plot on the left has a log scale on the vertical axis and
linear horizontal axis. In the plot on the right both axes have linear scales, and the
quantity 1/w is plotted on the vertical axis.
In the left figure the data points appear to line up along a straight line. This indi-
cates that an exponential function of the form can give a good fit to the
data. A program in a script file that determines the constants b and m, and that
plots the data points and the function is given below.
t 0.0 0.5 1.0 1.5 2.0 2.5 3.0 3.5 4.0 4.5 5.0
w 6.00 4.83 3.70 3.15 2.41 1.83 1.49 1.21 0.96 0.73 0.64
t=0:0.5:5;
w=[6 4.83 3.7 3.15 2.41 1.83 1.49 1.21 0.96 0.73 0.64];
p=polyfit(t,log(w),1);
w f t=
0 1 2 3 4 5
0
1
2
3
4
5
6
t
w
t 0=
t 0= w 0
0 1 2 3 4 5
10
0
10
1
t
w
0 1 2 3 4 5
0
0.5
1
1.5
2
t
1/w
y bemx=
Create vectors t and w with the coordinates of the data points.
Use the polyfit function with t and log(w).
285.
274 Chapter 8: Polynomials, Curve Fitting, and Interpolation
When the program is executed, the values of the constants m and b are displayed
in the Command Window.
The plot generated by the program, which shows the data points and the function
(with axis labels added with the Plot Editor) is
It should be pointed out here that in addition to the power, exponential, log-
arithmic, and reciprocal functions that are discussed in this section, many other
functions can be written in a form suitable for curve fitting with the polyfit
function. One example where a function of the form is fitted to
data points using the polyfit function with a third-order polynomial is
described in Sample Problem 8-7.
8.3 INTERPOLATION
Interpolation is the estimation of values between data points. MATLAB has inter-
polation functions that are based on polynomials, which are described in this sec-
tion, and on Fourier transformation, which is outside the scope of this book. In
one-dimensional interpolation each point has one independent variable (x) and one
dependent variable (y). In two-dimensional interpolation each point has two inde-
pendent variables (x and y) and one dependent variable (z).
m=p(1)
b=exp(p(2))
tm=0:0.1:5;
wm=b*exp(m*tm);
plot(t,w,'o',tm,wm)
m =
-0.4580
b =
5.9889
Determine the coefficient b.
Create a vector tm to be used for plotting the polynomial.
Calculate the function value at each element of tm.
Plot the data points and the function.
0 1 2 3 4 5
0
1
2
3
4
5
6
t
w
y e
a2x
2
a1x a0+ +
=
286.
8.3 Interpolation 275
One-dimensional interpolation:
If only two data points exist, the points can be connected with a straight line is and
a linear equation (polynomial of first order) can be used to estimate values
between the points. As was discussed in the previous section, if three (or four)
data points exist, a second- (or a third-) order polynomial that passes through the
points can be determined and then be used to estimate values between the points.
As the number of points increases, a higher-order polynomial is required for the
polynomial to pass through all the points. Such a polynomial, however, will not
necessarily give a good approximation of the values between the points. This is
illustrated in Figure 8-2 with n = 6.
A more accurate interpolation can be obtained if instead of considering all
the points in the data set (by using one polynomial that passes through all the
points), only a few data points in the neighborhood where the interpolation is
needed are considered. In this method, called spline interpolation, many low-order
polynomials are used, where each is valid only in a small domain of the data set.
The simplest method of spline interpola-
tion is called linear spline interpolation. In this
method, shown on the right, every two adjacent
points are connected with a straight line (a poly-
nomial of first degree). The equation of a
straight line that passes through two adjacent
points (xi, yj) and (xi+1, yj+1) and that can be used
to calculate the value of y for any x between the
points is given by:
In a linear interpolation the line between two data points has a constant
slope, and there is a change in the slope at every point. A smoother interpolation
curve can be obtained by using quadratic or cubic polynomials. In these methods,
called quadratic splines and cubic splines, a second-, or third-order polynomial is
used to interpolate between every two points. The coefficients of the polynomial
are determined by using data from points that are adjacent to the two data points.
The theoretical background for the determination of the constants of the polyno-
mials is beyond the scope of this book and can be found in books on numerical
analysis.
y
yi 1+ yi–
xi 1+ xi–
--------------------x
yixi 1+ yi 1+ xi–
xi 1+ xi–
------------------------------------+=
287.
276 Chapter 8: Polynomials, Curve Fitting, and Interpolation
One-dimensional interpolation in MATLAB is done with the interp1 (the
last character is the number one) function, which has the form:
• The vector x must be monotonic (with elements in ascending or descending
order).
• xi can be a scalar (interpolation of one point) or a vector (interpolation of
many points). yi is a scalar or a vector with the corresponding interpolated
values.
• MATLAB can do the interpolation using one of several methods that can be
specified. These methods include:
'nearest' returns the value of the data point that is nearest to the
interpolated point.
'linear' uses linear spline interpolation.
'spline' uses cubic spline interpolation.
'pchip' uses piecewise cubic Hermite interpolation, also called
'cubic'
• When the 'nearest' and the 'linear' methods are used, the value(s) of
xi must be within the domain of x. If the 'spline' or the 'pchip' meth-
ods are used, xi can have values outside the domain of x and the function
interp1 performs extrapolation.
• The 'spline' method can give large errors if the input data points are
nonuniform such that some points are much closer together than others.
• Specification of the method is optional. If no method is specified, the default is
'linear'.
Sample Problem 8-3: Interpolation
The following data points, which are points of the function ,
are given. Use linear, spline, and pchip interpolation methods to calculate the
value of y between the points. Make a figure for each of the interpolation methods.
In the figure show the points, a plot of the function, and a curve that corresponds
yi = interp1(x,y,xi,'method')
yi is the
interpolated
value.
x is a vector with the horizontal coordinates of
the input data points (independent variable).
y is a vector with the vertical coordinates of
the input data points (dependent variable).
xi is the horizontal coordinate of the interpo-
lation point (independent variable).
Method of
interpola-
tion, typed as
a string
(optional).
f x 1.5
x
2xcos=
289.
278 Chapter 8: Polynomials, Curve Fitting, and Interpolation
8.4 THE BASIC FITTING INTERFACE
The basic fitting interface is a tool that can be used to perform curve fitting and
interpolation interactively. By using the interface the user can:
• Curve-fit the data points with polynomials of various degrees up to 10, and
with spline and Hermite interpolation methods.
• Plot the various fits on the same graph so that they can be compared.
• Plot the residuals of the various polynomial fits and compare the norms of the
residuals.
• Calculate the values of specific points with the various fits.
• Add the equations of the polynomials to the plot.
To activate the basic fitting inter-
face, the user first has to make a plot of
the data points. Then the interface is
activated by selecting Basic Fitting in
the Tools menu, as shown on the right.
This opens the Basic Fitting Window,
shown in Figure 8-3. When the window
first opens, only one panel (the Plot fits
panel) is visible. The window can be
extended to show a second panel (the
Numerical results panel) by clicking
on the button. One click adds the
first section of the panel, and a second
click makes the window look as shown in Figure 8-3. The window can be reduced
back by clicking on the button. The first two items in the Basic Fitting Win-
dow are related to the selection of the data points:
Select data: Used to select a specific set of data points for curve fitting in a fig-
ure that has more than one set of data points. Only one set of data points can be
curve-fitted at a time, but multiple fits can be performed simultaneously on the
same set.
Center and scale x data: When this box is checked, the data is centered at zero
mean and scaled to unit standard deviation. This might be needed in order to
improve the accuracy of numerical computation.
The next four items are in the Plot fits panel and are related to the display of the
fit.
Check to display fits on figure: The user selects the fits to be displayed in the
figure. The selections include interpolation with spline interpolant (interpolation
method) that uses the spline function, interpolation with Hermite interpolant
that uses the pchip function, and polynomials of various degrees that use the
290.
8.4 The Basic Fitting Interface 279
polyfit function. Several fits can be selected and displayed simultaneously.
Show equations: When this box is checked, the equations of the polynomials
that were selected for the fit are displayed in the figure. The equations are dis-
played with the number of significant digits selected in the adjacent sign menu.
Plot residuals: When this box is checked, a plot that shows the residual at each
data point is created (residuals are defined in Section 8.2.1). Choices in the
menus include a bar plot, a scatter plot, and a line plot which can be displayed as
a subplot in the same Figure Window that has the plot of the data points, or as a
separate plot in a different Figure Window.
Show norm of residuals: When this box is checked, the norm of the residuals is
displayed in the plot of the residuals. The norm of the residual is a measure of
the quality of the fit. A smaller norm corresponds to a better fit.
The next three items are in the Numerical results panel. They provide the numer-
ical information for one fit, independently of the fits that are displayed:
Fit: The user selects the fit to be examined numerically. The fit is shown on the
plot only if it is selected in the Plot fit panel.
Coefficients and norm of residuals: Displays the numerical results for the
polynomial fit that is selected in the Fit menu. It includes the coefficients of the
polynomial and the norm of the residuals. The results can be saved by clicking
on the Save to workspace button.
Figure 8-3: The Basic Fitting Window.
291.
280 Chapter 8: Polynomials, Curve Fitting, and Interpolation
Find y = f(x): Provides a means for obtaining interpolated (or extrapolated)
numerical values for specified values of the independent variable. Enter the
value of the independent variable in the box, and click on the Evaluate button.
When the Plot evaluated results box is checked, the point is displayed on the
plot.
As an example, the basic fitting interface is used for fitting the data points
from Sample Problem 8-3. The Basic Fitting Window is the one shown in Figure
8-3, and the corresponding Figure Window is shown in Figure 8-4. The Figure
Window includes a plot of the points, one interpolation fit (spline), two polyno-
mial fits (linear and cubic), a display of the equations of the polynomial fits, and a
mark of the point x = 1.5 that is entered in the Find y = f(x) box of the Basic Fitting
Window. The Figure Window also includes a plot of the residuals of the polyno-
mial fits and a display of their norm.
Figure 8-4: A Figure Window modified by the Basic Fitting Interface.
292.
8.5 Examples of MATLAB Applications 281
8.5 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 8-4: Determining wall thickness of a box
The outside dimensions of a rectangular
box (bottom and four sides, no top), made
of aluminum, are 24 by 12 by 4 inches. The
wall thickness of the bottom and the sides
is x. Derive an expression that relates the
weight of the box and the wall thickness x.
Determine the thickness x for a box that
weighs 15 lb. The specific weight of alumi-
num is 0.101 lb/in.3.
Solution
The volume of the aluminum VAl is calculated from the weight W of the box by:
where is the specific weight. The volume of the aluminum based on the dimen-
sions of the box is given by
where the inside volume of the box is subtracted from the outside volume. This
equation can be rewritten as
which is a third-degree polynomial. A root of this polynomial is the required
thickness x. A program in a script file that determines the polynomial and solves
for the roots is:
Note in the second to last line that in order to add the quantity to
the polynomial Vin it has to be written as a polynomial of the same order as Vin
(Vin is a polynomial of third order). When the program (saved as
Chap8SamPro4) is executed, the coefficients of the polynomial and the value of x
are displayed:
W=15; gamma=0.101;
VAlum=W/gamma;
a=[-2 24];
b=[-2 12];
c=[-1 4];
Vin=conv(c, conv(a,b));
polyeq=[0 0 0 (VAlum-24*12*4)]+Vin
x=roots(polyeq)
VAl
W
-----=
VAl 24 12 4 24 2x– 12 2x– 4 x––=
24 2x– 12 2x– 4 x– VAl 24 12 4–+ 0=
Assign W and gamma.
Calculate the volume of the aluminum.
Assign the polynomial 24 – 2x to a.
Assign the polynomial 12 – 2x to b.
Assign the polynomial 4 – x to c.
Multiply the three polynomials above.
Add VAl – 24*12*4 to Vin.
Determine the roots of the polynomial.
VAl 24 12 4–
293.
282 Chapter 8: Polynomials, Curve Fitting, and Interpolation
Sample Problem 8-5: Floating height of a buoy
An aluminum thin-walled sphere is used as a
marker buoy. The sphere has a radius of 60 cm
and a wall thickness of 12 mm. The density of
aluminum is kg/m3. The buoy is
placed in the ocean, where the density of the
water is 1030 kg/m3. Determine the height h
between the top of the buoy and the surface of
the water.
Solution
According to Archimedes' law, the buoyancy force applied to an object that is
placed in a fluid is equal to the weight of the fluid that is displaced by the object.
Accordingly, the aluminum sphere will be at a depth such that the weight of the
sphere is equal to the weight of the fluid displaced by the part of the sphere that is
submerged.
The weight of the sphere is given by
where is the volume of the aluminum; and are the outside and inside
radii of the sphere, respectively; and g is the gravitational acceleration.
The weight of the water that is displaced by the spherical portion that is sub-
merged is given by:
Setting the two weights equal to each other gives the following equation:
The last equation is a third-degree polynomial for h. The root of the polynomial is
the answer.
A solution with MATLAB is obtained by writing the polynomials and using
the roots function to determine the value of h. This is done in the following
script file:
>> Chap8SamPro4
polyeq =
-4.0000 88.0000 -576.0000 148.5149
x =
10.8656 + 4.4831i
10.8656 - 4.4831i
0.2687
The polynomial is:
.4x3– 88x2 576x– 148.515+ +
The polynomial has one real root, x = 0.2687 in.,
which is the thickness of the aluminum wall.
Al 2690=
Wsph AlVAlg Al
4
3
--- ro
3 ri
3– g= =
VAl ro ri
Wwtr wtrVwtrg wtr
1
3
--- 2ro h–
2
ro h+ g= =
h
3
3roh
2
– 4ro
3
4
Al
wtr
--------- ro
3
ri
3
––+ 0=
294.
8.5 Examples of MATLAB Applications 283
When the script file is executed in the Command Window, as shown below, the
answer is three roots, since the polynomial is of the third degree. The only answer
that is physically possible is the second, where h = 0.9029 m.
Sample Problem 8-6: Determining the size of a capacitor
An electrical capacitor has an unknown
capacitance. In order to determine its capaci-
tance it is connected to the circuit shown.
The switch is first connected to B and the
capacitor is charged. Then, the switch is con-
nected to A and the capacitor discharges
through the resistor. As the capacitor is dis-
charging, the voltage across the capacitor is measured for 10 s in intervals of 1 s.
The recorded measurements are given in the table below. Plot the voltage as a
function of time and determine the capacitance of the capacitor by fitting an expo-
nential curve to the data points.
Solution
When a capacitor discharges through a resistor, the voltage of the capacitor as a
function of time is given by
where is the initial voltage, R the resistance of the resistor, and C the capaci-
tance of the capacitor. As was explained in Section 8.2.2 the exponential function
can be written as a linear equation for ln(V) and t in the form:
rout=0.60; rin=0.588;
rhoalum=2690; rhowtr=1030;
a0=4*rout^3-4*rhoalum*(rout^3-rin^3)/rhowtr;
p = [1 -3*rout 0 a0];
h = roots(p)
>> Chap8SamPro5
h =
1.4542
0.9029
-0.5570
t (s) 1 2 3 4 5 6 7 8 9 10
V (V) 9.4 7.31 5.15 3.55 2.81 2.04 1.26 0.97 0.74 0.58
Assign the radii to variables.
Assign the densities to variables.
Assign the coefficient a0.
Assign the coefficient vector of the polynomial.
Calculate the roots of the polynomial.
The polynomial has three roots. The only one that is
physically possible for the problem is 0.9029 m.
V V0e
t– RC
=
V0
Vln
1–
RC
--------t V0ln+=
295.
284 Chapter 8: Polynomials, Curve Fitting, and Interpolation
This equation, which has the form , can be fitted to the data points by
using the polyfit(x,y,1) function with t as the independent variable x and
ln(V) as the dependent variable y. The coefficients m and b determined by the
polyfit function are then used to determine C and by:
and
The following program written in a script file determines the best-fit exponential
function to the data points, determines C and , and plots the points and the fit-
ted function.
When the script file is executed (saved as Chap8SamPro6) the values of C and
are displayed in the Command Window as shown below:
The program creates also the following plot (axis labels were added to the plot
using the Plot Editor):
R=2000;
t=1:10;
v=[9.4 7.31 5.15 3.55 2.81 2.04 1.26 0.97 0.74 0.58];
p=polyfit(t,log(v),1);
C=-1/(R*p(1))
V0=exp(p(2))
tplot=0:0.1:10;
vplot=V0*exp(-tplot./(R*C));
plot(t,v,'o',tplot,vplot)
>> Chap8SamPro6
C =
0.0016
V0 =
13.2796
y mx b+=
V0
C
t–
Rm
--------= V0 e
b
=
V0
Define R.
Assign the data points to vectors t and v.
Use the polyfit function with t and log(v).
Calculate C from p(1), which is m in the equation.
Calculate V0 from p(2), which is b in the equation.
Create vector tplot of time for plotting the function.
Create vector vplot for plotting the function.
V0
The capacitance of the capacitor is 1,600 F.
0 2 4 6 8 10
0
2
4
6
8
10
12
14
t (s)
V(V)
296.
8.5 Examples of MATLAB Applications 285
Sample Problem 8-7: Temperature dependence of viscosity
Viscosity, , is a property of gases and fluids that characterizes their resistance to
flow. For most materials viscosity is highly sensitive to temperature. Below is a
table that gives the viscosity of SAE 10W oil at different temperatures (Data from
B.R. Munson, D.F. Young, and T.H. Okiishi, Fundamentals of Fluid Mechanics,
4th ed., John Wiley and Sons, 2002). Determine an equation that can be fitted to
the data.
Solution
To determine what type of equation
might provide a good fit to the data,
is plotted as a function of T (absolute
temperature) with a linear scale for T
and a logarithmic scale for . The
plot, shown on the right, indicates
that the data points do not appear to
line up along a straight line. This
means that a simple exponential
function of the form , which
models a straight line with these
axes, will not provide the best fit. Since the points in the figure appear to lie along
a curved line, a function that can possibly have a good fit to the data is:
This function can be fitted to the data by using MATLABs polyfit(x,y,2)
function (second-degree polynomial), where the independent variable is T and the
dependent variable is ln( ). The equation above can be solved for to give the vis-
cosity as a function of temperature:
The following program determines the best fit to the function and creates a plot
that displays the data points and the function.
T ( C) –20 0 20 40 60 80 100 120
(N s/m2)
( )
4 0.38 0.095 0.032 0.015 0.0078 0.0045 0.0032
T=[-20:20:120];
mu=[4 0.38 0.095 0.032 0.015 0.0078 0.0045 0.0032];
TK=T+273;
p=polyfit(TK,log(mu),2)
Tplot=273+[-20:120];
5–
10
250 300 350 400
10
-3
10
-2
10
-1
10
0
10
1
Temperature (K)
Viscosity(N*s/m
2
)
y bemx=
ln a2T2 a1T a0+ +=
e
a2T
2
a1T a0+ +
e
a0
e
a1T
e
a2T
2
= =
297.
286 Chapter 8: Polynomials, Curve Fitting, and Interpolation
When the program executes (saved as Chap8SamPro7), the coefficients that are
determined by the polyfit function are displayed in the Command Window
(shown below) as three elements of the vector p.
With these coefficients the viscosity of the oil as a function of temperature is:
The plot that is generated shows that the equation correlates well to the data points
(axis labels were added with the Plot Editor).
8.6 PROBLEMS
1. Plot the polynomial in the domain .
First create a vector for x, next use the polyval function to calculate y, and
then use the plot function.
2. Plot the polynomial in the
domain . First create a vector for x, next use the polyval function
to calculate y, and then use the plot function.
3. Use MATLAB to carry out the following multiplication of two polynomials:
muplot = exp(p(1)*Tplot.^2 + p(2)*Tplot + p(3));
semilogy(TK,mu,'o',Tplot,muplot)
>> Chap8SamPro7
p =
0.0003 -0.2685 47.1673
e
0.0003T
2
0.2685T– 47.1673+
e
47.1673
e
0.2685– T
e
0.0003T
2
= =
250 300 350 400
10
-3
10
-2
10
-1
10
0
10
1
Temperature (K)
Viscosity(N*s/m
2
)
y 0.4x4– 7x2 20.5x– 28–+= 5– x 4
y 0.001x4– 0.051x3 0.76x2– 3.8x 1.4–+ +=
1 x 14
2x2 3+ x3 3.5x2 5x 16–+ +
298.
8.6 Problems 287
4. Use MATLAB to carry out the following multiplication of polynomials:
Plot the polynomial for .
5. Divide the polynomial by the polynomial
.
6. Divide the polynomial by the polynomial
.
7. The product of three consecutive integers is 1,716. Using MATLAB's built-in
function for operations with polynomials, determine the three integers.
8. The product of four consecutive even integers is 13,440. Using MATLAB's
built-in function for operations with polynomials, determine the four integers.
9. A cylindrical aluminum fuel tank has an outside diameter
of 30 in. and a height of 50 in. The the thickness of the
wall is t, and the bottom and top ends are 25% thicker.
Determine t if the weight of the tank is 152 lb. The spe-
cific weight of aluminum is 165 lb/ft3.
10. A cylindrical aluminum fuel tank has a flat bottom and a
semi-spherical top. The outside diameter is 25 cm, and
the height of the cylindrical section is 40 cm. The thick-
ness of the side and the semi-spherical top walls is t, and
the thickness of the flat bottom is 1.5t. Determine t if the
mass of the tank is 27.5 kg. The density of aluminum is
2.7 g/cm3.
11. A 24 ft–long rod is cut into 12 pieces, which are welded
together to form the frame of a rectangular box. The
length of the box's base is three times its width.
(a) Create a polynomial expression for the volume V in
terms of x.
(b) Make a plot of V versus x.
(c) Determine the x that maximizes the volume and
determine that volume.
x 1.4+ x 0.4– x x 0.6+ x 1.4–
1.5– x 1.5
0.6x5– 7.7x3 8x2– 24.6x– 48+ +
0.6x3– 4.1x 8–+
x4 6x3– 13x2 12x– 4+ +
x3 3x2– 2+
50 in.
30 in.
t
40 cm
12.5 cm
x3x
h
299.
288 Chapter 8: Polynomials, Curve Fitting, and Interpolation
12. A rectangular piece of cardboard, 40 inches
long by 22 inches wide, is used for making a
rectangular box (open top) by cutting out
squares of x by x from the corners and folding
up the sides.
(a) Create a polynomial expression for the vol-
ume V in terms of x.
(b) Make a plot of V versus x.
(c) Determine x if the volume of the box is
1,000 in.3
.
(d) Determine the value of x that corresponds to the box with the largest pos-
sible volume, and determine that volume.
13. Write a user-defined function that adds or subtracts two polynomials of any
order. Name the function p=polyadd(p1,p2,operation). The first
two input arguments p1 and p2 are the vectors of the coefficients of the two
polynomials. (If the two polynomials are not of the same order, the function
adds the necessary zero elements to the shorter vector.) The third input argu-
ment operation is a string that can be either 'add' or 'sub', for adding
or subtracting the polynomials, respectively, and the output argument is the
resulting polynomial.
Use the function to add and subtract the following polynomials:
and .
14. Write a user-defined function that multiplies two polynomials. Name the
function p=polymult(p1,p2). The two input arguments p1 and p2 are
vectors of the coefficients of the two polynomials. The output argument p is
the resulting polynomial.
Use the function to multiply the following polynomials:
and .
Check the answer with MATLAB's built-in function conv.
15. Write a user-defined function that calculates the maximum (or minimum) of a
quadratic equation of the form:
Name the function [x,y,w] = maxormin(a,b,c). The input arguments are
the coefficients a, b, and c. The output arguments are x, the coordinate of the
maximum (or minimum); y, the maximum (or minimum) value; and w, which
is equal to 1 if y is a maximum and equal to 2 if y is a minimum.
Use the function to determine the maximum or minimum of the following
functions:
(a) (b)
40 in.
22 in.
x
x
L
W
H
f1 x x5 7x4– 11x3 4x2– 5x– 2–+= f2 x 9x2 10x– 6+=
f1 x x5 7x4– 11x3 4x2– 5x– 2–+= f2 x 9x2 10x– 6+=
f x ax2 bx c+ +=
f x 3x2 7x– 14+= f x 5x2– 11x– 15+=
300.
8.6 Problems 289
16. A cylinder of radius r and height h is constructed
inside a cone with base radius in. and
height in., as shown in the figure.
(a) Create a polynomial expression for the vol-
ume V of the cylinder in terms of r.
(b) Make a plot of V versus r.
(c) Determine r if the volume of the cylinder is
800 in.3
.
(d) Determine the value of r that corresponds to
the cylinder with the largest possible volume,
and determine that volume.
17. Consider the parabola and the
point .
(a) Create a polynomial expression for the distance
d from point P to an arbitrary point Q on the
parabola.
(b) Make a plot of d versus x for .
(c) Determine the coordinates of Q if .
(d) Determine the coordinates of Q that correspond
to the smallest d, and calculate the correspond-
ing value of d.
18. The boiling temperature of water at various alti-
tudes h is given in the following table. Determine a linear equation in the form
that best fits the data. Use the equation for calculating the
boiling temperature at 16,000 ft. Make a plot of the points and the equa-
tion.
19. The number of bacteria measured at different times t is given in the fol-
lowing table. Determine an exponential function in the form that
best fits the data. Use the equation to estimate the number of bacteria after
60 min. Make a plot of the points and the equation.
h (ft) 0 2000 5000 7500 10000 20000 26000
T ( F ) 212 210 203 198 194 178 168
t (min) 10 20 30 40 50
NB 15,000 215,000 335,000 480,000 770,000
r
R
H
R 10=
H 30=
2 4
2
4
6
d
P (3, 5.5)
Q
x
yy 1.5 x 5– 2 1+=
P 3 5.5
3 x 6
d 28=
TB
TB mh b+=
NB
NB Ne t=
301.
290 Chapter 8: Polynomials, Curve Fitting, and Interpolation
20. The van der Waals equation gives a relationship between the pressure p (in
atm), volume V (in L), and temperature T (in K) for a real gas:
where n is the number of moles, (L atm)/(mol K) is the gas con-
stant, and a (in L2
atm/mol2
), and b (in L/mol) are material constants. The
equation can be easily used for calculating p (given T and V) or T (given p and
V). The equation is not as readily solved for V when p and T are given, since it
is nonlinear in V. One useful way to solve for V is by rewriting the equation as
a third-order polynomial
and calculating the root of the polynomial.
Write a user-defined function that calculates V for given p, T, n, a, and b.
For function name and arguments use V=waals(p,T,n,a,b). The func-
tion calculates V by using MATLAB's built-in function roots. Note that the
solution of the polynomial can have non-real (complex) roots. The output
argument V in waals should be the physically realistic solution (positive and
real). (MATLAB's built-in function imag(x) can be used for determining
which root is real.)
Use the user-defined function to calculate V for atm, K,
, L2
atm/mol2
, L/mol.
21. The population of the world for selected years from 1750 to 2009 is given in
the following table:
(a) Determine the exponential function that best fits the data. Use the func-
tion to estimate the population in 1980. Make a plot of the points and the
function.
(b) Curve-fit the data with a third-order polynomial. Use the polynomial to
estimate the population in 1980. Make a plot of the points and the polyno-
mial.
(c) Fit the data with linear and spline interpolations. Estimate the population
in 1975 with linear and spline interpolations. Make a plot of the data
points and curves made of the interpolated points.
In each part make a plot of the data points (circle markers) and the fit curve or
the interpolation curves. Note that part (c) has two interpolation curves.
The actual population of the world in 1980 was 4453.8 million.
Year 1750 1800 1850 1900 1950 1990 2000 2009
Population
(millions)
791 980 1,260 1,650 2,520 5,270 6,060 6,800
p
nRT
V nb–
----------------
n2a
V2
--------–=
R 0.08206=
V
3
nb
nRT
p
----------+ V
2
–
n2a
p
--------V
n3ab
p
------------–+ 0=
p 30= T 300=
n 1.5= a 1.345= b 0.0322=
302.
8.6 Problems 291
22. The following points are given:
(a) Fit the data with a first-order polynomial. Make a plot of the points and
the polynomial.
(b) Fit the data with a second-order polynomial. Make a plot of the points and
the polynomial.
(c) Fit the data with a fourth-order polynomial. Make a plot of the points and
the polynomial.
(d) Fit the data with an eight-order polynomial. Make a plot of the points and
the polynomial.
23. The standard air density, D (average of measurements made), at different
heights, h, from sea level up to a height of 33 km is given below.
(a) Make the following four plots of the data points (density as a function of
height): (1) both axes with linear scale; (2) h with log axis, D with linear
axis; (3) h with linear axis, D with log axis; (4) both log axes. According
to the plots choose a function (linear, power, exponential, or logarithmic)
that best fits the data points and determine the coefficients of the function.
(b) Plot the function and the points using linear axes.
24. Write a user-defined function that fits data points to a power function of the
form . Name the function [b,m] = powerfit(x,y), where the
input arguments x and y are vectors with the coordinates of the data points,
and the output arguments b and m are the constants of the fitted exponential
equation. Use powerfit to fit the data below. Make a plot that shows the
data points and the function.
x –5 –3.4 –2.0 –0.8 0 1.2 2.5 4 5.0 7 8.5
y 4.4 4.5 4 3.6 3.9 3.8 3.5 2.5 1.2 0.5 -0.2
h (km) 0 3 6 9 12 15
D (kg/m3
) 1.2 0.91 0.66 0.47 0.31 0.19
h (km) 18 21 24 27 30 33
D (kg/m3) 0.12 0.075 0.046 0.029 0.018 0.011
x 0.5 2.4 3.2 4.9 6.5 7.8
y 0.8 9.3 37.9 68.2 155 198
y bxm=
303.
292 Chapter 8: Polynomials, Curve Fitting, and Interpolation
25. The aerodynamic drag force that is
applied to a car is given by:
where kg/m3 is the air density,
is the drag coefficient, A is the pro-
jected front area of the car, and v is the speed of the car (in units of m/s) rela-
tive to the wind. The product characterizes the air resistance of a car. (At
speeds above 70 km/h the aerodynamic drag force is typically more than half
of the total resistance to motion.) Data obtained in a wind tunnel test is dis-
played in the table. Use the data to determine the product for the tested
car using curve fitting. Make a plot of the data points and the curve-fitted
equation.
26. Viscosity is a property of gases and fluids that characterizes their resistance to
flow. For most materials viscosity is highly sensitive to temperature. For
gases, the variation of viscosity with temperature is frequently modeled by an
equation of the form
where is the viscosity, T is the absolute temperature, and C and S are empiri-
cal constants. Below is a table that gives the viscosity of air at different tem-
peratures (data from B.R. Munson, D.F. Young, and T.H. Okiishi,
Fundamentals of Fluid Mechanics, 4th ed., John Wiley and Sons, 2002).
Determine the constants C and S by curve-fitting the equation to the data
points. Make a plot of viscosity versus temperature (in C). In the plot show
the data points with markers and the curve-fitted equation with a solid line.
The curve fitting can be done by rewriting the equation in the form
and using a first-order polynomial.
v (km/h) 20 40 60 80 100 120 140 160
(N) 10 50 109 180 300 420 565 771
T ( C) –20 0 40 100 200 300 400 500 1,000
(N s/m2)
( )
1.63 1.71 1.87 2.17 2.53 2.98 3.32 3.64 5.04
FD
FD
1
2
--- CDAv2=
1.2=
CD
CDA
CDA
FD
CT
3 2
T S+
--------------=
5–
10
T
3 2
----------
1
C
----T
S
C
----+=
304.
8.6 Problems 293
27.Measurements of the fuel efficiency of a car FE at various speeds v are shown
in the table.
(a) Curve-fit the data with a second-order polynomial. Use the polynomial to
estimate the fuel efficiency at 60 mi/h. Make a plot of the points and the poly-
nomial.
(b) Curve-fit the data with a third-order polynomial. Use the polynomial to
estimate the fuel efficiency at 60 mi/h. Make a plot of the points and the poly-
nomial.
(c) Fit the data with linear and spline interpolations. Estimate the fuel effi-
ciency at 60 mi/h with linear and spline interpolations. Make a plot that shows
the data points and curves made of interpolated points.
28. The relationship between two variables P and t is known to be:
The following data points are given
Determine the constants m and b by curve-fitting the equation to the data
points. Make a plot of P versus t. In the plot show the data points with markers
and the curve-fitted equation with a solid line. (The curve fitting can be done
by writing the reciprocal of the equation and using a first-order polynomial.)
29. The yield strength, y, of many metals depends on the size of the grains. For
these metals the relationship between the yield stress and the average grain
diameter d can be modeled by the Hall-Petch equation:
The following are results from measurements of average grain diameter
and yield stress.
(a) Using curve fitting, determine the constants 0 and k in the Hall-Petch
equation for this material. Using the constants determine with the equa-
tion the yield stress of material with a grain size of 0.05 mm. Make a plot
that shows the data points with circle markers and the curve derived from
the Hall-Petch equation with a solid line.
v (mi/h) 5 15 25 35 45 55 65 75
FE (mpg) 11 22 28 29.5 30 30 27 23
t 1 3 4 7 8 10
P 2.1 4.6 5.4 6.1 6.4 6.6
d (mm) 0.005 0.009 0.016 0.025 0.040 0.062 0.085 0.110
y (MPa) 205 150 135 97 89 80 70 67
P
mt
b t+
-----------=
y 0 kd
1–
2
------
+=
305.
294 Chapter 8: Polynomials, Curve Fitting, and Interpolation
(b) Use linear interpolation to determine the yield stress of material with a
grain size of 0.05 mm. Make a plot that shows the data points with circle
markers and the linear interpolation with a solid line.
(c) Use cubic interpolation to determine the yield stress of material with a
grain size of 0.05 mm. Make a plot that shows the data points with circle
markers and cubic interpolation with a solid line.
30. The stress concentration factor k is the
ratio between the maximum stress
and the average stress ,
. For a stepped shaft
loaded in torsion, with dimensions as
shown in the figure, k is a function of and the maximum stress is at the
rounded corner. The average stress is given by , where T
is the applied torque. The stress concentration factors measured in tests using
shafts with and various ratios of are given in the table.
(a) Use an power function to model the relationship between k
and . Determine the values of b and m that best-fit the data.
(b) Plot the data points and the curve-fitted model.
(c) Use the model to predict the stress concentration factor for .
31. The ideal gas equation relates the volume, pressure, temperature, and the
quantity of a gas by:
where V is the volume in liters, P is the pressure in atm, T is the temperature in
kelvins, n is the number of moles, and R is the gas constant.
An experiment is conducted for determining the value of the gas constant
R. In the experiment 0.05 mol of gas is compressed to different volumes by
applying pressure to the gas. At each volume the pressure and temperature of
the gas are recorded. Using the data given below, determine R by plotting V
versus T/P and fitting the data points with a linear equation.
r/d 0.3 0.26 0.22 0.18 0.14 0.1 0.06 0.02
k 1.18 1.19 1.21 1.26 1.32 1.43 1.6 1.98
V (L) 0.75 0.65 0.55 0.45 0.35
T ( C) 25 37 45 56 65
P (atm) 1.63 1.96 2.37 3.00 3.96
dD
r
T Tmax
ave
k max ave=
r d
ave 16T d3=
d D 2= r d
k b r d m=
r d
r d 0.04=
V
nRT
P
----------=
306.
295
Chapter 9
Applications in
Numerical Analysis
Numerical methods are commonly used for solving mathematical problems that
are formulated in science and engineering where it is difficult or impossible to
obtain exact solutions. MATLAB has a large library of functions for numerically
solving a wide variety of mathematical problems. This chapter explains a number
of the most frequently used of these functions. It should be pointed out here that
the purpose of this book is to show users how to use MATLAB. Some general
information on the numerical methods is given, but the details, which can be
found in books on numerical analysis, are not included.
The following topics are presented in this chapter: solving an equation with
one unknown, finding a minimum or a maximum of a function, numerical integra-
tion, and solving a first-order ordinary differential equation.
9.1 SOLVING AN EQUATION WITH ONE VARIABLE
An equation with one variable can be written in the form . A solution to
the equation (also called a root) is a numerical value of x that satisfies the equa-
tion. Graphically, a solution is a point where the function crosses or touches
the x axis. An exact solution is a value of x for which the value of the function is
exactly zero. If such a value does not exist or is difficult to determine, a numerical
solution can be determined by finding an x that is very close to the solution. This
is done by the iterative process, where in each iteration the computer determines a
value of x that is closer to the solution. The iterations stop when the difference in x
between two iterations is smaller than some measure. In general, a function can
have zero, one, several, or an infinite number of solutions.
f x 0=
f x
307.
296 Chapter 9: Applications in Numerical Analysis
In MATLAB a zero of a function can be determined with the command
(built-in function) fzero with the form:
The built-in function fzero is a MATLAB function function (see Section 7.9),
which means that it accepts another function (the function to be solved) as an
input argument.
Additional details on the arguments of fzero:
• x is the solution, which is a scalar.
• function is the function to be solved. It can be entered in several different
ways:
1. The simplest way is to enter the mathematical expression as a string.
2. The function is created as a user-defined function in a function file and
then the function handle is entered (see Section 7.9.1).
3. The function is created as an anonymous function (see Section 7.8.1)
and then the name of the anonymous function (which is the name of the
handle) is entered (see Section 7.9.1).
(As explained in Section 7.9.2, it is also possible to pass a user-defined func-
tion and an inline function into a function function by using its name. How-
ever, function handles are more efficient and easier to use, and should be the
preferred method.)
• The function has to be written in a standard form. For example, if the function
to be solved is , it has to be written as . If this
function is entered into the fzero command as a string, it is typed as:
'x*exp(-x)-0.2'.
• When a function is entered as an expression (string), it cannot include pre-
defined variables. For example, if the function to be entered is
, it is not possible to define b=0.2 and then enter
'x*exp(-x)-b'.
• x0 can be a scalar or a two-element vector. If it is entered as a scalar, it has to
be a value of x near the point where the function crosses (or touches) the x axis.
If x0 is entered as a vector, the two elements have to be points on opposite
sides of the solution. If crosses the x axis, then has a different
sign than . When a function has more than one solution, each solution
can be determined separately by using the fzero function and entering values
for x0 that are near each of the solutions.
x = fzero(function,x0)
Solution The function to
be solved.
A value of x close to where
the function crosses the axis.
xe
x–
0.2= f x xe
x–
0.2– 0= =
f x xe
x–
0.2–=
f x f x0 1
f x0 2
308.
9.1 Solving an Equation with One Variable 297
• A good way to find approximately where a function has a solution is to make a
plot of the function. In many applications in science and engineering the
domain of the solution can be estimated. Often when a function has more than
one solution only one of the solutions will have a physical meaning.
Sample Problem 9-1: Solving a nonlinear equation
Determine the solution of the equation .
Solution
The equation is first written in the form of a
function: . A plot of the func-
tion, shown on the right, shows that the func-
tion has one solution between 0 and 1 and
another solution between 2 and 3. The plot is
obtained by typing
in the Command Window. The solutions of the function are found by using the
fzero command twice. First the equation is entered as a string expression, and a
value of x0 between 0 and 1 (x0 = 0.7) is used. Second, the equation to be solved
is written as an anonymous function, which is then used in fzero with x0
between 2 and 3 (x0 = 2.8). This is shown below:
Additional comments:
• The fzero command finds zeros of a function only where the function
crosses the x axis. The command does not find a zero at points where the func-
tion touches but does not cross the x axis.
• If a solution cannot be determined, NaN is assigned to x.
>> fplot('x*exp(-x)-0.2',[0 8])
>> x1=fzero('x*exp(-x)-0.2',0.7)
x1 =
0.2592
>> F=@(x)x*exp(-x)-0.2
F =
@(x)x*exp(-x)-0.2
>> fzero(F,2.8)
ans =
2.5426
xe
x–
0.2=
0 1 2 3 4 5 6 7 8
-0.2
-0.1
0
0.1
0.2
x
y
f x xe
x–
0.2–=
The function is entered as a
string expression.
The first solution is 0.2592.
Creating an anonymous function.
Using the name of the anonymous function in fzero.
The second solution is 2.5426.
309.
298 Chapter 9: Applications in Numerical Analysis
• The fzero command has additional options (see the Help Window). Two of
the more important options are:
[x fval]=fzero(function, x0) assigns the value of the function at x to
the variable fval.
x=fzero(function, x0, optimset('display','iter')) displays the
output of each iteration during the process of finding the solution.
• When the function can be written in the form of a polynomial, the solution, or
the roots, can be found with the roots command, as explained in Chapter 8
(Section 8.1.2).
• The fzero command can also be used to find the value of x where the function
has a specific value. This is done by translating the function up or down. For
example, in the function of Sample Problem 9-1 the first value of x where the
function is equal to 0.1 can be determined by solving the equation
. This is shown below:
9.2 FINDING A MINIMUM OR A MAXIMUM OF A FUNCTION
In many applications there is a need to determine the local minimum or maximum
of a function of the form . In calculus the value of x that corresponds to a
local minimum or maximum is determined by finding the zero of the derivative of
the function. The value of y is determined by substituting the x into the function.
In MATLAB the value of x where a one-variable function within the interval
has a minimum can be determined with the fminbnd command which
has the form:
• The function can be entered as a string expression, or as a function handle, in
the same way as with the fzero command. See Section 9.1 for details.
• The value of the function at the minimum can be added to the output by using
the option
[x fval]=fminbnd(function,x1,x2)
where the value of the function at x is assigned to the variable fval.
• Within a given interval, the minimum of a function can either be at one of the
end points of the interval or at a point within the interval where the slope of the
>> x=fzero('x*exp(-x)-0.3',0.5)
x =
0.4894
xe
x–
0.3– 0=
y f x=
f x
x1 x x2
x = fminbnd(function,x1,x2)
The value of x where the
function has a minimum.
The function. The interval of x.
310.
9.2 Finding a Minimum or a Maximum of a Function 299
function is zero (local minimum). When the fminbnd command is executed,
MATLAB looks for a local minimum. If a local minimum is found, its value is
compared to the value of the function at the end points of the interval. MAT-
LAB returns the point with the actual minimum value for the interval.
For example, consider the function
, which is plot-
ted in the interval in the figure on the
right. It can be observed that there is a local
minimum between 5 and 6, and that the abso-
lute minimum is at . Using the fminbnd
command with the interval to find the
location of the local minimum and the value of
the function at this point gives:
Notice that the fminbnd command gives the local minimum. If the interval is
changed to , fminbnd gives:
For this interval the fminbnd command gives the absolute minimum which is at
the end point .
• The fminbnd command can also be used to find the maximum of a function.
This is done by multiplying the function by –1 and finding the minimum. For
example, the maximum of the function (from Sample Prob-
lem 9-1) in the interval can be determined by finding the minimum of
the function as shown below:
>> [x fval]=fminbnd('x^3-12*x^2+40.25*x-36.5',3,8)
x =
5.6073
fval =
-11.8043
>> [x fval]=fminbnd('x^3-12*x^2+40.25*x-36.5',0,8)
x =
0
fval =
-36.5000
>> [x fval]=fminbnd('-x*exp(-x)+0.2',0,8)
x =
1.0000
fval =
-0.1679
0 1 2 3 4 5 6 7 8
-40
-30
-20
-10
0
10
20
30
x
f(x)
f x x3 12x2– 40.25x 36.5–+=
0 x 8
x 0=
3 x 8
The local minimum is at . The
value of the function at this point is –11.8043.
x 5.6073=
0 x 8
The minimum is at . The value
of the function at this point is –36.5.
x 0=
x 0=
f x xe
x–
0.2–=
0 x 8
f x xe
x–
– 0.2+=
The maximum is at x = 1.0. The value of
the function at this point is 0.1679.
311.
300 Chapter 9: Applications in Numerical Analysis
9.3 NUMERICAL INTEGRATION
Integration is a common mathematical operation in science and engineering. Cal-
culating area and volume, velocity from acceleration, and work from force and
displacement are just a few examples where integrals are used. Integration of sim-
ple functions can be done analytically, but more involved functions are frequently
difficult or impossible to integrate analytically. In calculus courses the integrand
(the quantity to be integrated) is usually a function. In applications of science and
engineering the integrand can be a function or a set of data points. For example,
data points from discrete measurements of flow velocity can be used to calculate
volume.
It is assumed in the presentation below that the reader has knowledge of
integrals and integration. A definite integral of a function from a to b has the
form:
The function is called the integrand, and the
numbers a and b are the limits of integration.
Graphically, the value of the integral q is the area
between the graph of the function, the x axis, and
the limits a and b (the shaded area in the figure).
When a definite integral is calculated analytically
is always a function. When the integral is calculated numerically can be
a function or a set of points. In numerical integration the total area is obtained by
dividing the area into small sections, calculating the area of each section, and add-
ing them up. Various numerical methods have been developed for this purpose.
The difference between the methods is in the way that the area is divided into sec-
tions and the method by which the area of each section is calculated. Books on
numerical analysis include details of the numerical techniques.
The following discussion describes how to use the three MATLAB built-in
integration functions quad, quadl, and trapz. The quad and quadl com-
mands are used for integration when is a function, and trapz is used when
is given by data points.
The quad command:
The form of the quad command, which uses the adaptive Simpson method of
integration, is:
f x
q f x xd
a
b
=
f x
f x f x
f x
f x
q = quad(function,a,b)
The value of the integral. The function to
be integrated.
The integration limits.
312.
9.3 Numerical Integration 301
• The function can be entered as a string expression or as a function handle, in
the same way as with the fzero command. See Section 9.1 for details. The
first two methods are demonstrated in Sample Problem 9-2.
• The function must be written for an argument x that is a vector (use
element-by-element operations) such that it calculates the value of the function
for each element of x.
• The user has to make sure that the function does not have a vertical asymptote
between a and b.
• quad calculates the integral with an absolute error that is smaller than 1.0e–6.
This number can be changed by adding an optional tol argument to the com-
mand:
q = quad('function',a,b,tol)
tol is a number that defines the maximum error. With larger tol the integral
is calculated less accurately but faster.
The quadl command:
The form of the quadl (the last letter is a lowercase L) command is exactly the
same as that of the quad command:
All of the comments that are listed for the quad command are valid for the
quadl command. The difference between the two commands is the numerical
method used for calculating the integration. The quadl command uses the adap-
tive Lobatto method, which can be more efficient for high accuracies and smooth
integrals.
Sample Problem 9-2: Numerical integration of a function
Use numerical integration to calculate the following integral:
f x
q = quadl(function,a,b)
The value of the integral. The function to
be integrated.
The integration limits.
xe
x0.8–
0.2+ xd
0
8
313.
302 Chapter 9: Applications in Numerical Analysis
Solution
For illustration, a plot of the function for the
interval is shown on the right. The
solution uses the quad command and shows
how to enter the function in the command in
two ways. In the first, it is entered directly by
typing the expression as an argument. In the
second, an anonymous function is created and
its name is subsequently entered in the com-
mand.
The use of the quad command in the Command Window, with the function
to be integrated typed in as a string, is shown below. Note that the function is
typed with element-by-element operations.
The second method is to first create a user-defined function that calculates
the function to be integrated. The function file (named y=Chap9Sam2(x)) is:
Note again that the function is written with element-by-element operations such
that the argument x can be a vector. The integration is then done in the Command
Window by typing the handle @Chap9Sam2 for the argument function in the
quad command as shown below:
The trapz command:
The trapz command can be used for integrating a function that is given as data
points. It uses the numerical trapezoidal method of integration. The form of the
command is
where x and y are vectors with the x and y coordinates of the points, respectively.
The two vectors must be of the same length.
>> quad('x.*exp(-x.^0.8)+0.2',0,8)
ans =
3.1604
function y=Chap9Sam2(x)
y=x.*exp(-x.^0.8)+0.2;
>> q=quad(@Chap9Sam2,0,8)
q =
3.1604
0 x 8
q = trapz(x,y)
314.
9.4 Ordinary Differential Equations 303
9.4 ORDINARY DIFFERENTIAL EQUATIONS
Differential equations play a crucial role in science and engineering since they are
in the foundation of virtually every physical phenomenon that is involved in engi-
neering applications. Only a limited number of differential equations can be
solved analytically. Numerical methods, on the other hand, can result in an
approximate solution to almost any equation. Obtaining a numerical solution
might not be simple task however. This is because a numerical method that can
solve any equation does not exist. Instead, there are many methods that are suit-
able for solving different types of equations. MATLAB has a large library of tools
that can be used for solving differential equations. To fully utilize the power of
MATLAB, however, requires that the user have knowledge of differential equa-
tions and the various numerical methods that can be used for solving them.
This section describes in detail how to use MATLAB to solve a first-order
ordinary differential equation. The possible numerical methods that can be used
for solving such an equation are described in general terms, but are not explained
from a mathematical point of view. This section provides information for solving
simple, "nonproblematic" first-order equations. This solution provides the basis
for solving higher-order equations and systems of equations.
An ordinary differential equation (ODE) is an equation that contains an
independent variable, a dependent variable, and derivatives of the dependent vari-
able. The equations that are considered here are of first order with the form
where x and y are the independent and dependent variables, respectively. A solu-
tion is a function that satisfies the equation. In general, many functions
can satisfy a given ODE, and more information is required for determining the
solution of a specific problem. The additional information is the value of the func-
tion (the dependent variable) at some value of the independent variable.
Steps for solving a single first-order ODE:
For the remainder of this section the independent variable is taken as t (time). This
is done because in many applications time is the independent variable, and also to
be consistent with the information in the Help menu of MATLAB.
Step 1: Write the problem in a standard form.
Write the equation in the form:
for , with at .
As shown above, three pieces of information are needed for solving a first order
ODE: An equation that gives an expression for the derivative of y with respect to t,
the interval of the independent variable, and the initial value of y. The solution is
the value of y as a function of t between and .
dy
dx
------ f x y=
y f x=
dy
dt
------ f t y= t0 t tf y y0= t t0=
t0 tf
315.
304 Chapter 9: Applications in Numerical Analysis
An example of a problem to solve is:
for with at .
Step 2: Create a user-defined function (in a function file) or an anonymous
function.
The ODE to be solved has to be written as a user-defined function (in a function
file) or as an anonymous function. Both calculate for given values of t and y.
For the example problem above, the user-defined function (which is saved as a
separate file) is:
When an anonymous function is used, it can be defined in the Command Window,
or be within a script file. For the example problem here the anonymous function
(named ode1) is:
Step 3: Select a method of solution.
Select the numerical method that you would like MATLAB to use in the solution.
Many numerical methods have been developed to solve first-order ODEs, and
several of the methods are available as built-in functions in MATLAB. In a typical
numerical method, the time interval is divided into small time steps. The solution
starts at the known point y0, and then by using one of the integration methods the
value of y is calculated at each time step. Table 9-1 lists seven ODE solver com-
mands, which are MATLAB built-in functions that can be used for solving a first-
order ODE. A short description of each solver is included in the table.
function dydt=ODEexp1(t,y)
dydt=(t^3-2*y)/t;
>> ode1=@(t,y)(t^3-2*y)/t
ode1 =
@(t,y)(t^3-2*y)/t
Table 9-1: MATLAB ODE Solvers
ODE Solver Name Description
ode45 For nonstiff problems, one-step solver, best to apply
as a first try for most problems. Based on explicit
Runge-Kutta method.
ode23 For nonstiff problems, one-step solver. Based on
explicit Runge-Kutta method. Often quicker but less
accurate than ode45.
ode113 For nonstiff problems, multistep solver.
dy
dt
------
t3 2y–
t
----------------= 1 t 3 y 4.2= t 1=
dy
dt
------
316.
9.4 Ordinary Differential Equations 305
In general, the solvers can be divided into two groups according to their
ability to solve stiff problems and according to whether they use on-step or multi-
step methods. Stiff problems are ones that include fast and slowly changing com-
ponents and require small time steps in their solution. One-step solvers use
information from one point to obtain a solution at the next point. Multistep solvers
use information from several previous points to find the solution at the next point.
The details of the different methods are beyond the scope of this book.
It is impossible to know ahead of time which solver is the most appropriate
for a specific problem. A suggestion is to first try ode45, which gives good
results for many problems. If a solution is not obtained because the problem is
stiff, trying the solver ode15s is suggested.
Step 4: Solve the ODE.
The form of the command that is used to solve an initial value ODE problem is the
same for all the solvers and for all the equations that are solved. The form is:
Additional information:
solver_name Is the name of the solver (numerical method) that is used (e.g.
ode45 or ode23s)
ODEfun The function from Step 2 that calculates for given values of
t and y. If it was written as a user-defined function, the function
handle is entered. If it was written as an anonymous function,
the name of the anonymous function is entered. (See the exam-
ple that follows.)
tspan A vector that specifies the interval of the solution. The vector
must have at least two elements but can have more. If the vector
has only two elements, the elements must be [t0 tf], which
are the initial and final points of the solution interval. The
ode15s For stiff problems, multistep solver. Use if ode45
failed. Uses a variable order method.
ode23s For stiff problems, one-step solver. Can solve some
problems that ode15s cannot.
ode23t For moderately stiff problems.
ode23tb For stiff problems. Often more efficient than
ode15s.
Table 9-1: MATLAB ODE Solvers (Continued)
ODE Solver Name Description
[t,y] = solver_name(ODEfun,tspan,y0)
dy
dt
------
317.
306 Chapter 9: Applications in Numerical Analysis
vector tspan can have, however, additional points between the
first and last points. The number of elements in tspan affects
the output from the command. See [t,y] below.
y0 The initial value of y (the value of y at the first point of the
interval).
[t,y] The output, which is the solution of the ODE. t and y are col-
umn vectors. The first and the last points are the beginning and
end points of the interval. The spacing and number of points in
between depends on the input vector tspan. If tspan has two
elements (the beginning and end points), the vectors t and y
contain the solution at every integration step calculated by the
solver. If tspan has more than two points (additional points
between the first and the last), the vectors t and y contain the
solution only at these points. The number of points in tspan
does not affect the time steps used for the solution by the pro-
gram.
For example, consider the solution to the problem stated in Step 1:
for with at ,
If the ODE function is written as a user-defined function (see Step 2), then the
solution with MATLAB's built-in function ode45 is obtained by:
The solution is obtained with the solver ode45. The name of the user-defined
function from Step 2 is ODEexp1. The solution starts at and ends at
with increments of 0.5 (according to the vector tspan). To show the solution, the
problem is solved again below using tspan with smaller spacing, and the solution
>> [t y]=ode45(@ODEexp1,[1:0.5:3],4.2)
t =
1.0000
1.5000
2.0000
2.5000
3.0000
y =
4.2000
2.4528
2.6000
3.7650
5.8444
dy
dt
------
t3 2y–
t
----------------= 1 t 3 y 4.2= t 1=
The handle of the user-defined function ODEexp1.
The initial value.
The vector tspan.
t 1= t 3=
318.
9.5 Examples of MATLAB Applications 307
is plotted with the plot command.
If the ODE function is written as an anonymous function called ode1 (see Step
2), then the solution (same as shown above) is obtained by typing:
[t y]=ode45(ode1,[1:0.5:3],4.2).
9.5 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 9-3: The gas equation
The ideal gas equation relates the volume (V in L), temperature (T in K), pressure
(P in atm), and the amount of gas (number of moles n) by:
where R = 0.08206 (L atm)/(mol K) is the gas constant.
The van der Waals equation gives the relationship between these quantities
for a real gas by
where a and b are constants that are specific for each gas.
Use the fzero function to calculate the volume of 2 mol CO2 at temperature of
50 C, and pressure of 6 atm. For CO2, a = 3.59 (L2
atm)/mol2
, and b = 0.0427 L/
mol.
Solution
The solution written in a script file is shown below.
>> [t y]=ode45(@ODEexp1,[1:0.01:3],4.2);
>> plot(t,y)
>> xlabel('t'), ylabel('y')
global P T n a b R
1 1.5 2 2.5 3
2
2.5
3
3.5
4
4.5
5
5.5
6
t
y
p
nRT
V
----------=
P
n2a
V2
--------+ V nb– nRT=
319.
308 Chapter 9: Applications in Numerical Analysis
The program first calculates an estimated value of the volume using the ideal gas
equation. This value is then used in the fzero command for the estimate of the
solution. The van der Waals equation is written as a user-defined function named
Waals, which is shown below:
In order for the script and function files to work correctly, the variables P, T, n, a,
b, and R are declared global. When the script file (saved as Chap9SamPro3) is
executed in the Command Window, the value of V is displayed, as shown next:
Sample Problem 9-4: Maximum viewing angle
To get the best view of a movie, a person has to
sit at a distance x from the screen such that the
viewing angle is maximum. Determine the
distance x for which is maximum for the con-
figuration shown in the figure.
Solution
The problem is solved by writing a function
for the angle in terms of x, and then finding
the x for which the angle is maximum. In the
triangle that includes , one side is given (the
height of the screen), and the other two sides
can be written in terms of x, as shown in the
figure. One way in which can be written in terms of x is by using the Law of
Cosines:
R=0.08206;
P=6; T=323.2; n=2; a=3.59; b=0.047;
Vest=n*R*T/P;
V=fzero(@Waals,Vest)
function fofx=Waals(x)
global P T n a b R
fofx=(P+n^2*a/x^2)*(x-n*b)-n*R*T;
>> Chap9SamPro3
V =
8.6613
Calculating an estimated value for V.
Function handle @waals is used to pass the
user-defined function waals into fzero.
The volume of the gas is 8.6613 L.
x2 52+
x2 412+ 36
cos
x2 52+ x2 412+ 362–+
2 x2 52+ x2 412+
-------------------------------------------------------------------=
320.
9.5 Examples of MATLAB Applications 309
The angle is expected to be between 0 and
/2. Since and the cosine is
decreasing with increasing , the maximum
angle corresponds to the smallest cos( ). A
plot of as a function of x shows that the
function has a minimum between 10 and 20.
The commands for the plot are:
The minimum can be determined with the fminbnd command:
Sample Problem 9-5: Water flow in a river
To estimate the amount of water that flows in
a river during a year, a section of the river is
made to have a rectangular cross section as
shown. In the beginning of every month
(starting at January 1st) the height h of the
water and the speed v of the water flow are
measured. The first day of measurement is
taken as 1, and the last day—which is Janu-
ary 1st of the next year—is day 366. The following data was measured:
Use the data to calculate the flow rate, and then integrate the flow rate to obtain an
estimate of the total amount of water that flows in the river during a year.
>>fplot('((x^2+5^2)+(x^2+41^2)-36^2)/(2*sqrt(x^2+ 5^2)*sqrt(x^2+
41^2))',[0 25])
>> xlabel('x'); ylabel('cos(theta)')
>>[x anglecos]=fminbnd('((x^2+5^2)+(x^2+41^2)-36^2)/
(2*sqrt(x^2+5^2)*sqrt(x^2+41^2))',10,20)
x =
14.3178
anglecos =
0.6225
>> angle=anglecos*180/pi
angle =
35.6674
Day 1 32 60 91 121 152 182 213 244 274 305 335 366
h (m) 2.0 2.1 2.3 2.4 3.0 2.9 2.7 2.6 2.5 2.3 2.2 2.1 2.0
v (m/s) 2.0 2.2 2.5 2.7 5 4.7 4.1 3.8 3.7 2.8 2.5 2.3 2.0
0 5 10 15 20 25
0.6
0.65
0.7
0.75
0.8
0.85
0.9
0.95
1
x
cos()
0cos 1=
cosIn degrees the angle is 35.6674 .
321.
310 Chapter 9: Applications in Numerical Analysis
Solution
The flow rate, Q (volume of water per second), at each data point is obtained by
multiplying the water speed by the width and height of the cross-sectional area of
the water that flows in the channel:
(m3/s)
The total amount of water that flows is estimated by the integral:
The flow rate is given in cubic meters per second, which means that time must
have units of seconds. Since the data is given in terms of days, the integral is mul-
tiplied by s/day.
The following is a program written in a script file that first calculates Q and
then carries out the integration using the trapz command. The program also
generates a plot of the flow rate versus time.
When the file (saved as Chap9SamPro5) is executed in the Command Window,
the estimated amount of water is displayed and the plot is generated. Both are
shown below:.
w=8;
d=[1 32 60 91 121 152 182 213 244 274 305 335 366];
h=[2 2.1 2.3 2.4 3.0 2.9 2.7 2.6 2.5 2.3 2.2 2.1 2.0];
speed=[2 2.2 2.5 2.7 5 4.7 4.1 3.8 3.7 2.8 2.5 2.3 2];
Q=speed.*w.*h;
Vol=60*60*24*trapz(d,Q);
fprintf('The estimated amount of water that flows in the
river in a year is %g cubic meters.',Vol)
plot(d,Q)
xlabel('Day'), ylabel('Flow Rate (m^3/s)')
>> Chap9SamPro5
The estimated amount of water that flows in the river in a
year is 2.03095e+009 cubic meters.
Q vwh=
V 60 60 24 Q td
t1
t2
=
60 60 24
322.
9.5 Examples of MATLAB Applications 311
Sample Problem 9-6: Car crash into a safety bumper
A safety bumper is placed at the end of a
racetrack to stop out-of-control cars. The
bumper is designed such that the force that
the bumper applies to the car is a function
of the velocity v and the displacement x of
the front edge of the bumper according to the equation:
where K = 30 (s kg)/m5 is a constant.
A car with a mass m of 1,500 kg hits the bumper at a speed of 90 km/h.
Determine and plot the velocity of the car as a function of its position for
m.
Solution
The deceleration of the car once it hits the bumper can be calculated from New-
ton's second law of motion,
which can be solved for the acceleration a as a function of v and x:
The velocity as a function of x can be calculated by substituting the acceleration in
the equation
which gives
The last equation is a first-order ODE that needs to be solved for the interval
with the initial condition km/h at .
A numerical solution of the differential equation with MATLAB is shown in
0 50 100 150 200 250 300 350 400
30
40
50
60
70
80
90
100
110
120
Day
FlowRate(m3
/s)
F Kv3 x 1+
3
=
0 x 3
ma Kv3 x 1+
3
–=
a
Kv3 x 1+
3
–
m
--------------------------------=
vdv adx=
dv
dx
------
Kv2 x 1+
3
–
m
--------------------------------=
0 x 3 v 90= x 0=
323.
312 Chapter 9: Applications in Numerical Analysis
the following program, which is written in a script file:
Note that the function handle @bumper is used for passing the user-defined func-
tion bumper into ode45. The listing of the user-defined function with the differ-
ential equation, named bumper, is:
When the script file executes (saved as Chap9SamPro6) the vectors x and v are
displayed in the Command Window (actually, they are displayed on the screen
one after the other, but to save room they are displayed below next to each other).
global k m
k=30; m=1500; v0=90;
xspan=[0:0.2:3];
v0mps=v0*1000/3600;
[x v]=ode45(@bumper,xspan,v0mps)
plot(x,v)
xlabel('x (m)'); ylabel('velocity (m/s)')
function dvdx=bumper(x,v)
global k m
dvdx=-(k*v^2*(x+1)^3)/m;
>> Chap9SamPro6
x =
0
v =
25.0000
0.2000 22.0420
0.4000 18.4478
0.6000 14.7561
0.8000 11.4302
1.0000 8.6954
1.2000 6.5733
1.4000 4.9793
1.6000 3.7960
1.8000 2.9220
2.0000 2.2737
2.2000 1.7886
2.4000 1.4226
2.6000 1.1435
2.8000 0.9283
A vector that specifies the interval of the solution.
Changing the units of v0 to m/s.
Solving the ODE.
324.
9.6 Problems 313
The plot generated by the program of the velocity as a function of distance is:
9.6 PROBLEMS
1. Determine the solution of the equation .
2. Determine the solution of the equation .
3. Determine the three positive roots of the equation .
4. Determine the positive roots of the equation .
5. A block of mass kg is being pulled
by a cable as shown. The force that is
required to move the box is given by:
where m, is the friction
coefficient, and m/s2. Determine
the distance x when the pulling force is equal to 230 N.
6. A scale is made of two springs, as
shown in the figure. The springs
are nonlinear such that the force
they apply is given by
, where the K's
are constants and is the
elongation of the spring ( and are the cur-
rent and initial lengths of the springs, respectively). Initially, the springs are
3.0000 0.7607
0 0.5 1 1.5 2 2.5 3
0
5
10
15
20
25
x (m)
velocity(m/s)
e0.5x x– 3=
3 3 xsin+ 0.5x3=
x3 8x2– 17x x+ + 10=
x2 5x 3xsin– 3+ 0=
F
m
x
h
15o
m 20=
F
mg 15cos mg 15sin+ x2 h2+
x h+
---------------------------------------------------------------------------------------=
h 8= 0.45=
g 9.81=
W
x
K
a
b K
KK
FS K1u K2u3+=
u L L0–=
L a
2
b x+
2
+= L0 a
2
b
2
+=
325.
314 Chapter 9: Applications in Numerical Analysis
not stretched. When an object is attached to the ring, the springs stretch and
the ring is displaced downward a distance x. The weight of the object can be
expressed in terms of the distance x by:
For the given scale m, m, and the springs' constants are
N/m and N/m3
. Plot W as a function of x for
. Determine the distance x when a 400 N object is attached to the
scale.
7. An estimate of the minimum velocity required for a round flat stone to skip
when it hits the water is given by (Lyderic Bocquet, "The Physics of Stone
Skipping," Am. J. Phys., vol. 71, no. 2, February 2003)
where M and d are the stone mass and diameter, is the water density, C is a
coefficient, is the tilt angle of the stone, is the incidence angle, and
m/s2
. Determine d if m/s. (Assume that kg, ,
kg/m3
, and .)
8. The diode in the circuit shown is forward
biased. The current I flowing through the
diode is given by:
where is the voltage drop across the
diode, T is the temperature in kelvins,
A is the saturation current,
coulombs is the elementary charge value, and
joule/K is Boltzmann's constant. The current I flowing
through the circuit (the same as the current in the diode) is given also by:
Determine if V, K, and . (Substitute I from
one equation into the other equation and solve the resulting nonlinear equa-
tion.)
W 2 FS
b x+
L
----------------=
a 0.22= b 0.08=
K1 1600= K2 100000=
0 x 0.25
V
16Mg
C wd2
--------------------
1 8Mtan2
d3C w sin
-------------------------------–
--------------------------------------------=
w
g 9.81= V 0.8= M 0.1= C 1=
w 1000= 10= =
Rvs
+
_
D
vD
I
I IS e
qvD
kT
---------
1–=
vD
IS 10
12–
=
q 1.6 10
19–
=
k 1.38 10
23–
=
I
vS vD–
R
----------------=
vD vS 2= T 297= R 1000=
326.
9.6 Problems 315
9. Determine the minimum and the maximum of the function
.
10. A paper cup shaped as a cone is designed to have a vol-
ume of 250 cm3
. Determine the radius and height h
such that the least amount of paper will be used for mak-
ing the cup.
11. Consider again the block that is being pulled in Problem 5. Determine the dis-
tance x at which the force that is necessary to pull the box is the smallest.
What is the magnitude of this force?
12. Determine the dimensions (radius r and height h)
and the volume of the cylinder with the largest vol-
ume that can be made inside of a sphere with a
radius R of 14 in.
13. Consider the ellipse . Determine
the sides a and b of the rectangle with the larg-
est area that can be enclosed by the ellipse.
14. Planck's radiation law gives the spectral radiancy R as a function of the wave
length and temperature T (in kelvins):
where m/s is the speed of light, J s is Planck's
constant, and J/K is the Boltzmann's constant.
Plot R as a function of for m at K,
and determine the wavelength that gives the maximum R at this temperature.
f x
x 2–
x 2– 4 2+ 1.8
--------------------------------------=
h
R
R
rh
R=14 in
x
y
a
b
x2
192
--------
y2
52
-----+ 1=
R
2 c2h
5
---------------
1
e
hc kT
1–
--------------------------------=
c 3.0 108= h 6.63 10
34–
=
k 1.38 10
23–
=
0.2 10
6–
6.0 10
6–
T 1500=
327.
316 Chapter 9: Applications in Numerical Analysis
15. A 108 in.–long beam AB is attached to the
wall with a pin at point A and to a 68 in.–
long cable CD. A load lb is
attached to the beam at point B. The ten-
sion in the cable T is given by
where L and LC are the lengths of the beam and the cable, respectively, and d
is the distance from point A to point D, where the cable is attached. Make a
plot of T versus d. Determine the distance d where the tension in the cable is
the smallest.
16. Use MATLAB to calculate the following integral:
(a) (b)
17. Use MATLAB to calculate the following integrals:
(a) (b)
18. The speed of a race car during the first seven seconds of a race is given by:
Determine the distance the car traveled during the first six seconds.
19. The length L of the main supporting cable
of a suspension bridge can be calculated
by
where a is half the length of the bridge
and h is the distance from the deck to the top of the tower where the cable is
attached. Determine the length of a bridge with m and m.
t (s) 0 1 2 3 4 5 6 7
v (mi/h) 0 14 39 69 95 114 129 139
L
Wd
LC
A B
C
D
W 250=
T
W L LC
d LC
2 d2–
-------------------------=
2x2
1 x+
---------------- xd
1
6 2xcos
x
-------------- xd
1
2
e2x
x
------- xd
1
2
e x2– xd
1–
1
x
y
h
aL 2 1
4h
2
a
4
--------x2+
1 2
xd
0
a
=
a 80= h 18=
328.
9.6 Problems 317
20. The flow rate Q (volume of fluid per sec-
ond) in a round pipe can be calculated
by:
For turbulent flow the velocity profile
can be estimated by: . Determine Q for in.,
, in./s.
21. The electric field E due to a charged circular disk
at a point at a distance z along the axis of the disk
is given by
where is the charge density, is the
permittivity constant, C2
/(N m2),
and R is the radius of the disk. Determine the electric field at a point located 5
cm from a disk with a radius of 6 cm, charged with C/m2.
22. The length of a curve given by a parametric equation , is given by:
The cycloid curve is given by , and . Deter-
mine the length of a cycloid with in. for .
23. The variation of gravitational acceleration g with altitude y is given by
where km is the radius of the earth, and m/s2 is the gravi-
tational acceleration at sea level. The change in the gravitational potential
energy, U, of an object that is raised from the earth is given by:
Determine the change in the potential energy of a satellite with a mass of 500
kg that is raised from the surface of the earth to a height of 800 km.
rR
Q 2 vr rd
0
r
=
v vmax 1
r
R
---–
1 n
= R 0.25=
n 7= vmax 80=
E
z
4 0
-------- z2 r2+
3 2–
2r rd
0
R
=
0
0 8.85 10
12–
=
300=
x t y t
x t 2 y t 2+ td
a
b
x R t tsin–= y R 1 tcos–=
R 8= 0 t 2
g
R2
R y+ 2
-------------------g0=
R 6371= g0 9.81=
U mg yd
0
h
=
329.
318 Chapter 9: Applications in Numerical Analysis
24. A cross section of a river with
measurements of its depth at
intervals of 40 ft is shown in the
figure. Use numerical integra-
tion to estimate the cross-sec-
tional area of the river.
25. An approximate map of the state of Ohio
is shown in the figure. Measurements of
the width of the state are marked at inter-
vals of 30 miles. Use numerical integra-
tion to estimate the area of the state.
Compare the result with the actual area
of Ohio, which is 44,825 square miles.
26. The time-dependent relaxation modulus of many biological materials
can be described by Fung's reduced relaxation function:
Use numerical integration to find the relaxation modulus at 10 s, 100 s, and
1,000 s. Assume ksi, , s, and s.
27. The orbit of Pluto is elliptical in shape, with
km and km.
The perimeter of an ellipse can be calculated by
where . Determine the distance
Pluto travels in one orbit. Calculate the average speed at which Pluto travels
(in km/h) if one orbit takes about 248 years.
28. The Fresnel integrals are:
and
Calculate and for (use spacing of 0.05). In one figure plot
two graphs—one of versus x and the other of versus x. In a second
figure plot versus .
40
96
140
147
121
117
139
62
18
140
40
100 15050 200
50
-50
x
y
G t
G t G 1 c
e
t– x
x
-------------- xd
1
2
+=
G 5= c 0.05= 1 0.05= 2 500=
a
b
a 5.9065 10
9
= b 5.7208 10
9
=
P 4a 1 k2 sin2– d
0
2
=
k
a2 b2–
a
---------------------=
S x t 2sin td
0
x
= C x t 2cos td
0
x
=
S x C x 0 x 4
S x C x
S x C x
330.
9.6 Problems 319
29. Solve:
for with
Plot the solution.
30. Solve:
for with
Plot the solution.
31. Solve:
for with
Plot the solution.
32. A water tank shaped as an ellipsoid ( m,
m, m) has a circular hole at the bot-
tom, as shown. According to Torricelli's law, the
speed v of the water that is discharging from the
hole is given by
where h is the height of the water and m/
s2. The rate at which the height, h, of the water in
the tank changes as the water flows out through
the hole is given by
where is the radius of the hole.
Solve the differential equation for y. The initial height of the water is
m. Solve the problem for different times and find an estimate for the
time when m. Make a plot of y as a function of time.
dy
dx
------ x x2 y
4
------------+= 1 x 5 y 1 1=
dy
dx
------ xy 0.5ye 0.1x––= 0 x 4 y 0 6.5=
dy
dt
------ 80e 1.6t– 4tcos 0.4y–= 0 t 4 y 0 0=
h
r=0.025m
v
x
y
z
a
b
c
a 1.5=
b 4.0= c 3=
v 2gh=
g 9.81=
dy
dt
------
2gy r2
ac 1–
h c– 2
c2
------------------+
--------------------------------------------=
rh
h 5.9=
h 0.1=
331.
320 Chapter 9: Applications in Numerical Analysis
33. The growth of a fish is often modeled by the von Bertalanffy growth model:
where w is the weight and a and b are constants. Solve the equation for w for
the case lb1/3
, day–1
, and lb. Make sure that the
selected time span is just long enough so that the maximum weight is
approached. What is the maximum weight for this case? Make a plot of w as a
function of time.
34. The sudden outbreak of an insect population can be modeled by the equation
The first term relates to the well-known logistic population growth model
where N is the number of insects, R is an intrinsic growth rate, and C is the
carrying capacity of the local environment. The second term represents the
effects of bird predation. Its effect becomes significant when the population
reaches a critical size . r is the maximum value that the second term can
reach at large values of N.
Solve the differential equation for days and two growth rates,
and day–1, and with . The other parameters
are , , day–1
. Make one plot comparing the two
solutions and discuss why this model is called an "outbreak" model.
35. An airplane uses a parachute and
other means of braking as it slows
down on the runway after land-
ing. Its acceleration is given by
m/s2. Since
, the rate of change of the
velocity is given by:
Consider an airplane with a velocity of 300 km/h that opens its parachute and
starts decelerating at t = 0 s.
(a) By solving the differential equation, determine and plot the velocity as a
function of time from t = 0 s until the airplane stops.
(b) Use numerical integration to determine the distance x the airplane travels
as a function of time. Make a plot of x versus time.
dw
dt
------- aw
2 3
bw–=
a 5= b 2= w 0 0.5=
dN
dt
------- RN 1 N
C
----– rN
2
Nc
2
N
2
+
-------------------–=
Nc
0 t 50
R 0.55= R 0.58= N 0 10000=
C 10
4
= Nc 104= r 10
4
=
a 0.0035v
2
– 3–=
a
dv
dt
------=
dv
dt
------ 0.0035v
2
– 3–=
332.
9.6 Problems 321
36. An RC circuit includes a voltage
source , a resistor , and a
capacitor F, as shown
in the figure. The differential equation
that describes the response of the cir-
cuit is:
where is the voltage of the capacitor. Initially, , and then at the
voltage source is changed. Determine the response of the circuit for the fol-
lowing three cases:
(a) V for .
(b) V for .
(c) V for s, and then for s (rectangular
pulse).
Each case corresponds to a different differential equation. The solution is the
voltage of the capacitor as a function of time. Solve each case for s.
For each case plot and versus time (make two separate plots on the same
page).
37. An RL circuit includes a voltage
source , a resistor , and an
inductor H, as shown in the
figure. The differential equation that
describes the response of the circuit is
where is the current in the inductor. Initially , and then at the
voltage source is changed. Determine the response of the circuit for the fol-
lowing three cases:
(a) V for .
(b) V for .
Each case corresponds to a different differential equation. The solution is the
current in the inductor as a function of time. Solve each case for s.
For each case plot and versus time (make two separate plots on the same
page).
R
Cvs
+
_ vC (t)
vs R 48=
C 2.4 10 6–=
dvc
dt
--------
1
RC
--------vc+
1
RC
--------vs=
vc vs 0= t 0=
vs 5 20 tsin= t 0
vs 5e t 0.08– 20 tsin= t 0
vs 12= 0 t 0.1 vs 0= t 0.1
0 t 0.4
vs vc
R
Lvs
+
_ vL (t)
vs R 1.8=
L 0.4=
L
R
---
diL
dt
------- iL+
vs
R
----=
iL iL 0= t 0=
vs 10 30 tsin= t 0
vs 10e t 0.06– 30 tsin= t 0
0 t 0.4
vs iL
333.
322 Chapter 9: Applications in Numerical Analysis
38. Tumor growth can be modeled with the equation
where is the area of the tumor and , k, and are constants. Solve the
equation for days, given , , , and
mm2
. Make a plot of A as a function of time.
dA
dt
------- A 1
A
k
---–=
A t
0 t 30 0.8= k 60= 0.25=
A 0 1=
334.
323
Chapter 10
Three-Dimensional
Plots
Three-dimensional (3-D) plots can be a useful way to present data that consists of
more than two variables. MATLAB provides various options for displaying three-
dimensional data. They include line and wire, surface, mesh plots, and many oth-
ers. The plots can also be formatted to have a specific appearance and special
effects. Many of the three-dimensional plotting features are described in this chap-
ter. Additional information can be found in the Help Window under Plotting and
Data Visualization.
In many ways this chapter is a continuation of Chapter 5, where two-dimen-
sional plots were introduced. The 3-D plots are presented in a separate chapter
because not all MATLAB users use them. In addition, new users of MATLAB will
probably find it easier to practice 2-D plotting first and learn the material in Chap-
ters 6–9 before attempting 3-D plotting. It is assumed throughout the rest of this
chapter that the reader is familiar with 2-D plotting.
10.1 LINE PLOTS
A three-dimensional line plot is a line that is obtained by connecting points in
three-dimensional space. A basic 3-D plot 'is created with the plot3 command,
which is very similar to the plot command and has the form:
plot3(x,y,z,'line specifiers','PropertyName',property value)
(Optional) Specifiers that
define the type and color of
the line and markers.
x, y, and z are
vectors of the
coordinates of
the points.
(Optional) Properties with val-
ues that can be used to specify
the line width, and marker's
size and edge and fill colors.
335.
324 Chapter 10: Three-Dimensional Plots
• The three vectors with the coordinates of the data points must have the same
number of elements.
• The line specifiers, properties, and property values are the same as in 2-D plots
(see Section 5.1).
For example, if the coordinates x, y, and z are given as a function of the parameter
t by
a plot of the points for can be produced by the following script file:
The plot shown in Figure 10-1 is created when the script is executed.
10.2 MESH AND SURFACE PLOTS
Mesh and surface plots are three-dimensional plots used for plotting functions of
the form where x and y are the independent variables and z is the
dependent variable. It means that within a given domain the value of z can be cal-
culated for any combination of x and y. Mesh and surface plots are created in three
t=0:0.1:6*pi;
x=sqrt(t).*sin(2*t);
y=sqrt(t).*cos(2*t);
z=0.5*t;
plot3(x,y,z,'k','linewidth',1)
grid on
xlabel('x'); ylabel('y'); zlabel('z')
Figure 10-1: A plot of the function , , for
.
x t 2tsin=
y t 2tcos=
z 0.5t=
0 t 6
-5
0
5
-5
0
5
0
2
4
6
8
10
x
y
z
x t 2tsin= y t 2tcos= z 0.5t=
0 t 6
z f x y=
336.
10.2 Mesh and Surface Plots 325
steps. The first step is to create a grid in the x y plane that covers the domain of the
function. The second step is to calculate the value of z at each point of the grid.
The third step is to create the plot. The three steps are explained next.
Creating a grid in the x y plane (Cartesian coordinates):
The grid is a set of points in the x y plane in the domain of the function. The den-
sity of the grid (number of points used to define the domain) is defined by the
user. Figure 10-2 shows a grid in the domain and . In this grid
the distance between the points is one unit. The points of the grid can be defined
by two matrices, X and Y. Matrix X has the x coordinates of all the points, and
matrix Y has the y coordinates of all the points:
and
The X matrix is made of identical rows since in each row of the grid the points
have the same x coordinate. In the same way the Y matrix is made of identical col-
umns since in each column of the grid the y coordinate of the points is the same.
MATLAB has a built-in function, called meshgrid, that can be used for
Figure 10-2: A grid in the x y plane for the domain and with
spacing of 1.
1– x 3 1 y 4
1– x 3 1 y 4
X
1– 0 1 2 3
1– 0 1 2 3
1– 0 1 2 3
1– 0 1 2 3
= Y
4 4 4 4 4
3 3 3 3 3
2 2 2 2 2
1 1 1 1 1
=
337.
326 Chapter 10: Three-Dimensional Plots
creating the X and Y matrices. The form of the meshgrid function is:
In the vectors x and y the first and last elements are the respective boundaries of
the domain. The density of the grid is determined by the number of elements in
the vectors. For example, the mesh matrices X and Y that correspond to the grid in
Figure 10-2 can be created with the meshgrid command by:
Once the grid matrices exist, they can be used for calculating the value of z at each
grid point.
Calculating the value of z at each point of the grid:
The value of z at each point is calculated by using element-by-element calcula-
tions in the same way it is used with vectors. When the independent variables x
and y are matrices (they must be of the same size), the calculated dependent vari-
able is also a matrix of the same size. The value of z at each address is calculated
from the corresponding values of x and y. For example, if z is given by
the value of z at each point of the grid above is calculated by:
>> x=-1:3;
>> y=1:4;
>> [X,Y]=meshgrid(x,y)
X =
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
-1 0 1 2 3
Y =
1 1 1 1 1
2 2 2 2 2
3 3 3 3 3
4 4 4 4 4
>> Z = X.*Y.^2./(X.^2 + Y.^2)
[X,Y] = meshgrid(x,y)
X is the matrix of the x coordi-
nates of the grid points.
Y is the matrix of the y coordi-
nates of the grid points.
x is a vector that divides the domain of x.
y is a vector that divides the domain of y.
z
xy2
x2 y2+
----------------=
338.
10.2 Mesh and Surface Plots 327
Once the three matrices have been created, they can be used to plot mesh or sur-
face plots.
Making mesh and surface plots:
A mesh or surface plot is created with the mesh or surf command, which has
the form:
where X and Y are matrices with the coordinates of the grid and Z is a matrix with
the value of z at the grid points. The mesh plot is made of lines that connect the
points. In the surface plot, areas within the mesh lines are colored.
As an example, the following script file contains a complete program that
creates the grid and then makes a mesh (or surface) plot of the function
over the domain and .
Note that in the program above the vectors x and y have a much smaller spacing
than the spacing earlier in the section. The smaller spacing creates a denser grid.
The figures created by the program are:
Z =
-0.5000 0 0.5000 0.4000 0.3000
-0.8000 0 0.8000 1.0000 0.9231
-0.9000 0 0.9000 1.3846 1.5000
-0.9412 0 0.9412 1.6000 1.9200
x=-1:0.1:3;
y=1:0.1:4;
[X,Y]=meshgrid(x,y);
Z=X.*Y.^2./(X.^2+Y.^2);
mesh(X,Y,Z)
xlabel('x'); ylabel('y'); zlabel('z')
mesh(X,Y,Z) surf(X,Y,Z)
z
xy2
x2 y2+
----------------= 1– x 3 1 y 4
Type surf(X,Y,Z) for surface plot.
-2
0
2
4
1
2
3
4
-1
0
1
2
x
y
z
-2
0
2
4
1
2
3
4
-1
0
1
2
x
y
z
Mesh plot Surface plot
339.
328 Chapter 10: Three-Dimensional Plots
Additional comments on the mesh command:
• The plots that are created have colors that vary according to the magnitude of z.
The variation in color adds to the three-dimensional visualization of the plots.
The color can be changed to be a constant either by using the Plot Editor in the
Figure Window (select the edit arrow, click on the figure to open the Property
Editor Window, then change the color in the Mesh Properties list), or by using
the colormap(C) command. In this command C is a three-element vector in
which the first, second, and third elements specify the intensity of Red, Green,
and Blue (RGB) colors, respectively. Each element can be a number between 0
(minimum intensity) and 1 (maximum intensity). Some typical colors are:
C = [0 0 0] black C = [1 0 0] red C = [01 0] green
C = [0 0 1] blue C = [1 1 0] yellow C = [1 0 1] magenta
C = [0.5 0.5 0.5] gray
• When the mesh command executes, the grid is on by default. The grid can be
turned off with the grid off command.
• A box can be drawn around the plot with the box on command.
• The mesh and surf commands can also be used with the form mesh(Z) and
surf(Z). In this case the values of Z are plotted as a function of their
addresses in the matrix. The row number is on the x axis and the column num-
ber is on the y axis.
There are several additional plotting commands that are similar to the mesh
and surf commands that create plots with different features. Table 10-1 shows
a summary of the mesh and surface plotting commands. All the examples in the
table are plots of the function over the domain
and .
Table 10-1: Mesh and surface plots
Plot type Example of plot Program
Mesh Plot
Function format:
mesh(X,Y,Z)
x=-3:0.25:3;
y=-3:0.25:3;
[X,Y] = meshgrid(x,y);
Z=1.8.^(-1.5*sqrt(X.^2+
Y.^2)).*cos(0.5*Y).*sin(X);
mesh(X,Y,Z)
xlabel('x'); ylabel('y')
zlabel('z')
z 1.8
1.5 x2 y2+–
x 0.5ycossin=
3– x 3 3– y 3
-4
-2
0
2
4
-4
-2
0
2
4
-0.4
-0.2
0
0.2
0.4
x
y
z
344.
10.4 The view Command 333
• Calculate the value of z at each point of the grid.
• Convert the polar coordinates grid to a grid in Cartesian coordinates. This can
be done with MATLAB's built-in function pol2cart (see example below).
• Make a 3-D plot using the values of z and the Cartesian coordinates.
For example, the following script creates a plot of the function over the
domain and .
The figures created by the program are:
10.4 THE view COMMAND
The view command controls the direction from which the plot is viewed. This is
done by specifying a direction in terms of azimuth and elevation angles, as seen in
Figure 10-3, or by defining a point in space from which the plot is viewed. To set
the viewing angle of the plot, the view command has the form:
• az is the azimuth, which is an angle (in degrees) in the x y plane measured
relative to the negative y axis direction and defined as positive in the
counterclockwise direction.
• el is the angle of elevation (in degrees) from the x y plane. A positive value
corresponds to opening an angle in the direction of the z axis.
• The default view angles are az = –37.5 , and el = 30 .
[th,r]=meshgrid((0:5:360)*pi/180,0:.1:2);
Z=r.*th;
[X,Y] = pol2cart(th,r);
mesh(X,Y,Z)
z r=
0 360 0 r 2
Type surf(X,Y,Z) for surface plot.
Mesh plot Surface plot
-2
0
2
-2
0
2
0
5
10
15
x
y
z
-2
0
2
-2
0
2
0
5
10
15
xy
z
view(az,el) or view([az,el])
347.
336 Chapter 10: Three-Dimensional Plots
• The view command can also set a default view:
view(2) sets the default to the top view, which is a projection onto the
x-y plane with az = 0 , and el = 90 .
view(3) sets the default to the standard 3-D view with az = –37.5 and
el = 30 .
• The viewing direction can also be set by selecting a point in space from which
the plot is viewed. In this case the view command has the form
view([x,y,z]), where x, y, and z are the coordinates of the point. The direc-
tion is determined by the direction from the specified point to the origin of the
coordinate system and is independent of the distance. This means that the view
is the same with point [6, 6, 6] as with point [10, 10, 10]. Top view can be set
up with [0, 0, 1]. A side view of the x z plane from the negative y direction can
be set with [0, –1, 0], and so on.
10.5 EXAMPLES OF MATLAB APPLICATIONS
Sample Problem 10-1: 3-D projectile trajectory
A projectile is fired with an initial velocity of
250 m/s at an angle of = 65 relative to the
ground. The projectile is aimed directly north.
Because of a strong wind blowing to the west,
the projectile also moves in this direction at a
constant speed of 30 m/s. Determine and plot
the trajectory of the projectile until it hits the
ground. For comparison, plot also (in the same figure) the trajectory that the pro-
jectile would have had if there was no wind.
Solution
As shown in the figure, the coordinate system is set up such that the x and y axes
point in the east and north directions, respectively. Then the motion of the projec-
tile can be analyzed by considering the vertical direction z and the two horizontal
components x and y. Since the projectile is fired directly north, the initial velocity
can be resolved into a horizontal y component and a vertical z component:
and
In addition, due to the wind the projectile has a constant velocity in the negative x
direction, m/s.
The initial position of the projectile (x0, y0, z0) is at point (3000, 0, 0). In the verti-
cal direction the velocity and position of the projectile are given by:
v0
v0y v0 cos= v0z v0 sin=
vx 30–=
348.
10.5 Examples of MATLAB Applications 337
and
The time it takes the projectile to reach the highest point is .
The total flying time is twice this time, . In the horizontal direction
the velocity is constant (both in the x and y directions), and the position of the pro-
jectile is given by:
and
The following MATLAB program written in a script file solves the problem by
following the equations above.
The figure generated by the program is shown below.
v0=250; g=9.81; theta=65;
x0=3000; vx=-30;
v0z=v0*sin(theta*pi/180);
v0y=v0*cos(theta*pi/180);
t=2*v0z/g;
tplot=linspace(0,t,100);
z=v0z*tplot-0.5*g*tplot.^2;
y=v0y*tplot;
x=x0+vx*tplot;
xnowind(1:length(y))=x0;
plot3(x,y,z,'k-',xnowind,y,z,'k--')
grid on
axis([0 6000 0 6000 0 2500])
xlabel('x (m)'); ylabel('y (m)'); zlabel('z (m)')
vz v0z gt–= z z0 v0zt
1
2
---gt2–+=
vz 0= thmax
v0z
g
------=
ttot 2thmax=
x x0 vxt+= y y0 v0yt+=
Creating a time vector with 100 elements.
Calculating the x, y, and z coordinates
of the projectile at each time.
Constant x coordinate when no wind.
Two 3-D line plots.
0
2000
4000
6000
0
2000
4000
6000
0
500
1000
1500
2000
2500
x (m)
y (m)
z(m)
349.
338 Chapter 10: Three-Dimensional Plots
Sample Problem 10-2: Electric potential of two point charges
The electric potential V around a charged particle is given by
where is the permittivity constant, q is the magni-
tude of the charge in coulombs, and r is the distance from the particle in meters.
The electric field of two or more particles is calculated by using superposition.
For example, the electric potential at a point due to two particles is given by
where , , , and are the charges of the particles and the distance from the
point to the corresponding particle, respectively.
Two particles with a charge of
C and C are
positioned in the x y plane at points (0.25, 0,
0) and (–0.25, 0, 0), respectively, as shown.
Calculate and plot the electric potential due
to the two particles at points in the x y plane
that are located in the domain
and (the units in the x y plane
are meters). Make the plot such that the x y
plane is the plane of the points, and the z axis is the magnitude of the electric
potential.
Solution
The problem is solved by following these steps:
(a) A grid is created in the x y plane with the domain and
.
(b) The distance from each grid point to each of the charges is calculated.
(c) The electric potential at each point is calculated.
(d) The electric potential is plotted.
The following is a program in a script file that solves the problem.
eps0=8.85e-12; q1=2e-10; q2=3e-10;
k=1/(4*pi*eps0);
x=-0.2:0.01:0.2;
y=-0.2:0.01:0.2;
[X,Y]=meshgrid(x,y);
V
1
4 0
-----------
q
r
---=
0 8.8541878 10 12– C
N m2
---------------=
V
1
4 0
-----------
q1
r1
-----
q2
r2
-----+=
q1 q2 r1 r2
q1 2 10 10–= q2 3 10 10–=
0.2– x 0.2
0.2– y 0.2
0.2– x 0.2
0.2– y 0.2
Creating a grid in the x y plane.
351.
340 Chapter 10: Three-Dimensional Plots
(a) Create an X, Y grid in the domain and . The length of the
plate, a, is divided into 20 segments, and the width of the plate, b, is divided
into 16 segments.
(b) Calculate the temperature at each point of the mesh. The calculations are done
point by point using a double loop. At each point the temperature is deter-
mined by adding k terms of the Fourier series.
(c) Make a surface plot of T.
The program was executed twice, first using five terms (k = 5) in the Fourier series
to calculate the temperature at each point, and then with k = 50. The mesh plots
created in each execution are shown in the figures below. The temperature should
be uniformly 80 C at y = 4 m. Note the effect of the number of terms (k) on the
accuracy at y = 4 m.
a=5; b=4; na=20; nb=16; k=5; T0=80;
clear T
x=linspace(0,a,na);
y=linspace(0,b,nb);
[X,Y]=meshgrid(x,y);
for i=1:nb
for j=1:na
T(i,j)=0;
for n=1:k
ns=2*n-1;
T(i,j)=T(i,j)+sin(ns*pi*X(i,j)/a).*sinh(ns*pi*Y(i,j)/
a)/(sinh(ns*pi*b/a)*ns);
end
T(i,j) = T(i,j)*4*T0/pi;
end
end
mesh(X,Y,T)
xlabel('x (m)'); ylabel('y (m)'); zlabel('T ( ^oC)')
0 x a 0 y b
Creating a grid in the x y plane.
First loop, i, is the index of the grid's row.
Second loop, j, is the index of the grid's column.
Third loop, n, is the nth term of the Fourier
series, k is the number of terms.
352.
10.6 Problems 341
10.6 PROBLEMS
1. The position of a moving particle as a function of time is given by:
Plot the position of the particle for .
2. An elliptical staircase that decreases in size
with height can be modeled by the paramet-
ric equations
where ,
a and b are the semimajor and semiminor axes of the ellipse, h is the staircase
height, and n is the number of revolutions that the staircase makes. Make a 3-
D plot of the staircase with m, m, m, and . (Cre-
ate a vector t for the domain 0 to , and use the plot3 command.)
3. The ladder of a fire truck can be ele-
vated (increase of angle ), rotated
about the z axis (increase of angle ),
and extended (increase of r). Initially
the ladder rests on the truck ( ,
, and m). Then the ladder
is moved to a new position by raising
the ladder at a rate of 5 deg/s, rotating
at a rate of 8 deg/s, and extending the ladder at a rate of 0.6 m/s. Determine
and plot the position of the tip of the ladder for 10 seconds.
k = 50k = 5
x 4 0.1t– 0.8tsin= y 4 0.1t– 0.8tcos= z 0.4t 3 2=
0 t 30
−20
0
20
−10
0
10
0
10
20
x (m)y (m)
z(m)
x r tcos= y r tsin= z
ht
2 n
----------=
r
ab
b tcos 2 a tsin 2+
-------------------------------------------------------------e 0.04t–=
a 20= b 10= h 18= n 5=
2 n
0=
0= r 8=
353.
342 Chapter 10: Three-Dimensional Plots
4. Make a 3-D surface plot of the function in the domain
and .
5. Make a 3-D surface plot of the function in the domain
and .
6. Make a 3-D mesh plot of the function , where in the
domain and .
7. Make a 3-D surface plot of the function in the
domain and .
8. An anti-symmetric cross-ply composite
laminate has two layers in which the fibers
are aligned perpendicular to one another. A
laminate of this type will deform into a sad-
dle shape due to residual thermal stresses as
described by the equation
where x and y are the in-plane coordinates,
w is the out-of-plane deflection, and k is the
curvature (a complicated function of material properties and geometry). Make
a surface plot showing the deflection of a six-inch square plate ( in.,
in.), assuming in–1
.
9. The van der Waals equation gives a relationship between the pressure p (atm),
volume V, (L), and temperature T (K) for a real gas:
where n is the number of moles, (L atm)/(mol K) is the gas con-
stant, and a (L2 atm/mol2
), and b (L/mol) are material constants.
Consider 1.5 moles of nitrogen ( L2
atm/mol2
, L/
mol). Make a 3-D plot that shows the variation of pressure (dependent vari-
able, z axis) with volume (independent variable, x axis) and temperature (inde-
pendent variable, y axis). The domains for the volume and temperature are
L and K.
z
x2
3
----- 2 3ysin+=
3– x 3 3– y 3
z 0.5 x y 0.5+=
2– x 2 2– y 2
z
Rsin
R
-----------= R x2 y2+=
10– x 10 10– y 10
z xycos x2 y2+cos=
– x – y
w k x2 y2–=
3– x 3
3– y 3 k 0.01=
P
nRT
V b–
------------
n2a
V
2
--------–=
R 0.08206=
a 1.39= b 0.03913=
0.3 V 1.2 273 T 473
354.
10.6 Problems 343
10. Molecules of a gas in a container are moving around at different speeds. Max-
well's speed distribution law gives the probability distribution as a func-
tion of temperature and speed:
where M is the molar mass of the gas in kg/mol, J/(mol K), is the gas
constant, T is the temperature in kelvins, and v is the molecule's speed in m/s.
Make a 3-D plot of as a function of v and T for m/s and
K for oxygen (molar mass 0.032 kg/mol).
11
Make a 3-D plot of as a function of v and T for mi/h and
F.
12. The flow Q (m3
/s) in a rectangular channel is given by the Manning's equa-
tion:
where d is the depth of water (m), w is the width of the channel (m), S is the
slope of the channel (m/m), n is the roughness coefficient of the channel
walls, and k is a conversion constant (equal to 1 when the units above are
used). Make a 3-D plot of Q (z axis) as a function of w (x axis) for m,
and a function of d (y-axis) for m. Assume and
m/m.
13. An RLC circuit with an alternating
voltage source is shown. The source
voltage is given by
, where ,
in which is the driving frequency.
The amplitude of the current, I, in this
circuit is given by
where R and C are the resistance of the resistor and capacitance of the
capacitor, respectively. For the circuit in the figure F,
P v
P v 4
M
2 RT
--------------
3 2
v
2
e
Mv
2
– 2RT
=
R 8.31=
P v 0 v 1000
70 T 320
Twc
Twc 35.74 0.6215T 35.75v0.16– 0.4275T v0.16+ +=
Twc 0 v 70
0 T 50
Q
kdw
n
---------- wd
w 2d+
----------------
2 3
S=
0 w 8
0 d 4 n 0.05=
S 0.001=
vs
vs vm dtsin= d 2 fd=
fd
I
vm
R
2
dL 1 dC–
2
+
--------------------------------------------------------------=
C 15 10
6–
=
355.
344 Chapter 10: Three-Dimensional Plots
H, and V.
a) Make a 3-D plot of I (z axis) as a function of (x axis) for
Hz, and as a function of R (y axis) for .
b) Make a plot that is a projection on the x z plane. Estimate from this plot
the natural frequency of the circuit (the frequency at which I is maxi-
mum). Compare the estimate with the calculated value of .
14. A defect in a crystal lattice where a row of atoms is missing is called an edge
dislocation. The stress field around an edge dislocation is given by:
where G is the shear modulus, b is the Burgers vector, and is Poisson's ratio.
Plot the stress components (each in a separate figure) due to an edge disloca-
tion in aluminum, for which Pa, m, and
. Plot the stresses in the domain m and
m. Plot the coordinates x and y in the horizontal plane,
and the stresses in the vertical direction.
15. The current I flowing through a semiconductor
diode is given by
where A is the saturation current,
C is the elementary charge value, J/K is Bolt-
zmann's constant, is the voltage drop across the diode, and T is the tem-
perature in kelvins. Make a 3-D plot of I (z axis) versus (x axis) for
, and versus T (y axis) for K.
16. The equation for the streamlines for uniform flow over a cylinder is
where is the stream function. For example, if , then . Since the
L 240 10
3–
= vm 24=
d
60 f 110 10 R 40
1 2 LC
xx
Gb–
2 1 –
------------------------
y 3x
2
y
2
+
x
2
y
2
+
2
---------------------------=
yy
Gb
2 1 –
------------------------
y x
2
y
2
–
x
2
y
2
+
2
-----------------------=
xy
Gb
2 1 –
------------------------
x x
2
y
2
–
x
2
y
2
+
2
-----------------------=
G 27.7 10
9
= b 0.286 10
9–
=
0.334= 5 10
9–
– x 5 10
9–
5 10
9–
– y 1– 10
9–
D
vDI
I IS e
qvD
kT
---------
1–=
IS 10
12–
=
q 1.6 10
19–
= k 1.38 10
23–
=
vD
vD
0 vD 0.4 290 T 320
x y y
y
x2 y2+
----------------–=
0= y 0=
356.
10.6 Problems 345
equation is satisfied for all x, the x axis is the zero ( ) streamline.
Observe that the collection of points where is also a streamline.
Thus, the stream function above is for a cylinder of radius 1. Make a 2-D con-
tour plot of the streamlines around a cylinder with 1 in. radius. Set up the
domain for x and y to range between –3 and 3. Use 100 for the number of con-
tour levels. Add to the figure a plot of a circle with a radius of 1. Note that
MATLAB also plots streamlines inside the cylinder. This is a mathematical
artifact.
17. The deflection w of a clamped circular membrane of radius subjected to
pressure P is given by (small deformation theory)
where r is the radial coordinate, and , where E, t, and are the
elastic modulus, thickness, and Poisson's ratio of the membrane, respectively.
Consider a membrane with psi, in., psi,
in., and . Make a surface plot of the membrane.
18. The Verhulst model, given in the following equation, describes the growth of
a population that is limited by various factors such as overcrowding and lack
of resources:
where is the number of individuals in the population, is the initial
population size, is the maximum population size possible due to the vari-
ous limiting factors, and r is a rate constant. Make a surface plot of ver-
sus t and assuming s–1, and . Let t vary between 0 and 100
and between 100 and 1,000.
19. The geometry of a ship hull (Wigley
hull) can be modeled by the equation
where x, y, and z are the length, width,
and height, respectively. Use MAT-
LAB to make a 3-D figure of the hull
as shown. Use , ,
, , and .
0=
x2 y2+ 1=
rd
w r
Prd
4
64K
---------- 1
r
rd
----
2
–
2
=
K Et3
12 1 2–
--------------------------=
P 15= rd 15= E 18 106=
t 0.08= 0.3=
N t
N
1
N
N0
------- 1– e
rt–
+
---------------------------------------=
N t N0
N
N t
N r 0.1= N0 10=
N
−2
0
2
−1
0
1
−0.4
−0.2
0
x
y
z
y
B
2
--- 1
2x
L
------
2
– 1
2z
T
-----
2
–=
B 1.2= L 4=
T 0.5= 2– x 2 0.5– z 0
357.
346 Chapter 10: Three-Dimensional Plots
20. The stresses fields near a crack tip of a
linear elastic isotropic material for mode I
loading are given by:
For ksi plot the stresses (each in a separate figure) in the domain
and in. Plot the coordinates x and y in the horizontal
plane, and the stresses in the vertical direction.
21. A ball thrown up falls back to the floor and
bounces many times. For a ball thrown up
in the direction shown in the figure, the
position of the ball as a function of time is
given by:
The velocities in the x and y directions are
constants throughout the motion and are
given by and
. In the vertical z direc-
tion the initial velocity is ,
and when the ball impacts the floor its
rebound velocity is 0.8 of the vertical
velocity at the start of the previous bounce.
The time between bounces is given by
, where is the vertical com-
ponent of the velocity at the start of the
bounce. Make a 3-D plot (shown in the figure) that shows the trajectory of the
ball during the first five bounces. Take m/s, , , and
m/s2
.
x
y
r
θxx
KI
2 r
-------------
2
--- 1
2
---
3
2
------sinsin–cos=
yy
KI
2 r
-------------
2
--- 1
2
---
3
2
------sinsin+cos=
xy
KI
2 r
-------------
2
---
2
---
3
2
------cossincos=
KI 300= in
0 90 0.02 r 0.2
θ
α
v0
x
y
z
0
50
100
0
50
100
150
0
5
10
x (m)y (m)
z(m)
x vxt= y vyt= z vzt
1
2
---gt2–=
vx v0 cossin=
vy v0 sinsin=
vz v0 cos=
tb 2vz g= vz
v0 20= 30= 25=
g 20=
358.
347
Chapter 11
Symbolic Math
All of the mathematical operations done with MATLAB in the first 10 chapters
were numerical. The operations were carried out by writing numerical expressions
that could contain numbers and variables with preassigned numerical values.
When a numerical expression is executed by MATLAB, the outcome is also
numerical (a single number or an array with numbers). The number, or numbers,
are either exact or a floating point–approximated value. For example, typing 1/4
gives 0.2500—an exact value, and typing 1/3 gives 0.3333—an approximated
value.
Many applications in math, science, and engineering require symbolic oper-
ations, which are mathematical operations with expressions that contain symbolic
variables (variables that don't have specific numerical values when the operation
is executed). The result of such operations is also a mathematical expression in
terms of the symbolic variables. One simple example involves solving an alge-
braic equation that contains several variables and solving for one variable in terms
of the others. If a, b, and x are symbolic variables, and , x can be solved
in terms of a and b to give . Other examples of symbolic operations are
analytical differentiation or integration of mathematical expressions. For instance,
the derivative of with respect to t is .
MATLAB has the capability of carrying out many types of symbolic opera-
tions. The numerical part of the symbolic operation is carried out by MATLAB
exactly, with no approximation of numerical values. For example, the result of
adding and is and not 0.5833x.
Symbolic operations can be performed by MATLAB once the Symbolic
Math Toolbox is installed. The Symbolic Math Toolbox is a collection of MAT-
LAB functions that are used for execution of symbolic operations. The commands
and functions for the symbolic operations have the same style and syntax as those
for the numerical operations. The symbolic operations themselves are executed
primarily by MuPad®, which is mathematical software designed for this purpose.
The MuPad software is embedded within MATLAB and is automatically activated
when a symbolic MATLAB function is executed. MuPad can also be used as sep-
arate independent software. That software uses the MuPAD language, which has a
ax b– 0=
x b a=
2t3 5t 8–+ 6t2 5+
x
4
---
x
3
---
7
12
------x
359.
348 Chapter 11: Symbolic Math
completely different structure and commands than MATLAB. The Symbolic Math
Toolbox is included in the student version of MATLAB. In the standard version,
the toolbox is purchased separately. To check if the Symbolic Math Toolbox is
installed on a computer, the user can type the command ver in the Command
Window. In response, MATLAB displays information about the version that is
used as well as a list of the toolboxes that are installed.
The starting point for symbolic operations is symbolic objects. Symbolic
objects are made of variables and numbers that, when used in mathematical
expressions, tell MATLAB to execute the expression symbolically. Typically, the
user first defines (creates) the symbolic variables (objects) that are needed, and
then uses them to create symbolic expressions that are subsequently used in sym-
bolic operations. If needed, symbolic expressions can be used in numerical opera-
tions
The first section in this chapter describes how to define symbolic objects
and how to use them to create symbolic expressions. The second section shows
how to change the form of existing expressions. Once a symbolic expression has
been created, it can be used in mathematical operations. MATLAB has a large
selection of functions for this purpose. The next four sections (11.3–11.6) describe
how to use MATLAB to solve algebraic equations, to carry out differentiation and
integration, and to solve differential equations. Section 11.7 covers plotting sym-
bolic expressions. How to use symbolic expressions in subsequent numerical cal-
culations is explained in the following section.
11.1 SYMBOLIC OBJECTS AND SYMBOLIC EXPRESSIONS
A symbolic object can be a variable (without a preassigned numerical value), a
number, or an expression made of symbolic variables and numbers. A symbolic
expression is a mathematical expression containing one or more symbolic objects.
When typed, a symbolic expression may look like a standard numerical expres-
sion. However, because the expression contains symbolic objects, it is executed
by MATLAB symbolically.
11.1.1 Creating Symbolic Objects
Symbolic objects can be variables or numbers. They can be created with the sym
and/or syms commands. A single symbolic object can be created with the sym
command:
where the string, which is the symbolic object, is assigned to a name. The string
can be:
• A single letter or a combination of several letters (no spaces). Examples: 'a',
'x', 'yad'.
object_name = sym('string')
360.
11.1 Symbolic Objects and Symbolic Expressions 349
• A combination of letters and digits starting with a letter and with no spaces
Examples: 'xh12','r2d2'.
• A number. Examples: '15', '4'.
In the first two cases (where the string is a single letter, a combination of several
letters, or a combination of letters and digits), the symbolic object is a symbolic
variable. In this case it is convenient (but not necessary) to give the object the
same name as the string. For example, a, bb, and x, can be defined as symbolic
variables as follows:
The name of the symbolic object can be different from the name of the variable.
For example:
As mentioned, symbolic objects can also be numbers. The numbers don't
have to be typed as strings. For example, the sym command is used next to create
symbolic objects from the numbers 5 and 7 and assign them to the variables c and
d, respectively.
As shown, when a symbolic object is created and a semicolon is not typed at the
end of the command, MATLAB displays the name of the object and the object
itself in the next two lines. The display of symbolic objects starts at the beginning
of the line and is not indented as is the display of numerical variables. The differ-
ence is illustrated below, where a numerical variable is created.
>> a=sym('a')
a =
a
>> bb=sym('bb')
bb =
bb
>> x=sym('x');
>>
>> g=sym('gamma')
g =
gamma
>> c=sym(5)
c =
5
>> d=sym(7)
d =
7
Create a symbolic object a and assign it to a.
The display of a symbolic
object is not indented.
The symbolic variable x is created but not displayed,
since a semicolon is typed at the end of the command.
The symbolic object is gamma, and
the name of the object is g.
Create a symbolic object from the number 5 and assign it to c.
The display of a symbolic
object is not indented.
361.
350 Chapter 11: Symbolic Math
Several symbolic variables can be created in one command by using the
syms command, which has the form:
The command creates symbolic objects that have the same names as the symbolic
variables. For example, the variables y, z, and d can all be created as symbolic
variables in one command by typing:
When the syms command is executed, the variables it creates are not displayed
automatically—even if a semicolon is not typed at the end of the command.
11.1.2 Creating Symbolic Expressions
Symbolic expressions are mathematical expressions written in terms of symbolic
variables. Once symbolic variables are created, they can be used for creating sym-
bolic expressions. The symbolic expression is a symbolic object (the display is not
indented). The form for creating a symbolic expression is:
A few examples are:
When a symbolic expression, which includes mathematical operations that can be
executed (addition, subtraction, multiplication, and division), is entered, MAT-
LAB executes the operations as the expression is created. For example:
>> e=13
e =
13
>> syms y z d
>> y
y =
y
>> syms a b c x y
>> f=a*x^2+b*x + c
f =
a*x^2 + b*x + c
>> g=2*a/3+4*a/7-6.5*x+x/3+4*5/3-1.5
The display of the value of a
numerical variable is indented.
13 is assigned to e (numerical variable).
syms variable_name variable_name variable_name
The variables created by the syms command are
not displayed automatically. Typing the name of
the variable shows that the variable was created.
Expression_name = Mathematical expression
Define a, b, c, x, and y as symbolic variables.
Create the symbolic expression
and assign it to f.ax2 bx c+ +
The display of the symbolic expression is not indented.
is entered.
2a
3
------
4a
7
------ 6.5x–
x
3
--- 4
5
3
--- 1.5–+ + +
362.
11.1 Symbolic Objects and Symbolic Expressions 351
Notice that all the calculations are carried out exactly, with no numerical approxi-
mation. In the last example, and were added by MATLAB to give ,
and was added to . The operations with the terms that contain only
numbers in the symbolic expression are carried out exactly. In the last example,
is replaced by .
The difference between exact and approximate calculations is demonstrated
in the following example, where the same mathematical operations are carried
out—once with symbolic variables and once with numerical variables.
An expression that is created can include both symbolic objects and numer-
ical variables. However, if an expression includes a symbolic object (or several),
all the mathematical operations will be carried out exactly. For example, if c is
replaced by a in the last expression, the result is exact, as it was in the first exam-
ple.
Additional facts about symbolic expressions and symbolic objects:
• Symbolic expressions can include numerical variables that have been obtained
from the execution of numerical expressions. When these variables are inserted
in symbolic expressions their exact value is used, even if the variable was dis-
played before with an approximated value. For example:
g =
(26*a)/21 - (37*x)/6 + 31/6
>> a=sym(3); b=sym(5);
>> e=b/a+sqrt(2)
e =
2^(1/2) + 5/3
>> c=3; d=5;
>> f=d/c+sqrt(2)
f =
3.0809
>> g=d/a+sqrt(2)
g =
2^(1/2) + 5/3
>> h=10/3
is displayed.26a
21
--------- 37x
6
---------– 31
6
------+
2a
3
------
4a
7
------
26a
21
---------
6.5x–
x
3
---+
37x
6
---------
4
5
3
--- 1.5+
31
6
------
Define a and b as symbolic 3 and 5, respectively.
Create an expression that includes a and b.
An exact value of e is displayed as a symbolic
object (the display is not indented).
Define c and d as numerical 3 and 5, respectively.
Create an expression that includes c and d.
An approximated value of f is displayed
as a number (the display is indented).
h is defined to be 10/3 (a numerical variable).
363.
352 Chapter 11: Symbolic Math
• The double(S) command can be used to convert a symbolic expression
(object) S that is written in an exact form to numerical form. (The name "dou-
ble" comes from the fact that the command returns a double-precision floating-
point number representing the value of S.) Two examples are shown. In the
first, the p from the last example is converted into numerical form. In the sec-
ond, a symbolic object is created and then converted into numerical form.
• A symbolic object that is created can also be a symbolic expression written in
terms of variables that were not first created as symbolic objects. For example,
the quadratic expression can be created as a symbolic object
named f by using the sym command:
It is important to understand that in this case, the variables a, b, c, and x included
in the object do not exist individually as independent symbolic objects (the whole
expression is one object). This means that it is impossible to perform symbolic
math operations associated with the individual variables in the object. For exam-
ple, it will not be possible to differentiate f with respect to x. This is different
from the way in which the quadratic expression was created in the first example in
this section, where the individual variables are first created as symbolic objects
and then used in the quadratic expression.
h =
3.3333
>> k=sym(5); m=sym(7);
>> p=k/m+h
p =
85/21
>> pN=double(p)
pN =
4.0476
>> y=sym(10)*cos(5*pi/6)
y =
-5*3^(1/2)
>> yN=double(y)
yN =
-8.6603
>> f=sym('a*x^2+b*x+c')
f =
a*x^2 + b*x +c
An approximated value of h (numerical variable) is displayed.
Define k and m as symbolic 5 and 7, respectively.
h, k, and m are used in an expression.
The exact value of h is used in the determination of p.
An exact value of p (symbolic object) is displayed.
p is converted to numerical form (assigned to pN).
Create a symbolic expression y.
Exact value of y is displayed.
y is converted to numerical form (assigned to yN).
ax2 bx c+ +
364.
11.1 Symbolic Objects and Symbolic Expressions 353
• Existing symbolic expressions can be used to create new symbolic expressions.
This is done by simply using the name of the existing expression in the new
expression. For example:
11.1.3 The findsym Command and the Default Symbolic Variable
The findsym command can be used to find which symbolic variables are
present in an existing symbolic expression. The format of the command is:
The findsym(S)command displays the names of all the symbolic variables
(separated by commas) that are in the expression S in alphabetical order. The
findsym(S,n)command displays n symbolic variables that are in expression
S in the default order. For one-letter symbolic variables, the default order starts
with x, and followed by letters, according to their closeness to x. If there are two
letters equally close to x, the letter that is after x in alphabetical order is first (y
before w, and z before v). The default symbolic variable in a symbolic expression
is the first variable in the default order. The default symbolic variable in an
expression S can be identified by typing findsym(S,1). Examples:
>> syms x y
>> SA=x+y, SB=x-y
SA =
x+y
SB =
x-y
>> F=SA^2/SB^3+x^2
F =
(x+y)^2/(x-y)^3+x^2
>> syms x h w y d t
>> S=h*x^2+d*y^2+t*w^2
S =
t*w^2 + h*x^2 + d*y^2
>> findsym(S)
ans =
d, h, t, w, x, y
>> findsym(S,5)
ans =
x,y,w,t,h
Define x and y as symbolic variables.
Create two symbolic expressions SA and SB.
SA x y+=
SB x y–=
Create a new symbolic expression F using SA and SB.
F SA2 SB3 x2+
x y+ 2
x y– 3
------------------ x2+= =
findsym(S) findsym(S,n)or
Define x, h, w, y, d, and t as symbolic variables.
Create a symbolic expression S.
Use the findsym(S) command.
The symbolic variables are displayed in alphabetical order.
Use the findsym(S,n) command (n = 5).
Five symbolic variables are displayed in the default order.
365.
354 Chapter 11: Symbolic Math
11.2 CHANGING THE FORM OF AN EXISTING SYMBOLIC EXPRESSION
Symbolic expressions are either created by th
| 677.169 | 1 |
Ever wondered what algebra is? You may have an impression that algebra is math with nothing more than a bunch of symbols and letters. I can understand if you think algebra is for the "birds" but trust me if it were not for algebra there would be no internet, iPhone and the other great material stuff in our world not likely exist. So try to respect the subject as a powerful force for good! I put together a video on what algebra is and how you can kind of think of the subject. My goal is to show you that anyone can learn the topic with the right attitude and teacher.
| 677.169 | 1 |
Mathematics for Physicists
9780534379971
ISBN:
0534379974
Pub Date: 2003 Publisher: Thomson Learning
Summary: This essential new text by Dr. Susan Lea will help physics undergraduate and graduate student hone their mathematical skills. Ideal for the one-semester course, MATHEMATICS FOR PHYSICISTS has been extensively class-tested at San Francisco State University--and the response has been enthusiastic from students and instructors alike. Because physics students are often uncomfortable using the mathematical tools that they... learned in their undergraduate courses, MATHEMATICS FOR PHYSICISTS provides students with the necessary tools to hone those skills. Lea designed the text specifically for physics students by using physics problems to teach mathematical concepts.
Lea, Susan M. is the author of Mathematics for Physicists, published 2003 under ISBN 9780534379971 and 0534379974. Three hundred ninety three Mathematics for Physicists textbooks are available for sale on ValoreBooks.com, fifty nine used from the cheapest price of $83.85, or buy new starting at $119.22.[read more
| 677.169 | 1 |
Brand new. We distribute directly for the publisher. This book provides a stimulating presentation of the history of Greek mathematics, with special emphasis on the Alexandrian ...school. Beginning with number systems of the ancients and Egyptian influences on Greek mathematics, the book traces the development up to Pappus and Proclus in the fourth century A.D.This is a standard work on the history of Greek mathematics, with special emphasis on the Alexandrian school of mathematics.Read moreShow Less
More About
This Textbook
Overview
This book provides a stimulating presentation of the history of Greek mathematics, with special emphasis on the Alexandrian school. Beginning with number systems of the ancients and Egyptian influences on Greek mathematics, the book traces the development up to Pappus and Proclus in the fourth century A.D. This is a standard work on the history of Greek mathematics, with special emphasis on the Alexandrian school
| 677.169 | 1 |
Elementary Linear Algebra A Matrix Approach
9780137167227
ISBN:
0137167229
Publisher: Prentice Hall
Summary: For a sophomore-level course in Linear Algebra. Based on the recommendations of the LACSG, this introduction to linear algebra offers a matrix-oriented approach with more emphasis on problem solving and applications and less emphasis on abstraction than in a traditional course. Throughout the text, use of technology is encouraged. The focus is on matrix arithmetic, systems of linear equations, properties of Euclidean... n-space, eigenvalues and eigenvectors, and orthogonality. Although matrix-oriented, the text provides a solid coverage of vector spaces.
Friedberg, Stephen H. is the author of Elementary Linear Algebra A Matrix Approach, published under ISBN 9780137167227 and 0137167229. Six Elementary Linear Algebra A Matrix Approach textbooks are available for sale on ValoreBooks.com, five used from the cheapest price of $0.02, or buy new starting at $40
| 677.169 | 1 |
Additional Product Information
Features/Benefits
Emphasis on learning objectives and outcomes--Every section begins with a list of learning objectives called What You Should Learn. Each objective is restated in the margin at the point where it is covered. Why Should You Learn It provides a motivational explanation for learning the given objectives.
Detailed, titled examples to develop concepts--Each example has been carefully chosen to illustrate a particular mathematical concept or problem-solving technique. The examples cover a wide variety of problems and are titled for easy reference. Many include detailed, step-by-step solutions with side comments that explain the key steps of the solution process.
Real-world applications--Identified by an icon, a wide variety of real-life applications are integrated throughout the text in examples and exercises, demonstrating the relevance of algebra in the real world. Many of the applications use current, real data.
Straightforward problem-solving approach--The text provides many opportunities for students to sharpen problem-solving skills. In both the examples and the exercises, students are asked to apply verbal, numerical, analytical, and graphical approaches to problem solving. The authors' five-step strategy for solving applied problems begins with constructing a verbal model and ends with checking the answer.
Plentiful exercises and tests--Graded exercise sets are grouped into three categories, offering a diversity of computational, conceptual, and applied problems to accommodate many learning styles. Detailed solutions to odd-numbered exercises are in the Student Solutions Guide; answers to odd-numbered exercises are in the back of the text.
In-text learning aids--Definitions and rules are highlighted, Study Tips offer suggestions for studying algebra and point out common errors, and Technology Tips point out where the use of a graphing calculator is helpful in visualizing concepts and solving the problem.
What's New
Emphasis on study skills and self-responsibility--Each chapter opener presents a study skill essential to success in mathematics, followed by a Smart Study Strategy that offers concrete ways that students can help themselves with the skill. These chapter openers were written by noted study skills expert, Kimberly Nolting. Quotes from real students who have successfully used the strategy appear in It Worked for Me! Later in the chapter, a Smart Study Strategy note points out an appropriate time to use the strategy.
Concept Checks--Each exercise set is preceded by four non-computational exercises that check students' understanding of the main concepts of the section. These exercises could be completed in class to make sure that students are ready to start the exercise set.
Checkpoints--Each example is followed by a checkpoint exercise. After working through an example, students can try the checkpoint exercise in the exercise set to check their understanding of the concepts presented in the example.
Interactive chapter summaries--The What Did You Learn? section at the end of each chapter has been reorganized and expanded to promote interactivity and better help students prepare for exams. The Plan for Test Success provides a place for students to actively plan their studying for a test; it also includes a checklist of things to review. Students can check off chapter Key Terms and Key Concepts as they are reviewed. A space to record assignments for each section of the chapter is also provided.
Cumulative review exercises--Each exercise set (except those in Chapter 1) is followed by exercises that cover concepts from previous sections. This serves as a review for students and also helps them connect old concepts with new concepts.By Gerry Fitch, Louisiana State University, this guide includes detailed ,step-by-step solutions to all odd-numbered exercises in the section exercise sets and in the review exercises. It also includes detailed step-by-step solutions to all Mid-Chapter Quiz, Chapter Test, and Cumulative Test questions.
By Gerry Fitch, Louisiana State University, this manual is available online and includes Chapter and Final Exam test forms with answer keys, individual test items and answers for chapters 1-10 and notes to instructors including tips and strategies on student assessment, cooperative learning, classroom management, study skills, and problem solving.
IMPORTANT: When purchasing this instant access code for Developmental Math, ensure that you are using it in one of the following courses: Basic Math, Prealgebra, Elementary Algebra, Introductory Algebra, Intermediate your students need to retake the course and you are using the same book AND edition then they will not need to buy a new code.
This instant access code will be delivered via email when purchased. If you are not certain this is the correct access code for your course, please contact your Cengage Learning Consultant.
The annotated instructor's edition contains answers in place for exercise sets, review exercises, Mid-Chapter Quizzes, Chapter tests, and Cumulative tests. It also includes annotations at point of use that offer strategies and suggestions for teaching the course and point out common student pitfallsThis handy manual contains detailed, step-by-step solutions to all odd-numbered exercises in the section exercise sets and in the review exercises. In addition, it also includes detailed step-by-step solutions to all Mid-Chapter Quiz, Chapter Test, and Cumulative Test questions.
IMPORTANT: When purchasing this instant access code for Developmental Math, ensure that you are using it in one of the following courses: Basic Math, Prealgebra, Elementary Algebra, Introductory Algebra, Intermediate you need to retake the course and your instructor is using the same book AND edition then you will not need to buy a new code.
This instant access code will be delivered via email when purchased. If you are not certain this is the correct access code for your course, please contact your instructorMeet the Author
About the Author
Ron Larson
| 677.169 | 1 |
Core-Plus Mathematics, Course 2 - 08 edition
Summary: Core-Plus Mathematics, is a standards-based, four-year integrated series covering the same mathematics concepts students learn in the Algebra 1-Geometry-Algebra 2-Precalculus sequence. Concepts from algebra, geometry, probability, and statistics are integrated, and the mathematics is developed using context-centered investigations. Developed by the CORE-Plus Math Project at Western Michigan University with funding from the National Science Foundation (NSF),Core-Plus Mathematicsis w...show moreritten for all students to be successful in mathematics. Core-Plus Mathematicsis the number one high school NSF/reform program and it is published by Glencoe/McGraw-Hill, the nation's number one secondary mathematics company. ...show less
Unused! Book Leaves in 1 Business Day or Less! Leaves Same Day if Received by 2 pm EST! Slight shelf wear. Contents Unused. Like New.
$11.1512.00 +$3.99 s/h
Good
AlphaBookWorks Alpharetta, GA
0078772583
| 677.169 | 1 |
Enter your mobile number or email address below and we'll send you a link to download the free Kindle Reading App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
Return to the fundamentals with Big Ideas in Math. This book promotes mastery of the concepts and skills in the three mathematical content ideas/topics identified by the NCTM Curriculum Focal Points for grade 8, along with the corresponding connections.
Continental Press has expanded its product offerings to support students in key curriculum areas and at many levels of learning. We offer exceptional materials for students, parents, teachers, and administrators at fair and affordable prices.
{"currencyCode":"USD","itemData":[{"priceBreaksMAP":null,"buyingPrice":9.17,"ASIN":"0845455966","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":9.15,"ASIN":"0845455958","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":9.29,"ASIN":"084545594X","isPreorder":0}],"shippingId":"0845455966::4edaxfdBHLSczKZwWMADVi%2FRhkW2kxWpA20%2FEv3QTq%2BjTrwZhW2OaMDUs3QaKqoa6rnCo56y8nApq84h2iVG1Qw5uzkAGHANm672tHGDocroGN8wkLYkeg%3D%3D,0845455958::TODq1EOEv%2FCu5PswfISNTs5Ef1axgWol8jN87Hcf9io%2FFgAQ31o3MnFzfCt7dEqkgMEKjhuMGnnorzFd%2FFU9Mwijp7xvaRkGM00KYcf1yepjx1YH9n4MBw%3D%3D,084545594X::TODq1EOEv%2FCu5PswfISNTvSHDct7xRaRMyiu%2FrqF6srZD9gr9ynzpENZXYkF9wxoiOZa%2Bip2JTajvjX7p6QSPBITFD4Hk5PCXuLEu3UOtkD4GfnMkGVhd
| 677.169 | 1 |
Synopses & Reviews
Publisher Comments
The book's primary aim is not so much to impart new information as to teach an active, creative attitude toward mathematics. The sole prerequisites are high-school algebra and (for Multicolor Problems) a familiarity with the methods of mathematical induction. The book is designed for the reader's active participation. The problems are carefully integrated into the text and should be solved in order. Although they are basic, they are by no means elementary. Some sequences of problems are geared toward the mastery of a new method, rather than a definitive result, and others are practice exercises, designed to introduce new concepts. Complete solutions appear at the end.
Synopsis
| 677.169 | 1 |
Thinking Mathematically, Sixth Edition, Bob Blitzer's distinctive and relatable voice motivates students from diverse backgrounds and majors, engaging them in the math through compelling, real-world applications. Understanding that most students in a liberal arts math course are not math majors, and are unlikely to take another math class, Blitzer has provided tools in every chapter to help them master the material with confidence, while also showing them the beauty and fun of math. The variety of topics and flexibility of sequence make this text appropriate for a one- or two-term course in liberal arts mathematics or general education mathematicsAuthor Biography Precalculus, and Trigonometry all published by Pearson.
Table of Contents
1. Problem Solving and Critical Thinking
1.1 Inductive and Deductive Reasoning
1.2 Estimation, Graphs, and Mathematical Models
1.3 Problem Solving
2. Set Theory
2.1 Basic Set Concepts
2.2 Subsets
2.3 Venn Diagrams and Set Operations
2.4 Set Operations and Venn Diagrams with Three Sets
2.5 Survey Problems
3. Logic
3.1 Statements, Negations, and Quantified Statements
3.2 Compound Statements and Connectives
3.3 Truth Tables for Negation, Conjunction, and Disjunction
3.4 Truth Tables for the Conditional and the Biconditional
3.5 Equivalent Statements and Variations of Conditional Statements
3.6 Negations of Conditional Statements and De Morgan's Laws
3.7 Arguments and Truth Tables
3.8 Arguments and Euler Diagrams
4. Number Representation and Calculation
4.1 Our Hindu-Arabic System and Early Positional Systems
4.2 Number Bases in Positional Systems
4.3 Computation in Positional Systems
4.4 Looking Back at Early Numeration Systems
5. Number Theory and the Real Number System
5.1 Number Theory: Prime and Composite Numbers
5.2 The Integers; Order of Operations
5.3 The Rational Numbers
5.4 The Irrational Numbers
5.5 Real Numbers and Their Properties; Clock Addition
5.6 Exponents and Scientific Notation
5.7 Arithmetic and Geometric Sequences
6. Algebra: Equations and Inequalities
6.1 Algebraic Expressions and Formulas
6.2 Linear Equations in One Variable and Proportions
6.3 Applications of Linear Equations
6.4 Linear Inequalities in One Variable
6.5 Quadratic Equations
7. Algebra: Graphs, Functions, and Linear Systems
7.1 Graphing and Functions
7.2 Linear Functions and Their Graphs
7.3 Systems of Linear Equations in Two Variables
7.4 Linear Inequalities in Two Variables
7.5 Linear Programming
7.6 Modeling Data: Exponential, Logarithmic, and Quadratic Functions
8. Personal Finance
8.1 Percent, Sales Tax, and Discounts
8.2 Income Tax
8.3 Simple Interest
8.4 Compound Interest
8.5 Annuities, Methods of Saving, and Investments
8.6 Cars
8.7 The Cost of Home Ownership
8.8 Credit Cards
9. Measurement
9.1 Measuring Length; The Metric System
9.2 Measuring Area and Volume
9.3 Measuring Weight and Temperature
10. Geometry
10.1 Points, Lines, Planes, and Angles
10.2 Triangles
10.3 Polygons, Perimeter, and Tessellations
10.4 Area and Circumference
10.5 Volume and Surface Area
10.6 Right Triangle Trigonometry
10.7 Beyond Euclidean Geometry
11. Counting Methods and Probability Theory
11.1 The Fundamental Counting Principle
11.2 Permutations
11.3 Combinations
11.4 Fundamentals of Probability
11.5 Probability with the Fundamental Counting Principle, Permutations, and Combinations
| 677.169 | 1 |
0764563890
9780764563898
CliffsQuickReview Trigonometry:CliffsQuickReview course guides cover the essentials of your toughest classes. Get a firm grip on core concepts and key material, and test your newfound knowledge with review questions.CliffsQuickReview Trigonometry provides you with all you need to know to understand the basic concepts of trigonometry — whether you need a supplement to your textbook and classes or an at-a-glance reference. Trigonometry isn't just measuring angles; it has many applications in the real world, such as in navigation, surveying, construction, and many other branches of science, including mathematics and physics. As you work your way through this review, you'll be ready to tackle such concepts asTrigonometric functions, such as sines and cosinesGraphs and trigonometric identitiesVectors, polar coordinates, and complex numbersInverse functions and equationsYou can use CliffsQuickReview Trigonometry in any way that fits your personal style for study and review — you decide what works best with your needs. You can read the book from cover to cover or just look for the information you want and put it back on the shelf for later. Here are just a few ways you can search for topics:Use the free Pocket Guide full of essential informationGet a glimpse of what you'll gain from a chapter by reading through the Chapter Check-In at the beginning of each chapterUse the Chapter Checkout at the end of each chapter to gauge your grasp of the important information you need to knowTest your knowledge more completely in the CQR Review and look for additional sources of information in the CQR Resource CenterUse the glossary to find key terms fastWith titles available for all the most popular high school and college courses, CliffsQuickReview guides are a comprehensive resource that can help you get the best possible grades.
Back to top
Rent CliffsQuickReview Trigonometry 1st edition today, or search our site for David A. textbooks. Every textbook comes with a 21-day "Any Reason" guarantee. Published by Cliffs Notes.
| 677.169 | 1 |
Our mathematics classes use the TI 83 graphing calculators. If you choose to purchase
your own, it would be best to purchase one of these models.
Students may progress through levels of math courses downward sequentially or
laterally. Any lateral movement should be with permission of the instructor. Students
may not move backwards by level. (i.e. A student who has taken Geometry may not
enroll in Applied Math I or II) Students must pass a course in one level before
progressing to the next.
Applied Math I (Course #301) Level I 1.00 credit
Applied Math I is a course designed as a beginning study of Algebra. The course covers
real numbers, variables, linear equations, and probability. Emphasis is placed on
strengthening basic skills, real like problem solving strategies and graphing.
One semester course
prerequisite: Successful completion of Pre-Algebra
Applied Math II (Course #313) Level II 1.00 credit
Applied Math II is a second-year, one credit course for students who have successfully
completed Applied Math I or Algebra I. The course integrates topics from algebra,
geometry and trigonometry. The student will learn to discover and apply mathematical
strategies through labs, projects and group activities and a computer program called
cognitive tutor. The course is designed to help students apply higher level mathematics
to real life situations.
One semester course
prerequisite: successful completion of one semester of Applied Math I or Algebra I.
Applied Math III (Course #323) Level III 1.00 credit
Applied Math III is a third year mathematics course involving algebra, geometry, and
statistics. Cognitive Tutor Algebra is used to reinforce algebra concepts. Algebra topics
include linear equations, systems of linear equations, exponents, and quadratic
equations. Geometry topics include the language of geometry (points, line, planes,
angles, etc.), triangles, circles, perimeter, area, surface area, and volume. Basic
statistics concepts such as measures of center, measures of variation, and probability
are also covered.
One semester course
prerequisite: successful completion of Applied Math I and II
Algebra I (Course #301) Level I 1.00 credit
Algebra I is designed as a beginning study of Algebra. This course covers real numbers,
variables, linear equations and inequalities, linear systems, exponents, functions,
factoring and probability. Emphasis is placed on real life problem solving strategies and
graphing.
One nine week course
Prerequisite: Successful completion of Pre-Algebra
Algebra II (Course #311) Level III 1.00 credit
Algebra II is a course designed for students who have successfully completed Algebra I.
The course presents function and graphing through a contemporary approach utilizing
hands-on experiments, technology, creating mathematical models for real world
applications and team explorations. The course is designed to introduce students to the
topics needed for successful work in advanced mathematics.
One semester course
prerequisite: successful completion of Algebra I
Algebra II Accelerated (Course #300) Level I 1.00 credit
Algebra II Accelerated is a course dealing with the theory of algebra as well as a
development and expansion of eighth grade algebra skills. This is a rigorous course
designed to provide students with the prerequisite skills needed for the successful
completion of higher level math courses. The main topics include matrices, polynomial
functions and equations, conic sections and rational expressions. A scientific calculator is
required.
One semester course
prerequisite: recommendation of the school
Advanced Algebra/Trigonometry Accelerated (Course #320) Level III 1.00 credit
Advanced Algebra/Trig is a course, which builds on the skills learned in Algebra I, II and
Geometry. It is a fast paced and academically demanding course dealing with topics
such as linear functions, quadratic functions, exponential functions, logarithmic
functions, rational expressions and functions, radicals, sequences, series and the
trigonometric functions and their inverse functions. This is a rigorous course designed to
provide students with the prerequisite skills needed for the successful completion of
higher level math courses.
One semester course
prerequisite: Successful completion of Geometry ACC and recommendation
Geometry (Course #321) Level I 1.00 credit
Geometry is a course for students who have successfully completed Algebra II or
Applied Math I, II and III. This course presents geometry by using a guided-discovery
approach, whereby students work with the tools of geometry and application,
technology, mathematical models and team explorations are utilized. This course is
designed to introduce students to the topic needed for successful work in trigonometry
and pre-calculus.
One semester course
prerequisite: successful completion of Algebra I or Applied Math I, II, and III
Geometry Accelerated (Course #310) Level II 1.00 credit
Geometry Accelerated is open to students in the 10th grade in the accelerated
curriculum. The course is rigorous and covers all topics of traditional plane geometry
and many topics of solid geometry. Logic and problem solving is emphasized through
content knowledge, formal and informal proof, utilizing manipulative and application
problems.
One semester course
Prerequisite: Successful completion of Algebra II Accelerated
Trigonometry (Course #331) Level IV .50 credit
Trigonometry is a half-credit, nine week, college preparatory course for juniors and
seniors who have successfully completed Algebra I and II and a course in geometry. The
course presents analytical and applied trigonometry and its applications to fields such as
architecture, surveying, astronomy periodic motion and natural phenomena. The content
is designed to prepare college-bound students for future mathematical experiences in
science, medicine, social and behavioral sciences, engineering, and technical fields.
A Texas Instruments T1-83 or T1-84 plus graphing calculator is required for this course.
One nine week course
prerequisite: successful completion of Algebra I & II and Geometry
Pre calculus (Course #332) Level IV .50 credit
Pre calculus is a half-credit, nine week, college preparatory course for juniors and
seniors who have successfully completed Algebra I & II, Geometry, and Trigonometry.
The course covers the graphing, analysis, and application of functions, rates of change,
growth and decay, series and other advanced topics. The course is designed to
introduce students to the topics and techniques needed for successful work in calculus
and advanced mathematics.
A Texas Instruments T1-83 or T1-84 plus graphing calculator is required for this course.
One nine week course
prerequisite: successful completion of four terms of Algebra I & II, Geometry, and
Trigonometry
AP Calculus AB (Course #330) Level V 1.00 credit
AP Calculus AB is a weighted, advanced placement, elective course covering the calculus
of a single variable. This course has been audited and approved by the College Board as
an advanced placement course and its curriculum is recognized by colleges and
universities. The content covers the same content as first level college calculus classes.
Numerical, graphical, analytical and verbal representations will be used to present the
concepts of differential and integral calculus including rates of change, limits, derivatives
and their applications, anti derivatives, techniques of integration and applications of
definite integrals. Computers and graphing calculators will be utilized. The syllabus of
the course satisfies the College Board's requirements for Advanced Placement Calculus
AB.
A Texas Instruments T1-84 or T1-83 plus graphing calculator is required for this course.
One semester course (Elective)
prerequisite: successful completion of Adv. Algebra/Trigonometry Acc. or completion of
Trigonometry/Pre calculus with 80% or better recommended.
Calculus II BC (Course #333) Level VI 1.00 credit
Calculus II BC is an advanced placement, one-credit weighted elective course designed
to allow students to explore topics typically covered in second or third level college
calculus classes. This course has been audited and approved by the College Board as an
advanced placement course and its curriculum is recognized by colleges and universities.
The course covers differential equations, hyperbolic functions, advanced techniques of
integration, infinite series, complex implicit relations and their applications, parametric
functions, and polar equations. Applications of calculus to other disciplines will be
explored. The syllabus of this course will follow the outline of topics provided by the
college board for AP Calculus BV. Students will also be provided the opportunity to
prepare for the AP Calculus exam if they elect to take the exam.
A Texas Instruments T1-84 or T1-83 plus graphing calculator is required for this course.
One semester course (Selective)
prerequisite: successful completion of AP Calculus AB and the permission of the
instructor.
Contemporary Statistics & Data Analysis (Course #350) .50 credit
Students will explore contemporary issues through statistics and data analysis.
Descriptive and inferential statistics will be covered in the course. Topics include
measures of center, measures of variation, probability, discrete and normal probability
distributions, confidence intervals, and hypothesis testing. The TI-83 and statistical
software will be used to analyze statistical data.
One nine week course
elective
prerequisite: successful completion of Algebra I and Algebra
| 677.169 | 1 |
Ordinary Differential Equations
This book aims to lead the reader through the topic of differential equations, a vital area of modern mathematics and science. This book provides information about the whole area of differential equations, concentrating first on the simpler equations.
| 677.169 | 1 |
Linear Algebra
9780135367971
ISBN:
0135367972
Edition: 2 Pub Date: 1971 Publisher: Prentice Hall
Summary: This introduction to linear algebra features intuitive introductions and examples to motivate important ideas and to illustrate the use of results of theorems. Linear Equations; Vector Spaces; Linear Transformations; Polynomials; Determinants; Elementary canonical Forms; Rational and Jordan Forms; Inner Product Spaces; Operators on Inner Product Spaces; Bilinear Forms For all readers interested in linear algebra. ...> Hoffman, Kenneth is the author of Linear Algebra, published 1971 under ISBN 9780135367971 and 0135367972. Five hundred five Linear Algebra textbooks are available for sale on ValoreBooks.com, nine used from the cheapest price of $125.00, or buy new starting at $188
| 677.169 | 1 |
Learn about the scientific study of the structure of the atom, its energy states, and its interactions with other particles...
see more
Learn about the scientific study of the structure of the atom, its energy states, and its interactions with other particles and fields. Provides materials for pre-service teacher trainees.Compulsory Readings for Atomic Physics (PDF)
Learn how organisms interact with one another and how they interact with the environment. Key ecological concepts in the...
see more
Learn how organisms interact with one another and how they interact with the environment. Key ecological concepts in the organization of organisams , populatin growth, and community dynamics which are important components of pre-univesity ecology curriculum will also be covered.Compulsory Readings for Biology III: Ecology (PDF)
This PDF provides the second half of the basic first year University course in Chemistry. This module will review chemical...
see more
This PDF provides the second half of the basic first year University course in Chemistry. This module will review chemical reactions and the energy laws that govern them, examine various types of solutions and their properties, and discuss some introductory aspects of organic chemistry.Compulsory Readings for Introduction to Chemistry II (PDF)
Assists teachers in understanding and interpreting the properties of numbers and provides a background to the numerous proofs...
see more
Assists teachers in understanding and interpreting the properties of numbers and provides a background to the numerous proofs and solutions to various mathematical equations. Material is crucial for the teaching of secondary school mathamatics.Compulsory Readings for Mathematics II: Number Theory (PDF)
Develops a working knowledge of and ability to apply numerical methods in solving some basic mathematical problems such as...
see more
Develops a working knowledge of and ability to apply numerical methods in solving some basic mathematical problems such as interpolation, numerical integration, and finding roots of functions.Compulsory Readings for Numerical Methods (PDF)
| 677.169 | 1 |
Course Detail
Links
Math Methods for Scientists
Instructor
Belloni
Designed to develop a basic competence in many areas of mathematics needed for junior/senior level work in the sciences. Basic methods of power series, complex numbers, Fourier analysis, linear algebra, ordinary and partial differential equations, multivariable and vector calculus covered clearly and carefully but without detailed proofs. Symbolic computation and scientific visualization tools used as appropriate. May not be taken for major credit in the senior year.
Students entering 2012 and after: satisfies the Mathematical and Quantitative Thought distribution requirement.
Students entering before 2012: counted toward the fulfillment of the Natural Science and Mathematics distribution requirement.
| 677.169 | 1 |
Aims at giving a comprehensive review of literature on perspective constructions from the Renaissance to the end of the eighteenth century. Covering the work of some 175 authors, this book treats the emergence of the various methods of constructing perspective, the development of the theories underlying the constructions, and more. more...
Presents an introductory material for topics covered in the IMA workshops on 'Optimization and Control' and 'Applications in Biology, Dynamics, and Statistics' held during the IMA year on Applications of Algebraic Geometry. This title also presents a fresh direction towards a study of non-commutative real algebraic geometry. more...
This new-in-paperback edition provides an introduction to algebraic and arithmetic geometry, starting with the theory of schemes, followed by applications to arithmetic surfaces and to the theory of reduction of algebraic curves. Clear explanations of both theory and applications, and almost 600 exercises are included in the text. - ;This new-in-paperback... more...
Rationality problems link algebra to geometry, and the difficulties involved depend on the transcendence degree of $K$ over $k$, or geometrically, on the dimension of the variety. A major success in 19th century algebraic geometry was a complete solution of the rationality problem in dimensions one and two over algebraically closed ground fields of... more...
Students and researchers in physics, engineering and other sciences will find this compilation of one letter abbreviations used in mathematics and physics invaluable. All the information included is practical, rarely used results are excluded. Excellent to keep as a handy reference! Selected abbreviations you will find inside this guide: A - Ampere,... more...
Students and research workers in mathematics, physics, engineering and other sciences will find this compilation of Logarithmic Identities invaluable. All the information included is practical, rarely used results are excluded. Great care has been taken to present all results concisely and clearly. Excellent to keep as a handy reference! If you don'tComprises of articles that were offered as a tribute to one of the world's greatest mathematician, Alexander Grothendieck. This book carries contributions that contain material that is considered foundational to the subject. It carries topics that are addressed by top-notch contributors to match the breadth of Grothendieck's own interests. more...
This volume is a homage to the memory of the Spanish mathematician Federico Gaeta (1923-2007). Apart from a historical presentation of his life and interaction with the classical Italian school of algebraic geometry, the volume presents surveys and original research papers on the mathematics he studied. Specifically, it is divided into three parts:... more...
| 677.169 | 1 |
Mathematical Ideas (12th Edition)
9780321693815
ISBN:
0321693817
Edition: 12 Pub Date: 2011 Publisher: Addison Wesley
Summary: Mathematical Ideas offers students a comprehensive understanding of how they can relate math to everyday situations and even more unique situations such as those from film and television. It uses an innovative approach to guide students through the complex mathematical concepts through relatively easy to understand approaches that are easy to apply. These methods form part of a very readable and accessible textbook. ...It also offers excellent study tools to aid subject comprehension. We offer many mathematics textbooks of this calibre to buy brand new or to rent in good condition. We also offer a buyback service for those with used textbooks to sell.
Miller, Charles David is the author of Mathematical Ideas (12th Edition), published 2011 under ISBN 9780321693815 and 0321693817. Four hundred thirty five Mathematical Ideas (12th Edition) textbooks are available for sale on ValoreBooks.com, one hundred sixteen used from the cheapest price of $44.43, or buy new starting at $92 [more Standard Edition. We will ship same day or next day. Expedited Shipping Available. A++ Service. 15 days money back guarantee. We do not guarantee supplemental mater [more]
Brand new. StandardThe book clearly showed the breakdown for all of the different types of problems that were introduced and had plenty of practice problems to work on, which was very helpful for studying before tests especially with a teacher that did not always explain the problems very well.
It was one of the basic concepts of math class that students had to chose from.
I used this book for a mathematical course for liberal arts degree. It was the second part and the course number was 152. We studied line graphs, geometry, statistics, and probability. I felt that the material was well described both in the book and in class, the online tutorials were overkill.
I felt that this book only partially prepared me for the GRE exam, I did study for the test using this particular text, and I did complete the practice quizzes, but I did not do quite as well as I had hoped. Overall I thought that it prepared pretty well, but could use some improvement in the English and Math sections.
| 677.169 | 1 |
Precise Calculator has arbitrary precision and can calculate with complex numbers, fractions, vectors and matrices. Has more than 150 mathematical functions and statistical functions and is programmable (if, goto, print, return, for).
| 677.169 | 1 |
Trigonometry With Infotrac
9780534403928
ISBN:
0534403921
Edition: 5 Pub Date: 2003 Publisher: Thomson Learning
Summary: This text provides students with a solid understanding of the definitions and principles of trigonometry and their application to problem solving. Identities are introduced early in Chapter 1. They are reviewed often and are then covered in more detail in Chapter 5. Also, exact values of the trigonometric functions are emphasized throughout the textbook. There are numerous calculator notes placed throughout the text....
McKeague, Charles P. is the author of Trigonometry With Infotrac, published 2003 under ISBN 9780534403928 and 0534403921. Sixty six Trigonometry With Infotrac textbooks are available for sale on ValoreBooks.com, sixty four used from the cheapest price of $0.01, or buy new starting at $25.40.[read more
| 677.169 | 1 |
Introductory Modern Algebra: A Historical Approach [NOOK Book] ...
More About
This Book With a few pertinent excerpts from the writings of some of the greatest mathematicians, the Second Edition uniquely facilitates the understanding of pivotal algebraic ideas. Edition also includes:
An in-depth explanation of the principles and practices of modern algebra in terms of the historical development from the Renaissance solution of the cubic equation to Dedekind's ideals
Historical discussions integrated with the development of modern and abstract algebra in addition to many new explicit statements of theorems, definitions, and terminology
A new appendix on logic and proofs, sets, functions, and equivalence relations
Over 1,000 new examples and multi-level exercises at the end of each section and chapter as well as updated chapter summaries
Introductory Modern Algebra: A Historical Approach, Second Edition is an excellent textbook for upper-undergraduate courses in modern and abstract algebra.
Editorial Reviews
Booknews
A textbook for a one-semester introduction for undergraduate mathematics majors and prospective high-school teachers of mathematics. Explains the principles and practices of modern algebra in terms of its historical development from the Renaissance solution to the cubic equation to Galois' exposition of his major ideas. Includes both computer and pencil-and-eraser exercises, the answers to which are in the teacher's manual. Annotation c. by Book News, Inc., Portland, Or.
From the Publisher
"This book is an excellent book for an upper-level, undergraduate, one or two semester course, in modern algebra, for a typical University student population that is not especially strong in proofs." (MAA Reviews, 13 January 2014)
Related Subjects
Meet the Author
SAUL STAHL, PhD, is Professor in the Department of Mathematics at the University of Kansas. In addition to authoring six previous books and more than thirty papers in the field of geometry, Dr. Stahl has twice been the recipient of the Carl B. Allendoerfer Award from the Mathematical Association
| 677.169 | 1 |
Precalculus: Graphs and ModelsBarnett Graphs & Modelsseries in college algebra and precalculus maximizes student comprehension by emphasizing computational skills, real-world data analysis and modeling, and problem solving rather than mathematical theory. Many examples feature side-by-side algebraic and graphical solutions, and each is followed by a matched problem for the student to work. This active involvement in the learning process helps students develop a more thorough understanding of concepts and processes.A hallmark of the Barnett series, the function concept serves as a unifying theme. A major objective of this book is to develop a library of elementary functions, including their important properties and uses. Employing this library as a basic working tool, students will be able to proceed through this course with greater confidence and understanding as they first learn to recognize the graph of a function and then learn to analyze the graph and use it to solve the problem. Applications included throughout the text give the student substantial experience in solving and modeling real world problems in an effort to convince even the most skeptical student that mathematics is really useful.
Graphs and Models
Functions, graphs, and models
Using Graphing Utilities
Functions
Functions
Graphs and Properties
1-4
Graphs and Transformations
Operations on Functions; Composition
Inverse Functions
Review
Group Activity
Mathematical Modeling–Choosing a Long Distance Calling Plan
Modeling with linear and quadratic functions
Linear Functions
Linear Equations and Models
Quadratic Functions
Complex Numbers
Quadratic Equations and Models
Additional Equation Solving Techniques
Solving Inequalities
Review
Group Activity
Mathematical Modeling in Population Studies Cumulative Review Exercise for Chapters
| 677.169 | 1 |
Mathematical sciences include the areas of pure and applied mathematics, mathematics education, actuarial science, and statistics. Mathematics involves the study of problems in areas such as algebra, geometry, analysis, and logic and of problems arising in the real world. Mathematics, actuarial science and statistics are used in the physical sciences, engineering, the social, life, and management sciences. Mathematics education involves the training of prospective secondary teachers.
| 677.169 | 1 |
Mathematics - Calculus (464Florian Cajori's A History of Mathematics is a seminal work in American mathematics. The book is a summary of the study of mathematics from antiquity through World War I, exploring the evolution of advanced mathematics. As the first history of mathematics published in the United States, it has an important place in the libraries of scholars and universities. A History of Mathematics is a history of mathematics, mathematicians, equations and theories; it is not a textbook, and the early chapters do not demand a thorough understanding of mathematical concepts. The book starts with the use of mathematics in antiquity, including contributions by the Babylonians, Egyptians, Greeks and Romans. The sections on the Greek schools of thought are very readable for anyone who wants to know more about Greek arithmetic and geometry. Cajori explains the advances by Indians and Arabs during the Middle Ages, explaining how those regions were the custodians of mathematics while Europe was in the intellectual dark ages. Many interesting mathematicians and their discoveries and theories are discussed, with the text becoming more technical as it moves through Modern Europe, which encompasses discussion of the Renaissance, Descartes, Newton, Euler, LaGrange and Laplace. The final section of the book covers developments in the late 19th and early 20th Centuries. Cajori describes the state of synthetic geometry, analytic geometry, algebra, analytics and applied mathematics. Readers who are not mathematicians can learn much from this book, but the advanced chapters may be easier to understand if one has background in the subject matter. Readers will want to have A History of Mathematics on their bookshelves.
The present small volume is intended to form a sound introduction to a study of the Differential Calculus suitable for the beginner. It does not therefore aim at completeness, but rather at the omission of all portions which are usually considered best left for a later reading. At the same time it has been constructed to include those parts of the subject prescribed in Schedule I. of the Regulations for the Mathematical Tripos Examination for the reading of students for Mathematical Honours in the University of Cambridge.<br><br>Particular attention has been given to the examples which are freely interspersed throughout the text. For the most part they are of the simplest kind, requiring but little analytical skill. Yet it is hoped they will prove sufficient to give practice in the processes they are intended to illustrate.
The present volume is intended to form a sound introduction to a study of the Integral Calculus, suitable for a student beginning the subject. Like its companion, the Differential Calculus for Beginners, it does not therefore aim at completeness, but rather at the omission of all portions of the subject which are usually regarded as best left for a later reading.<br><br>It will be found, however, that the ordinary processes of integration are fully treated, as also the principal methods of Rectification and Quadrature, and the calculation of the volumes and surfaces of solids of revolution. Some indication is also afforded to the student of other useful applications of the Integral Calculus, such as the general method to be employed in obtaining the position of a Centroid, or the value of a Moment of Inertia.
One of the purposes of the elementary working courses in mathematics of the freshman and sophomore years is to exhibit the bond that unites the experimental sciences. "The bond of union among the physical sciences is the mathematical spirit and the mathematical method which pervade them." For this reason, the applications of mathematics, not to artificial problems, but to the more elementary of the classical problems of natural science, find a place in every working course in mathematics. This presents probably the most difficult task of the text-book writer,- namely, to make clear to the student that mathematics has to do with the laws of actual phenomena, without at the same time undertaking to teach technology, or attempting to build upon ideas which the student does not possess. It is easy enough to give examples of the application of the processes of mathematics to scientific problems; it is more difficult to exhibit by these problems, how, in mathematics, the very language and methods of thought fit naturally into the expression and derivation of scientific laws and of natural concepts.<br><br>It is in this spirit that the authors have endeavored to develop the fundamental processes of the calculus which play so important a part in the physical sciences; namely, to place the emphasis upon the mode of thought in the hope that, even though the student may forget the details of the subject, he will continue to apply these fundamental modes of thinking in his later scientific or technical career. It is with this purpose in mind that problems in geometry, physics, and mechanics have been freely used. The problems chosen will be readily comprehended by students ordinarily taking the first course in the calculus.<br><br>A second purpose in an elementary working course in mathematics is to secure facility in using the rules of operation which must be applied in calculations.
The Directly-Useful Technical Series requires a few words by of introduction. Technical books of the past have arranged themselves largely under two sections: the Theoretical and the Practical and the exercises are to be of a directly-useful topics in this book are arranged for primary courses in calculus in which the formal division into differential calculus and integral calculus is deemed necessary. The book is mainly made up of matter from my Infinitesimal Calculus. Changes, however, have been made in the treatment of several topics, and some additional matter has been introduced, in particular that relating to indeterminate forms, solid geometry, and motion. The articles on motion have been written in the belief that familiarity with the notions of velocity and acceleration, as treated by the calculus, is a great advantage to students who have to take mechanics.<br><br>Part of the preface of my Infinitesimal Calculus applies equally well to this book. Its purpose is to provide an introductory course for those who are entering upon the study of calculus either to prepare themselves for elementary work in applied science or to gratify and develop their interest in mathematics. Little more has been discussed than what may be regarded as the essentials of a primary course. An attempt is made to describe and emphasise the fundamental principles of the subject in such a way that, as much as may reasonably be expected, they may be clearly understood, firmly grasped, and intelligently applied by young students. There has also been kept in view the development in them of the ability to read mathematics and to prosecute its study by themselves.<br><br>With regard to simplicity and clearness in the exposition of the subject, it may be said that the aim has been to write a book that will be found helpful by those who begin the study of calculus without the guidance and aid of a teacher.
eBook
Vector AnalysisA Text-Book for the Use of Students of Mathematics and Physics
by Edwin Bidwell Wilson
When I undertook to adapt the lectures of Professor Gibbs on Vector Analysis for publication in the Yale Bicentennial Series, Professor Gibbs himself was already so fully engaged upon his work to appear in the same series, Elementary Principles in Statistical Mechanics, that it was understood no material assistance in the composition of this book could be expected from him. For this reason he wished me to feel entirely free to use my own discretion alike in the selection of the topics to be treated and in the mode of treatment. It has been my endeavor to use the freedom thus granted only in so far as was necessary for presenting his method in text-book form.<br><br>By far the greater part of the material used in the following pages has been taken from the course of lectures on Vector Analysis delivered annually at the University by Professor Gibbs. Some use, however, has been made of the chapters on Vector Analysis in Mr. Oliver Heaviside's Electromagnetic Theory (Electrician Series, 1893) and in Professor Föppl's lectures on Die Maxwell'sche Theorie der Electricitāt (Teubner, 1894). My previous study of Quaternions has also been of great assistance.<br><br>The material thus obtained has been arranged in the way which seems best suited to easy mastery of the subject. Those Arts, which it seemed best to incorporate in the text but which for various reasons may well be omitted at the first reading have been marked with an asterisk (*). Numerous illustrative examples have been drawn from geometry, mechanics, and physics. Indeed, a large part of the text has to do with applications of the method.
The significance of the Calculus, the possibility of applying it in other fields, its usefulness, ought to be kept constantly and vividly before the student during his study of the subject, rather than be deferred to an uncertain future.<br><br>Not only for students who intend to become engineers, but also for those planning a profound study of other sciences, the usefulness of the Calculus is universally recognized by teachers; it should be consciously realized by the student himself. It is obvious that students interested primarily in mathematics, particularly if they expect to instruct others, should recognize the same fact.<br><br>To all these, and even to the student who expects only general culture, the use of certain types of applications tends to make the subject more real and tangible, and offers a basis for an interest that is not artificial. Such an interest is necessary to secure proper attention and to insure any real grasp of the essential ideas.<br><br>For this reason, the attempt is made in this book to present as many and as varied applications of the Calculus as it is possible to do without venturing into technical fields whose subject matter is itself unknown and incomprehensible to the student, and without abandoning an orderly presentation of fundamental principles.<br><br>The same general tendency has led to the treatment of topics with a view toward bringing out their essential usefulness.
AcTUAEiAL science is peculiarly dependent upon the Theory of Probabilities, the solution of many of its problems is best effected by resort to the Differential and Integral Calculus and in practical work the Calculus of Finite Differences is almost indispensable. Excellent text-books on these subjects are, of course, available but none of them has been written with the special requirements of the actuary in view. In beginning his training the student is, therefore, confronted by the difficulty of judicious selection and in the circumstances it has appeared to the Council of the Institute of Actuaries that a mathematical text-book sufficiently comprehensive, with the standard works on Higher Algebra, to provide the ground-work of an actuarial education would be of great value. At the request of the Council, Mr Alfred Henry has undertaken the preparation of such a work and the resulting volume is issued in the confident expectation that it will materially lighten the toil of those who essay to qualify themselves for an actuarial career. A. W.W. May 1922.
In this text on differential calculus I have continued the plan adopted for my Analytic Geometry, wherein a few central methods are expounded and appUed to a la, rge variety of examples to the end that the student may learn principles, and gain power. In this way the differential calculus makes only a brief text suitable for a terms work and leaves for the integral calculus, which in many respects is far more important, a greater proportion of time than is ordinarily devoted to it. As material for review and to provide problems for which answers are not given, a supplementary list, containing about haKas many exercises as occur in the text, is placed at the end of the book. I wish to acknowledge my indebtedness to Professor H.W. Tyler and Professor E.B. Wilson for advice and criticism and to Dr. Joseph Lipka for valuable assistance in preparing the manuscript and revising the proof. H.B. Phillips. Boston, Mass., August, 1916.
The present volume is the outgrowth of lists of problems prepared by the author from year to year to supplement the textbook used in the Sheffield Scientific School. Many of the problems have been furnished by his colleagues through the media of test and examination papers, or by direct contribution to this collection at some stage in its development. Since many of these in turn were doubtless adapted from other sources, no attempt has been made to assign a problem to an original source. The principles embodied in the problems are surely common property. The book does not aim to be a textbook on the calculus, nor simply a collection of applied problems in science and engineering. It is believed that a teacher can find here a supplementary list of workable problems on any topic ordinarily included in a general course in the calculus. No attempt is made to explain the theory of any science involved in a problem except in so far as it is necessary to an intelligent understanding of the problem and its purpose. The text introducing the exercises aims to explain the technique of the subject and to point out some common pitfalls to the student. The answers to a large number of the problems have been purposely omitted. The general object has been to give the answer to one or more examples of each type so that the student may attack further examples of a similar nature with increased confidence. At the same time, other answers have been omitted so that the book may be used in tests and in work where it is not desirable for the student to have the answers.
This is not a book on ealculus or analytic geometry (the market is flooded with them); noris this a book on engineering or any branch of it. The book is intended to enable an engineer to make a better and more extended Tise of higher mathematics in his work. The purpose of the book may be best amplified by a parable. In a manual-training school (on the moon) machinist apprentices were taught their trade in the following manner: During the first year they had a highly theoretical course on the subject of various tools used on lathes, planers, boring mills, miUing machines, etc. The shapes of the tools were derived and explained in detail on compUcated drawings; most general theorems were proved concerning these tools; it was shown how to design these tools, not only for a few simple practical cases, but principally for many hypothetical cases which were supposed to be of some importance on Mars. This latter part of the course was justified on the plea of mental gymnastics. No actual machine-tools were provided in this department and no practice was afforded the student in the use of the tools. During the next two years the students were required to finish, fit, and assemble the parts of various engines and other pieces of mechanical apparatus. Had they been previously trained in the use of machine-tools, their shop-work would have been much simplified.
The time which has elapsed since the publication of the first edition of this treatise has been a period of great activity in the development of the Theory of Functions of a real variable. In particular, the introduction of the Lebesgue Integral, which was new in 1907, has since produced its full effect, in the generalization of the Theory of Integration, and upon the theory of the representation of functions by means of Fourier's, and other, series and integrals.<br><br>In order to give an adequate account of the subject in its present condition, a large amount of new matter has had to be introduced; and this has made it necessary to divide the treatise into two volumes. The matter contained in the first edition has been carefully revised, amplified, and in many cases rewritten.<br><br>The parts of the subject which were dealt with in the first five chapters of the first edition have been expanded into the eight chapters of the present first volume of the new edition. With a view to greater unity of treatment of the Theory of Integration, some theorems which appeared in Chapter VI, of the first edition, have however been included in the present volume. A considerable part of the Theory of Integration, in relation to series and sequences, still however remains for treatment in Volume II.<br><br>On controversial matters connected with the fundamentals of the Theory of Aggregates, the considerable diversity of opinion which has arisen amongst Mathematicians has been taken into account, but in general no attempt has been made to give dogmatic decisions between opposed opinions. In view of the delicate questions which arise as to the legitimacy and meaning of the axiom known as the Multiplicative Axiom, or as the Principle of Zermelo, the policy has been adopted of so framing the proofs of theorems as to avoid an appeal to the axiom, whenever that course appeared to be possible; in other cases, the necessity for the employment of the axiom has been pointed out.<br><br>Ample references to sources of information are given throughout, but such references do not provide the means for compiling a complete list of writings on the subject. No attempt has been made to settle questions of priority of discovery.<br><br>My thanks are due to Dr H. F. Baker, F.R.S., Lowndean Professor of Astronomy and Geometry, in the University of Cambridge, who has kindly read nearly all the proofs as they passed through the Press.
eBook
The Integral CalculusOn
by James Ballantyne
The Integral Calculus: On was written by James Ballantyne in 1919. This is a 44 page book, containing 12245 words and 4 pictures. Search Inside is enabled for this title.
The first five show distinctly that the independent variable is ac, whereas the last three do not explicitly indicate the variable and should not be used unless there is no chance of a misunderstanding.2. The fundamental formulas of differential calculus are derived directly from the application of the dehnition (2)or (3)and from a few fundamental propositions in limits. First may be mentioned(5) D(u 31; 11) -- Du j;Dv, +vDu. (6) (7)It may be recalled that(4), which is the rule for differentiating a function of a function, follows from the application of the theorem that the limit of a product is the product of the limits to the fractional identity- -- ;whence Aa: Ay Aa: lim 55: limA 2 lim 534: limi lim 934, which is equivalent to(4). Similarly, if y= f(.1:)and if rc, as the inverse function of y, be written re :f-1(y) from analogy withy =-sins: and :c=- sin 1 y, the relation(5) follows from the fact that AxAy and AyAa: are reciprocals. The next three result from the immediate application of the theorems concerning limits of sums, products, and quotients( 21).The rule for differentiating a power is derived in case nis integral by the application of the binomial theorem. and the limit when A.r=0is clearly n:1: 1.The result may be extended to rational values of the index nby writing n= B, y :xii, 1 I ::xl and by differentiating both sides of the equation and reducing. To prove that(7) still holds when nis irrational, it would be necessary to have a workable definition of irrational numbers and to develop the properties of such numbers in greater detail than seems wise at this point. The formula is therefore assumed in accordance with the principle of permanence of form( 178), just as formulas like ama =a +of the theory of exponents, which may readily be proved for rational bases and exponents, are assumed without proof to hold also for irrational bases and exponents. See, however, 18-25 and the exercises thereunder. It is frequently better to regard the quotient as the product u- v-1and apply(6). TFor when Arn = 0, then Ay= 0 or AyAn: could not approach a limit.
The following volume is a sequel to my treatise on the Differential Calculus, and, like that, is written as a text-book. The last chapter, however, a Key to the Solution of Differential Equations, may prove of service to working mathematicians.<br><br>I have used freely the works of Bertrand, Benjamin Peirce, Todhunter, and Boole; and I am much indebted to Professor J. M. Peirce for criticisms and suggestions.<br><br>I refer constantly to my work on the Differential Calculus as Volume I.; and for the sake of convenience I have added Chapter V. of that book, which treats of Integration, as an appendix to the present volume.
We may distinguish different stages in the solution of a problem. The first stage we might say is the proof that the quantities sought for really exist, that it is possible to satisfy the given conditions or, as the case may be, the proof that it is impossible. In the latter case we have done with the problem. Take for instance the celebrated question of the squaring of the circle. We may in a more generalized form state it thus: Find the integral numbers, which are the coefficients of an algebraic equation, of which It is one of the roots. Thirty years ago Lindemann showed that integral numbers subject to these conditions do not exist and thus a problem as old almost as human history came to an end. Or to give another instance take Fermats problem, for the solution of which the late Mr. Wolfskehl, of Darmstadt, has left$25, 000 in his will. Find the integral numbers x, y, zthat satisfy the equation Tn-4- 7 n7n x Ty- z, where nis an integral number greater than two. Fermat maintained that it is impossible to satisfy these conditions and he is probably right. But as yet it has not been shown. So the solution of the problem may or may not end in its first stage. In many other cases the first stage of the solution may be so easy, that we immediately pass on to the second stage of finding methods to calculate the unknown quantities sought for. Or even if the first stage of the solution is not so easy, it may be expedient to pass on to the second stage.
It is somewhat remarkable that, whilst almost every department of human knowledge has been simplified and brought down to the level of ordinary capacities, scarcely any attempt has been made to simplify and illustrate by familiar examples one of the most elegant and useful branches of mathematical science. Most of the existing works on the Differential and Integral Calculus are written for the use of Students in the Universities, and require a previous knowledge of almost every branch of Pure Mathematics. It is quite obvious, however, that the great leading principles of this science may be communicated to youth at a much earlier period, and with much less acquaintance with the other branches of mathematics than is generally supposed. The pupil may begin to study the Differential and Integral Calculus after he has acquired the elements of Geometry, and the principles of Algebra as far as the end of quadratic equations. Instead of continuing to prosecute his algebraic studies through the Theory of Equations, Indeterminate Problems, Diophantine Analysis, c.he might advantageously at this period be made acquainted with the A 3 I im.
The aim of this work is to give a brief exposition of some of the devices employed in solving differential equations. The book presupposes only a knowledge of the fundamental formulæ of integration, and may be described as a chapter supplementary to the elementary works on the integral calculus.<br><br>The needs of two classes of students, with whom the author has been brought into contact in the course of his experience as a teacher, have determined the character of the work. For the sake of students of physics and engineering who wish to use the subject as a tool, and have little time to devote to general theory, the theoretical explanations have been made as brief as is consistent with clearness and sound reasoning, and examples have been worked in full detail in almost every case. Practical applications have also been constantly kept in mind, and two special chapters dealing with geometrical and physical problems have been introduced.<br><br>The other class for which the book is intended is that of students in the general courses in Arts and Science, who have more time to gratify any interest they may feel in this subject, and some of whom may be intending to proceed to the study of the higher mathematics.
This book describes what has for many years been the most important part of the regular course in the Calculus for Mechanical and Electrical Engineering students at the Finsbury Technical College. It was supplemented by easy work involving Fourier, Spherical Harmonic, and Bessel Functions which I have been afraid to describe here because the book is already much larger than I thought it would become.<br><br>The students in October knew only the most elementary mathematics, many of them did not know the Binomial Theorem, or the definition of the sine of an angle. In July they had not only done the work of this book, but their knowledge was of a practical kind, ready for use in any such engineering problems as I give here.<br><br>One such student, Mr. Norman Endacott, has corrected the manuscript and proofs. He has worked out many of the exercises in the third chapter twice over. I thank him here for the care he has taken, and I take leave also to say that a system which has, year by year, produced many men with his kind of knowledge of mathematics has a good deal to recommend it. I say this through no vanity but because I wish to encourage the earnest student.
Differential Calculus on the method of Limits. In the more elementary portions I have entered into considerable detail in the explanations with the hope that a reader who is without the assistance of a tutor may be enabled to acquire a competent acquaintance with the subject. To the different chapters will be found appended Examples sufficiently numerous to render another book unnecessary. These examples have been selected almost exclusively from the College and University Examination Papers: the greater part of them will be found to present no very serious difficulty to the student, although a few may reqtdre peculiar analytical skill. My own experience with pupils has been decidedly unfavourable to the system of Differentials; many successful teachers whom I have consulted have expressed a similar opinion, and I have therefore adopted exclusively the method of Differential Coefficients. I have frequently given more than one investigation of a theorem, because I believe that the student derives advantage from viewing the same proposition under different aspects, and that, in order to succeed in the examinations which he may have to undergo, he should be prepared for a considerable variety in the order of arranging the several branches of the subject, and for a corresponding variety in the mode of demonstration.
The first part of this work which contains problems in machine design was published in 1912, and the favorable reception accorded it gave the author the courage to publish the rest of the problems which he had collected and used in his classes for some years. The second and third parts contain problems selected from various branches of hydrauUcs and thermodynamics respectively, in the solution of which it is necessary to use calculus and analytic geometry. The part now offered contains problems selected from various topics in mechanics of materials, and the last part contains problems on electrical engineering. A student or an engineer who wishes to review calculus or analytics, or to acquire faciUty in appUcations of higher mathematics to engineering problems, may thus select at first the part of the work which deals with problems with which he is most familiar, or in which he is particularly interested. The reader will find the authors views on teaching mathematics to engineering students in the Preface to Part I and in the Dialogue following that preface. He is also referred to Part I for a fist of reference works on mathematics and for an Appendix entitled What a Senior in Engineering ought to kno Wabout Mathematics. The author wishes to acknowledge gratefully the assistance of Mr. A.C. Stevens, M.E., instructor in Cornell University, who read the proofs and made some valuable suggestions for the text. CoBNELXi TJnivbbsitt, Ithaca, N.
| 677.169 | 1 |
books.google.co.uk - Engineers looking for an accessible approach to calculus will appreciate Young's introduction. The book offers a clear writing style that helps reduce any math anxiety they may have while developing their problem-solving skills. It incorporates Parallel Words and Math boxes that provide detailed annotations...
| 677.169 | 1 |
Welcome!
The Mathematics and Computer Science Department at
Albion College includes the disciplines of pure and applied
mathematics, computer science, and statistics. The department
offers majors and minors in Mathematics and
Computer Science. See our links on the left for more details.
Mathematics is an
essential element in fields as diverse as medicine, the human genome,
epidemiology, and research analysis.
The above image depicts the
electrical activity of a normal heart as if it were stimulated at a single
point. Color is used to highlight the arrival time of the electrical
signal as it propagates through the heart. The rectangular domain
represents a large slab of the ventricular wall, and all domains use
geometry and fiber orientation that are taken from anatomical data.
Without mathematics there is no other way to view this three-dimensional
concept.
Visit the 1999 Mathematics Awareness Website for more information.
April is Mathematics Awareness Month.
Each year the mathematics community
celebrates the importance of mathematics in our lives.
The theme for 1999 was "Mathematics and Biology".
| 677.169 | 1 |
Mathematical software for the Mac, DOS, Windows, OS/2 and various Unix platforms from Wolfram Research, Inc., Champaign, IL ( Launched in 1988, Mathematica includes numerical, graphical and symbolic computation capabilities, all linked to the Mathematica programming language. Introduced in 2005, Version 5.2 supports 64-bit memory addressing and 64-bit long number partitioning. It also supports threading of numerical linear algebra over multiple CPUs and multicore processors
| 677.169 | 1 |
We went through the entire thing over the semester and I think the structure is perfect for moving students from a basic to complex understanding of analysis. While you may be using Rudin, don't hesitate to look to this book for a really simple breakdown that most math undergrads should be able to understand.
A family friend's boyfriend was a knife salesman and came over to give a presentation. He shows off a few and then gets to his 'favorite' which he promptly uses to cut open a soda can. He then passes the knife around for all see.
When it gets to me, I decide I need to test it's sharpness by lightly running the blade over my index finger. My dad had to take me to the hospital for stitches while my mom stayed back and purchased the knife.
| 677.169 | 1 |
Singapore is number one in Mathematics and number two in Science worldwide in the Third International Mathematics And Science Study (TIMSS) 1999. 93% and 80% of our students are in the international top half for Mathematics and Science respectively.
The mathematics and science curriculum in Singapore has been found to be more comprehensive than that of many countries. Singapore's rigorous curriculum is continually reviewed to ensure that it remains relevant for our students.
Editor's picks
This is a comprehensive curriculum that will give your child a solid foundation in mathematics, build up their confidence and give them a head start on their peers.
"Dear SGBox The books arrived last Friday. The parcel arrived in perfect condition and we are very satisfied with the contents. My daughter has started work in the maths books and finds that they are very well laid out with clear examples and instruction. We have had a quick look through the science books and they promise to be as good as the maths! So far we find that these are excellent products and look forward to ordering from you in the future. Best wishes Sandie McDonnell"
. C. H."
This is a comprehensive curriculum that will give your child a solid foundation in mathematics, build up their confidence and give them a head start on their peers.
"While I have used the Singapore Primary Math books for over 10 years (pre-2001 syllabus), I had not realized that there were more contemporary textbooks available for US based customers. As a homeschool parent, these new texts have far exceeded my expectations and are a significant improvement on the Primary Mathematics texts currently available from US based retailers. The graphics are much more engaging and the supporting materials are very thorough and provide a significant amount of extra practice. I will say, making the transition from 5B old text to 6A new text, the 6A (except for algebra) will predominantly be review (3 of the six chapters) of 5B with some additional challenging problems and twists. That said, for the student having previously worked with Singapore Math, the transition in texts should be a confidence booster because the problems build in complexity at a nice pace. I also can not emphasize enough how pleased I am with the supplementary texts, which include answer keys. The explanations are clear and the additional practice problems are excellent for building skill, speed, accuracy, and fundamental understanding. I would highly recommend these products - not just the textbooks and workbooks but also the additional guides. Karen D."
This is a comprehensive curriculum that will give your child a solid foundation in mathematics, build up their confidence and give them a head start on their peers.
"Hello SGBox! Thank you so very much for your kind prompt service. My 9 year old daughter loves her new books (math) and I love the conceptual way the topic is expressed. Thank you for being an excellent company in a world where customer service is dying. Melina Winterton - Virginia USA"
Bestsellers
This GCE A level Maths textbook incorporates many modern approaches to mathematical understanding while keeping the best of the traditional methods.
"I ordered on line and have to pay by credit card and it was very safe and trouble-free to do business with Sg Box. I paid in AS dollars and was converted to US dollars and even though I am in Australia, the books were delivered to Ghana in Africa without any problems. It was also received without any damage and some days before the estimated time. thanks a lot and very willing to do business with you at all times. R. O. Debrah"
Your child will develop lifelong learning skills, social skills such as effective communication, cooperation and team spirit, and IT skills through participation in these hands-on and IT activities.
"We received our order of books today. They arrived in perfect shape and both our children have begun devouring them. The books look to have excellent content on our initial review. We are all excited to have these resources to work through this summer! S D"
Your child will learn new concepts in a straight-forward and interesting way. He will develop creative and critical thinking and master problem-solving strategies through the worked examples in this section.
This is a comprehensive curriculum that will give your child a solid foundation in mathematics, build up their confidence and give them a head start on their peers.
"I received my order and I am so pleased with the quality of this product! I have an autistic son that I am trying to catch up on his math throughout this summer, and these books are so perfect! They are eye-catching, fun, and progressively logical in their approach to mathematics. I am sold on this product! Thanks for a great product! J. Halisky"
This is a comprehensive curriculum that will give your child a solid foundation in mathematics, build up their confidence and give them a head start on their peers.
"Hello, So sorry for the delay in reply. We did receive our order and we as always are pleased. We are most pleased that we have answer keys which saves me, the parent more time. We have found your products to be a great help with our childrens success in school. Very Best Regards, S. Z."
The questions in this Singapore Mathematics workbook are designed to develop and enhance your child's problem-solving skills, stimulate their creative thinking and build up their interest in Mathematics.
| 677.169 | 1 |
Domain and range
7 videos
3 skills
What values can you and can you not input into a function? What values can the function output? The domain is the set of values that the function is defined for (i.e., the values that you can input into a function). The range is the set of values that the function output can take on.
This tutorial covers the ideas of domain and range through multiple worked examples. These are really important ideas as you study higher mathematics.
| 677.169 | 1 |
More About
This Textbook
Overview
The
Algorithms are presented in English, eliminating the need for knowledge of a particular programming language. Computational and algorithmic exercise sets follow each chapter section and supplementary exercises and computer projects are included in the end-of-chapter material. This Fifth Edition features a new Chapter 3 covering matrix codes, error correcting codes, congruence, Euclidean algorithm and Diophantine equations, and the RSA algorithm.
MARKET: Intended for use in a one-semester introductory course in discrete
| 677.169 | 1 |
Elementary Algebra For College Students Early Graphing
9780136134169
ISBN:
0136134165
Edition: 3 Pub Date: 2007 Publisher: Prentice Hall
Summary: Angel's texts are a proven favorite among students and instructors alike. The Angel texts consistently receive praise for their readability - short, clear sentences are used to ensure the text is readable even for those with weak reading skills- and for the abundance of detailed, worked-out examples... more than any other text! In this revised, 3rd edition of Elementary Algebra Early Graphing for College Students, An...gel continues to focus on the needs of the students taking this class and the instructors teaching them.
Angel, Allen R. is the author of Elementary Algebra For College Students Early Graphing, published 2007 under ISBN 9780136134169 and 0136134165. Twenty six Elementary Algebra For College Students Early Graphing textbooks are available for sale on ValoreBooks.com, eight used from the cheapest price of $40.95, or buy new starting at $201.71.[read more36134169-4-0-3 Orders ship the same or next business day. Expedited shipping within U.S. [more]
May include moderately worn cover, writing, markings or slight discoloration. SKU:9780136134169 [more3613417636134176-2-0-1 Orders ship the same or next business day. Expedited shipping within U.S. will arrive in 3-5 days. Hassle free 14 day return policy. Contact Customer Service for questions.[less]
| 677.169 | 1 |
More About
This Textbook
Overview
This book provides an accessible treatment of multivariable calculus which is useful to readers in disciplines that include mathematics, computer science, physics, chemistry, and engineering. The book's organization draws strong analogies with the basic ideas of elementary calculus (derivative, integral, and fundamental theorem). Traditional in its approach, it nonetheless assumes that the reader may have computing facilities for two- and three-dimensional graphics and for doing symbolic algebra. The book contains hundreds of figures and through exposition and exercises, the reader is encouraged to visualize with the aid of hand drawings and computers. It introduces geometry in three dimensional space early in the book along with Cylindrical and Spherical coordinates, anticipating their later use in connection with the Chain Rule and change of variable in double and triple integrals. It also introduces matrix notation and the rudiments of linear algebra early in the book to facilitate exposition throughout the rest of the book. It also provides approximately 1200 exercises that include drills, applications, proofs, and "technologically active" projects. A valuable mathematics reference book for professionals in disciplines that include computer science, physics, chemistry, and
| 677.169 | 1 |
A Guide to MATLAB: For Beginners and Experienced Users [NOOK Book] ...
More About
This Book graphics, enabling the user to master quickly the various symbolic and numerical plotting routines; and a robust presentation of MuPAD® and how to use it as a stand-alone platform. The authors have also updated the text throughout, reworking examples and exploring new applications. The book is essential reading for beginners, occasional users and experienced users wishing to brush up their skills. Further resources are available from the authors' website at www-math.umd.edu/schol/a-guide-to-matlab.html.
Editorial Reviews
From the Publisher
"Major highlights of the book are completely transparent examples of classical yet always intriguing mathematical, statistical, engineering, economics, and physics problems. In addition, the book explains a seamless use with Microsoft Word for integrating MATLAB outputs with documents, reports, presentations, or other on-line processes. Advanced topics with examples include: Monte Carlo simulation, population dynamics, and Linear Programming. Overall, it is an outstanding textbook, and, likewise, should be an integral part of the technical reference shelf for most IT professionals. It is a great resource for wherever MATLAB is available!"
ACM Ubiquity
Related Subjects
Meet the Author
Brian R. Hunt is a Professor in the Department of Mathematics and the Institute for Physical Science and Technology at the University of Maryland.
Ronald L. Lipsman is Professor Emeritus of Mathematics at the University of Maryland.
Jonathan M. Rosenberg is Ruth M. Davis Professor of Mathematics at the University of
| 677.169 | 1 |
Intermediate Algebra for College Students - 6th edition
Summary: The Blitzer Algebra Series combines mathematical accuracy with an engaging, friendly, and often fun presentation for maximum appeal. Blitzer's personality shows in his writing, as he draws readers into the material through relevant and thought-provoking applications. Every Blitzer page is interesting and relevant, ensuring that students will actually use their textbook to achieve success Good 07675.61 +$3.99 s/h
Good
newrecycleabook centerville, OH
0321758935 does not contain access code-Choose Expedited Shipping for fastest delivery! Used Texts May Have Used Book Stickers on the Cover. Free USPS Tracking Number. Used texts may NOT contain suppl...show moreemental materials such as CD's, info-trac, access codes, etc... Satisfaction Guaranteed! ...show less
$81.66 +$3.99 s/h
Good
Texts Direct Lexington, KY
Hardcover Good 0321758935 This is an AIE copy and includes answers.
$89.20 +$3.99 s/h
LikeNew
Bookbyte-OR Salem, OR
Almost new condition. SKU:9780321758934-2-0
$99.00 +$3.99 s/h
VeryGood
NateDealz minnetonka, MN
Great condition! no highlights or notes, clean A++ had small dents from being carried around in a book bag.
$115.2386
| 677.169 | 1 |
Giving students more detailed explanations, this resource supplements the brief answers found at the back of the book for selected exercises by providing fully worked-out solutions. It also contains problem-solving strategies, additional algebra steps, and review for selected problems.
Book Description:Cengage Learning, 2008. Book Condition: New. Brand New, Unread Copy in Perfect Condition. A+ Customer Service! Summary: Giving you more in-depth explanations, this insightful resource includes fully worked-out solutions for the answers to select exercises included at the back of the textbook, as well as problem-solving strategies, additional algebra steps, and review for selected problems. Bookseller Inventory # ABE_book_new_0495389285
| 677.169 | 1 |
Browse related Subjects
...Read More exercises. Students understand from the very beginning that doing math is an essential part of learning it. Motivational, real-world applications demonstrate how integral mathematical understanding is to a variety of disciplines, careers, and everyday situations.Read Less
Good. Paperback. May include moderately worn cover, writing, markings or slight discoloration. SKU: 97803217333Very good. Paperback. Has minor wear and/or markings. SKU: 9780321733399Fair. Custom edition for Norwalk Community College. Book is in overall good condition! ! Custom edition for Norwalk Community College. Book is in overall good condition! ! Cover shows some edge wear and corners are lightly worn. Pages have a minimal to moderate amount of markings. FAST SHIPPING W/USPS TRACKING! ! !
Fair. Custom edition for Norwalk Community College
| 677.169 | 1 |
More About
This Textbook
Overview
This book introduces interested readers, practitioners, and researchers to Mathematica methods for solving practical problems in linear algebra. It contains step-by-step solutions of problems in computer science, economics, engineering, mathematics, statistics, and other areas of application. Each chapter contains both elementary and more challenging problems, grouped by fields of application, and ends with a set of exercises. Selected answers are provided in an appendix. The book contains a glossary of definitions and theorem, as well as a summary of relevant Mathematica tools. Applications of Linear Algebra can be used both in laboratory sessions and as a source of take-home problems and projects.
* Concentrates on problem solving and aims to increase the readers' analytical skills
* Provides ample opportunities for applying theoretical results and transferring knowledge between different areas of application; Mathematica plays a key role in this process
* Makes learning fun and builds confidence
* Allows readers to tackle computationally challenging problems by minimizing the frustration caused by the arithmetic intricacies of numerical linear algebra
Fred E. Szabo is professor in the Department of Mathematics and Statistics at Concordia University in Canada. He completed his undergraduate studies at Oxford University under the guidance of Sir Michael Dummett and received a Ph.D. in mathematics from McGill University under the supervision of Joachim Lambek. After postdoctoral studies at Oxford University and visiting professorships at several European universities, he returned to Concordia University as a faculty member and dean of graduate studies. For more than twenty years, he developed methods for the teaching of mathematics with technology. In 2012 he was honored at the annual Wolfram Technology Conference for his work on "A New Kind of Learning" with a Wolfram Innovator Award. He is currently professor and Provost Fellow at Concordia
| 677.169 | 1 |
Using old batteries and a voltage sensor, students get a real feel of the meaning of negative and positive numbers. Students...
see more
Using old batteries and a voltage sensor, students get a real feel of the meaning of negative and positive numbers. Students explore addition of signed numbers by placing batteries end to end (in the same direction or opposite directions) and observe the sum of the batteries' voltages
After covering the standard course material on infinite series and their sums and the Integral Test for series convergence,...
see more
After covering the standard course material on infinite series and their sums and the Integral Test for series convergence, Calculus II students are given a write-pair-share activity that directs them to clearly explain the difference between a series and its related integral and explain why the sum of the series is greater than the value of the corresponding integral. Afterwards, the instructor employs a Web-based applet that visually displays graphs of both the series and the integral so that students can see the relationship between them
| 677.169 | 1 |
Practical Math Success in 20 Minutes a Day - 3rd edition
Summary: This book is geared toward anyone wishing to overcome math anxiety. Updated and re-evaluated by math experts to ensure the most current lessons and practice exercises, this resource includes: essential math basics and tips for test-takers.
| 677.169 | 1 |
Math Courses
Undergraduate97 Basic Algebra Skills
This course is designed to reinforce and extend students' knowledge of basic algebra and to set the groundwork for success in more advanced courses. Topics covered include solving linear equations and inequalities, working with polynomials, operations with rational expressions, linear coordinate graphing, and solving quadratic equations through factoring. The content of this course matches that of the Developmental Math 097 class as taught at Adams State University. This course does not provide degree credit.
MATH 097 Introductory Algebra
This course is designed to reinforce and extend students' knowledge of basic algebra and to set the groundwork for success in more advanced courses. Topics covered include review of arithmetic and properties of integers and rational numbers, solving linear equations and inequalities, evaluating exponents, operations with polynomials, factoring of polynomials, simplifying and operations with rational expressions, and graphing linear equations and inequalities. The content of this course matches that of the Developmental Math 097 class as taught at Adams State University. This course does not provide degree credit.
MATH 099 Intermediate Algebra
This is a second course in algebra, designed to prepare students for the math courses that will be required for their selected areas of study. General topics covered include systems of linear equations, quadratic equations and functions, radicals and complex numbers, as well as extended work with rational expression and equations and operations with polynomials.
MATH 099 Intermediate Algebra
This course is designed to reinforce and extend students' knowledge of algebraic principles and set the groundwork for success in more advanced courses. Topics covered include extended work with linear equations and inequalities, further work with rational numbers, quadratic equations, radicals, complex numbers, functions and their graphs. The content of this course matches that of the Developmental Math 099 class as taught at Adams State University. This course does not provide degree credit The goal of this course is to improve and enhance the basic math skills of the student, specifically in the areas of graphs, matrices, probability, and statistics. The purpose of the course is to provide a wider perspective of applied mathematics, how it works, and why and how it is utilized in the real world. This is imperative to the student no matter what the field of study and completes the mathematics requirement for several degree programs
The goal of this course is to improve and enhance the basic math skills of the student,
specifically in the areas of graphs, matrices, probability, and statistics.
The purpose of the course is to provide a wider perspective of applied mathematics, how it
works, and why and how it is utilized in the real world. This is imperative to the student no matter what the field of study and completes the mathematics requirement for several degree
programs.
MATH 107 Trigonometry & Analytic Geometry
An introduction to the tools and techniques of trigonometry. Topics include angles and their measure, the six trigonometric functions and their properties, inverse trigonometric functions, graphs, identities including the Law of Sines and the Law of Cosines, trigonometric equations, and solving triangles. Optional topics include complex numbers, De Moivre's Theorem, polar coordinates, and analytic geometry.
MATH 140 Geometry Using Technology
This course provides an introduction to the major concepts of Euclidean Geometry using interactive technology such as Geometer's Sketchpad and an investigative approach. Students will utilize technology to investigate Euclidean Geometry and discover some if its basic principles and theorems. Topics will include Euclid's Postulates, Triangle Geometry, Circle Geometry, and Analytical Geometry.
MATH 150 MATH Liberal Arts Math
This course will involve both quantitative and qualitative explorations of some of the great ideas and methods of mathematics. Topics covered include problem solving, infinity, logic, probability, statistics, Fibonacci numbers, the golden ratio, topology, non-Euclidean geometry, Pascal's triangle, tiling, fractals, chaos, and higher dimensions. The course is intended for non - math majors and will focus on problem solving and critical thinking skills.
MATH 155 Integrated Mathematics I
This is the first of a 2-course sequence presenting arithmetic and algebra from a modern
perspective. Students work to understand and be able to articulate connections among
mathematical structures, including natural numbers, integers, rational numbers, relations,
functions, and equations.
MATH 155 Integrated Mathematics I
This is the first of a 2-course sequence presenting arithmetic and algebra from a modern perspective. Students work to understand and be able to articulate connections among mathematical structures, including natural numbers, integers, rational numbers, relations, functions, and equations.
| 677.169 | 1 |
book containing over 200 problems spanning over 70 specific topic areas covered in a typical Algebra II course. Learners can encounter a selection of application problems featuring astronomy, earth science and space exploration, often with...(View More) more than one example in a specific category. Learners will use mathematics to explore science topics related to a wide variety of NASA science and space exploration endeavors. Each problem or problem set is introduced with a brief paragraph about the underlying science, written in a simplified, non-technical jargon where possible. Problems are often presented as a multi-step or multi-part activities. This book can be found on the Space Math@NASA website.(View Less)
This is a booklet containing 37 space science mathematical problems, several of which use authentic science data. The problems involve math skills such as unit conversions, geometry, trigonometry, algebra, graph analysis, vectors, scientific...(View More) notation, and many others. Learners will use mathematics to explore science topics related to Earth's magnetic field, space weather, the Sun, and other related concepts. This booklet can be found on the Space Math@NASA website.(View Less)
is a booklet containing 87 problem sets that involve a variety of math skills, including scale, geometry, graph analysis, fractions, unit conversions, scientific notation, simple algebra, and calculus. Each set of problems is contained on one...(View More) page. Learners will use mathematics to explore varied space science topics in the areas of Earth science, planetary science, and astrophysics, among many others. This booklet can be found on the Space Math@NASA website.(View Less)
This is a booklet containing 36 problem sets that involve a variety of math skills, including scientific notation, algebra, geometry, and calculus. Each set of problems is contained on one page. Learners will use mathematics to explore varied space...(View More) science topics including radiation effects on humans and technology, solar science, and other mathematics topics.(View Less)
This is a booklet containing 15 problems that incorporate data and information from the Hinode solar observatory. The problems involve math skills such as finding the scale of an image to determine actual physical sizes in images, time calculations,...(View More) volumes of cylinders, graph analysis, and scientific notation. Learners will use mathematics to explore solar science topics such as sunspot structure, spectroscopy, solar rotation, magnetic fields, density and temperature of hot gases, and solar flares. This booklet can be found on the Space Math@NASA website.(View Less)
| 677.169 | 1 |
Prerequisites
Students must have earned a grede or "C" or better in
courses equivalent to MAT 211 and MAT 271 to be eligible to
enroll in MAT 347.
Objectives
After completing MAT 347 the student should be able to
understand Euclidean geometry as a deductive system
use the basic assumptions, techniques, and constructions
of Euclidean geometry: parallel postulate, construction of
triangles, congruence, similarity, angles, transformations,
the Pythagorean theorem, circles, trigonometric ratios, to
prove theorems and solve applied problems in two and three
dimensions
demonstrate an understanding of the basic synthetic and
analytic theory of conic sections and its uses
understand the consequences of the Euclidean parallel
postulate and be familiar with at least one example of a
non-Euclidean geometry e.g. spherical geometry, hyperbolic
geometry, the geometry of curved surfaces
demonstrate familiarity with the use of other
non-classical geometries: e.g. projective geometry, Minkowski
geometry
use the theory of conic sections, and non-Euclidean and
non-classical geometries to solve applied problems
write coherent and readable deductive arguments and
proofs.
Expected outcomes
Students should be able to demonstrate through written
assignments, tests, and/or oral presentations, that they
have achieved the objectives of MAT 347.
Method of Evaluating Outcomes
Evaluations are based on homework, class participation,
short tests and scheduled examinations covering students'
understanding of Euclidean and non-Euclidean geometry,
deductive reasoning, applications of geometry to applied
problems, and related topics that are covered in MAT 347.
Text
Modern Geometry with Applications, by George
Jennings. Springer-Verlag, 1994.
Table of contents
1. Euclidean Geometry
2. Spherical Geometry
3. Conics
4. Projective Geometry
5. Special Relativity
Grading Policy
Students' grades are based on homework, class participation,
short tests, and scheduled examinations covering students'
understanding of the topics covered in MAT 347. The instructor
determines the relative weights of these factors.
Attendance Requirements
Attendance policy is set by the instructor.
Policy on Due Dates and Make-Up Work
Due dates and policy regarding make-up work are set by
the instructor.
Schedule of Examinations
The instructor sets all test dates except the date of the
final exam. The final exam is given at the date and time
announced in the Schedule of Classes.
Academic Integrity
The mathematics department does not tolerate cheating.
Students who have questions or concerns about academic
integrity should ask their professors or the counselors in the
Student Development Office, or refer to the University Catalog
for more information. (Look in the index under "academic
integrity".)
Accomodations for Students with Disabilities
Cal State Dominguez Hills adheres to all applicable federal, state, and local laws, regulations, and guidelines with respect to providing reasonable accommodations for students with temporary and permanent disabilities. If you have a disability that may adversely affect your work in this class, I encourage you to register with Disabled Student Services (DSS) and to talk with me about how I can best help you. All disclosures of disabilities will be kept strictly confidential. Please note: no accommodation may be made until you register with the DSS in WH B250. For information call (310) 243-3660 or to use telecommunications Device for the Deaf, call (310) 243-2028.
| 677.169 | 1 |
Resources
Sometimes a quick review of a topic or procedure is all you need to progress comfortably in a quantitative class. Listed below are some internet resources (with links) and also some supplemental book titles. You may use these resources on your own or request a QR tutor to assist you with your review. Please note that access to a tutor is not guaranteed; tutors will be assigned first to students in MCSR courses without study groups and to students in courses with groups who need additional assistance. Students requesting tutors for general review are most likely to be matched with a tutor if the request is received early in a semester.
Self Help
The QR Program recommends that you work with others in study groups to improve your quantitative skills. If the course you are taking does not have a study group, an individual tutorial may be a possibility. To inquire about services available, contact Eric Gaze, Director of the Quantitative Reasoning Program located in The Center for Learning and Teaching in #102 Kanbar Hall. Students may stop by during the day, or make an appointment by calling 725-3135, or email egaze@bowdoin.edu
If you want to improve your skills independently, the following may help.
Web Sites
Your text book publisher may provide on-line help. Check in the front of your text book for a link.
WT Virtual Math Lab: help in College Algebra and more basic levels plus preparation for GRE and other tests
These applets include the famous "birthday problem" among many others.
URL:
Recommended Readings
On the importance of good quantitative skills:
Innumeracy: Mathematical Illiteracy and Its Consequences, by John Allen Paulos. Hill and Wang, 1988.
Mathematics and Democracy: The Case for Quantitative Literacy, by the National Council on Education and the Disciplines, Lynn Arthur Steen, Executive Director. The Woodrow Wilson National Fellowship Foundation, 2001.
For those wanting some review of basic skills, a text to review before taking the Q-Skills Assessment:
| 677.169 | 1 |
Shipping prices may be approximate. Please verify cost before checkout.
About the book:
The second edition of this highly successful textbook has been completely revised and now includes a new chapter on vectors. Mathematics is the basis of all science and engineering degrees, and a source of difficulty for some students. Jenny Olive helps resolve this problem by presenting the core mathematics needed by students starting science or engineering courses in user-friendly comprehensible terms. First Edition Hb (1998): 0-521-57306-8 First Edition Pb (1998): 0-521-57586-9bookscollection via India
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 0521017076 Publisher: Cambridge University Press, 2003 2nd 0521017076 Publisher: Cambridge University Press, 2003 ~~ATTENTION~~ Please Read Description Before Purchase,This is an International Edition.Cover & ISBN may be different from US edition but Contents are the same as US Edition.!!
Softcover, ISBN 0521017076 Publisher: Cambridge University Press 0521017076 Publisher: Cambridge University Press, 2003 0521017076 Publisher: Cambridge University Press21017076 Publisher: Cambridge University Press, 2003 Brand New. Softcover International Edition. Same contents as US edition. Ships SAME or NEXT business day. We Ship to PO BOX Address also. EXPEDITED shipping option also available for faster delivery.
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 paperback. New. Brand New Softcover International Edition, Have same content as US Edition. ISBN is different. Never Used, in English Language. Printed in Black and White. 100% return and refund.
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 0521017076 Publisher: Cambridge University Press, 2003 Usually dispatched within 1-2 business days, This brand new copy is waiting for you. Unfortunately we are no longer able to guarantee delivery in time for Christmas.
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 Usually dispatched within 1-2 business days, New Book. Delivered from our UK warehouse in 3 to 5 business days. Established seller since 2000
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 Usually ships in 1-2 business days, Brand New. Delivery is usually 5 - 8 working days from order, International is by Royal Mail Airmail Cambridge University Press, 2003 Used. This Book is in Good Condition. Clean Copy With Light Amount of Wear. 100% Guaranteed. Summary: 1. Basic algebra: some reminders of how it works; 2. Graphs and equations; 3. Relations and functions; 4. Some trigonometry and geometry of triangles and circles; 5. Extending trigonometry to angles of any size; 6. Sequences and series; 7. Binomial series and proof by induction; 8. Differentiation; 9. Integration; 10. Complex numbers; 11. Working with vectors.
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, Cambridge, 2009 Used. Fifth Edition, 634pp, Soft Cover. Book Condition: Acceptable to Good, Contents clear and unmarked, marking on the front and back cover, 5cm stain on oage edges, some bumping. Posting within the UK will be at our usual rate but shipping overseas may incur extra charge. All proceeds support Oxfam's work fighting poverty and suffering worldwide.
Softcover, ISBN 0521017076 Publisher: Cambridge Used - Good, Usually ships in 1-2 business days, This Book is in Good Condition. Used Copy With Light Amount of Wear. 100% Guaranteed.
Softcover, ISBN 0521017076 Publisher: Cambridge 0521017076 Publisher: Cambridge University Press, 2003 Cambridge University Press. Used - Good. Shows some signs of wear, and may have some markings on the inside. 100% Money Back Guarantee. Shipped to over one million happy customers. Your purchase benefits world literacy!
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 Used - Good. Shows some signs of wear, and may have some markings on the inside. Shipped to over one million happy customers. Your purchase benefits world literacy!
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 Softcover, International. Brand New Softcover International Edition, Printed in Black and White, Have same content as US Edition. ISBN is different. Never Used, in English Language. Excellent customer service..
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 Good. 012 Item may show signs of shelf wear. Pages may include limited notes and highlighting. Includes supplemental or companion materials if applicable. Access codes may or may not work. Connecting readers since 1972. Customer service is our top priority. . 012 Item may show signs of shelf wear. Pages may include limited notes and highli...
Softcover, ISBN 0521017076 Publisher: Cambridge University Press, 2003 Used - Good, Usually ships in 1-2 business days, Paperback. Used - Good Good ., Usually dispatched within 1-2 business days, This Book is in Good Condition. Used Copy With Light Amount of Wear. 100% Guaranteed.
Softcover, ISBN 0521017076 Publisher: Cambridge University Press
| 677.169 | 1 |
Math 311w - Concepts of Discrete Mathematics
This course introduces students to the use of mathematics as language. Using a theorem-proof framework much like that used in Euclid's geometry textbook 2, 400 years ago, we will study elementary number theory, modular arithmetic, set theory, formal logic, groups, and other discrete-math topics. The course will include several writing assignments to help students develop their own communications skills.
I understand that some of you who missed class on the 28th started the wrong assignment. If you did that or would like to, I'll consider it as extra credit to improve quiz and homework assignment grades. See here.
| 677.169 | 1 |
An open access, self-paced Prealgebra Module on Integers with a pretest, 4 sections, and a posttest.PreAlgebra Module 2:...
see more
An open access, self-paced Prealgebra Module on Integers with a pretest, 4 sections, and a posttest.PreAlgebra Module 2: IntegersLO: Student will use properties of integers to solve simple equations and application problems• PA Module 2 Section 1: Integers and the Number LineStudent will compare integer values using properties of inequalities, opposites, and absolute values.• PA Module 2 Section 2: Operations with IntegersStudent will apply the rules of addition, subtraction, multiplication and division to simplify expressions involving positive and negative integers.• PA Module 2 Section 3: Order of Operations with IntegersStudent will use the properties and methods for the order of operations when evaluating and simplifying mathematical expressions.• PA Module 2 Section 4: Solving Linear One Variable EquationsStudent will use properties and methods to solve linear equations with one variable.
Discrete stochastic processes are essentially probabilistic systems that evolve in time via random changes occurring at...
see more
Discrete stochastic processes are essentially probabilistic systems that evolve in time via random changes occurring at discrete fixed or random intervals. This course aims to help students acquire both the mathematical principles and the intuition necessary to create, analyze, and understand insightful models for a broad range of these processes. The range of areas for which discrete stochastic-process models are useful is constantly expanding, and includes many applications in engineering, physics, biology, operations research and financeThis course provides students with the basic analytical and computational tools of linear partial differential equations...
see more
This course provides students with the basic analytical and computational tools of linear partial differential equations (PDEs) for practical applications in science engineering, including heat/diffusion, wave, and Poisson equations. Analytics emphasize the viewpoint of linear algebra and the analogy with finite matrix problems. Numerics focus on finite-difference and finite-element techniques to reduce PDEs to matrix problems.
This course covers differential, integral and vector calculus for functions of more than one variable. These mathematical...
see more
This course covers differential, integral and vector calculus for functions of more than one variable. These mathematical tools and methods are used extensively in the physical sciences, engineering, economics and computer graphics.
| 677.169 | 1 |
I maybe able to help you if you can be more specific and provide details about orleans hanna algebra prognosis test sample. A right software would be best option rather than a algebra tutor. After trying a number of program I found the Algebrator to be the best I have so far found . It solves any math problem from your book . It also clarifies all the steps (of the solution). You can just reproduce as your homework assignment. However, you should use it to learn algebra, and simply not use it to copy answers.
Thanks for the advice . Algebrator is indeed a pretty good math software. I was able to get answers to questions I had about quadratic equations, binomials and subtracting fractions. You just have to type in a problem, click on Solve and you get the all the results you need. You can use it for all types of , like Algebra 1, Algebra 2 and Intermediate algebra. I would highly recommend Algebrator.
I am a regular user of Algebrator. It not only helps me finish my assignments faster, the detailed explanations given makes understanding the concepts easier. I recommend using it to help improve problem solving skills.
| 677.169 | 1 |
Beginning Algebra With Applications - 7th edition
Summary: Intended for developmental math courses in beginning algebra ...show moreproblem areas, and, overall, promoting student success.
New! Interactive Exercises appear at the beginning of an objective's exercise set (when appropriate), and provide students with guided practice on some of the objective's underlying principles.
New! Think About It Exercises are conceptual in nature and appear near the end of an objective's exercise set. They ask the students to think about the objective's concepts, make generalizations, and apply them to more abstract problems. The focus is on mental mathematics, not calculation or computation, and help students synthesize concepts.
New! Important Points have been highlighted to capture students' attention. With these signposts, students are able to recognize what is most important and to study more efficiently.
New! A Concepts of Geometry section has been added to Chapter 1.
New! Coverage of operations on fractions has been changed in Section 1.3 so that multiplication and division of rational numbers are presented first, followed by addition and subtraction
New! A Complex Numbers section has been added to Chapter 11, "Quadratic Equations."
New Media! Two key components have been added to the technology package: HM Testing (powered by Diploma) and, as part of the Eduspace course management tool, HM Assess, an online diagnostic assessment tool38 +$3.99 s/h
Good
Recycle-A-Textbook Lexington, KY
06188035996.99 +$3.99 s/h
Good
HPB-Bethel Columbus0618803599Hardcover Very Good 0618803599 MULTIPLE COPIES AVAILABLE. This book is in very nice condition and may show minor shelf wear, contain a school stamp, sticker or class set number on the inside our ou...show moretside cover. This book may also contain some minor highlighting and other
| 677.169 | 1 |
books.google.com - At.... Equations
Radical Equations: Civil Rights from Mississippi to the Algebra Project
At.
Begun in 1982, the Algebra Project is transforming math education in twenty-five cities. Founded on the belief that math-science literacy is a prerequisite for full citizenship in society, the Project works with entire communities-parents, teachers, and especially students-to create a culture of literacy around algebra, a crucial stepping-stone to college math and opportunity.
Telling the story of this remarkable program, Robert Moses draws on lessons from the 1960s Southern voter registration he famously helped organize: "Everyone said sharecroppers didn't want to vote. It wasn't until we got them demanding to vote that we got attention. Today, when kids are falling wholesale through the cracks, people say they don't want to learn. We have to get the kids themselves to demand what everyone says they don't want."
We see the Algebra Project organizing community by community. Older kids serve as coaches for younger students and build a self-sustained tradition of leadership. Teachers use innovative techniques. And we see the remarkable success stories of schools like the predominately poor Hart School in Bessemer, Alabama, which outscored the city's middle-class flagship school in just three years.
Radical Equations provides a model for anyone looking for a community-based solution to the problems of our disadvantaged schools.
User ratings
I came to this book as part of research on the contribution of Ms Ella Baker to the civil rights movement as well as the role of radical pedagogy in the struggle. As a lead organizer in the Student ...Read full review
Don't take the star rating too seriously. I had to read it for class and I'm resentful because it took up valuable time I could have spent studying for other, better classes, playing Skyrim, or ...Read full review
About the author (2001)
Robert P. Moses is the winner of many awards including a MacArthur fellowship and a Heinz Award in the Human Condition. Coauthor Charles E. Cobb, Jr., for thirty years a journalist for major magazines, is currently senior writer at allAfrica.com.
Bibliographic information
Title
Radical Equations: Civil Rights from Mississippi to the Algebra Project
| 677.169 | 1 |
Find a Florence, AZIt starts with the fundamental theorem of counting: if there are n ways of getting A and m ways of getting B, then there are n x m ways of A and then B. Counting progresses with the useful ideas of permutations (for ordered sets) and combinations (for sets without order). Using counting and simp have covered basic mathematics, algebra, and trigonometry for many years. Also, the application of algebra to higher mathematics is a really important skill to have. Linear algebra is quickly replacing differential equations as being the most important mathematical skill to have in the engineering disciplines.
| 677.169 | 1 |
ALGEBRA
An Introduction for Kids
Algebra is rather
a mysterious sounding word. What is algebra?
In its simplest form,
algebra is a part of mathematics in which symbols such as letters of the alphabet
stand for numbers. While this may sound very strange to mix letters and numbers
in mathematics, you, in fact, know a lot about algebra already. Algebra in
many ways is a special way of writing and representing ideas you already know.
This site will help you, through the use of mystery doors, to learn more about
algebra. In addition there are other graphics and little quizzes to help you
along the way.
Along the way we will
also review other important ideas related to algebra.
For those that use
screen readers, there are animated letters at the top of each content page
spelling out the title of the page. The link on the first letter goes to the
beginning of the page content. The link on the second letter goes to the menu
table at the bottom of the page.
| 677.169 | 1 |
Introduction
It's very useful to have free worksheets to practice your understanding of key college algebra concepts. This collection of bottomless worksheets for algebra will help you get endless practice in a variety of algebra topics, by generating ten problems at a time for you to solve. Each worksheet is printable, comes with an answer key, and is sure to help you master algebra in no time!
Sadly many do not master it, but alot of others do master it very quickly. i learned these around 7th grade. And am sure glad i did! especially now that i tutor the people who do not understand it with the depth that i do. plus its very helpful when you get to Diffy Q.
Do you mind if I quote a few of your articles as long as I provide credit and sources back to your website? My blog is in the exact same niche as yours and my users would really benefit from a lot of the information you provide here. Please let me know if this ok with you. Thank you!
im not sure what country your in but im from america and it took me 9 years sense 8th grade to learn and master the very basics. and im still not completely there yet. my girlfriend is 2 years younger then i am and she has never learned this in school at all so i am teaching her personally. we are both trying to go through college right now
| 677.169 | 1 |
97898123893 Mathematics With Maple
The principal aim of this book is to introduce university level mathematics - both algebra and calculus. The text is suitable for first and second year students. It treats the material in depth, and thus can also be of interest to beginning graduate students. New concepts are motivated before being introduced through rigorous definitions. All theorems are proved and great care is taken over the logical structure of the material presented. To facilitate understanding, a large number of diagrams are included. Most of the material is presented in the traditional way, but an innovative approach is taken with emphasis on the use of Maple and in presenting a modern theory of integration. To help readers with their own use of this software, a list of Maple commands employed in the book is provided. The book advocates the use of computers in mathematics in general, and in pure mathematics in particular. It makes the point that results need not be correct just because they come from the computer. A careful and critical approach to using computer algebra systems persists throughout the
| 677.169 | 1 |
Category theory provides a general conceptual framework that has proved fruitful in subjects as diverse as geometry, topology, theoretical computer science and foundational mathematics. Here is a friendly, easy-to-read textbook that explains the fundamentals at a level suitable for newcomers to the subject. Beginning postgraduate mathematicians will find this book an excellent introduction to all of the basics of category theory. It gives the basic definitions; goes through the various associated gadgetry, such as functors, natural transformations, limits and colimits; and then explains adjunctions. The material is slowly developed using many examples and illustrations to illuminate the concepts explained. Over 200 exercises, with solutions available online, help the reader to access the subject and make the book ideal for self-study. It can also be used as a recommended text for a taught introductory course.
{"currencyCode":"USD","itemData":[{"priceBreaksMAP":null,"buyingPrice":33.24,"ASIN":"0521283043","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":52.81,"ASIN":"0199237182","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":65,"ASIN":"052171916X","isPreorder":0}],"shippingId":"0521283043::NuhTs%2BBerJ8is6uoxZx2YNAQn3MrTOFv%2BMFoHDIDFOlVEOW03seMSbE77UJ29z%2BpsbLjA9Te75s3z7xV%2BI96QtYJ%2FZU81qj4lf2weOJChc4qdQ237w%2F%2F7g%3D%3D,0199237182::KoVEs9itWb2u%2FhehpqLxey3Mw9EsEQGUKGh4%2BpiHf1zelFOi1i10dCsdRnIRW0O%2BfOM5%2Bky1CWANHIsQ9VZZhhTimvslUOljNIwkLUae8KY%3D,052171916X::pnxiqEkyOk%2FsSfPjQ9nolRzpJA3yMSN9RbkiNidwhcaPHH3GZKQjGBKPkgi%2FEGY1agjHA3iJaqQD1W2%2BjY3Hy39pLTNu%2FVS67iOWWRnZXg textbook presents a useful introduction to basic category theory, and would be suitable for a first course at the undergraduate level in computer science or mathematics." Steve Awodey, Mathematical Reviews
Book Description
A crystal clear introduction to category theory that demystifies functors, natural transformations, limits and colimits, adjunctions and more. Any beginning postgraduate mathematician will find all they need in this excellent text to access the subject. Over 200 exercises are provided with solutions available online.
Maybe this book is good for one who already new Category Theory but not for a person who tries to learn it from scratch. What I don't like basically is that not every term was explained. I had to go over all wikipedia for explanation. Even though those missed terms were closely related to Category theory, not that I don't know math at all. I'm quite technical guy.
Some reviews indicate this book is an "easy" introduction to category theory (CT)--and it is well written--but that's not its primary virtue. It is something even better: Simmons has the knack for writing concretely about an inherently abstract topic.
One aspect of this talent is that he focuses on CT as a problem-solving tool. I've extensively explored the CT literature, and chapter four of this book provides one of the most cogent descriptions that I have seen of how to use CT as an analytic technique. The book also has one of the better accounts of how CT's many 'gadgets' work together.
Simmons provides an extensive number of exercises, with solutions available online. Any reader who works through them will be well prepared for the more abstract CT exemplars that dominate the field.
| 677.169 | 1 |
-algebra algebra provides students with an opportunity to practice the areas tested on the exam. The worksheets are designed to accompany the CAHSEE Math Curriculum as well as allowing students to apply... More > their knowledge and expand their understanding of number sense, statistics, data analysis, and probability, measurement and geometry, algebra and functions, mathematical reasoning, and algebra I. For curriculum information, contact us at info@ssformath.com< Less
| 677.169 | 1 |
This student-friendly textbook for the Statistics 1 Module of A-Level Maths comprehensively covers the Edexcel exam specification. It contains straightforward, accessible notes explaining all the theory, backed up with useful step-by-step examples. There are practice questions throughout the book to test understanding, with recap and exam-style questions at the end of each section (detailed answers to all the questions are included at the back). Finally, there's a CD-ROM containing two complete Statistics 1 practice exam papers - ideal to print out for realistic practice before the final tests
| 677.169 | 1 |
10TH GRADE CONTEMPORARY MATHEMATICS IN CONTEXT STUDY GUIDE FOR
FINAL EXAM
I. CONTENT: Your final exam will have questions based on the following book units and
objectives.
- BOOK 1 UNIT 7 QUADRATIC FUNCTIONS
o LESSON 1: QUADRATIC PATTERNS
Recognize quadratic patterns
Use of tables and graphs to answer questions about quadratic situations.
Describe effects of parameters on y ax2 bx c
o LESSON 2: EQUIVALENT QUADRATIC EXPRESSIONS
Expand linear factors
Factor
o LESSON 3: SOLVING QUADRATIC EQUATIONS
Solve by reasoning, factoring, use of tables and graphs
Use discriminant and graphs to describe nature of the roots
Use the quadratic fuormula to solve.
- BOOK 2 UNIT 1 FUNCTIONS EQUATIONS AND SYSTEMS
o LESSON 1: DIRECT AND INVERSE VARIATION
Recognize direct and inverse patterns
Express direct and inverse patterns
Recognize and represent power functions in graph, equation and table form.
Solve problems involving direct and inverse variation.
o LESSON 2: MULTIVARIABLE FUNCTIONS
Write rules of two variables.
Solve for one variable in terms of another
Graph linear equations in the form ax + by = c
o LESSON 3: SYSTEMS OF LINEAR EQUATIONS
Write systems to match given conditions
Solve linear systems by: graphing, substitution, elimination
Recognize systems with infinite and no solutions.
- BOOK 2 UNIT 2: MATRIX METHODS
o LESSON 1: CONSTRUCTING, INTERPRETING, AND OPERATING ON
MATRICES
Construct and Interpret matrices for real life situations.
Operate with matrices: Row, Column, Sum, Difference, Scalar multiplication
o LESSON 2: MULTIPLYING MATRICES
Use matrix multiplication to solve problems.
o LESSON 3: MATRICES AND SYSTEMS OF LINEAR EQUATIONS
Use matrix equations to solve systems of equations.
- BOOK 2 UNIT 3: COORDINATE METHODS
o LESSON 1: A COORDINATE MODEL OF A PLANE
Find distance and midpoints.
Find slopes of parallel and perpendicular lines.
Prove properties of quadrilaterals and triangles on the Cartesian plane, using
slopes, distance and midpoint formulas
Find equations of circles
- BOOK 2 UNIT 5: NONLINEAR FUNCTIONS AND EQUATIONS
o LESSON 1: QUADRATIC FUNCTIONS AND EQUATIONS
Function concept and Notation
Domain and Range
Factoring and Expanding
Advanced Factoring
Solving Quadratic Equations using quadratic formula and factoring
Break Even Analysis
- BOOK 2 UNIT 7: TRIGONOMETRIC METHODS
o LESSON 1: TRIGONOMETRIC FUNCTIONS
Find sine cosine and tangent of angles in degrees and in standard position.
Find sine, cosine and tangent of right triangles.
Solve right triangles
o LESSON 2: USING TRIGONOMETRY IN ANY TRIANGLE
Use Law of Sines and Law of cosines and trigonometric methods to solve
triangulation and indirect measurement problems.
II. Format
Your exam will consist of 3 parts: One multiple choice question section where calculators will not
be allowed, one short answer section where you may use a calculator, and a performance section
where you will have to decide on the appropriate methods to model two real life problems.
III. Materials needed
Please remember to bring to your exam a graphing calculator and your math tool kit. Remember you
will be allowed to use it. If you need a calculator from the resource, please let me know
immediately.
1V. Review Package
Completing the review package will add 5 points to your exam grade.
2011 10TH GRADE REVIEW PACKAGE FOR FINAL EXAM
Multiple Choice
Identify the choice that best completes the statement or answers the question.
____ 1. The expression (2x 3)2 is equivalent to
a. 4x2 9 b. 4x2 + 9 c. 4x2 12x 9 d. 4x2 12x + 9 e. 2x2 + 12x + 9
____ 2. The solutions to x2 + 5x – 2 = 3 are
a. b. c. x = –2 and x = –4 d. x = –1 and x = –5 e. None of these
____ 3. A baseball is hit off a tee that is 1 feet high with an initial upward velocity of 15 feet per second. Which of the
following rules relates the ball's height above the ground h to its time in the air t?
a. h = –16t2 + 15t + 1 b. h = –15t2 – 25t + 1 c. h = –15t2 – t + 25 d. h = 15t + 1 e. none of these
____ 4. Suppose that y is inversely proportional to x with constant of proportionality k = 3.4. What is the value of x
when y = 6?
a. x = -5.4 b. x = 0.4 c. x = 2.5 d. x = 12.6 e. none of these
____ 5. The cost of buying s shirts and h hats can be determined using the equation C = 8s + 4h. Suppose that you
have $200 to spend. Which of the following statements is not true?
a. Each shirt costs $8. b. Each hat costs $4. c. Eight shirts and 12 hats will cost $112. d. You can buy 15
shirts and 18 hats. e. You can buy 20 shirts and 15 hats.
____ 6. The graph of the function y = is shown below. Which of the following must be true about k and n?
a. k 0 and n is even. b. k 0 and n is odd. c. k 0 and n is even. d. k 0 and n is odd. e. It is not
possible to say anything about the values of k and n.
____ 7. The number of children at the Boys and Girls Club each day last week is given by the matrix N.
Next week is a school vacation week, and the Club is expecting a 30% increase in the number of children who
attend each day. Which of the following will give you a matrix indicating the number of students expected at
the Club each day next week?
a. 1.30N b. 1.30 + N c. d. 0.30N e. 0.30 + N
____ 8. If A is a 3 4 matrix and B is a 2 3 matrix, then the size of B A is:
a. 6 12 b. 3 3 c. 3 2 d. 4 2 e. 4 3
____ 9. Let A = and B = . Find the value of x so that the second row second column entry in A B
is 5.
a. x = -9 b. x = -2 c. x = -1 d. x = 0 e. x = 1.4
____ 10. A circle in the standard (x, y) coordinate plane has center at (-5, 5) and contains the point (-5, 0). Which of the
following is an equation for the circle?
a. b. c. + = 25 d. + = 5 e. +
= 25
____ 11. What is the slope of any line parallel to the line 6x - 2y = 12?
a. b. c. d. e. 3
____ 12. What value of k will make the line kx + 6y = 10 perpendicular to the line y = + 4?
a. k = -9 b. k = -4 c. k = d. k = 4 e. k = 9
____ 13. What is the distance between the points (2, -3) and (-1, 5)?
a. b. c. 10 d. e. none of these
____ 14. The graph of a quadratic function opens down and has a maximum point of (2, 7). Which of the following
could be the x-intercepts of the graph?
I. (1, 0), and (4, 0) II. (-8, 0) and (12, 0) III. (0, 0) and (4, 0)
a. I only b. II only c. III only d. II and III e. It is not possible to determine anything about the x-
intercepts.
____ 15. Which of the following equations has exactly one solution?
a. x - 1 = b. - c. +2 -6= - 8 d. = - 25 e. - + 3 =
____ 16. To the nearest degree, what is the degree measure of the angle formed by the line with equation and
the positive x-axis?
a. 37° b. 39° c. 51° d. 53° e. 144°
____ 17. In right triangle ABC, the cosine of is . Which of the following is sin ?
a. b. c. d. e.
18. h( x) 2 x 3 x 2 Find h(-1)
A) 0 B) -1 C) 1 D) 5
19. Identify the property(ies) that justify equivalence of the following pair of algebraic
expressions:
(a + 2b) +3c = a + (3c + 2b)
I. Associative (+) II. Distributive (x, +) III. Commutative (+)
(A) I only (B) II only (C) I and II only (D) I and III only
20. Suppose h(x) is a quadratic function with the zeros indicated below. Which of these
is the standard polynomial form of this function: h(-2)=0 and h(5)=0
( A)h( x) x 2 3x 10 ( B)h( x) x 2 3x 10 (C )h( x) x 2 3x 5 ( D)h( x) x 2 3x 5
21. Which of the following graphs is not a graph of a function?
a. b. c.
d.
22. In a right triangle ABC with right angle C and sides a, b, c, which of the following
represents sin A
B
c a
A b C
a a b b
A) B) C) D)
b c c a
23. In the same right triangle of question 10, if you knew the measure of angle B, and side
a, which trigonometric function would be most appropriate to use to find b?
(A) sin B B) sin A C) cos A D) tan B
24. For a right triangle ABC, with right angle C which of the following statements must
be incorrect?
A) sin A 3 B) tan A 4 C) tan A 0.5 D)
4
4
cos A
3
Short Answer
1. Consider the graph of the equation y = 2x2 – 6x.
a. Without using your calculator, find the x-intercepts of the graph.
b. Without using your calculator, find the minimum or maximum point of this graph.
2. A height of a softball, in feet, that has been pitched by a slow-pitch softball pitching machine is given by the
rule h = –16t2 + 30t + 2.5 for any time t seconds after it is pitched.
a. Explain the meaning of the –16, the 30, and the 2.5 in the equation.
b. How long is the ball in the air?
c. What is the maximum height that the ball reaches? When does it reach that height?
d. At what time(s) is the ball at least 10 feet above the ground?
3. Chris can buy ice-cream bars for 20¢ each. Based upon experience she knows that the function rule n = 150 –
100p will give a good estimate of the number of ice-cream bars she will sell in one day if she charges p
dollars for one bar.
a. Write a function rule that will give the income Chris can expect if she charges p dollars for each ice-cream
bar.
b. Write a function rule that will give the profit that Chris will make each day if she charges p dollars for one
ice-cream bar.
c. For what price(s) will Chris make at least $15 per day?
d. What is the maximum amount of profit that Chris can make, and what price should she charge to make the
maximum profit?
e. How many ice-cream bars will Chris sell if she makes the maximum profit?
4. Rewrite each of the following in standard quadratic form.
a. 2x(4x – 15)
b. 3x(2x + 1) - 3(2x + 1)
c. (x - 4)(x – 3)
d. (x + 3)(x – 3)
5. Solve each equation by reasoning with the symbols themselves.
a. 2x2 + 10 = 17
b. 8x2 + 5x = 0
c. x2 – 7x + 12 = 0
d. 3x2 + 4x + 1 = 0
e. 5 = x2 + 6x
6. To answer the following, refer to the equation z = where x, y, and z are all positive.
a. If x is held constant and y increases, how does z change?
b. If y is held constant and x increases, how does z change?
c. Write an equivalent rule that shows x as a function of y and z.
d. Write an equivalent rule that shows y as a function of x and z.
7. The time required to complete a 100-mile bike race is inversely proportional to the average speed that the
rider maintains.
a. Write a rule that expresses the relationship between average speed s and race time t.
b. What is the constant of proportionality for this situation?
c. Tina took 5 hours and 15 minutes to complete the race. What was her average speed?
d. Gregory maintained an average speed of 16 miles per hour. How long did it take him to complete the race?
8. Towne Sporting Goods establishes a selling price S for an item based on the cost C that it paid the
manufacturer and the rate R of markup that it charges in order to cover its expenses and make a profit. These
variables are related by the following equation:
S = C(1 + R)
a. Towne Sporting Goods gets a pair of in-line skates from the manufacturer at a cost of $80. If Towne uses a
28% markup, what is the selling price of the skates to the nearest dollar?
b. Use the equation S = C(1 + R) to write an equivalent equation that gives C as a function of S and R.
c. After the holidays, Towne Sporting Goods had a sale during which it sold all items in the store for a
markup of only 10%. The sale price of a tennis racket was $32. To the nearest dollar, how much did it cost
Towne Sporting Goods to buy the racket from the manufacturer?
9. Draw a graph of the equation 5x - 3y = 24.
10. Consider the following system of equations:
y = 2x – 10
3x + 4y = 15
a. Use an algebraic method to solve this system of equations. Show your work.
b. How does the solution you found in Part a relate to the graphs of the two equations?
11. Joe looked at the following system of equations and announced that the system had infinitely many solutions.
6x + 8y = 24
9x + 12y = 24
Is Joe correct? Describe how you can determine this just by looking at the equations.
12. A system of linear equations can have 0, 1, or infinitely many solutions.
a. Write a system of equations that has no solution. Explain how you know the system does not have a
solution.
b. Write a system of equations that has exactly one solution. Explain how you know it has exactly one
solution.
c. Write a system of equations that has an infinite number of solutions. Explain how you know there are an
infinite number of solutions.
13. Determine whether each statement is True or False. It False, explain your reasoning.
a. You can add any two matrices together.
b. For all matrices A and B that can be added together, A + B = B + A.
c. For all matrices A and B that can be multiplied together, A B=B A.
d. If A = , then .
e. For any 2 2 matrix A, it is always possible to find a matrix B such that A B = I where I is the identity
matrix.
f. When you add two matrices together, you add the corresponding entries.
14. The Burlington-Edison School District athletic director is writing a funding proposal to the school board for
new athletic equipment for the five middle schools (I–V) in the district. She decides that the schools need a
variety of equipment including baseball bats (BB), volleyballs (VB), and football helmets (FH). The matrix,
Equipment Request by School, summarizes her request.
a. The equipment can be ordered at different levels of quality and cost. The matrix below gives the cost of
each piece in dollars.
Use a matrix operation to complete the total-equipment-cost matrix below. Show how you obtained this
answer.
b. If school V orders average-quality equipment instead of high-quality equipment, how much will the school
save? Show your work.
c. Find the total savings if the athletic director orders average-quality equipment for all schools.
d. The athletic director decides to order high-quality football helmets for safety reasons but only average-
quality baseball bats and volleyballs.
• Construct a 1 3 cost matrix that gives the cost of each piece of equipment that is requested.
Be sure to properly label your matrix.
• Then find a matrix for total cost per school. Indicate the matrices to be multiplied. Be sure to
properly label your total cost per school matrix.
15. Refer to the following system of linear equations.
3x + 2y = 15
x-y=2
a. Graph this system of equations and estimate the (x, y) pair that solves it.
b. Check your estimate in Part a. Was your estimate correct?
c. Write a matrix equation that represents this system of linear equations.
d. Solve the system of equations using matrices. Show or explain your work.
16. Pablo is remodeling parts of his house. The bill for work done in his study was $146.10 and covered 3 sheets
of paneling and 2.25 hours of labor. The bill for work done in his basement was $457.10 and covered 8 sheets
of the same paneling and 7.5 hours of labor. Use a system of equations to determine the hourly charge for
labor and the cost of each sheet of paneling.
17. Is the quadrilateral ABCD with vertices A(-3, -2), B(-1, 2), C(4, 3), and D(3, -1) a parallelogram? Provide a
mathematical argument that supports your answer.
18. Quadrilateral ABCD is a rhombus.
a. Determine the coordinates of point C. Show your work and explain your reasoning.
b. Prove that .
c. Prove that bisects .
19. Shown below is a circle with radius 4 and center at the origin. Identify the coordinates of two points that are
on the circle and are not on the x- or y-axis. Show your work or explain your reasoning.
20. The graph below shows the height (in meters) of a baseball in flight as time (in seconds) passes and y=
h(x).
a. Why is it correct to say that height of a baseball is a function of time in flight?
b. Is time in flight of a baseball a function of the height of the baseball? Explain your reasoning.
c. What does the equation h(1.2) = 16.8 tell about the flight of the ball?
d. What is the value of h(3) and what does it tell about the flight of the ball?
e. Estimate the values of x that satisfy the equation 10 = h(x), and what do those values tell about the flight of
the ball?
f. Identify the practical domain and range of h(x).
g. The maximum value of the graph is 20 and the x-intercepts are (0, 0) and (4, 0). Find a function rule for
h(x).
h. Identify the theoretical domain and range of h(x).
21. Consider the equation -7 +6=0
a. Solve the equation algebraically.
b. Explain how you could solve the equation using a different algebraic method.
c. Solve the equation using technology.
22. The graph of a particular quadratic function has one of its x-intercepts at (4, 0) and a minimum point of (0, -
16).
a. What is the other x-intercept of the function? Explain your reasoning.
b. Find a function rule for this quadratic function.
c. If possible, find a function rule for another quadratic function that has the same x-intercepts as this function
but has a different y-intercept. If not possible, explain why not.
23. Write each product in equivalent form.
a. (x + 6)(x - 12)
b. (x - 7)(x + 7)
c. (x + 8)
d. (3x - 7)(4x - 6)
24. Write each quadratic expression in equivalent factored form.
a. x + 2x - 35
b. x - 8x + 16
c. 2x + 16x + 30
d. 3x - 22x + 7
25. Use algebraic reasoning to solve each equation. Show your work.
a. x + 5x + 15 = 3
b. x - 36 = 0
c. 3x + 5 = - 6x + 9
d. x + 4 =
26. The tractor-pulling contest is one of the most popular contests each year at the Johnson County Fair. Based on
data from previous years, the organizers can expect that income I(p) and expenses E(p) both depend on the
price of admission. They predicted that
-6 + 100x and E(p) = 15x + 230.
a. Use algebraic reasoning to determine the ticket price(s) for which income will equal expenses.
b. Write a rule that gives predicted profit F(p) as a function of the admission price.
c. Use your profit function to determine the maximum predicted profit.
d. What admission price should they charge in order to get the maximum predicted profit?
27. The Great Pyramid of Cheops in Egypt has a square base 230 meters on each side. Each face of the pyramid
makes an angle of approximately 52 with the ground. A sketch of the pyramid is shown below.
a. Find the height of the pyramid.
b. Find the area of one triangular face of the pyramid.
28. The pitcher's mound on a softball field is 40 feet from home plate, and the distance between bases is 60 feet.
As shown in the diagram below, m = 45°. (Note: is not a
right angle.)
a. How far is the pitcher's mound P from first base F?
b. Find m .
29. Find the indicated measures for each triangle.
a.
AB = ___________
AC = ___________
b.
___________
m ___________
MK = ___________
30. Given right triangle ABC. If C is the right angle, AC = 5 3 and BC = 5 what is the
measurement of AB, and the measurements of angles A and B?
AB=
m<A=___________
m<B=___________
Factor
31. 25x 2 - 64y 4
32. 2 xy 6 y xz 3z
Rewrite the following expressions in standard polynomial form.
33. ( (2 x 3 4 x) 3(4 x 3 x 2 5 x 9)
34. g ( x) 2(6 3x)(4 x x)
4 x x
| 677.169 | 1 |
Mathematics SoftwareSoftware for teaching and learning mathematical proofs
Where most mathematical proof software concentrates on formal logic (or some other specialty area of mathematics), Lurch aims to be truly general-purpose, with an attracitve user interface.
| 677.169 | 1 |
Abstract Algebra A Geometric Approach
9780133198317
ISBN:
0133198316
Pub Date: 1995 Publisher: Prentice Hall
Summary: Appropriate for a 1 or 2 term course in Abstract Algebra at the Junior level. This book explores the essential theories and techniques of modern algebra, including its problem-solving skills, basic proof techniques, many unusual applications, and the interplay between algebra and geometry. It takes a concrete, example-oriented approach to the subject matter.
Shifrin, Theodore is the author of Abstract Algebr...a A Geometric Approach, published 1995 under ISBN 9780133198317 and 0133198316. One hundred nine Abstract Algebra A Geometric Approach textbooks are available for sale on ValoreBooks.com, four used from the cheapest price of $61.06, or buy new starting at $136.15
| 677.169 | 1 |
Course in Enumeration
9783540390329
ISBN:
3540390324
Pub Date: 2007 Publisher: Springer
Summary: Combinatorial enumeration is a readily accessible subject full of easily stated, but sometimes tantalizingly difficult problems. This book leads the reader in a leisurely way from the basic notions to a variety of topics, ranging from algebra to statistical physics. Its aim is to introduce the student to a fascinating field, and to be a source of information for the professional mathematician who wants to learn more ...about the subject. The book is organized in three parts: Basics, Methods, and Topics. There are 666 exercises, and as a special feature every chapter ends with a highlight, discussing a particularly beautiful or famous result.
Aigner, Martin is the author of Course in Enumeration, published 2007 under ISBN 9783540390329 and 3540390324. Four hundred twenty Course in Enumeration textbooks are available for sale on ValoreBooks.com, fifty three used from the cheapest price of $50.24, or buy new starting at $80.63
| 677.169 | 1 |
Browse related Subjects
...Read More motivation, careful explanations, and numerous examples, with an ongoing focus on real-world problem solving. Pedagogical elements including chapter opening applications, graphing explorations, technology tips, calculator investigations, and discovery projects are some of the tools students will use to master the material and begin applying the mathematics to solve real-world problems. CONTEMPORARY COLLEGE ALGEBRA AND TRIGONOMETRY includes a full review of basic algebra in Chapter 0 and full coverage of trigonometry to prepare students for the standard science/engineering calculus sequence. (The companion volume, CONTEMPORARY COLLEGE ALGEBRA includes all of the non-trigonometry topics, covered in sufficient detail to prepare a student for a business/social science calculus course.) Those who are familiar with the author's CONTEMPORARY PRECALCULUS should note that this book covers topics in a different order, and with a slower, gentle approach. Also, more drill exercises are included CD UNOPEN
| 677.169 | 1 |
Probability Textbooks
Probability textbooks explore the chance of an event occurring by using mathematics. In addition to exploring core concepts such as probability distribution and probability and statistics, probability textbooks also have subcategories of more specific subjects such as probability theory. A probability textbook could also focus on practical applications of probability math, such as risk assessment. Probability textbooks often include probability examples to help students learn how to calculate probability and memorize different probability formulas. Textbooks.com offers a wide variety of new and used textbooks so you can find the probability textbook you need at a price you can afford.
| 677.169 | 1 |
Main menu
Secondary Navigation Menu
At Denison, you will initially continue your high school Calculus education, but you will quickly be exposed to some of the more fascinating questions that really excite mathematicians. Mathematics is the study of abstraction. Mathematicians search for similar patterns in seemingly different settings and then strive to communicate those patterns precisely. Mathematics is a creative process, not a mechanical one.
Go to:
Pi Mu Epsilon
Founded in 1914
Pi Mu Epsilon, a national honorary mathematics society, was founded in 1914 at Syracuse University. Its roots date back to a mathematics club that was founded at Syracuse in 1903. The purpose of Pi Mu Epsilon is the promotion of scholarly activity in mathematics among students in academic institutions.
Denison's chapter was chartered in 1963.
In order to be considered for admission to Denison's chapter of Pi Mu Epsilon, sophomores must have completed 4 courses in mathematics (Calculus I and up) with a cumulative GPA of 3.5. Juniors and seniors must have completed 4 classes (Calculus I and up) with a cumulative GPA of 3.3.
| 677.169 | 1 |
Algebra One on One his game makes math exciting by allowing a two-player head to head competiton option. Full step by step solution of all problems. For all levels from 4th grade on up - special Einstein level for math
Easy Algebra Master Algebra in 24 hours! This Tutorial. intended for mature students, covers the Algebra Topics taught in School and required for College. It makes Algebra easy by carefully explaining the Algebra
commutative algebra in description
SINGULAR SINGULAR is an Algebra software which was designed to help you manage polynomial computations with special emphasis on the needs of commutativealgebra, algebraic geometry, and singularity theory.
Sagemath This includes a huge range of mathematics, including algebra, calculus, elementary to very advanced number theory, cryptography, numerical computation, commutativealgebra, group theory, combinatorics...
Algebra calculatorAlgebra calculator is a handy and reliable utility designed to provide users with possibilities to perform complex algebra calculations. Algebra calculator allows users to store up to fifteen algebrai...
Algebra 1 for 7th Grade Designed as an educational and interactive software, algebra 1 for 7th Grade can be used to improve your mathematics skills. Algebra 1 for 7th Grade is built in Java and comes included with algebra an...
| 677.169 | 1 |
...
More About
This Book
problems, and the math doctors at The Math Forum have helped them find the answers with lots of clear explanations and helpful hints. Now, with Dr. Math Introduces Geometry, you'll learn just what it takes to succeed in this subject. You'll find the answers to dozens of real questions from students who needed help understanding the basic concepts of geometry, from lines, rays, and angles to measuring three-dimensional objects and applying geometry in the real world. Pretty soon, everything from recognizing types of quadrilaterals to finding surface area to counting lines of symmetry will make sense. Plus, you'll get plenty of tips for working with tricky problems submitted by other kids who are just as confused as you are.
You won't find a better introduction to the world and language of geometry anywhere!
Editorial Reviews
Children's Literature
This book covers topics of geometry including the undefined terms (point, line, and plane), two-dimensional and three-dimensional figures, and symmetry. There are some real world correlations, such as, the concept of surface area to the need for elephants to have large ears to create additional surface area helping them keep cool. There is a good discussion of the irrational number pi in the chapter on circles. The format of the book is question and answer. While not a textbook with complete explanations, the book is a relative easy read that explains many points that confuse students in language that relates to high school students. (There is a typographical error at the bottom of page 126 in the formula to find the height of a cylinder when the volume of the cylinder and the radius of the circular base are known. There should be no square root radical in the formula.) There are "Rx" hints scattered throughout the book that are quite helpful. The cartoon drawings contain additional information. There are numerous web sites listed at the end of each chapter where students may find additional information and activities. Some of the sites may have membership requirements. This is good resource for a math classroom. 2004, John Wiley & Sons, Ages 13 up.
—Sally Niezgoda
Related Subjects
Meet the Author
THE MATH FORUM @ Drexel ( is an award-winning Web site and one of the most popular online math resources for students and teachers. The Math Forum offers answers to all kinds of math questions, prepared by a team of math experts. It also keeps archives of previous questions and answers, hosts online communities, and posts several "problems of the week."
Read an Excerpt
Dr. Math Introduces Geometry
John Wiley & Sons
ISBN: 0-471-22554-1
Chapter One
Introduction to Two-Dimensional (2-D) Geometric Figures
Two-dimensional geometry, coordinate plane geometry, Cartesian geometry, and planar (pronounced PLANE-er) geometry refer to the same thing: the study of geometric forms in the coordinate plane. Do you remember the coordinate plane? It's a grid system in which two numbers tell you the location of a point-the first, x, tells you how far left or right to go from the origin (the center point), and the second number, y, tells you how far up or down to go. The y-axis is vertical and the x-axis is horizontal (like the horizon).
You'll see a lot more of the coordinate plane in geometry, but sometimes all that matters is knowing that a figure is in the plane or two-dimensional without knowing a precise address for it. This part will introduce you to some of the most common figures in two-dimensional geometry and give you some names for their parts and ways to work with them.
In this part, Dr. Math explains
points, lines, and planes
angles
triangles
quadrilaterals
1 Points, Lines, and Planes
Points, lines, and planes correspond to talking about no dimensions, one dimension, and two dimensions in the coordinate plane. A line is one-dimensional, since one number, the distance from zero, tells you where you are. A plane is two-dimensional, since you need x and y to locate apoint. A point is dimensionless. It consists only of location, so it's only possible to be one place if you're on a point-you don't need any extra numbers to tell you where you are. Points, lines, and planes are the foundations of the whole system of geometry.
But point, line, and plane are all undefined terms. How can that be? Well, any definition we could give them would depend on the definition of some other mathematical idea that these three terms help define. In other words, the definition would be circular!
Undefined Geometry Terms
Dear Dr. Math,
I know that they call point, line, and plane the undefined terms of geometry, but is there a way to give those terms a definition? I've been thinking, could a line be defined as the joining of two rays going in separate directions? I've never really thought that anything couldn't have a definition, so is it possible for any of these geometric terms to be defined?
Yours truly, Leon
Dear Leon,
Your definition would require us to first define "ray" and "direction." Can you do that without reference to "point," "line," and "plane"?
Think of it this way: math is a huge building, in which each part is built by a logical chain of reasoning upon other parts below it. What is the foundation? What is everything else built on?
There must be some lowest level that is not based on anything else; otherwise, the whole thing is circular and never really starts anywhere. The undefined terms are part of that foundation, along with rules that tell us how to prove things are true. The goal of mathematicians has not been to make math entirely self-contained, with no undefined terms, but to minimize the number of definitions so that we have to accept only a few basics, and from there we will discover all of math to be well defined. Also, the goal is to make those terms obvious so that we have no trouble accepting them, even though we can't formally prove their existence.
To put it another way, these terms do have a definition in human terms-that is, we can easily understand what they mean. They simply don't have a mathematical definition in the sense of depending only on other previously defined terms. -Dr. Math, The Math Forum
What Is a Point?
Dear Dr. Math,
Define a point, please.
Yours truly, Lorraine
Dear Lorraine,
The word "point" is undefined in geometry. But it is pretty easy for us to describe a point, even though it can't be defined. A point is an entity that has only one characteristic: its position. A point has no size, color, smell, or feel. When we talk about points, we are referring to one specific location.
For example, along a number line the number 2 exists at just one point. Points are infinitely small, which means the point at 2 is different from the point at 2.000000001. Here's a picture of a number line:
If you want to distinguish one place along a number line, you "point" at it. You label that place with the corresponding number and refer to it with that number.
Now, how do you distinguish a location in two-dimensional space (e.g., a sheet of paper)? Imagine that we have two number lines: one horizontal and the other vertical. We are pointing at a place p:
How do we describe where the point p is? We can't just say p is at 2 because we don't know which number line that refers to. Is it at 2 along the horizontal number line or the vertical one?
To describe where p is, you must talk about where it is both horizontally and vertically. So, you can say
p is at 2 horizontally and 1 vertically
However, this is a mouthful. Because describing points in two dimensions is really useful, we have defined some conventions to make life easier. We call the horizontal number line the x-axis and the vertical number line the y-axis. The convention for talking about points in two dimensions is to write
(position along x-axis, position along y-axis)
Therefore,
p is at (2, 1)
Points in two dimensions can be described by any pair of numbers. For example, (4, 5), (6.23432, 3.14), and (-12, 4) are all points. -Dr. Math, The Math Forum
Rays, Line Segments, and Lines
Dear Dr. Math,
I need to know what a ray, a line segment, and a line are.
Sincerely, Leon
Dear Leon,
In geometry, you can think of a line just like a normal straight line, with a couple of special features. The things that make a line in geometry different from a line in any other context-for example, art class-are that it goes on forever in both directions, it's perfectly straight, and it's not thick.
Mathematicians say that their lines have zero thickness, which is pretty hard to imagine. When we draw lines on paper, they always have at least a little bit of width. But when we study lines in geometry, we think of them as having no width at all.
Here's how a lot of people draw lines on paper. The arrows at the ends mean that the line continues forever in both directions:
Rays and line segments are a lot like lines. A ray is like a line, except that it only goes on forever in one direction. So it starts at one point and goes on forever in some direction. You can think of the light coming from the sun as an example of a ray: the starting point is at the sun, and the light goes on forever away from the sun.
Here's how we draw rays:
A line segment is a little chunk of a line. It starts at one point, goes for a while, and ends at another point. We draw it like this:
Sometimes we like to attach little dots to represent the endpoints of rays and line segments like this: -Dr. Math, The Math Forum
2 Angles
There are angles all around us-between the hands on a clock, the opening created by a door, even the joints of your body. Any time two lines or line segments or rays intersect, they make angles.
What makes one angle different from another? Angles differ in how far open their "jaws" are. If you think of opening an angle starting with two line segments on top of each other, you could open it a little bit, or a pretty big amount, or a whole lot; you could bend it back on itself until the line segments are almost on top of each other again. We often measure angles in degrees to describe how far open the angles are.
In this section, we'll talk about the different kinds of angles and the ways we measure them.
What Is a Vertex?
Dear Dr. Math
What does vertex mean?
Sincerely, Lorraine
Dear Lorraine,
A vertex is the point at which two rays of an angle or two sides of a polygon meet. Vertices (pronounced VER-tih-seez) is the plural of vertex.
A triangle has three vertices. -Dr. Math, The Math Forum
Types of Angles: Acute, Right, Obtuse, and Reflex
Dear Dr. Math,
How can I remember what the types of angles mean-for example, acute angle or right angle?
Yours truly, Leon
Dear Leon,
There are three main types of angles. We tell them apart by how big they are. (Angles are often measured in degrees; there are 360 degrees in a circle.) Here they are:
We can start with the right angle: a right angle measures exactly 90 degrees. It's called a right angle because it stands upright. Just remember it's an upright angle.
Next is the acute angle. Acute angles measure less than 90 degrees. The word "acute" comes from a word that means "sharp." Remember that a sharp pencil or a sharp knife has an acute angle at its point or blade. An acute pain is a sharp pain. Acupuncture uses sharp needles. And, if all else fails, you can remember that an acute angle can cut you!
Finally, we have the wide-open obtuse angles, which measure between 90 and 180 degrees. The word "obtuse" comes from a Latin verb meaning "to make blunt or dull." If a person isn't very sharp (doesn't have an acute intelligence), he may be called obtuse. If that doesn't stick in your mind, just remember that if it isn't right or acute, it's obtuse.
I should mention a fourth kind of angle: the reflex angle. A reflex angle is the other side of any other type of angle. Reflex angles measure more than 180 degress. For example, in this diagram, the angle labeled A is the reflex angle. (The other angle in the diagram is obtuse.)
One meaning of reflex is "to bend back"; and the angle kind of looks bent back, like an elbow bent too far. Actually, some people can make a reflex angle with their elbow, and some can't. Can you?
I hope the names are memorable for you now. -Dr. Math, The Math Forum
Complementary and Supplementary Angles
Dear Dr. Math,
In class we're studying complements and supplements of angles. I do not understand any of the terminology behind the problems. Today we took a test, and one of the questions was to find the complement of this angle, c degrees, and I didn't even know where to begin. Another was to find the degrees in the third angle in an isosceles triangle, x degrees, x - 10, or something like that. Can you explain this a little better?
Sincerely, Lorraine
Dear Lorraine,
Part of the problem here is that the names "complement" and "supplement" are kind of confusing, since the literal meanings of these words aren't different enough for us to know which is which, other than by memorizing them.
What are complements and supplements?
If you place two angles next to each other so that they add up to 90 degrees, we say that the angles are complements.
If you place two angles next to each other so that they add up to 180 degrees, we say that the angles are supplements.
So what you need to remember is which one adds up to 90 degrees and which one adds up to 180 degrees.
How can you keep them straight? The person who runs the Math Forum's Geometry Problem of the Week tells me that she remembers them this way: c comes before s, and 90 comes before 180. It's the best idea I've heard so far.
If you know that two angles are complements or supplements, you can figure out one given the other. How? Well, if they're supplements, you know that they have to add up to 180:
this + that = 180
So it must be true that
this = 180 - that and
that = 180 - this
You can do the corresponding calculations for complements using 90 degrees instead of 180 degrees.
So whenever you see the phrase "the supplement of (some angle)°," you can immediately translate it to "180° - (the angle)°." When you have a value for the angle, you end up with something like
the supplement of 26° = (180° - 26°)
which you can just simplify to get a single number. But if you only have a variable like x, or an expression for the angle, like x - 10, then you just have to deal with that by substituting the variable or the expression in the equation. For example:
the supplement of (x° - 10°) = [180° - (x° - 10°)]
Note that you have to put the expression in parentheses (or brackets), or you can end up with the wrong thing. In this case,
Well, in geometry you're constantly dividing things into triangles in order to make them easier to work with. And in every triangle, the measures of the interior angles add up to 180 degrees. So if you know two angles, the third is the supplement of the sum of the other two.
The nicest kind of triangle to work with is a right triangle. In a right triangle, you have one right angle and two other angles. Since they all have to add up to 180 degrees, and since the right angle takes up 90 of those degrees, the other two angles must add up to 90 degrees. So if you know one of the acute angles in a right triangle, the other is just the complement of that angle. -Dr. Math, The Math Forum
RX ORDER OF OPERATIONS
In case you've forgotten, here's a quick review of the correct order of operations for any expression:
1. Parentheses or brackets
2. Exponents
3. Multiplication and division (left to right)
4. Addition and subtraction (left to right)
For more about this topic, see Section 5, Part 1 of Dr. Math Gets You Ready for Algebra.
Alternate and Corresponding Angles
Dear Dr. Math,
Please explain alternate and corresponding angles.
Sincerely, Leon
Dear Leon,
Let's first look at a diagram that we can refer to when we define corresponding angles and alternate angles:
There are a lot of numbers in this diagram! Don't worry, though-we'll figure out what everything means.
Assume that the two horizontal lines are parallel (that means they have the same slope and never intersect). The diagonal is called a transversal, and as you can see, the intersection of the transversal with the horizontal lines makes lots of different angles. I labeled these angles 1 through 8. Whenever you have a setup like this in which you have two parallel lines and a transversal intersecting them, you can think about corresponding angles and alternate angles.
Look at the diagram. Do you see how we could easily split the angles into two groups? Angles 1, 2, 3, and 4 would be the first group-they are the angles the transversal makes with the higher horizontal line. Angles 5, 6, 7, and 8 would be the second group-they are the angles the transversal makes with the lower horizontal line.
Can you see how the bottom set of four angles looks a lot like the top set of four angles? We say that two angles are corresponding angles if they occupy corresponding positions in the two sets of angles. For example, 1 and 5 are corresponding angles because they are both in the top left position: 1 is in the top left corner of the set of angles {1, 2, 3, 4}, while 5 is in the top left corner of the set of angles {5, 6, 7, 8}.
Similarly, 3 and 7 are corresponding angles. There are two more pairs of corresponding angles in the diagram. Can you find them?
One neat and helpful fact about corresponding angles is that they are always equal. Can you see why? (Think about the way the nonparallel line intersects the parallel lines.)
Let's move on to alternate angles.
(Continues...)
Excerpted from Dr. Math Introduces Geometry
| 677.169 | 1 |
Enter your mobile number or email address below and we'll send you a link to download the free Kindle Reading App. Then you can start reading Kindle books on your smartphone, tablet, or computer - no Kindle device required.
Comment: BC120 mat...
Think all Praxis II Middle School Mathematics study guides are the same? Think again! With easy to understand lessons and practice test questions esigned to maximize your score, you'll be ready. You don't want to waste time - and money! - retaking an exam. You want to accelerate your education, not miss opportunities for starting your future career! Every year, thousands of people think that they are ready for the Praxis II Middle School Mathematics exam but realize too late when they get their score back that they were not ready at all. They weren't incapable, and they certainly did their best, but they simply weren't studying the right way. There are a variety of methods to prepare for the Praxis II Middle School Math test...and they get a variety of results. Trivium Test Prep's Praxis II Middle School Mathematics study guide provides the information, secrets, and confidence needed to get you the score you need - the first time around. Losing points on the Praxis II Middle School Math exam can cost you precious time, money, and effort that you shouldn't have to spend. What is in the book? In our Praxis II Middle School Math study guide, you get the most comprehensive review of all tested concepts. The subjects are easy to understand, and have fully-explained example questions to ensure that you master the material. Best of all, we show you how this information will be applied on the real exam; Praxis II Middle School Mathematics practice questions are included so that you can know, without a doubt, that you are prepared. Our study guide is streamlined and concept-driven so you get better results through more effective study time. Why spend days or even weeks reading through meaningless junk, trying to sort out the helpful information from the fluff? We give you everything you need to know in a concise, comprehensive, and effective package.
{"currencyCode":"USD","itemData":[{"priceBreaksMAP":null,"buyingPrice":34.43,"ASIN":"1492875090","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":18.22,"ASIN":"0470278226","isPreorder":0},{"priceBreaksMAP":null,"buyingPrice":16.43,"ASIN":"1607873400","isPreorder":0}],"shippingId":"1492875090::lsEpdoJ3LJs0mzAt5V0NA8l22Dr4uwV31A%2FbR1j5CZCJr8P%2BB9Hf6GuafakiKwogrbt6oQpVhxzzfgBt9hs%2FyF0EBP2SsTTgeULl9OFkp9IHsW%2BGT%2BDXQw%3D%3D,0470278226::LNsQKWmXHdqlZ%2BfFeoi3jH3mH3FPG2xX73FqpSKQCjL5Ghfjc2g2jEztSilFaEHy5linzuPiQQor6aG0SzGMcm7KgX9KwmaTj1AkcNggsds%3D,1607873400::zhYZSg%2FFbTb9fTMMbk8Qew5UPyHtJBDnux4bCMxXc4iV7%2FUo%2BYaWPlCRvlQDX2M5h2v33Jb%2BRloMT1DJXl7NW82O5kBVIKLX0jBFNcOzvF4D8B0MXHUcc only book out there for the 5169 test, so I guess it is better than nothing. But it is awful. It doesn't go over basic concepts before doing an equation or expression. There are only 10 review questions for each chapter (5 chapters) and no practice test. It also do not have many examples for types of problems (about half have no examples and the other half have 1). I have taken other praxis tests and used different study guides and was thoroughly impressed with those, so I was very upset with the quality of this book.
I purchased this book because I have taken the new Middle Grades Mathematics praxis before. After failing it the first time, I purchased this book to help me study for the retake. I can tell you from experience that this book is not an accurate reflection of what you will be tested on. I'm sending it back! It's definitely not worth the $40 it cost me. Buyers Beware!
This book doesn't reflect the Praxis test at all. The "Test Your Knowledge" looks nothing like the actual Praxis test. There are no true/false or fill in the blank on the Praxis! Content is organized in an incomprehensible way. Do not buy this book!!! You'd do better to study a general math book.
| 677.169 | 1 |
Is My Child Ready for VideoText Algebra?
This is a question that we often receive, and our answer sometimes surprises parents. Students CAN be ready sooner than many parents realize. One reason directly relates to the VideoText approach to the teaching of Algebra. Module A could be called "Algebra Readiness" because it RE-TEACHES essential arithmetic concepts the way they will be used in a formal Algebra course. This focus on the "WHY" behind each and every arithmetic procedure is the key to student understanding and success in Algebra.
So, if you're asking the question, "How do I know if my student is ready?", take a look at what Tom Clark has to say:
What to REMEMBER:
Even if your student has not completely mastered these arithmetic concepts, we will re-teach them as if they have never seen them before, using computer-generated graphics, animation and color-sequencing, to ensure their complete understanding.
"It doesn't have to be that hard when you use a video textbook!"
Contact Information
Office Hours: Monday-Friday 10-6PM ET
Voice Mail: 24 hours
PHONE: 1-800-ALGEBRA (1-800-254-3272)
FAX: 1-317-622-1396
For Technical Assistance: ext. 107
For Orders: ext. 103
Email: customercare@videotext.com
eNEWS and Updates
Enter your name and email address below in order to receive the FREE VideoText email newsletter!
| 677.169 | 1 |
nonlinear programming
major reference
mathematical programming
...a variety of purposes. If the basic descriptions involved take the form of linear algebraic equations, the technique is described as linear programming. If more complex forms are required, the term nonlinear programming is applied. Mathematical programming is used in planning production schedules, in transportation, in military logistics, and in calculating economic growth, by inserting assumed...
| 677.169 | 1 |
Basic College Mathematics with Early Integers
9780321726438
ISBN:
032172643X
Edition: 2 Pub Date: 2011 Publisher: Pearson Education
Summary: Martin-Gay, Elayn is the author of Basic College Mathematics with Early Integers, published 2011 under ISBN 9780321726438 and 032172643X. Two hundred seventy five Basic College Mathematics with Early Integers textbooks are available for sale on ValoreBooks.com, fifty two used from the cheapest price of $61.72 shipping within U.S. will arrive in 3-5 days. Hassle free 14 day return policy. Contact Customer Service for questions.[less]
To be so honest with you, math is not my favorite subject. The instructor I had was not so good on teaching the subject to the class as well as she would of. The most useful would be the basics and the variables. I plan on joining the military and thoses will be on the test. So those where the most helpful.
I believe it was a great book. I just had the wrong instructor teaching me. I didn't learn as much as I wanted too.
All the information used inside the book was helpful for my desire to re-learn math from the bottom up.
Developmental math appreciation, I simply took the course so I could re-learn math from the bottom due to not having had a math class in over 10 yrs as well as I don't remember ever having a math teacher that really cared if I learned and understood.
| 677.169 | 1 |
You are here
The Three-Body Problem
Publisher:
Cambridge University Press
Number of Pages:
345
Price:
80.00
ISBN:
0521852242
An undergraduate, having taken calculus and some physics, comes across the two-body problem. Specifically, what is the motion of two bodies in space acting under their mutual gravitational attraction? She quickly finds that she can solve the equations, and for given initial conditions, the solutions are conic sections. Then, the natural question to ask is: What is the solution if we now expand the system to three bodies? Here the problem is not so easy. In fact, it is impossible to solve in closed form.
This book begins by recounting what the student would have learned in that physics class and then goes into specifics of the three-body problem. Not only is the problem unsolvable in closed form; the solution, in general, involves chaotic dynamics. Nonetheless, there is much that can be learned by studying various forms of the problem under differing conditions. This book goes a long way to exploring these forms and explaining how the different scenarios can be approached.
The authors begin with a presentation of Newtonian mechanics and the solution of the two-body problem. The authors use physics to motivate the mathematics and derive the equations of motion — here, and throughout the book. Thus, the discussions are complete and present the ideas from the view of mathematical physics.
After discussion of the two-body problem we are introduced to Hamiltonian mechanics and some restricted three-body problems such as satellite orbits, and scatterings of bodies from a binary orbit. Other topics include escapes, three body scattering, and capture. The final topics deal with perturbations and various astrophysical problems such as black holes and the evolution of comet orbits.
Throughout the book the authors present diagrams to illustrate their points but these diagrams are limited in their utility. The authors could have presented more illustrative diagrams and figures to better qualify the text.
When I started reading I thought the book would discuss chaos and its relationship to the three body problem. After all, that's the first thought that comes to mind today. There is mention of this phenomenon, but very little, and no attention given to simulating orbits of three-body motion. For me, this was a disappointment.
Finally, the spirit of the book is mathematical physics; consequently, the authors often leave it to the reader to sort through the mathematics. I often found, for example, that I had to review earlier parts of the text and search for the equations — always present somewhere in the text but not explicitly noted nor cited — needed to follow the derivations and fill in many of the steps.
In short, this is a good text on the mathematical physics of the problem for the experienced practitioner. Everyone else, I'm afraid, will find it a challenge to read and follow the mathematics.
David Mazel received his doctorate from Georgia Tech and is a practicing engineer in Washington, DC. His research interests are in the dynamics of billiards, signal processing, and cellular automata.
| 677.169 | 1 |
GED Math Training Module
Problem Solving
In the section on problem solving, you will have an opportunity to learn four basic steps that you can use to help your students become better problem solvers. You will also have a chance to use some problem-solving strategies in each of the four content areas of the GED Mathematics Test.
Calculator
In the calculator section, you will have an opportunity to learn more about how to operate the Casio fx-260 Solar Scientific calculator, as well as learn about the functions students will find helpful for the test.
Grid Format
In the section on grid formats, you will learn the basics of recording and bubbling in answers, as well as plotting coordinates, all in an easy to follow format that you can use with your students.
You may work on this module at your own pace and at any time that you choose. Now it is time for you to learn some of the basic facts about the GED Mathematics Test.
| 677.169 | 1 |
Everything a student needs to succeed in one place. Can be packaged with selected Prentice Hall texts, or available for purchase as a stand-alone. The Study Pack contains: Student Solutions Manual: Fully worked solutions to odd-numbered exercises only. Pearson Tutor Center: Tutors provide one-on-one tutoring for any problem that has an answer at the back of the book. Students access the Tutor Center via toll-free phone, fax, or email. CD Lecture Series: A comprehensive set of CD-ROMS, tied to the textbook, containing short video clips of an instructor working key book examples. Algebra Review: (available only with the Sullivan, 7E series) Four chapters of intermediate algebra review. Perfect for a slower-paced course or for individual review.
--This text refers to an out of print or unavailable edition of this title.
--This text refers to an out of print or unavailable edition of this title.
Editorial Reviews
From the Publisher
A proven motivator for students of diverse mathematical backgrounds, this text is organized and written with all students in mind. Striving to teach mathematics as a way of life, Sullivan provides understandable, realistic applications that are consistent with the abilities of any student. This text develops the trigonometric funtions using a right triangle approach and showing how it leads to the unit circle approach. Graphing techniques are emphasized, including a thorough discussion of polar coordinates, parametric equations, and conics using polar coordinates.
--This text refers to an out of print or unavailable edition of this title.
From the Back Cover
Represents mathematics as it appears in life, providing understandable, realistic applications consistent with the abilities of any reader. This book develops trigonometric functions using a right triangle approach and progresses to the unit circle approach. Graphing techniques are emphasized, including a thorough discussion of polar coordinates, parametric equations, and conics using polar coordinates. Those looking to master essential skills of Algebra and Trigonometry.
--This text refers to the
Hardcover
edition.
| 677.169 | 1 |
PRACTICE TEST ON PRECALCULUS
There is certain precalculus material that we consider it necessary that
you know quite well in order to succeed in Calculus, MA 131. This includes
being able to do such problems in a reasonable amount of time. Within two
weeks of the beginning of the semester, you will be given a "Basics Exam"
covering this material. The results will be used to advise you whether you
are ready for Calculus. The practice tests on the Web are available for
you to use as much as you want or need in preparation for the "Basics
Exam". The "Basics Exam" is timed. Therefore, the practice tests are timed.
You will have 50 minutes. The practice tests are multiple choice but the
"Basics Exam" will not be. Therefore, it is best for you to work out each
of the problems on the practice test as if you had no answer choices.
Most of the "Basics Exam" will be worked without a calculator. Therefore,
we have indicated which problems are appropriate for use of a calculator.
Assume you are NOT to use a calculator unless the problem statement begins
with [Calculator].
Below are some further comments concerning notation:
Assume all functions are real valued.
[a,b) is interval notation for all numbers between a and b, including a but not including b.
When using trigonometric functions, if angles are measured in degrees, this will be
indicated by use of the degree symbol, o, as a superscript (such as 10o). If the degree
symbol is NOT present, assume that the angle measurements are in RADIANS.
PRACTICE TEST OPTIONS
Each practice test will contain 15 problems. The problem bank available
for the practice tests is organized into 6 categories: algebra, geometry, graphs
(recognition and interpretation of graphs of functions), trigonometry,
exponentials and logarithms, and problem solving. (Several of these categories
overlap.) There are two basic options, described below, for generating a
practice test from the problem bank. Your 50 minutes of time will begin as
soon as the practice test appears after you choose an option. You may choose
the DEFAULT option (in which a random sample of problems covering all categories
will be chosen) or you may choose the CUSTOMIZE option (in which you will be
asked how many problems from each category you wish, with the total number
of problems adding to 15).
Name:
To take default test:
To customize test, fill in the number of questions from each category. Remember, there can be no
more than 15 questions.
| 677.169 | 1 |
Hello math wizards, I need some urgent help. I have a set of math problems that I need to answer and I am hopelessly lost. I don't know where to begin or how to go about and this paper is due next week. Kindly let me know if you are good in radicals or if there is a good site which can assist me.
Due to health reasons you might have missed a few lectures at school, but what if I can you can have your own little classroom , in the place where you live? In fact, right on the computer that you are working on? All of us have missed some lectures at some point or the other during our life, but thanks to Algebrator I've never been left behind . Just like an instructor would explain in the class, Algebrator solves our problems and gives us a detailed description of how it was answered. I used it basically to get some help on graphing systems of inequalities worksheet and mixed numbers. But it works well for just about everything you can think of .
Algebrator is one handy tool. I don't have much interest in math and have found it to be complicated all my life. Yet one cannot always leave math because it sometimes becomes a compulsory part of one's course work. My friend is a math expert and I found this program in his palmtop . It was only then I understood why he finds this subject to be so simple .
Algebrator is a very remarkable software and is definitely worth a try. You will also find quite a few interesting stuff there. I use it as reference software for my math problems and can swear that it has made learning math more fun .
| 677.169 | 1 |
Algebra and Trigonometry
Browse related Subjects
...Read More real-life problems. These applications help answer the question "When will I ever use this?" Students stay engaged because the book helps them remain focused as they study. The three-step learning system-See It, Hear It, Try It-makes examples easy to follow, while frequent annotations offer the support and guidance of an instructor,s voice. Every page is interesting and relevant, ensuring that students will actually use their textbook to achieve success!Read Less
Customer Reviews
Well written
I got this book to finish my algebra requirement and it has really helped me...plus I have a talented instructor. Although I find the book a great asset, I think the author has tried too hard to explain things with too many details. All the labels and arrows are hard to follow and do more to confuse the student. I have learned not to rely too heavily on the answer key in the back due to a number of errors we have found. Use the answer key as a tool to learn and get the student solutions manual that goes with this textbook. But watch for mistakes in there too.
butter75
Nov 11, 2011
the book provides helpful explanations
this book provides you helpful step by step explanations on every topic
| 677.169 | 1 |
0387908390
9780387908397
Basic Topology:In this broad introduction to topology, the author searches for topological invariants of spaces, together with techniques for calculating them. Students with knowledge of real analysis, elementary group theory, and linear algebra will quickly become familiar with a wide variety of techniques and applications involving point-set, geometric, and algebraic topology. Over 139 illustrations and more than 350 problems of various difficulties will help students gain a rounded understanding of the subject.
Back to top
Rent Basic Topology 1st edition today, or search our site for M. A. textbooks. Every textbook comes with a 21-day "Any Reason" guarantee. Published by Springer.
| 677.169 | 1 |
Elementary and Intermediate Algebra: A Combined Approach, 6th Edition
Master the fundamentals of algebra with ELEMENTARY AND INTERMEDIATE ALGEBRA: A COMBINED APPROACH, Sixth Edition. Learn from clear and concise explanations, many examples, and numerous problem sets in an easy-to-read format. The text's "Learn, Use and Apply" formula helps you learn a skill, use the skill to solve equations, and then apply it to solve application problems. This simple, straightforward approach helps you understand and apply the key problem-solving skills necessary for success in future mathematics courses304.95
Purchase Options
Hardcover $304.95
$304Loose Leaf $193.95
$193.95
Save $11148.49
from$48.49
Save up to $256.46!
Rent until 02/21/15 for $48.49
$48.49
Save $256.46!
Rent until 03/23/15 for $54.49
$54.49
Save $250.46!
Rent until 05/02/15 for $60.49
$60.49
Save $244.46!
Rent until 09/19/15 for $69.99
$69.99
Save $234.96!
Rent until 06/15/16 for $75.99
$75.99
Save $22890.99
from$90.99
Save up to $213.96!
Access until 06/21/15 for $90.99
$90.99
Save $213.96!
Access until 12/18/15 for $104.49
$104.49
Save $200.46!
Access until 12/12/16 for $113.49
$113.49
Save $191.46!
Access until 12/02/18 for $126.99
$126.99
Save $177
| 677.169 | 1 |
20.1722.2239.37 +$3.99 s/h
Good
Cruixshanks Booksellers North Port, FL
PAPERBACK Good 08215822757112 +$3.99 s/h
VeryGood
Books Revisited Chatham, NJ
Very good.
$71.77 +$3.99 s/h
VeryGood
AlphaBookWorks Alpharetta, GA
0821582299 +$3.99 s/h
New
Thebigestbook North Bergen, NJ
In alignment with the Common Core State Standards, the scope and sequence of Fundamentals of Algebra is organized into bite-sized, manageable lessons allowing for deeper understanding of skills and co...show morencepts so students get the necessary skills for Algebra and beyond. Fundamentals of Algebra:• Focuses on conceptual development for all learners.• Builds knowledge lesson by lesson and across grade levels with coherent lessons.• Develops fluency and conceptual understanding in a multitude of ways.• Deepens understanding with vocabulary, cognitive rigor, and higher-level thinking skills.The Source book allows students to focus on learning skills and concepts before moving onto independent practice in the Practice Book. ...show less
$131
| 677.169 | 1 |
Importance of maths not fully understood by students
Jun 25, 2014
Too many sixth form students do not have a realistic understanding of either the relevance of Mathematics and Statistics to their discipline or of the demands that will be put upon them in undergraduate study, according to a new report published today by the Higher Education Academy (HEA). The report examines the mathematical and statistical needs of students in undergraduate disciplines including Business and Management, Chemistry, Economics, Geography, Sociology and Psychology.
Professor Jeremy Hodgen, lead author of the report from the Department of Education & Professional Studies, said: 'Too few students in the UK study Mathematics after the age of 16, yet the study demonstrates that Mathematics matters across a range of subjects at university. The report recommends that prospective undergraduates are better informed of this when applying to higher education.'
Lack of confidence and anxiety about Mathematics and Statistics is also a problem for many students, making the transition into higher education particularly challenging. A number of recommendations are made within the report to address this problem, but overall it calls for better dialogue between the sectors so that pre-university students have a better understanding of what is expected of them and the higher education sector has a better understanding of what their undergraduates can do.
The report also draws attention to developments at pre-university level, where new 'Core Maths' courses are being designed to meet the needs of the many students (the report estimates at least 200,000 a year) who need Mathematics but for whom a full A-level would not be appropriate. It calls for higher education to become actively involved in and to influence this work.
Dr Mary McAlinden, Discipline Lead for Mathematics, Statistics and Operational Research at the HEA said: 'Many students are surprised at the amount of mathematical content in their undergraduate programmes and some struggle to cope with this content.
'This project, and the accompanying reports, seeks to promote greater understanding between the higher education and pre-university sectors so that students will arrive at university better prepared and better able to cope with the mathematical and statistical demands of their undergraduate studies.'
Dr Janet De Wilde, Head of STEM at the HEA said: 'This report demonstrates the importance that the HEA places on this topic. The recommendations it contains are valuable to the sector to help further the discussion between the secondary and tertiary sector to inform policy development and teaching practice to address the importance of mathematical and statistical skills.'
The solution to England's poor participation rate in post-16 maths education could lie in a new qualification that provides a clear and attractive alternative for students who don't currently go on to study ...
For many years, studies have shown that American students score significantly lower than students worldwide in mathematics achievement, ranking 25th among 34 countries. Now, researchers from the University of Missouri haveAll young people should continue to study maths at least until they are 18, even if they have already gained a good GCSE in the subject, the Sutton Trust said today, because the GCSE curriculum fails to give them the practical
| 677.169 | 1 |
Higher Mathematics (VOL - 1 Higher Mathematics (VOL - 1) (Paperback).
You will be Notified by Email when it becomes available.
Higher Mathematics (VOL - 1) (Paperback)
Price: Rs. 330
* Designed for HS, JEE and IIT Admission test. * Helpful for B. Stat and other Competitive Exams. * Includes a comprehensive set of Questions and Answers. * Special notes and profuse examples on each topic. * Solved MCQs included.
| 677.169 | 1 |
Schaum's Outline of Trigonometry - 3rd edition
Summary: Updated to match the emphasis in today's courses, this clear study guide focuses entirely on plane trigonometry. It summarizes the geometry properties and theorems that prove helpful for solving trigonometry problems. Also, where solving problems requires knowledge of algebra, the algebraic processes and the basic trigonometric relations are explained carefully. Hundreds of problems solved step by step speed comprehension, make important points memorable, and teach p...show moreroblem-solving skills. Many additional problems with answers help reinforce learning and let students gauge their progress as they goEx-Library Book - will contain Library Markings. Selection as wide as the Mississippi.
| 677.169 | 1 |
Introductory Algebra - 2nd edition
ISBN13:978-0077281120 ISBN10: 0077281128 This edition has also been released as: ISBN13: 978-0073406091 ISBN10: 0073406090
Summary: Introductory Algebraoffers a refreshing approach to the traditional content of the course. Presented in worktext format,Introductory Algebrafocuses on solving equations and inequalities, graphing, polynomials, factoring, rational expressions, and radicals. Other topics include quadratic equations and an introduction to functions and complex numbers. The text reflects the compassion and insight of its experienced author team with features developed to address the specific needs of dev...show moreelopmental level students. ...show less
2008 Paperback Fair This book is in acceptable conditon. It is a good reading copy for personal use if you want to save some money but do not try and give as a gift94 +$3.99 s/h
Acceptable
SellBackYourBook Aurora, IL
0077281128
| 677.169 | 1 |
You are here
Achieving Quantitative Literacy
Publisher:
Mathematical Association of America
Number of Pages:
124
Price:
29.50
ISBN:
0-88385-816-9
In 2001, the National Council on Education and the Disciplines (NCED) published Mathematics and Democracy: The Case for Quantitative Literacy, which set the stage for the Mathematical Sciences Education Board to host a forum that December, co-sponsored by NCED and the MAA, titled Quantitative Literacy: Why Numeracy Matters for Schools and Colleges. Proceedings of the forum were published by NCED under the same title, and distributed along with Mathematics and Democracy as MAA Notes #44 and #43. In Achieving Quantitative Literacy, Lynn Steen summarizes the results of that forum, including numerous and generous quotations from presenters.
While Achieving Quantitative Literacy is that synopsis, its primary value to the educational community is likely to be that it is a superb introduction, overview, and inspiration for anyone who wants to know what QL is and why something needs to be done about it. With his usual grace and style, and possessing a view of Quantitative Literacy that is both broad and deep, the author has provided a small volume (only 115 pages) that makes clear the urgency for QL, that characterizes the enterprise of QL, and that calls for broad institutional commitments to interdisciplinary infusion of QL throughout college curricula.
Briefly, Quantitative Literacy is about reasoning in context and about making judgments based on real-world data and having real-world consequences. For example, if an article describes the size of a population as a "percent more than" another known group, can you calculate what that population is? From a newspaper graph that shows changes in the price of a stock, can you tell when the price was at its highest? If you are tested positive for a disease that has a low incidence, how worried should you be? If a drug is reported to have a side effect of doubling the risk of heart attack and stroke, should you stop taking the drug or is there other information that would be useful in making that decision? These examples demonstrate some of the reading and reasoning skills described as Quantitative Literacy.
Part I of Achieving Quantitative Literacy begins with a statement of the Five Findings of the forum, upon which the subsequent chapters elaborate. The Findings are:
Many students finish their education ill prepared for the quantitative demands of contemporary life.
The increasing importance of quantitative literacy is not sufficiently recognized by the public or by educational, political, and policy leaders.
The lack of agreement on QL expectations at different levels of education makes it difficult to establish effective programs for QL education.
QL is largely absent from our current system of assessment and accountability.
Faculty in all disciplines need significant professional support in order for them to enhance the role of quantitative literacy in their courses.
Although there has been general agreement for millennia that mathematics is a useful skill for everyday life, Steen begins by making clear that the 21st century will require the use of quantitative reasoning to a degree not previously even imagined. The ubiquity of technology, and especially its use of large databases and computer modeling, means that "success in the new information economy requires a new set of problem-solving and behavioral skills ... [including] the ability to make sense of real-world situations and to make judgments grounded in data [pp. 9-10]." Questions of social policy and civic health will require quantitative methods of analysis; individuals will need these skills to control their own lives and to participate in social decision making. Throughout, Steen makes clear that QL is a concern for both personal quality of life and for the survival of democratic society.
The focus on personal and societal well-being makes clear that Quantitative Literacy is not simply a set of "basic skills" that can be taught in a single academic course: it is a cumulative knowledge responsive to the dynamics of real life problems and experiential data, requiring the ability to develop appropriate analytic strategies and apply quantitative tools in context.
This is not to suggest that at present QL is widely taught in schools and colleges, or even that it a likely outcome of what is taught. Many college students finish a required mathematics course believing that the mathematics they have seen has little to do with their life outside the classroom. (Steen notes in a fascinating sidebar that while patterns in twentieth century college enrollments reflect increasing democratization of higher education, and while other disciplinary curricula have evolved over that century, college mathematics curricula have remained largely static, in a design emphasizing the priorities of an age when the college population represented a primarily elite class.) This is not to say that revised versions of presently required college courses should not be implemented for the new literacy (and examples of several institutional programs are found in Part II), but the reader is alerted early on that no single course, modified or not, will be able to provide the repeated exposures in a variety of contexts that the development of a functional quantitative literacy will require.
Those who are looking for a definitive list of "the QL skills" will not find it in this volume, but rather will find characterizations of Quantitative Literacy: QL requires, above all, "engagement with the world;" it includes "the ability to apply quantitative ideas in unfamiliar contexts;" and it requires "flexible thinking that adapts readily to new circumstances [p. 24]." Quantitative Literacy involves "sophisticated thinking with elementary mathematics more often than elementary thinking with sophisticated mathematics [p. 9]." QL is not a discipline but a way of thinking, a habit of mind.
Given that Quantitative Literacy is concerned with making sense of quantitative information found in contexts, and that the relatively recent phenomena of computer modeling and data collection create new contexts almost daily, it should not be surprising that a precise consensus of the skills comprising the QL tools has not yet evolved. In fact, it is easier to highlight counterexamples: QL is not College Algebra and is not likely to be found in such a course; QL is not Calculus, and the funneling of high school and college students into a Calculus track may well be counterproductive for such literacy; QL is not merely deductive reasoning. But beyond what Quantitative Literacy is not, QL programs will require challenging, college-level thinking, and must not be perceived to be "lower-track" or remedial mathematics.
Even without a consensus definition of QL skills, directions are emerging and some topics are generally accepted: ratios, percentages, probabilities, interpretation of information presented in graphical form, the language of statistics. To wait for more precision could tempt the community to reduce the QL enterprise to that of designing a single QL course with an ideal syllabus, but given that QL is inextricable from contexts, such an effort may itself be at odds with the QL task. Instead, Professor Steen calls for Quantitative Literacy to have a presence in the college curriculum analogous to the place it will have in today's students' lives: occurring in multiple and unexpected applications, wherever quantitative data and questions arise.
This perspective sets the stage for thinking about the implementation of Quantitative Literacy as a curricular component of higher education. It must be embedded in and infused throughout college curricula. It will deal with real questions, where they occur. It will use quantitative reasoning to make real-life judgments. It will be visited and re-visited, in multiple contexts and with increasing depth. And to reach this goal, broad institutional commitment will be required.
How will we get there? And what will be the role of mathematics? Mathematicians are obviously not the only educators who will need to address QL; in fact, they may not be the best qualified to teach it. Data-driven real-world problems are usually messy, often with unclear assumptions to be ferreted out and evaluated, using techniques far removed from what is learned in much of graduate mathematics education. The colleagues in the disciplines will be needed to explicate the issues and the methods of their professional areas for mathematicians, who may have to learn to listen in a new way. Because of the interdisciplinary composition of QL, no particular discipline has a natural leadership role in implementing a pedagogy. Nonetheless, the public accurately perceives mathematics' special foundational role for QL, and, while interdependent with colleagues across the curriculum, mathematics departments will necessarily bear a special responsibility for nurturing QL programs.
A particular difficulty for QL will be the problem of assessment. Because standardized test items are "generally decontextualized by design," meaningful assessment of QL "challenges the very notion of 'test' as that term is ordinarily understood [p. 57]." Nonetheless, "quantitative literacy must develop accepted methods of assessment if it is to achieve its goals [p. 59]," and Steen recommends the policy goal suggested by NSF director Rita Colwell of establishing benchmarks for QL proficiency as students move throughout their K-16 education.
Part I of this report concludes with Responses to the Five Findings of the Forum, including directions and clear suggestions for action. Many of these recommendations are viable starting points for a department or interdisciplinary task force that is ready to pursue Quantitative Literacy on its own campus.
Part II is the hands-on section of this volume. The first chapter contains a number of dialogues between mathematical insiders and skeptical outsiders that Steen has edited from e-mail discussions following the Forum. They will be helpful for the reader who anticipates conversations with colleagues, both in setting the stage for outsiders' perceptions of mathematics and the need for QL, and for challenging mathematicians' commonly held assumptions.
Having resisted definitions, Steen now provides a chapter of sample problems taken from QL course and assessment materials at a variety of institutions, including the examples cited above. The problems range from number sense (what is the approximate population of the United States? of the world?) to reading graphs (what characteristics do the clusters of points on a scatterplot represent?), to interpreting tabular data (what is the significance of this particular entry in a table compared to the other entries?), to percentages (should a company's change in participation in a retirement plan from 30% to 90% be reported as a 60% increase or a 200% increase?), to actual newspaper excerpts that call for analysis of their conclusions (do the 93% of those Chicago students who qualify for bussing to better schools but elect not to take it really prefer to attend a failing school?). The examples given make vividly clear the difference between what have been called (textbook) "exercises," i.e. problems that have been decontextualized, and (real) "problems."
Part II ends with brief descriptions of QL programs at six of the institutions that have joined forces to form the National Numeracy Network. The programs vary, each in keeping with the needs and resources of its home institution. Each is available as a resource to interested institutions, and contact persons are listed.
Achieving Quantitative Literacy appears ten years after the 1994 report of the CUPM Subcommittee on Quantitative Literacy, a five-year project chaired by Linda Sons. That report, which is available at includes a recommendation for two-tiered college Quantitative Literacy programs consisting of foundation experiences followed by continuing application experiences. In the decade since the report, a modest number of colleges (are known to) have implemented a variety of QL programs, and in 2004 the MAA established a Quantitative Literacy SIGMAA and the National Numeracy Network was founded. The QL SIGMAA maintains a webpage that is reachable through and which contains links to a variety of resources. A particularly rich site containing downloadable interdiscplinary material is found at Dartmouth Another link reaches Professor Steen's summaries of QL activity at 25 institutions, including contact persons for each and URLs for several of the programs.
So who needs this book? If you are a teacher of mathematics at the school or college level, you need to read this book. If you are on a committee to investigate or implement Quantitative Literacy at your institution, you need to give copies to all your committee members--and to your Dean and President as well. If you want to convey the spirit of QL to a skeptical colleague, give them this book.
Whether your institution has already established a Quantitative Literacy requirement or is just now investigating such a program, this reviewer highly recommends membership in the National Numeracy Network and the QL SIGMAA, and attendance at their sponsored sessions at the national MAA meetings. The members of both of these groups are most generous in sharing their experiences, insights and materials, much of which can be found through the mentioned websites.
The great accomplishment of Achieving Quantitative Literacy is that it articulates the urgent need with an eloquent philosophy of education and democracy, and a vision that is both compelling and awesome; yet it never forgets that the real-world mathematical/QL problems to be solved are everyday tasks that will often be contextually messy. As the Responses to the Findings demonstrate, the real-world implementation of QL education will also require everyday tasks that are not always elegant, and not always comfortable for mathematicians. Professor Steen says in the Preface that the purpose of Achieving Quantitative Literacy is "to pervade undergraduate education with a consciousness of the importance of QL." We hope that its readers will make that so.
Charlotte Chell is Professor of Mathematics and Computer Science at Carthage College in Kenosha, WI. She has served as Chair of Mathematics and Chair of the Division of Natural Science at Carthage. Her training is in mathematical logic, and her current interests are in quantitative literacy and applications of mathematics.
| 677.169 | 1 |
Math Fundamentals 1 condition, clean copy with light amount of wear. Same day shipping. Thank you.
Helping Hands Global
MO, USA
$8.29
FREE
New:
100% Brand New!
More Books
FL, USA
$9.45
FREE
Used Like New(9 Copies):
Fine 100% Brand New!
More Books
FL, USA
$9.45
FREE
New:
New
NEEBO # 294
WI, USA
$9.50
FREE
New:
Brand New! Fast shipping! Great customer service. You will be happy!
booklab
VA, USA
$10.43
FREE
Used Like New(9 Copies):
Fine Brand New! Fast shipping! Great customer service. You will be happy!
booklab
VA, USA
$10.43
FREE
New:
New 142320395X Special order direct from the distributor.
Russell Books
BC, CAN
$12.80
FREE
Used Good(1 Copy):
Good Satisfaction 100% guaranteed.
Bookmans
AZ, USA
$13.12
FREE
About the Book
Designed to follow state and national standards for middle-school math curricula, Math Fundamentals 1, 2, 3 & 4 will work equally well together as a group of four guides or each as a standalone guide. All four 2-panel guides were written by members of the National Council of Teachers of Mathematics. Bright colors and graphic details offer proven ease of learning to this age group. Time-tested tips help students learn more effectively and avoid common pitfalls. This guide covers: Number theory, operations & measurements. Topics include: Computation, place value, Roman numerals, order of operations, scientific notation, symbols, fraction operations, divisibility rules, factorization, equivalent percents, decimals & fractions, metric system, rate conversions, time, temperature and much more!
| 677.169 | 1 |
Fair Text book is in acceptable condition, it does not include CD or access code. Book contains moderate to heavy writing and highlighting. Cover/dust cover ...shows moderate to heavy wear; may have bumps, scratches, creases. Corners/edges may be kinked and fore edge may have marks1439046956 BRAND NEW! [ 5th U.S. Edition, Paperback / softback | ISBN: 9781439046951 | Same as picture shown ] SUPERFAST Delivery-sent out same day with notification of tracking ...number. Same book as sold by your college bookstore. Order Now!As in previous editions, the focus in ALGEBRA: INTRODUCTORY & INTERMEDIATE remains on the Aufmann Interactive Method (AIM). Students are encouraged to be active participants in the classroom and in their own studies as they work through the How To examples and the paired Examples and You Try It problems. The role of "active participant" is crucial to success. Presenting students with worked examples, and then providing them with the opportunity to immediately work similar problems, helps them build their confidence and eventually master the concepts. To this point, simplicity plays a key factor in the organization of this edition, as in all other editions. All lessons, exercise sets, tests, and supplements are organized around a carefully-constructed hierarchy of objectives. This "objective-based" approach not only serves the needs of students, in terms of helping them to clearly organize their thoughts around the content, but instructors as well, as they work to design syllabi, lesson plans, and other administrative documents. The Eighth Edition features a new design, enhancing the Aufmann Interactive Method and the organization of the text around objectives, making the pages easier for both students and instructors to follow.
Related Subjects
Meet the Author
Richard Aufmann is the lead author of two bestselling developmental math series and a bestselling college algebra and trigonometry series, as well as several derivative math texts. He received a BA in mathematics from the University of California, Irvine, and an MA in mathematics from California State University, Long Beach. Mr. Aufmann taught math, computer science, and physics at Palomar College in California, where he was on the faculty for 28 years. His textbooks are highly recognized and respected among college mathematics professors. Today, Mr. Aufmann's professional interests include quantitative literacy, the developmental math curriculum, and the impact of technology on curriculum development.
Joanne Lockwood received a BA in English Literature from St. Lawrence University and both an MBA and a BA in mathematics from Plymouth State University. Ms. Lockwood taught at Plymouth State University and Nashua Community College in New Hampshire, and has over 20 years' experience teaching mathematics at the high school and college level. Ms. Lockwood has co-authored two bestselling developmental math series, as well as numerous derivative math texts and ancillaries. Ms. Lockwood's primary interest today is helping developmental math students overcome their challenges in learning
| 677.169 | 1 |
In this tutorial on the inverse functions: y = 2 ^ x and y = log base 2 of x, I am using the program Camtasia Studio 2 to...
see more
In this tutorial on the inverse functions: y = 2 ^ x and y = log base 2 of x, I am using the program Camtasia Studio 2 to visually capture the key strokes of a cursor on a virtual TI 83 + calculator, and to also record the sound of my voice which is explaining the different steps taken. Students can regulate the flow of information in this tutorial as they wish. Furthermore, as suggested by Bill Hemme, my Program Director, I have included a page of Word, next to the calculator, which allows me to display the equations of the functions used, and some of the steps of computations written in Math Type. I would like to thank Nancy Doolittle for her technological assistance with this project.
Free tutorials and problems on solving trigonometric equations, trigonometric identities and formulas can also be found. Java...
see more
Free tutorials and problems on solving trigonometric equations, trigonometric identities and formulas can also be found. Java applets are used to explore, interactively, important topics in trigonometry such as graphs of the 6 trigonometric functions, inverse trigonometric functions, unit circle, angle and sine law.
This section of a broader work, gives students a series of tutorial exercises in matrix multiplication. Topics include...
see more
This section of a broader work, gives students a series of tutorial exercises in matrix multiplication. Topics include matrix multiplication, vector multiplication, and the identity matrix. This page presents students with question that the enter answers to. Students are given feedback based on there entry.
| 677.169 | 1 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.