100% found this document useful (2 votes)
56 views37 pages

(Ebooks PDF) Download MATLAB Programming Mathematical Problem Solutions de Gruyter STEM 1st Edition Dingyü Xue Full Chapters

Solutions

Uploaded by

awadahebahl6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (2 votes)
56 views37 pages

(Ebooks PDF) Download MATLAB Programming Mathematical Problem Solutions de Gruyter STEM 1st Edition Dingyü Xue Full Chapters

Solutions

Uploaded by

awadahebahl6
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 37

Download the Full Version of textbook for Fast Typing at textbookfull.

com

MATLAB Programming Mathematical Problem Solutions


De Gruyter STEM 1st Edition Dingyü Xue

https://textbookfull.com/product/matlab-programming-
mathematical-problem-solutions-de-gruyter-stem-1st-edition-
dingyu-xue/

OR CLICK BUTTON

DOWNLOAD NOW

Download More textbook Instantly Today - Get Yours Now at textbookfull.com


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

Differential Equation Solutions With MATLAB Fundamentals


and Numerical Implementations De Gruyter STEM Dingyu Xue

https://textbookfull.com/product/differential-equation-solutions-with-
matlab-fundamentals-and-numerical-implementations-de-gruyter-stem-
dingyu-xue/
textboxfull.com

Calculus Problem Solutions With MATLAB 1st Edition Dingyü


Xue

https://textbookfull.com/product/calculus-problem-solutions-with-
matlab-1st-edition-dingyu-xue/

textboxfull.com

C Programming De Gruyter STEM 1st Edition Yuan Dong

https://textbookfull.com/product/c-programming-de-gruyter-stem-1st-
edition-yuan-dong/

textboxfull.com

Water Resources Management Innovative and Green Solutions


De Gruyter STEM 2nd Edition Brears

https://textbookfull.com/product/water-resources-management-
innovative-and-green-solutions-de-gruyter-stem-2nd-edition-brears/

textboxfull.com
Corrosion Prevention Nanoscience Nanoengineering Materials
and Technologies de Gruyter Stem 1st Edition Berdimurodov
Elyor Tukhlievich
https://textbookfull.com/product/corrosion-prevention-nanoscience-
nanoengineering-materials-and-technologies-de-gruyter-stem-1st-
edition-berdimurodov-elyor-tukhlievich/
textboxfull.com

Scientific Computing with MATLAB Second Edition Dingyu Xue

https://textbookfull.com/product/scientific-computing-with-matlab-
second-edition-dingyu-xue/

textboxfull.com

Matlab A Practical Introduction to Programming and Problem


Solving Stormy Attaway

https://textbookfull.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-stormy-attaway/

textboxfull.com

MATLAB A Practical Introduction to Programming and Problem


Solving Stormy Attaway

https://textbookfull.com/product/matlab-a-practical-introduction-to-
programming-and-problem-solving-stormy-attaway-2/

textboxfull.com

Linear Algebra and Matrix Computations With MATLAB 1st


Edition Dingyü Xue

https://textbookfull.com/product/linear-algebra-and-matrix-
computations-with-matlab-1st-edition-dingyu-xue/

textboxfull.com
Dingyü Xue
MATLAB® Programming
Also of Interest
Fractional-Order Control Systems, Fundamentals
and Numerical Implementations
Dingyü Xue, 2017
ISBN 978-3-11-049999-5, e-ISBN (PDF) 978-3-11-049797-7,
e-ISBN (EPUB) 978-3-11-049719-9

Calculus Problem Solutions with MATLAB®


Dingyü Xue, 2020
ISBN 978-3-11-066362-4, e-ISBN (PDF) 978-3-11-066697-7,
e-ISBN (EPUB) 978-3-11-066375-4

Linear Algebra and Matrix Computations with MATLAB®


Dingyü Xue, 2020
ISBN 978-3-11-066363-1, e-ISBN (PDF) 978-3-11-066699-1,
e-ISBN (EPUB) 978-3-11-066371-6

Solving Optimization Problems with MATLAB®


Dingyü Xue, 2020
ISBN 978-3-11-066364-8, e-ISBN (PDF) 978-3-11-066701-1,
e-ISBN (EPUB) 978-3-11-066369-3

Differential Equation Solutions with MATLAB®


Dingyü Xue, 2020
ISBN 978-3-11-067524-5, e-ISBN (PDF) 978-3-11-067525-2,
e-ISBN (EPUB) 978-3-11-067531-3
Dingyü Xue
®
MATLAB
Programming
|
Mathematical Problem Solutions
Author
Prof. Dingyü Xue
School of Information Science and Engineering
Northeastern University
Wenhua Road 3rd Street
110819 Shenyang
China
[email protected]

MATLAB and Simulink are registered trademarks of The MathWorks, Inc. See www.mathworks.com/
trademarks for a list of additional trademarks. The MathWorks Publisher Logo identifies books that
contain MATLAB and Simulink content. Used with permission. The MathWorks does not warrant the
accuracy of the text or exercises in this book. This book’s use or discussion of MATLAB and Simulink
software or related products does not constitute endorsement or sponsorship by The MathWorks of
a particular use of the MATLAB and Simulink software or related products. For MATLAB® and
Simulink® product information, or information on other related products, please contact:

The MathWorks, Inc.


3 Apple Hill Drive
Natick, MA, 01760-2098 USA
Tel: 508-647-700
Fax: 508-647-7001
E-mail: [email protected]
Web: www.mathworks.com

ISBN 978-3-11-066356-3
e-ISBN (PDF) 978-3-11-066695-3
e-ISBN (EPUB) 978-3-11-066370-9

Library of Congress Control Number: 2019955271

Bibliographic information published by the Deutsche Nationalbibliothek


The Deutsche Nationalbibliothek lists this publication in the Deutsche Nationalbibliografie;
detailed bibliographic data are available on the Internet at http://dnb.dnb.de.

© 2020 Tsinghua University Press Limited and Walter de Gruyter GmbH, Berlin/Boston
Cover image: Dingyü Xue
Typesetting: VTeX UAB, Lithuania
Printing and binding: CPI books GmbH, Leck

