This book mainly focuses on helping readers understand the fundamental mathematical concepts and practice problem‐solving skills using MATLAB‐based numerical methods, skipping some tedious derivations/proofs. Obviously, basic concepts must be taught so that readers can properly formulate the mathematics problems. Afterward, readers can directly use the MATLAB codes to solve practical problems. Almost every algorithm introduced in this book is followed by example MATLAB code with a friendly interface so that students can easily modify the code to solve their own problems. The selection of exercises follows the same philosophy of making the learning easy and practical. Readers should be able to solve similar problems immediately after reading the materials and codes listed in this book. For most students – and particularly non‐math majors – understanding how to use numerical tools correctly in solving their problems of interest is more important than doing lengthy proofs and derivations.
MATLAB is one of the most developed software packages available today. It provides many numerical methods and it is very easy to use, even for those having no programming technique or experience. We have supplemented MATLAB's built‐in functions with over 100 small MATLAB routines. Readers should find these routines handy and useful. Some of these routines give better results for some problems than the built‐in functions. Readers are encouraged to develop their own routines following the examples.
Compared with the first edition, Bairstow's method (Section 4.7), Integration Involving PWL Function (Section 5.11), Mixed Integer Linear Programming (Section 7.3.4), Neural Network (Section 7.4), Adaptive Filter (Section 7.5), Recursive Least‐Squares Estimation (Section 7.6), and DoA Estimation (Section 8.8) have been added to the second edition.
Program files can be downloaded from < https://wyyang53.wixsite.com/mysite/publications>. Any questions, comments, and suggestions regarding this book are welcome and they should be mailed to wyyang53@hanmail.net.
Won Y. Yang et al.
March 2020
The knowledge in this book is derived from the work of many eminent scientists, scholars, researchers, and MATLAB developers, all of whom we thank. We thank our colleagues, students, relatives, and friends for their support and encouragement. We thank the reviewers, whose comments were so helpful in tuning this book. We gratefully acknowledge the editorial, Brett Kurzman and production staff of John Wiley & Sons, Inc. including Project Editor Antony Sami and Production Editor Gayathree Sekar for their kind, efficient, and encouraging guide.
About the Companion Website
Don't forget to visit the companion website for this book:
www.wiley.com/go/yang/appliednumericalmethods
Scan this QR code to visit the companion website:
There you will find valuable material designed to enhance your learning, including:
Learning Outcomes for all chapters
Exercises for all chapters
References for all chapters
Further reading for all chapters
Figures for chapters 16, 22 and 30
1 MATLAB Usage and Computational Errors
Chapter Outline
1.1 Basic Operations of MATLAB 1.1.1 Input/Output of Data from MATLAB Command Window 1.1.2 Input/Output of Data Through Files 1.1.3 Input/Output of Data Using Keyboard 1.1.4 Two‐Dimensional (2D) Graphic Input/Output 1.1.5 Three Dimensional (3D) Graphic Output 1.1.6 Mathematical Functions 1.1.7 Operations on Vectors and Matrices 1.1.8 Random Number Generators 1.1.9 Flow Control
1.2 Computer Errors vs. Human Mistakes 1.2.1 IEEE 64‐bit Floating‐Point Number Representation 1.2.2 Various Kinds of Computing Errors 1.2.3 Absolute/Relative Computing Errors 1.2.4 Error Propagation 1.2.5 Tips for Avoiding Large Errors
1.3 Toward Good Program 1.3.1 Nested Computing for Computational Efficiency 1.3.2 Vector Operation vs. Loop Iteration 1.3.3 Iterative Routine vs. Recursive Routine 1.3.4 To Avoid Runtime Error 1.3.5 Parameter Sharing via GLOBAL Variables 1.3.6 Parameter Passing Through VARARGIN 1.3.7 Adaptive Input Argument List Problems
1.1 Basic Operations of MATLAB
MATLAB is a high‐level software package with many built‐in functions that make the learning of numerical methods much easier and more interesting. In this section, we will introduce some basic operations that will enable you to learn the software and build your own programs for problem solving. In the workstation environment, you type “matlab” to start the program, while in the PC environment, you simply double‐click the MATLAB icon.
Once you start the MATLAB program, a Command window will open with the MATLAB prompt ≫. On the command line, you can type MATLAB commands, functions together with their input/output arguments, the names of script files containing a block of statements to be executed at a time or functions defined by users. The MATLAB program files must have the extension name ***.m to be executed in the MATLAB environment. If you want to create a new M‐file or edit an existing file, you click File/New/M‐file or File/Open in the top left corner of the main menu, find/select/load the file by double‐clicking it, and then begin editing it in the Editor window. If the path of the file you want to run is not listed in the MATLAB search path, the file name will not be recognized by MATLAB. In such cases, you need to add the path to the MATLAB‐path list by clicking the menu ‘Set_Path’ in the Command window, clicking the ‘Add_Folder’ button, browsing/clicking the folder name and finally clicking the SAVE button and the Close button. The lookfor command is available to help you find the MATLAB commands/functions that are related with a job you want to be done. The help command helps you know the usage of a particular command/function. You may type directly in the Command window
>lookfor repeat or >help for
to find the MATLAB commands in connection with ‘repeat’ or to find information about the ‘for loop’
1.1.1 Input/Output of Data from MATLAB Command Window
MATLAB remembers all input data in a session (anything entered through direct keyboard input or running a script file) until the command ‘ clear()
’ is given or you exit MATLAB.
One of the many features of MATLAB is that it enables us to deal with the vectors/matrices in the same way as scalars. For instance, to input the matrices/vectors,
type the following statements in the MATLAB Command window:
>A=[1 2 3;4 5 6] A= 1 2 3 4 5 6 >B=[3;-2;1]; %put the semicolon at the end of the statement to suppress the result printout onto the screen >C=[1 -2 3 -4]
At the end of the statement, press key if you want to check the result of executing the statement immediately. Otherwise, type a semicolon ‘;’ before pressing key so that the Command window will not be overloaded by a long display of results.
1.1.2 Input/Output of Data Through Files
MATLAB can handle two types of data files. One is the binary format mat‐files named ***.mat. This kind of files can preserve the values of more than one variable, but will be handled only in the MATLAB environment and cannot be shared with other programming environments. The other is the ASCII dat‐files named ***.txt, which can be shared with other programming environments, but preserve the values of only one variable.
Читать дальше