www.degruyter.com
Preface
Scientific computing is commonly and inevitably encountered in course learning, sci-
entific research and engineering practice for each scientific and engineering student
and researcher. For the students and researchers in the disciplines which are not pure
mathematics, it is usually not a wise thing to learn thoroughly low-level details of re-
lated mathematical problems, and also it is not a simple thing to find solutions of com-
plicated problems by hand. It is an effective way to tackle scientific problems, with
high efficiency and in accurate and creative manner, with the most advanced com-
puter tools. This method is especially useful in satisfying the needs for those in the
area of science and engineering.
The author had made some effort towards this goal by addressing directly the so-
lution methods for various branches in mathematics in a single book. Such a book,
entitled “MATLAB based solutions to advanced applied mathematics”, was published
first in 2004 by Tsinghua University Press. Several new editions are published after-
wards: in 2015, the second edition in English by CRC Press, and in 2018, the fourth
edition in Chinese were published. Based on the latest Chinese edition, a brand new
MOOC project was released in 2018,1 and received significant attention. The number
of the registered students was about 14 000 in the first round of the MOOC course,
and reached tens of thousands in later rounds. The textbook has been cited tens of
thousands times by journal papers, books, and degree theses.
The author has over 30 years of extensive experience of using MATLAB in scientific
research and education. Significant amount of materials and first-hand knowledge has
been accumulated, which cannot be covered in a single book. A series entitled “Profes-
sor Xue Dingyü’s Lecture Hall” of such works are scheduled with Tsinghua University
Press, and the English editions are included in the DG STEM series with De Gruyter.
These books are intended to provide systematic, extensive and deep explorations in
scientific computing skills with the use of MATLAB and related tools. The author wants
to express his sincere gratitude to his supervisor, Professor Derek Atherton of Sussex
University, who first brought him into the paradise of MATLAB.
This MATLAB series is not a simple revision of the existing books. With decades of
experience and material accumulation, the idea of “revisiting” is adopted in author-
ing these books, in contrast to other mathematics and other MATLAB-rich books. The
viewpoint of an engineering professor is established and the focus is on solving var-
ious applied mathematical problems with tools. Many innovative skills and general-
purpose solvers are provided to solve problems with MATLAB, which is not possible
by any other existing solvers, so as to better illustrate the applications of computer
tools in solving mathematical problems in every mathematics branch. It also helps

1 MOOC (in Chinese) address: https://www.icourse163.org/learn/NEU-1002660001

https://doi.org/10.1515/9783110666953-201
VI | Preface

the readers broaden their viewpoints in scientific computing, and even in finding in-
novative solutions by themselves to scientific computing which cannot be solved by
any other existing methods.
The first title in the MATLAB series can be used as an entry-level textbook or refer-
ence book to MATLAB programming, so as to establish a solid foundation and deep un-
derstanding for the application of MATLAB in scientific computing. Each subsequent
volume tries to cover a branch or topic in mathematical courses. These MATLAB books
are suitable for the readers who have already learnt the related mathematical courses,
and revisit the courses to learn how to solve the problems by using computer tools.
It can also be used as a companion in synchronizing the learning of related mathe-
matics courses, and for viewing the course from a different angle. The readers may
expand their knowledge in learning the related courses, so as to better understand
and practice the relevant materials. Bearing in mind the “computational thinking” in
authoring the series, deep understanding and explorations are made for each mathe-
matics branch involved.
This book is the first in the MATLAB series. Systematic illustration of MATLAB pro-
gramming is provided in the book. The commonly used data and statement structures
in MATLAB are introduced first, followed by algebraic and transcendental function
evaluations of matrices, and data manipulations. Flow controls and applications in
MATLAB programming are then introduced, and MATLAB function programming and
skills are provided. Scientific visualization in MATLAB are addressed. Advanced top-
ics such as the designs of MATLAB interface to other languages, object-oriented pro-
gramming and graphical user interface are illustrated, such that a better foundation
can be established for the readers to continue learning scientific computing and the
knowledge of other related mathematical fields.
At the time the books are published, the author wishes to express his sincere grat-
itude to his wife, Professor Yang Jun. Her love and selfless care over the decades pro-
vided the author immense power, which supports his academic research, teaching
and writing.

September 2019 Xue Dingyü


Contents
Preface | V

1 Introduction to computer mathematics languages | 1


1.1 Introduction to solving mathematical problems | 1
1.1.1 Why learn a computer mathematics language? | 1
1.1.2 Analytical and numerical solutions | 5
1.1.3 Development of mathematical packages | 6
1.1.4 Limitations of conventional computer languages | 8
1.2 History of computer mathematics languages | 10
1.2.1 The early days of computer mathematics languages | 10
1.2.2 Representative modern computer mathematics languages | 11
1.3 Three-phase solution of scientific computing problems | 12
1.4 Problems | 14

2 Fundamentals of MATLAB programming | 17


2.1 Command windows and fundamental commands | 18
2.1.1 Regulations in variable names | 18
2.1.2 Reserved constants | 19
2.1.3 Setting of display formats | 20
2.1.4 Low-level operating system commands | 21
2.1.5 Setting of MATLAB working environment | 21
2.1.6 MATLAB workspace and management | 23
2.1.7 Other supporting facilities | 23
2.2 Commonly used data types | 24
2.2.1 Numeric data types | 24
2.2.2 Symbolic data | 26
2.2.3 Generation of arbitrary symbolic matrices | 28
2.2.4 Symbolic functions | 29
2.2.5 Integer and logic variables | 29
2.2.6 Recognition of data types | 29
2.2.7 Sizes and lengths of matrices | 30
2.3 String data type | 30
2.3.1 Expression of string variables | 30
2.3.2 String processing methods | 32
2.3.3 Conversion of string variables | 33
2.3.4 Executions of string commands | 34
2.3.5 Interface of MuPAD language | 35
2.4 Other commonly used data types | 36
2.4.1 Multidimensional arrays | 36
2.4.2 Cell arrays | 37
VIII | Contents

2.4.3 Tables | 38
2.4.4 Structured variables | 41
2.4.5 Other data types | 42
2.5 Fundamental statement structures | 42
2.5.1 Direct assignment statements | 42
2.5.2 Function call statements | 43
2.5.3 Functions with different syntaxes | 43
2.5.4 Colon expressions | 44
2.5.5 Submatrix extractions | 45
2.5.6 Generation of equally spaced row vectors | 46
2.6 Reading and writing of different data types | 46
2.6.1 Reading and writing of data files | 46
2.6.2 Low-level reading and writing commands | 47
2.6.3 Reading and writing of Excel files | 48
2.7 Problems | 50

3 Fundamental mathematical computations | 53


3.1 Algebraic computation of matrices | 53
3.1.1 Transposing, flipping and rotating matrices | 53
3.1.2 Arithmetic operations | 55
3.1.3 Complex matrices and transformations | 56
3.1.4 Powers and roots of matrices | 57
3.1.5 Dot operations | 59
3.2 Logic and comparison operations | 59
3.2.1 Logic operations with matrices | 59
3.2.2 Comparisons of matrices | 60
3.2.3 Searching commands in matrix elements | 60
3.2.4 Attribute judgement | 62
3.3 Computation of transcendental functions | 62
3.3.1 Exponentials and logarithmic functions | 63
3.3.2 Trigonometric functions | 63
3.3.3 Inverse trigonometric functions | 65
3.3.4 Transcendental functions of matrices | 66
3.4 Simplifications and conversions of symbolic expressions | 68
3.4.1 Polynomial operations | 68
3.4.2 Conversions and simplifications of trigonometric functions | 69
3.4.3 Simplification of symbolic expressions | 70
3.4.4 Variable substitution of symbolic expressions | 71
3.4.5 Conversions of symbolic expressions | 72
3.5 Fundamental computations with data | 72
3.5.1 Integer rounding and rationalization of data | 73
3.5.2 Sorting and finding maximum and minimum of vectors | 74
Contents | IX

3.5.3 Mean, variance and standard deviation | 75


3.5.4 Prime factors and polynomials | 76
3.5.5 Permutations and combinations | 78
3.6 Problems | 79

4 Flow control structures of MATLAB language | 83


4.1 Loop structures | 83
4.1.1 The for loop structure | 83
4.1.2 The while loop structure | 86
4.1.3 Loop implementation of iterations | 87
4.1.4 Assistant statements of loop structures | 90
4.1.5 Vectorized implementation of loops | 90
4.2 Conditional structures | 93
4.2.1 Simple conditional structures | 93
4.2.2 General form of conditional structures | 94
4.2.3 Vectorized expressions of piecewise functions | 96
4.3 Switch structures | 98
4.4 Trial structure | 100
4.5 Problems | 101

5 Function programming and debugging | 105


5.1 MATLAB scripts | 105
5.2 Fundamental structures of MATLAB functions | 106
5.2.1 Fundamental function structures | 106
5.2.2 Regulations in function names | 108
5.2.3 Examples of function programming | 108
5.3 Skills of MATLAB function programming | 112
5.3.1 Recursive structures | 112
5.3.2 Functions with variable numbers of inputs and outputs | 114
5.3.3 Fault tolerance manipulation | 116
5.3.4 Global variables | 117
5.3.5 Reading and writing of MATLAB workspace | 118
5.3.6 Anonymous and inline functions | 119
5.3.7 Subfunctions and private functions | 121
5.4 MATLAB function debugging | 122
5.4.1 Debugging of MATLAB functions | 122
5.4.2 Pseudocode and code protection | 125
5.5 MATLAB live editor | 125
5.5.1 Live editor interface | 126
5.5.2 Creating a live document | 126
5.5.3 Execution of embedded code | 128
5.5.4 Embed other objects in live editor | 128
X | Contents

5.5.5 Output of live files | 131


5.6 Problems | 131

6 Two-dimensional graphics | 135


6.1 Drawing two-dimensional plots | 135
6.1.1 Plotting data | 135
6.1.2 Plots of mathematical functions | 139
6.1.3 Plots of piecewise functions | 139
6.1.4 Titles in plots | 141
6.1.5 Plots with multiple vertical axes | 143
6.2 Decoration of plots | 145
6.2.1 Plot decoration with interface tools | 145
6.2.2 LATEX support commands | 146
6.2.3 Superimposing formulas in plots | 148
6.3 Other two-dimensional plotting functions | 149
6.3.1 Polar plots | 150
6.3.2 Plots of discrete samples | 151
6.3.3 Histograms and pie charts | 152
6.3.4 Filled plots | 155
6.3.5 Logarithmic plots | 156
6.3.6 Error bar plots | 157
6.3.7 Dynamic trajectories | 157
6.3.8 Two-dimensional animation | 158
6.4 Plot window partitioning | 159
6.4.1 Regular partitioning | 159
6.4.2 Arbitrary segmentation | 161
6.5 Implicit functions | 162
6.6 Displaying and simple manipulation of images | 165
6.6.1 Input images | 165
6.6.2 Editing and displaying images | 166
6.6.3 Color space conversion | 167
6.6.4 Edge detection | 167
6.6.5 Histogram equalization | 168
6.7 Output of MATLAB graphs | 170
6.7.1 Output menus and applications | 170
6.7.2 Output commands of plots | 171
6.8 Problems | 171

7 Three-dimensional graphics | 175


7.1 Three-dimensional curves | 175
7.1.1 Drawing three-dimensional plots from data | 175
7.1.2 Three-dimensional plots of mathematical functions | 176
Contents | XI

7.1.3 Filled plots | 177


7.1.4 Bar and pie charts | 178
7.1.5 Ribbon plots | 180
7.2 Three-dimensional surfaces | 182
7.2.1 Mesh grids and surfaces | 182
7.2.2 Shading and lights | 186
7.2.3 Three-dimensional surface from images | 188
7.2.4 Representation of functions | 189
7.2.5 Surfaces from scattered data | 190
7.3 Viewpoint setting in three-dimensional plots | 191
7.3.1 Definition of viewpoints | 192
7.3.2 Orthographic views | 193
7.3.3 Setting of arbitrary viewpoints | 193
7.4 Other three-dimensional plots | 194
7.4.1 Contour lines | 194
7.4.2 Quiver plots | 196
7.4.3 Three-dimensional implicit plots | 197
7.4.4 Surfaces of parametric equations | 199
7.4.5 Surfaces of complex functions | 199
7.4.6 Spheres and cylinders | 200
7.4.7 Voronoi diagrams and Delaunay triangulation | 203
7.5 Special treatment of three-dimensional plots | 205
7.5.1 Rotation of surfaces | 205
7.5.2 Axis specification for surfaces | 207
7.5.3 Cutting of surfaces | 208
7.5.4 Patches in surfaces | 208
7.6 Four-dimensional plots | 210
7.6.1 Slices | 210
7.6.2 A volume visualization interface | 212
7.6.3 Creating and playing of three-dimensional animations | 213
7.7 Problems | 214

8 MATLAB and its interface to other languages | 217


8.1 Introduction to C interfaces with MATLAB | 218
8.1.1 Environment setting of compilers | 218
8.1.2 Data types in Mex | 218
8.1.3 Mex file structures | 220
8.1.4 Mex file programming and procedures | 223
8.2 Mex manipulation of different data types | 225
8.2.1 Processing of various input and output data types | 225
8.2.2 Reading and writing of string variables | 226
8.2.3 Processing of multidimensional arrays | 228
XII | Contents

8.2.4 Processing of cells | 229


8.2.5 Reading and writing of MAT files | 231
8.3 Direct calling of MATLAB functions from C programs | 233
8.4 Standalone program conversion from MATLAB functions | 238
8.5 Problems | 239

9 Fundamentals in object-oriented programming | 241


9.1 Concepts of object oriented programming | 241
9.1.1 Classes and objects | 241
9.1.2 Data type of classes and objects | 242
9.2 Design of classes | 243
9.2.1 The design of a class | 244
9.2.2 Design and input of classes | 245
9.2.3 Class display | 246
9.3 Programming of overload functions | 247
9.3.1 Overload addition functions | 247
9.3.2 Simplification functions via like-term collection | 248
9.3.3 Overload subtraction functions | 249
9.3.4 Overload multiplication functions | 250
9.3.5 Overload power functions | 252
9.3.6 Assignment and extraction of fields | 253
9.4 Inheritance and extension of classes | 254
9.4.1 Definition and display of extended classes | 254
9.4.2 Overload functions for ftf objects | 256
9.4.3 Frequency domain analysis of fractional-order transfer
functions | 258
9.5 Problems | 259

10 Graphical user interface design using MATLAB | 261


10.1 Essentials in graphical user interface design | 261
10.1.1 The relationships of objects in MATLAB interface | 261
10.1.2 Window objects and properties | 262
10.1.3 Commonly used properties in window objects | 262
10.1.4 Extraction and modification of object properties | 265
10.1.5 Easy dialog boxes | 267
10.1.6 Standard dialog boxes | 269
10.2 Fundamental controls in interface design | 272
10.2.1 Commonly used controls supported | 273
10.2.2 Commonly used properties in controls | 274
10.2.3 Getting the handles | 275
10.3 Graphical user interface design tool – Guide | 276
10.4 Advanced techniques in interface design | 286
Contents | XIII

10.4.1 Design of menu systems | 287


10.4.2 Design of toolbars | 287
10.4.3 Embedding ActiveX controls | 289
10.5 APP packaging and publication | 291
10.6 Problems | 291

Bibliography | 293

MATLAB function index | 295

Index | 301
1 Introduction to computer mathematics languages
1.1 Introduction to solving mathematical problems
Mathematical problems are essential in almost all aspects of scientific and engineer-
ing research. The mathematical models should normally be established first, then the
solutions of the models under investigation can be obtained. Specific knowledge is
required for the establishment of mathematical models, which needs the expertise of
the researchers, and with the established models, the numerical and analytical ap-
proaches presented in this series can be used to solve the problems. In this chap-
ter, a brief introduction to computer mathematical problems is proposed. It will be
illustrated through simple examples why computer mathematics languages should
be learned. A concise history of the development of computer mathematics languages
and mathematical tools will be introduced.

1.1.1 Why learn a computer mathematics language?

It is well known that manual formulation of mathematical problems is a useful skill


if the problems are not too complicated. Unfortunately, for a great variety of mathe-
matical problems in real world, manual formulation is laborious or even impossible.
Computer tools must be employed for tackling these problems.
There are essentially two ways for solving mathematical problems with comput-
ers. One is to implement the existing numerical algorithms with general-purpose com-
puter languages, such as C and Fortran. The other way is to use specific computer
languages with good reputation. Appropriate computer languages such as MATLAB,
Mathematica[17] , and Maple[13] can be adopted. In this book, the languages are referred
to as the computer mathematics languages. Numerical algorithms can only be used to
tackle computation problems with numbers, while for problems like finding the solu-
tions to the quadratic equation ax 2 + bx + c = 0, where a, c, d are not given numerical
values but symbolic variables, numerical algorithms, no matter how sophisticated,
cannot be adopted. The professional computer mathematics languages capabilities
should be adopted instead.
The term “mathematical computation” will be used throughout the series,
whereas the term really means both numerical and analytical computation of so-
lutions to mathematical problems. Normally, analytical solutions are explored first,
and if there are no analytical solutions, numerical solutions are obtained.
The following examples are shown so that the readers may understand and ap-
preciate the necessity of using the computer mathematics languages.

https://doi.org/10.1515/9783110666953-001
2 | 1 Introduction to computer mathematics languages

Example 1.1. Consider a simple problem. What is the last digit of 2 0192 019 ?

Solutions. If computers are not used, all the mathematicians know about the result
is its last digit, since tricks can be used in finding it. In fact, the solution is useless
in reality, since if you spend some money to buy something, you will never care what
the last digit is. It makes almost no difference to you whether the last digit is 1 or 9.
What you care about is what the highest digit is and how many digits there are in
total. It is always useful if you can find all the digits. However, these problems cannot
be solved at all without the use of computers. Dedicated computer software tools are
also essential. If computer mathematics languages are used, for instance, with the
command in MATLAB

>> a=sym(2019)^2019

all the digits in the result can be obtained as

a = 11 755 143 827 466 954 841 312 ⋅ ⋅ ⋅ 732 793 278 321 979.

There are 6 674 digits in total, which may fill about two pages of the book.

Example 1.2. In conventional calculus courses, the readers may have learnt how to
find the derivative of a given function, with manual formulation approach. Emphasis
is on manual computation in conventional courses. Assuming that a function f (x) is
given as f (x) = cos x/(x2 + 3x + 2), are you able to derive manually d4 f (x)/dx4 ?

Solutions. The reader may use the methods learnt in calculus courses to compute
the derivatives. The first-order derivative df (t)/dx should be evaluated first, and then
the subsequent derivatives such as second-, third- and fourth-order derivatives of the
given function f (x) can be derived in turn. Even higher-order derivatives can be formu-
lated in this way. The procedure is, in fact, more suitable for computers. With MATLAB,
the fourth-order derivative of the function f (x) can be calculated using a single line

>> syms x; f=cos(x)/(x^2+3*x+2); y=diff(f,x,4) % find the derivative

and the result obtained is

d4 f (t) cos x 12 cos x 24 cos x


= 2 + +
dx4 x + 3x + 2 (x2 + 3x + 2)2 (x 2 + 3 x + 2)3
12 cos x(2x + 3)2 48 cos x(2x + 3)2 24 cos x(2x + 3)4
− 3
− 4
+ 5
(x2 + 3x + 2) (x 2 + 3x + 2) (x 2 + 3x + 2)
24 sin x(2x + 3)3 4 sin x(2x + 3) 16 sin x(2x + 3)
+ 4
− 2
− 3
(x2 + 3x + 2) (x 2
+ 3x + 2) (x 2 + 3x + 2)
8 sin x(8x + 12) 6 cos x(2x + 3)(8x + 12)
− 3
− 4
.
(x2 + 3x + 2) (x 2 + 3x + 2)
1.1 Introduction to solving mathematical problems | 3

It is immediately seen from this example that manual evaluation is a laborious


and tedious work. Even a slightly careless manipulation may lead to erroneous results.
Well, with tools such as MATLAB, d100 f (x)/dx100 can be derived within four seconds!

Example 1.3. How to find the determinant of an n × n matrix?

Solutions. The determinant of a large matrix is recommended to be evaluated with


the algebraic cofactor method in linear algebra courses. For an n × n matrix, the deter-
minant can be evaluated from determinants of n matrices of size (n − 1) × (n − 1). The
determinant of each (n − 1) × (n − 1) matrix, on the other hand, can be evaluated from
the determinants of n−1 matrices of size (n−2)×(n−2). In this manner, the determinant
of an n × n matrix can be found eventually as the algebraic sum of a certain number of
determinants of 1 × 1 matrices, i. e., the scalars themselves. It can then be concluded
that the exact expression of the determinant of any given square matrix exists.
Unfortunately, the above conclusion neglected the computability and feasibility
issues. The computation load could be extremely heavy, requiring (n − 1)(n + 1)! + n
operations. For instance, if n = 25, the number of floating point operations (flops) is
9.68 × 1027 , which is equivalent to 204 years of computation on a supercomputer of
125.4 trillion (1.254 × 1017 ) flops (i. e., the fastest supercomputer in the world in 2016,
Sunway TaihuLight). Although elegant and instructive, the algebraic cofactor method
is not practically feasible. In genuine applications, usually the determinants of even
larger-sized matrices are expected, which is evidently not feasible by directly applying
the mentioned algebraic cofactor method.
Various numerical algorithms are available in numerical analysis courses. Unfor-
tunately, under the double-precision data type, the algorithms may lead to unexpected
errors for nearly all matrices. Consider now the Hilbert matrix defined as

1 1/2 1/3 ... 1/n


[ 1/2 1/3 1/4 ... 1/(n + 1) ]
[ ]
H=[
[ .. .. .. .. .. ].
]
[ . . . . . ]
[1/n 1/(n + 1) 1/(n + 2) ... 1/(2n − 1)]

If n = 80, a wrong determinant det(H) = 0 is found if double-precision data type


is adopted. If computer mathematics language such as MATLAB is used, the exact so-
lution of the determinant of the matrix is found within 1.23 seconds as
1
det(H) = ≈ 1.00979 × 10−3 790 .
990 301 014 669 934 778 788 676 784 101 ⋅ ⋅ ⋅ 00 000
⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟⏟
a total of 3 789 digits, with many omitted

The evaluation of determinants needs computer mathematics languages, and es-


pecially for special matrices, symbolic methods should be used to avoid errors. The
following MATLAB statements can be used:

>> tic, H=sym(hilb(80)); d=det(H); toc, d


4 | 1 Introduction to computer mathematics languages

Example 1.4. Solve the following two systems of equations:

{ x + 3y3 + 2z 2 = 1/2,
x + y = 35, {
{ 2
{ { x + 3y + z 3 = 2,
2x + 4y = 94, {
{ 3 2
{x + 2z + 2y = 2/4.

Solutions. It can be seen that the first is the well-known chicken–rabbit cage problem
in Chinese legends. Even if computers are not used, the solution can easily be found.
With MATLAB, the following statements can be used:

>> syms x y; [x0,y0]=vpasolve(x+y==35,2*x+4*y==94)

With powerful computer tools such as MATLAB, the solution of the second equation
is as simple as the former when solving the chicken–rabbit cage problem, from the
user’s viewpoint. The user can represent the equations directly in symbolic expres-
sions. Then with the same vpasolve() function call, all the 27 solutions can be found
directly. When the roots are substituted back to the original equations, the error norm
is as small as 10−34 .

>> syms x y z; % declare symbolic variables


f1(x,y,z)=x+3*y^3+2*z^2-1/2; f2(x,y,z)=x^2+3*y+z^3-2;
f3(x,y,z)=x^3+2*z+2*y^2-2/4; [x0,y0,z0]=vpasolve(f1,f2,f3),
size(x0), norm([f1(x0,y0,z0) f2(x0,y0,z0) f3(x0,y0,z0)])

Example 1.5. Solve the linear programming problem given below

min (−2x1 − x2 − 4x3 − 3x4 − x5 )


{
{ 2x2 +x3 +4x4 +2x5 ⩽54,
{
{
x s. t.{3x1 +4x2 +5x3 −x4 −x5 ⩽62,
{
{
{
{x1 ,x2 ⩾0, x3 ⩾3.32, x4 ⩾0.678, x5 ⩾2.57.

Solutions. Since the problem involves constrained optimization, the analytical un-
constrained method by setting the derivatives of the objective function with respect
to each decision variable xi to zero cannot be used. With linear programming tools in
MATLAB, the following statements can be employed:

>> clear; P.f=[-2 -1 -4 -3 -1]; P.Aineq=[0 2 1 4 2; 3 4 5 -1 -1];


P.Bineq=[54 62]; P.lb=[0;0;3.32;0.678;2.57]; P.solver=’linprog’;
P.options=optimset; x=linprog(P) % linear programming problem solution

With MATLAB, the solution can be obtained directly as x1 = 19.7850, x2 = 0, x3 =


3.3200, x4 = 11.3850, and x5 = 2.5700.
1.1 Introduction to solving mathematical problems | 5

With the algorithms in numerical analysis or optimization courses, conventional


constrained optimization problems can be solved. However, if other special con-
straints are introduced, for instance, the decision variables are constrained to be
integers, the integer programming must be used. There are not so many books intro-
ducing software that can tackle the integer and mixed-integer programming problems.
If MATLAB is used, the solution to this example problem is easily found as x1 = 19,
x2 = 0, x3 = 4, x4 = 10, x5 = 5.

Example 1.6. In many other courses, such as on complex-valued functions, integral


transforms, data interpolation and fitting, partial differential equations, probability
and statistics, can you still solve typical problems after the final exams?

Example 1.7. With the rapid development of modern science and technology, many
new mathematical theories, such as those of fuzzy and rough sets, artificial neural
networks, and evolutionary computing algorithms have emerged. It would be a hard
and time consuming task to use such theories to solve particular problems, without
using specific computer tools. If low-level programming is expected, the researcher
needs to fully understand the technical contents of the theories, as well as how to
implement the algorithms with computer languages. However, if the existing tools and
frameworks are used instead, the problems can be solved in a much simpler manner.

In many courses, such as on electronics, electric circuits, mechanical systems,


power electronics, automatic control theory, and motor drive, more sophisticated ex-
amples and problems are deliberately avoided due to the lack of high-level computer
software tools support. If MATLAB or other computer mathematics languages are used
extensively in those courses, complicated practical problems can be tackled. Even in-
novative solutions to some specific problems can be found.

1.1.2 Analytical and numerical solutions

The development of modern science and engineering depends heavily on mathemat-


ics. Unfortunately, the viewpoints of pure mathematicians are different from other
scientists and engineers. Mathematicians are often interested in the existence and
uniqueness of the solutions. They are interested in finding the analytical or closed-
form solutions to mathematical problems. If solutions are not possible, they may in-
vent special conditions such that their theoretical method can be carried out. Perfect
solutions may usually be found, while unfortunately, the solutions of their revised
problems may not be suitable for the original problems. Scientists and engineers are
interested in finding the exact solutions to the problems, and usually do not care much
about the trivial details on how the results are found, provided that the results are
meaningful and reliable. If the exact solutions are not available, scientists and engi-
6 | 1 Introduction to computer mathematics languages

neers are happy to accept approximate solutions obtained with the numerical tech-
niques.
In real applications, it is often seen that analytical solutions do not exist. For ex-
a
2 2
ample, the definite integral ∫ e−x dx is known to have no analytical solution. Math-
√π
0
ematicians invented a special function erf(a) to solve the problem, and do not care
what the numerical value is in particular. To find an approximate solution, engineers
and scientists have to adopt numerical approaches.
Another example is the irrational number π. It is known that π has no closed-
form expression. The ancient Chinese scientist and astronomer Zu Chongzhi (429–
500), also known as Tsu Ch’ung-chih, found in about ce480 that the value is between
3.1415926 and 3.1415927. This value is accurate enough in most engineering and sci-
entific applications. Even using the less accurate value of 3.14 found by Archimedes
(bce287–bce212) in about bce250(?), the solutions to most practical problems are of-
ten acceptable.
In many scientific and engineering areas, numerical techniques have already been
widely used. For example, in aerospace and control, numerical solutions to ordinary
differential equations and linear algebra problems are successfully used for centuries.
In mechanical engineering, finite element methods (FEMs) have been adopted in solv-
ing partial differential equations. For simulation experiments in engineering and non-
engineering areas, numerical solutions to differential and difference equations are the
core techniques. In hi-tech developments, fast Fourier transform (FFT) based digital
signal processing has been recognized as an essential task. There is no doubt that if
one masters one or more practical computer tools, the capabilities in solving scientific
computation problems will be significantly boosted, and innovative achievement can
be expected.

1.1.3 Development of mathematical packages

The achievement in digital computer and dedicated software fueled the developments
of numerical and analytical scientific computation techniques. At the early stages of
numerical computation techniques, some well-established software packages played
an important part. These packages include the linear algebra package LINPACK[4] and
the eigenvalue-based package EISPACK[5, 16] developed in the USA, the NAG package
by the Numerical Algorithm Group in the UK, and the package in the well-accepted
book Numerical Recipes[14] . They are widely accepted by the users and with good rep-
utation.
The famous packages such as LINPACK and EISPACK are both developed for nu-
merical linear algebra computations. EISPACK and LINPACK packages were originally
1.1 Introduction to solving mathematical problems | 7

written in Fortran. An example is given next to show how to use these packages in
solving linear algebra problems.

Example 1.8. The eigenvalues of an N × N real matrix A are expressed as W R and W I


for the real and imaginary parts, respectively. The eigenvectors Z are also expected. As
suggested by EISPACK, the following code is needed in the sequentially subroutine-
calling sequence:

CALL BALANC(NM,N,A,IS1,IS2,FV1)
CALL ELMHES(NM,N,IS1,IS2,A,IV1)
CALL ELTRAN(NM,N,IS1,IS2,A,IV1,Z)
CALL HQR2(NM,N,IS1,IS2,A,WR,WI,Z,IERR)
IF (IERR.EQ.0) GOTO 99999
CALL BALBAK(NM,N,IS1,IS2,FV1,N,Z)

Apart from the main body of the program, the user should also write a few lines to
input or initialize the matrix A to the above program and return or display the results
obtained by adding some display or printing statements. Then, the whole program
should be compiled and linked with the EISPACK library to generate an executable
program. It can be seen that the procedure is quite complicated. Moreover, if another
matrix is to be investigated, the whole procedure might be repeated, which makes the
solution process even more complicated.

Unlike EISPACK and LINPACK, Numerical Recipes and NAG packages include nu-
merical subroutines in various mathematics branches. The names of the subroutines
are not quite informative, since they are composed of letters and numbers. Beginners
may find it difficult to select a suitable subroutine for their own problems, not to men-
tion the sophisticated syntaxes of the subroutines. Programming using the packages
is not an easy job. Each subroutine comes with many input arguments. They are some-
times too complicated to use.
Numerical Recipes is a widely used numerical package used worldwide. There are
different versions such as C, Fortran, and Pascal. It is suitable for use directly by sci-
entific researchers and engineers. There are altogether about 200 high-efficiency and
practical subroutines in the package. Generally, the subroutines are of high-standard
and reliable, therefore, trusted by the researchers.
For the readers with good knowledge of languages such as Fortran and C, it is im-
mediately found that programming for ordinary scientific computing problems is usu-
ally complicated, especially when matrices and graphics are involved. For instance, if
one wants to solve a linear equation system, low-level programming is involved. The
user has to write a solver, for instance, with Gaussian elimination method, then the
program has to be compiled and linked. If there is no ready-to-use subroutine, the
users must input the whole subroutine into a computer. For such a method, a subrou-
tine with about 100 source code lines is expected, and it is rather a time-consuming
8 | 1 Introduction to computer mathematics languages

work to validate the code and to ensure the correctness of the code. For a complicated
task such as eigenvalue computation with OR method, about 500 source code lines are
required. Any slight carelessness may lead to errors in the final results. These pack-
ages sometimes have limitations, since most of them may fail if complex matrices are
involved.
The mathematical software packages are continuously evolving, with the leading-
edge numerical algorithms being implemented. More reliable, efficient, stable,
and faster packages are provided. For example, in numerical linear algebra, a new
LaPACK[1] is becoming the leading package. Unlike the original purposes of the old
packages, the objectives of the new ones are changed. LaPACK is no longer aiming at
providing facilities or libraries for direct user applications. Instead, LaPACK provides
support to professional software and languages. For example, MATLAB and a free-
ware Scilab[8] are not using the packages of LINPACK and EISPACK, instead LaPACK
is adopted as the low-level supporting library.
Mathematical software packages appeared in certain mathematical branches so
that one may call them from Fortran, C/C++, or other programming languages. Specific
interface can be made so that the packages can be called from MATLAB. There are
also significantly many mathematical toolboxes written in MATLAB or other computer
mathematical languages. Once one has certain typical mathematical problems to be
solved, the related official toolboxes in MATLAB can be called directly, since they are
usually written by experts with very good reputation in the corresponding fields. The
results obtained may be considered reliable, compared with those written in low-level
commands.

1.1.4 Limitations of conventional computer languages

Many people are using conventional computer languages, such as C and Fortran, in
their research. Needless to say, these languages were very useful, and they were the
low-level supporting languages of the computer mathematics languages such as MAT-
LAB. However, for the modern scientific and engineering researchers, these languages
are not adequate for solving their complicated computational problems. For instance,
even very experienced C programmers may not be able to write C code to find the indef-
inite integral of a given function, such problems involve knowledge of mathematical
mechanization. Even for numerical computations, there are limitations. Here two ex-
amples are given to illustrate the problems.

Example 1.9. It is known that the Fibonacci sequence can be generated with the fol-
lowing recursive formula: a1 = a2 = 1, and ak = ak−1 + ak−2 , k = 3, 4, . . . Compute its
first 100 terms.

Solutions. Data type for each variable must be assigned first in C programming lan-
guage. Since the terms in the sequence are integers, it is natural to select the data types
1.1 Introduction to solving mathematical problems | 9

int or long. If int is selected, the following C program can be written:

#include <stdio.h>
main()
{ int a1, a2, a3, i;
a1=1; a2=1; printf("%d %d ",a1,a2);
for (i=3; i<=100; i++)
{ a3=a1+a2; printf("%d ",a3); a1=a2; a2=a3;
}}

The Fibonacci sequence can be obtained simply by using the program. But wait. Are
the results obtained correct? If the program is executed, from the 24th term on, the
value of the sequence becomes negative, and from that term on, the subsequent terms
are sometimes positive, sometimes negative. It is obvious that some peculiar things
must have happened in the program. The problem is caused by the int data type,
since its range is (−32 767, 32 767). If a term is beyond this range, wrong results are
generated. Even if long data type is adopted instead, the correct answers may only
last till about 10 more terms. To solve the problem of finding the first 100 terms, or
even more, of the Fibonacci sequence is certainly beyond the capabilities of average
C users, or even experienced C programmers. Extremely slight carelessness may lead
to misleading results.
With the use of MATLAB, such trivial things need not be considered. The following
code can be written directly:

>> a=[1 1]; % the first two terms


for i=3:100, a(i)=a(i-1)+a(i-2); end; a(end) % loop structure

Besides, for more accurate representation of the terms, symbolic data type can be used
instead, by substituting the first statement with a=sym([1,1]). In this case, the 100th
term is a100 = 354 224 848 179 261 915 075, and even more, the 10 000th term may be
obtained, with about 32 seconds of computation, and all the 2 089 decimal digits can
be found, whose display may occupy more than half a page of the book.

Example 1.10. Write a general purpose C program to compute the product of two ma-
trices A and B.

Solutions. If A is an n × p matrix and B is a p × m one, it is known from linear algebra


that matrix C can be obtained, whose elements are
p
cij = ∑ aik bkj , i = 1, . . . , n, j = 1, . . . , m.
k=1

Based on the above algorithm, the kernel part of C program can be written in a
triple-loop structure:
10 | 1 Introduction to computer mathematics languages

for (i=0; i<n; i++){for (j=0; j<m; j++){


c[i][j]=0; for (k=0; k<p; k++) c[i][j]+=a[i][k]*b[k][j];}}

It seems again that the problem can be solved with these simple statements. Unfor-
tunately, there is still a serious problem in the short code, the multiplicability of the
two matrices is not considered. Imprecisely speaking, when the number of columns of
A equals the number of rows of B, the product can be found, otherwise, they are not
multiplicable. To solve the problem, an extra if statement is needed.

if cols of A != rows of B, display an error message

Unfortunately, by introducing such a statement, a new problem emerges. In mathe-


matics, when A or B is a scalar, the product of A and B can be found, however, this
case is expelled by introducing the above if statement. To solve the problem, more if
statements are expected to check the scalar cases.
Even though the above modifications are made, this program is not a universal
one, since complex matrices were not considered at all. More statements are needed
to make the program universal.
It can be seen from the example that if C or similar computer languages are used,
the programmers must be very careful to consider all the possible cases. If one or more
cases were not considered, wrong or misleading results may be obtained. In MATLAB,
such trivial issues need not be considered at all. The command C=A*B can be used
directly. If the two matrices are multiplicable, the product can be obtained, otherwise,
an error message will be displayed to indicate why the product cannot be found.

1.2 History of computer mathematics languages


1.2.1 The early days of computer mathematics languages

Earlier in 1978, Professor Cleve Moler, the Chairman of the Department of Computer
Science at the University of New Mexico, found that the students in his linear algebra
class had difficulties in solving linear algebraic problems with the then most advanced
LINPACK and EISPACK packages. He conceived and implemented MATLAB (MATrix
LABoratory). The first release of MATLAB was then freely distributed. Cleve Moler and
Jack Little co-founded MathWorks in 1984 to further develop the MATLAB language.
By that time, control system theory involving state space methods was rapidly de-
veloping. Significantly many algebraic problems needed to be solved. The emergence
of MATLAB and its Control Systems Toolbox attracted the researchers’ attention from
the control community. More and more control oriented toolboxes were developed by
the distinguished scholars in different control disciplines, which popularized MAT-
LAB. It was first initiated by a numerical mathematician, but MATLAB impact and
reputation were first built up in the control community and became the top-selected
1.2 History of computer mathematics languages | 11

general purpose computer language of control scientists and engineers. With more
new dedicated toolboxes appearing in many other engineering disciplines, MATLAB
is becoming the de facto standard language in science and engineering.
The well-established Mathematica and Maple, which appeared later, are also
widely used computer mathematics languages.
Besides, the free language Scilab developed by INRIA in France can also be used
in solving certain scientific computing problems. The most significant benefit is that it
is a free and open-source software. Unfortunately, its behavior in scientific computing
has not reached the standard of the commercial languages such as MATLAB.

1.2.2 Representative modern computer mathematics languages

In the scientific world, there are three leading computer mathematics languages with
high reputation, namely MATLAB by MathWorks, Maple by Waterloo Maple, and Math-
ematica by Wolfram Research. They each have their own distinguishing advantages.
For example, MATLAB is easy in programming and good at numerical computation,
while Mathematica and Maple are more powerful in tackling pure mathematics prob-
lems.
The numerical capability of MATLAB is much stronger. Besides, various nice tool-
boxes by well-known scholars can be adopted to tackle the problems with high effi-
ciency. In addition, the symbolic computation engine in Maple was used to carry out
symbolic computations, and now it is replaced by the MuPAD engine. Therefore, the
symbolic computation capabilities are essentially the same as those of Mathematica
and Maple for average users in engineering and science.
MATLAB is extensively used in this book series. It appears that the series is pre-
senting some mathematical problems in certain depth. However, the ultimate objec-
tive of the series is to help the readers, after understanding roughly the mathematical
background, to bypass the tedious and complex technical details of mathematics and
find the reliable and accurate solutions to the mathematical problems of interest with
the help of MATLAB computer mathematics language. There is no doubt that the read-
ers’ capability in tackling mathematical problems can be significantly enhanced after
reading the books.
This the first volume in the series. MATLAB programming and skills are fully pre-
sented in the book. The applications of MATLAB in various branches of mathematics
are covered in other volumes, where thorough explorations on related materials in
other fields are studied with the tools provided in MATLAB. A MATLAB-based solu-
tion pattern is created such that much more information can be obtained from differ-
ent viewpoints. Creative research can be carried out with the help of MATLAB, and the
new results unknown to others may be discovered with the extensive use of the tools.
12 | 1 Introduction to computer mathematics languages

1.3 Three-phase solution of scientific computing problems


A three-phase methodology proposed by the author is used throughout the series
in presenting mathematical problem solutions[18] . The three phases are respectively
“What,” “How”, and “Solve.” In the “What” phase, the physical explanation of the
mathematical problem to be solved is presented. Even though the readers have not yet
learnt the corresponding mathematics course, they can understand roughly what the
problem is really about. In the “How” phase, the mathematical problem is described
in a manner understandable by MATLAB. In the final “Solve” phase, appropriate MAT-
LAB functions are called to solve the problem directly. If there is an existing MATLAB
function, the syntax of the function is presented, and if not, a universal function is
written to solve the problem.

Example 1.11. Let us revisit Example 1.5, where a linear programming problem was
involved. The philosophy used in the series will be illustrated.

min −2x1 − x2 − 4x3 − 3x4 − x5


{
{ 2x2 +x3 +4x4 +2x5 ⩽54,
{
{
x s. t.{3x1 +4x2 +5x3 −x4 −x5 ⩽62,
{
{
{
{x1 ,x2 ⩾0, x3 ⩾3.32, x4 ⩾0.678, x5 ⩾2.57.

Solutions. To solve such a problem, even though the reader may have not learnt any
optimization related courses, the solution can be obtained in the following three-
phases.
(1) “What” phase. In this book, we shall explain first the physical meaning of the
mathematical problem. In this particular example, the mathematical formula means
that under the simultaneous inequality constraints

2x + x3 + 4x4 + 2x5 ⩽ 54,


{ 2
{
3x + 4x2 + 5x3 − x4 − x5 ⩽ 62,
{ 1
{
{x1 , x2 ⩾ 0, x3 ⩾ 3.32, x4 ⩾ 0.678, x5 ⩾ 2.57,

we need to find a set of decision variables xi to minimize the objective function f (x) =
−2x1 − x2 − 4x3 − 3x4 − x5 . Even though the reader may have not studied optimization,
it is not difficult to understand what he/she is expected to do from the mathematical
formulas.
(2) “How” phase. We now illustrate how to represent the problem in MATLAB. The
code in Example 1.5 can be used to establish variable P. The mathematical problem
should be expressed in a format understandable by MATLAB.

>> clear; P.f=[-2 -1 -4 -3 -1]; % objective function


P.Aineq=[0 2 1 4 2; 3 4 5 -1 -1]; P.Bineq=[54 62]; % inequalities
P.solver=’linprog’; P.lb=[0;0;3.32;0.678;2.57]; % bounds
P.options=optimset; % the whole linear programming problem in P
1.3 Three-phase solution of scientific computing problems | 13

(3) “Solve” phase. We call the solver linprog() directly and get the result.

>> x=linprog(P) % call linprog() function to solve the problem

Example 1.12. Artificial neural network is an intelligent mathematical tool widely


used today. It is useful in data fitting and classification. Assume that a set of samples
can be generated with

>> x=0:0.1:pi; y=exp(-x).*sin(2*x+2);

Create an artificial neural network model for the samples and fit the curve of the func-
tion.

Solutions. If you do not want to spend time learning theoretical aspects of artificial
neural networks, and only want to use a neural network to solve the data fitting prob-
lem, consider the three-phase solution pattern presented earlier. Then a few minutes
of time are needed to learn what is an artificial neural network and how it can be used.
The data fitting problem can be tried with neural networks. Let us start with the three-
phase solution method:
(1) What is an artificial neural network? There is no need to understand the techni-
cal details. An artificial neural network can be regarded as an information processing
unit. It accepts several channels of input signals, and after internally processing the
signals, the output signals can be generated.
(2) How to create a neural network in MATLAB? With function fitnet(), a blank
neural network can be created. With the function train(), the parameters of the net-
work can be obtained from the given samples, and the structure of the usable neural
network is obtained as shown in Figure 1.1.

>> net=fitnet(5); net=train(net,x,y), view(net)

(3) Now we use this neural network to solve a data fitting problem. Generating a
set of data to fit, the output of the neural network can be obtained. Comparisons with

Figure 1.1: Structure of an artificial neural network.


14 | 1 Introduction to computer mathematics languages

the theoretical data are shown in Figure 1.2. It can be seen that even though we do
not have time to learn the details of neural networks, we are still able to use them to
solve our problems. Also the user may modify the structures and parameters of neural
networks, for instance, the number of neurons, so as to observe the quality of data
fitting through practice.

>> t0=0:0.01:pi; y1=net(t0); y0=exp(-t0).*sin(2*t0+2);


plot(t0,y0,t0,y1)

Figure 1.2: Fitting results with artificial neural network.

It can be seen by browsing the series that significantly many mathematical formu-
las are involved. Some of the knowledge seems to be rather deep in mathematics. If the
readers feel unconfident about their own mathematical background, they should not
worry about that. The aim of the book series is not to present technical details in math-
ematics, rather, the eventual goal is to help the readers first understand roughly the
physical meaning of the related mathematical problems, then by avoiding the trivial
details in mathematics, send the problems to computers in a way understandable by
computers, and wait for the results. With the powerful tools provided by computers,
our capability in dealing with practical scientific computing may well beat the first-
class mathematicians who are not professionals in using computer tools. Through the
study of the series, practical capabilities in scientific computing will be significantly
boosted.

1.4 Problems
1.1 Install MATLAB environment on your machine and run the command demo. From
the dialog boxes and menu items of the demonstration program, experience the
powerful facilities provided in MATLAB.
Discovering Diverse Content Through
Random Scribd Documents
Section 4. Information about Donations to
the Project Gutenberg Literary Archive
Foundation
Project Gutenberg™ depends upon and cannot survive without
widespread public support and donations to carry out its mission
of increasing the number of public domain and licensed works
that can be freely distributed in machine-readable form
accessible by the widest array of equipment including outdated
equipment. Many small donations ($1 to $5,000) are particularly
important to maintaining tax exempt status with the IRS.

The Foundation is committed to complying with the laws


regulating charities and charitable donations in all 50 states of
the United States. Compliance requirements are not uniform
and it takes a considerable effort, much paperwork and many
fees to meet and keep up with these requirements. We do not
solicit donations in locations where we have not received written
confirmation of compliance. To SEND DONATIONS or determine
the status of compliance for any particular state visit
www.gutenberg.org/donate.

While we cannot and do not solicit contributions from states


where we have not met the solicitation requirements, we know
of no prohibition against accepting unsolicited donations from
donors in such states who approach us with offers to donate.

International donations are gratefully accepted, but we cannot


make any statements concerning tax treatment of donations
received from outside the United States. U.S. laws alone swamp
our small staff.

Please check the Project Gutenberg web pages for current


donation methods and addresses. Donations are accepted in a
number of other ways including checks, online payments and
credit card donations. To donate, please visit:
www.gutenberg.org/donate.

Section 5. General Information About


Project Gutenberg™ electronic works
Professor Michael S. Hart was the originator of the Project
Gutenberg™ concept of a library of electronic works that could
be freely shared with anyone. For forty years, he produced and
distributed Project Gutenberg™ eBooks with only a loose
network of volunteer support.

Project Gutenberg™ eBooks are often created from several


printed editions, all of which are confirmed as not protected by
copyright in the U.S. unless a copyright notice is included. Thus,
we do not necessarily keep eBooks in compliance with any
particular paper edition.

Most people start at our website which has the main PG search
facility: www.gutenberg.org.

This website includes information about Project Gutenberg™,


including how to make donations to the Project Gutenberg
Literary Archive Foundation, how to help produce our new
eBooks, and how to subscribe to our email newsletter to hear
about new eBooks.
Welcome to our website – the ideal destination for book lovers and
knowledge seekers. With a mission to inspire endlessly, we offer a
vast collection of books, ranging from classic literary works to
specialized publications, self-development books, and children's
literature. Each book is a new journey of discovery, expanding
knowledge and enriching the soul of the reade

Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.

Let us accompany you on the journey of exploring knowledge and


personal growth!

textbookfull.com

You might also like