Computer mathematics Lecture Notes

computer mathematics for beginners and computer engineering mathematics book. computer application in mathematics and science. Free pdf download
RyanCanon Profile Pic
RyanCanon,United Arab Emirates,Teacher
Published Date:21-07-2017
Your Website URL(Optional)
Comment
Computer Mathematics for the Engineer: Efficient Computation and Symbolic Manipulation Lecture Notes Compiled by Tom Fredman Laboratory of Thermal and Flow Engineering, Åbo Akademi University 20141 These lectures were compiled for the course “Computer Mathematics for the Engineer: Efficient Computation and Symbolic Manipulation” (3/5 cr. ECTS) aimed at students on the advanced or graduate levels at Åbo Akademi Univer- sity. The course is arranged by the Laboratory of Thermal and Flow Engineer- ingatÅbo Akademi Universityand supported by the Finnish nationalgraduate programme “Graduate School in Chemical Engineering”. The material included in these notes is based on the literature cited below and should not be regarded as a complete user’s manual for the computer-aided mathematical tools presented in the course, but merely as an introduction to how these can be used for improving and assisting day-to-day mathematical chores of the modern engineer. We begin with a minimal introduction of the softwarepackagesadopted for the courseand continue with details fromvarious engineering topics. To encourage the reader to engage in a “hands-on” learning process, we tend to give only the necessary input for different themes and leave it to the reader to try the various cases for him/herself. Comments on the expected output is provided in most cases, however. Åbo, October 2014,2Bibliography 1 M. B. Cutlip, J. J. Hwalek, H. E. Nuttall, M. Shacham et. al The Use of Mathematical Software Packages in Chemical Engineering. Chemical Engineering Summer School, Snowbird UT., August 1997. 2 R. Piché and K. Ruohonen Partial Differential Equations with Maple. Tampere University of Technology, December 1997. 3 R. W. Pike Optimization for Engineering Systems. Louisiana State University, Minerals Processing Research Institute, 2001. 4 C. Moler Cleve’s Corner: Stiff Differential Equations. Matlab News & Notes, May 2003. 5 R. Dodier Minimal Maxima. http://maxima.sourceforge.net/docs/tutorial/en/minimal-maxima.pdf September 2005 6 J. H. Mathews Module for Monte Carlo Integration. http://math.fullerton.edu/mathews, 2005. 7 J. W. Eaton, D. Bateman and S. Hauberg GNU Octave. A high-level interactive language for numerical computations. Ed. 3 for Octave version 3.2.2., July 2007. 8 P. Lutus Symbolic Mathematics Using Maxima. http://www.arachnoid.com/maxima/index.html, 2007. 9 H. Selhofer, M. Oliver and T. L. Scofield Introduction to GNU Octave. August 2008. 10 E. L. Wollett Maxima by Example: A Series of Tutorial Notes. Department of Physics, CSULB San Luis Obispo, CA, 2009. 11 R. H. Rand Introduction to Maxima. Department of Theoretical and Applied Mechanics, Cornell University Ithaka, NY, 2010. 12 Maxima, a Computer Algebra System. http://maxima.sourceforge.net/documentation.html 13 E. Gkioulekas Introduction to Maxima. Department of Mathematics, University of Texas-Pan American Edinburg, TX, 2011. 34 BIBLIOGRAPHYContents 1 An Overview of wxMaxima 11 1.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11 1.2 Examples . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12 1.3 Expressions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13 1.3.1 Utility Functions . . . . . . . . . . . . . . . . . . . . . . . 18 1.3.2 Expression Construction . . . . . . . . . . . . . . . . . . . 19 1.4 Evaluation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20 1.4.1 Evaluation of Atomic and Non-Atomic Expressions . . . . 20 1.4.2 Modifications of Evaluations . . . . . . . . . . . . . . . . 20 1.4.3 Defaults and Argument Evaluation . . . . . . . . . . . . . 21 1.4.4 Callable Functions . . . . . . . . . . . . . . . . . . . . . . 22 1.4.5 Automatically Quoted Arguments . . . . . . . . . . . . . 22 1.4.6 Preventing Evaluation . . . . . . . . . . . . . . . . . . . . 24 1.4.7 Extra Evaluation . . . . . . . . . . . . . . . . . . . . . . . 24 1.4.8 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 26 1.4.9 Arguments . . . . . . . . . . . . . . . . . . . . . . . . . . 27 1.5 Simplification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27 1.5.1 Examples of Maxima Simplification . . . . . . . . . . . . 28 1.5.2 Exceptions to Maxima Simplification . . . . . . . . . . . . 29 1.6 Special Purpose Functions . . . . . . . . . . . . . . . . . . . . . . 29 1.6.1 Applying arguments to functions . . . . . . . . . . . . . 29 1.6.2 The mapping function . . . . . . . . . . . . . . . . . . . 30 1.6.3 The lambda-function . . . . . . . . . . . . . . . . . . . . 31 1.7 Built-in object types . . . . . . . . . . . . . . . . . . . . . . . . . 31 1.7.1 Lists . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 31 1.7.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32 1.7.3 Sets . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33 1.8 Maxima Programming . . . . . . . . . . . . . . . . . . . . . . . . 34 1.8.1 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 1.8.2 Iteration . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 1.9 Some Useful Flags . . . . . . . . . . . . . . . . . . . . . . . . . . 40 1.10 Summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42 56 CONTENTS 2 Symbolic Calculation 43 2.1 Initialization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43 2.2 Saving and Loading . . . . . . . . . . . . . . . . . . . . . . . . . 45 2.3 Functions and Equations . . . . . . . . . . . . . . . . . . . . . . . 47 2.3.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 47 2.3.2 Equations - A Practical Application . . . . . . . . . . . . 49 2.4 Systems of Equations . . . . . . . . . . . . . . . . . . . . . . . . . 52 2.5 Evaluating Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . 53 2.6 Differential Calculus . . . . . . . . . . . . . . . . . . . . . . . . . 54 2.6.1 Computation of Solutions with the Laplace Transformation 57 2.6.2 Differentiation Using the Chain Rule . . . . . . . . . . . . 61 2.7 Integral Calculus . . . . . . . . . . . . . . . . . . . . . . . . . . . 65 2.7.1 Integration Examples . . . . . . . . . . . . . . . . . . . . 66 2.7.2 Integration by Parts . . . . . . . . . . . . . . . . . . . . . 72 2.7.3 Change of Variable . . . . . . . . . . . . . . . . . . . . . . 73 2.8 Matrix Computations . . . . . . . . . . . . . . . . . . . . . . . . 74 2.9 Visualization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75 A 2.9.1 Publication-Quality Graphics for LT X . . . . . . . . . . 76 E 2.10 Numerical Data . . . . . . . . . . . . . . . . . . . . . . . . . . . . 76 3 An Overview of Octave 77 3.1 Introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 77 3.1.1 Help . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 78 3.1.2 Input Conventions . . . . . . . . . . . . . . . . . . . . . . 78 3.1.3 Variables and Standard Operations . . . . . . . . . . . . . 78 3.2 Vector and Matrix Operations . . . . . . . . . . . . . . . . . . . . 79 3.2.1 Vectors . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 3.2.2 Matrices . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79 3.2.3 Basic Matrix Arithmetic . . . . . . . . . . . . . . . . . . . 80 3.2.4 Element-wise Operations . . . . . . . . . . . . . . . . . . 80 3.2.5 Indexing and Slicing . . . . . . . . . . . . . . . . . . . . . 81 3.2.6 Solving Linear Systems of Equations . . . . . . . . . . . . 81 3.2.7 Inverses, Decompositions and Eigenvalues . . . . . . . . . 82 3.2.8 Testing for Zero Elements . . . . . . . . . . . . . . . . . . 82 3.3 Control Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3.3.1 Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . 82 3.3.2 Global Variables . . . . . . . . . . . . . . . . . . . . . . . 83 3.3.3 Loops . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 83 3.3.4 Branching . . . . . . . . . . . . . . . . . . . . . . . . . . . 84 3.3.5 Functions of Functions . . . . . . . . . . . . . . . . . . . . 84 3.3.6 Efficiency Considerations . . . . . . . . . . . . . . . . . . 85 3.4 Input and Output . . . . . . . . . . . . . . . . . . . . . . . . . . 85 3.5 Graphics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.5.1 2D Graphics . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.5.2 3D Graphics . . . . . . . . . . . . . . . . . . . . . . . . . 86 3.5.3 Commands for 2D and 3D Graphics . . . . . . . . . . . . 87CONTENTS 7 A 3.5.4 Publication-Quality Graphics for LT X . . . . . . . . . . 87 E 4 Numerical Computation 89 4.1 Preliminaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89 4.1.1 Running Octave . . . . . . . . . . . . . . . . . . . . . . . 89 4.1.2 Editing What You Have Typed . . . . . . . . . . . . . . . 89 4.1.3 Startup Files . . . . . . . . . . . . . . . . . . . . . . . . . 90 4.1.4 Quitting Octave . . . . . . . . . . . . . . . . . . . . . . . 90 4.1.5 Help and Documentation . . . . . . . . . . . . . . . . . . 91 4.2 Functions and Scripts . . . . . . . . . . . . . . . . . . . . . . . . 91 4.2.1 Defining Functions . . . . . . . . . . . . . . . . . . . . . . 92 4.2.2 Multiple Return Values . . . . . . . . . . . . . . . . . . . 94 4.2.3 Variable-length Argument Lists . . . . . . . . . . . . . . . 95 4.2.4 Variable-length Return Lists . . . . . . . . . . . . . . . . 96 4.2.5 Returning From a Function . . . . . . . . . . . . . . . . . 97 4.2.6 Function Files . . . . . . . . . . . . . . . . . . . . . . . . 97 4.2.7 Subfunctions . . . . . . . . . . . . . . . . . . . . . . . . . 98 4.2.8 Private Functions . . . . . . . . . . . . . . . . . . . . . . . 98 4.2.9 Script Files . . . . . . . . . . . . . . . . . . . . . . . . . . 99 4.2.10 FunctionHandles,InlineFunctions,andAnonymousFunc- tions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 100 4.3 Equations and Optimization . . . . . . . . . . . . . . . . . . . . . 101 4.3.1 Nonlinear Equations . . . . . . . . . . . . . . . . . . . . . 101 4.3.2 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 103 4.4 Boundary/Initial Value Problems . . . . . . . . . . . . . . . . . . 105 4.4.1 Integrating Differential Equations. . . . . . . . . . . . . . 105 4.5 Partial Differential Equations . . . . . . . . . . . . . . . . . . . . 106 4.6 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 106 4.6.1 Functions of One Variable . . . . . . . . . . . . . . . . . . 106 4.6.2 Functions of Multiple Variables . . . . . . . . . . . . . . . 108 4.7 Interpolation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109 4.7.1 One-Dimensional Interpolation . . . . . . . . . . . . . . . 109 4.7.2 n-Dimensional Interpolation . . . . . . . . . . . . . . . . . 111 5 Exercises 113 5.1 wxMaxima . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113 5.1.1 Inverse Functions . . . . . . . . . . . . . . . . . . . . . . . 113 5.1.2 Limits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 114 5.1.3 Differentiation . . . . . . . . . . . . . . . . . . . . . . . . 114 5.1.4 Integration . . . . . . . . . . . . . . . . . . . . . . . . . . 115 5.1.5 Integral and Differential Equations . . . . . . . . . . . . . 116 5.1.6 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . 117 5.2 Octave . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117 5.2.1 Linear Algebra . . . . . . . . . . . . . . . . . . . . . . . . 117 5.2.2 Timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 118 5.2.3 Stability Functions of BDF-integrators . . . . . . . . . . . 1198 CONTENTS 5.2.4 3D Plotting . . . . . . . . . . . . . . . . . . . . . . . . . . 120 5.2.5 Hilbert Matrix . . . . . . . . . . . . . . . . . . . . . . . . 121 5.2.6 Least Square Fit of a Straight Line . . . . . . . . . . . . . 121 5.2.7 Numerical Differentiation . . . . . . . . . . . . . . . . . . 122 5.2.8 Trapezoidal Rule . . . . . . . . . . . . . . . . . . . . . . . 122 5.2.9 Optimization . . . . . . . . . . . . . . . . . . . . . . . . . 123 5.2.10 Sequences . . . . . . . . . . . . . . . . . . . . . . . . . . . 123 6 Course problems 125 6.1 Single Nonlinear Equation . . . . . . . . . . . . . . . . . . . . . . 125 6.2 Another Single Nonlinear Equation . . . . . . . . . . . . . . . . . 126 6.3 A Set of Linear Equations . . . . . . . . . . . . . . . . . . . . . . 127 6.4 Nonlinear Regression . . . . . . . . . . . . . . . . . . . . . . . . . 129 6.5 A Set of Nonlinear Equations . . . . . . . . . . . . . . . . . . . . 130 6.6 A Set of Ordinary Differential Equations . . . . . . . . . . . . . . 131 6.7 Another Set of Ordinary Differential Equations . . . . . . . . . . 132 6.8 A Second-Order Ordinary Differential Equation . . . . . . . . . . 134 6.9 Ordinary Differential Equations and Algebraic Equations . . . . 134 6.10 A Control Loop . . . . . . . . . . . . . . . . . . . . . . . . . . . . 135 6.11 Stiff Differential Equations . . . . . . . . . . . . . . . . . . . . . . 137 6.12 Partial Differential Equations . . . . . . . . . . . . . . . . . . . . 138 6.13 Integral Equations . . . . . . . . . . . . . . . . . . . . . . . . . . 139 6.14 Special Topics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 141 6.14.1 Perturbation Theory . . . . . . . . . . . . . . . . . . . . . 141 6.14.2 Calculus of Variations . . . . . . . . . . . . . . . . . . . . 142 6.14.3 JWKB-approximation . . . . . . . . . . . . . . . . . . . . 143 6.14.4 Monte Carlo Methods . . . . . . . . . . . . . . . . . . . . 145 6.14.5 Coding Theory . . . . . . . . . . . . . . . . . . . . . . . . 146Background The use of advanced mathematical methods has become increasingly significant for many modern engineering disciplines. As many of these methods nowadays arecomputer-aided,theirefficientuserequiresapartfromunderlyingtheoretical knowledge also familiarity with relevant software packages. The aim of these notesistocombinethesetwointoanengineeringintroductiontocomputer-aided mathematics, with emphasis on symbolic manipulation. We will use the freeware applications “wxMaxima” for symbolic calculation and“Octave” fornumericalcalculation. Ourmainfocusforbothoftheseisbased on command-driven use, although the former of these also features interactive menusandinitializationwindows. Thereasonforthisisthatmenu-drivenuseof the softwareisto largeextentself-instructiveand ourpreferenceto learnhowto programbatch computations later on. Therefore, we choose to leave the details for using integrated menus to the interested student and proceed to a survey of the relevant commands involved in the themes treated in this course. In our attempt to awake interest for further learning, we will start with a “minimal” introduction to Maxima and later to Octave. Both Maxima and Octave invoke the public-domain graphics package Gnu- plot for visualizing computation results. The graphs produced this way cannot be as readily customized as by using Gnuplot in a standalone fashion, however. A For example, if graphs are intended for use in a LT X-document, correct fonts E and formulas can be produced by generating a “.tex”-figure and including this A file in the LT X-document. Brief instructions on how to do this is given below. E 910 CONTENTSChapter 1 An Overview of wxMaxima 1.1 Introduction wxMaxima is a system, consisting of the core code package Maxima that does the actual computations and an interactive user interface based on so called x-widgets. The main working purpose is to handle expressions, such as x+y, sin(a+bπ),anduv−vu. Itisuptotheuserwhetheranexpressionismeaningful or not, however, manipulations can be done without assigning numerical values to variables and parameters. Maxima belongs to a category of mathematics software known as computer algebrasystems–orCASforshort. ThisimpliesthatMaximaisatoolprimarily for manipulation of mathematical objects as symbols rather than as numerical entities. The package Octave, which will be introduced later during the course, is more suitable for doing numerical computation. RunningwxMaximaopensaninteractivewindowwithseveraldifferentmenus and shortcuts across the headboard. These, which are designed for utilities as well as for different types of calculations, will be discussed in detail later. Com- mands can be entered both through submenus invoked by these and by using the command prompt. In earlier versions of wxMaxima, the command prompt isvisiblethroughout,however,inlaterversionsvariouspromptsarechosenfrom “Cell” in the “Edit”-menu with shortcuts: F5 New Input Cell F6 New Text Cell F7 New Subsection Cell F8 New Section Cell F9 New Title Cell Forthese,hitting“Enter” intheearlierversioncorrespondstochoosing“Evaluate AllCells” fromthesamesubmenuortheshortcutCtrl-R.Forinstance,theresult 1112 CHAPTER 1. AN OVERVIEW OF WXMAXIMA Figure 1.1: The wxMaxima graphical interface. A displayedinFigure1.1canberenderedinLT Xbyselecting“DisplayTeX-form” E from the “Maxima”-menu to give:        √ √ √ √      2i+ 2 π      2i− 2 π √ √ √ √ √ √ √ √ √      π 2i+ 2 sin1+ 2i− 2 cos1 erf + 2i− 2 sin1+ 2i+ 2 cos1 erf 4 4 − 8 1.2 Examples In the following, we will take a look at some brief examples on the use of wxMaxima. Example 1.2.1. The command “stardisp” controls the way wxMaxima displays the operation of multiplication. Setting (%i1) stardisp:true; will show all multiplications with an asterisk. The value “false” shows products with a blank space, which can distracting in more complicated expressions. Example 1.2.2. The sequence (%i2) V:4/3 %pi r3;1.3. EXPRESSIONS 13 3 4πr assigns the value to the name V. Names in Maxima are also termed iden- 3 tifiers. The value of the name r (for radius) is “itself”, in place of a specific numerical value, at this point – that is, r is r. Note that the number pi is en- tered using the Maxima special character %pi. Now, we assign the value r = 10 to the radius (%i3) r:10; Asseen, theway toassign aspecific valuetoanameis byusingacolon character (:) and not the symbol “equal to”. We can think of this as assigning “equality by definition”. So, we defined the value of V to be equal to the expression above and the radius equal to 10, demonstrating that names may be assigned different kinds of objects. It should be noted that V does not change after assigning a numerical value to the radius r - it is still an expression. If we want to evaluate thisexpressionwith thevalue assigned tor, we usedouble single quotesaccording to: (%i5) ’’V; This results in r = 10 being substituted into the expression for V and the nu- merical constants, except π, being simplified (also try what happens if the as- signment r = 10 is done before assigning the expression to V). All irrational numbers having similar special symbols, i.e. starting with % are treated like this in Maxima. In a situation where we want a numerical result, however, an approximation has to be used for π. This is done as follows: (%i6) ’’V, numer; producing a floating-point number approximation for the volume V. 1.3 Expressions EssentiallyeverythinginMaximaisexpressions,whichcanbedividedintothree types or classes: (1) Mathematical expressions (2) Object expressions (3) Programming constructs AMaximaexpressionisbuiltupfrom“atoms” andoperatorswithcorresponding arguments.When an expression is evaluated, the result is its value which can differ from the expression itself. This was illustrated above. For example, in the expression 1+2, we have the operator + (the binary operator of addition). The two arguments to this operator are literal numerals in the form of the two “atoms” 1 and 2. The expression sin(x) consists of an operator with one argument, the single letter symbol x – an atom in the form of a literal name.14 CHAPTER 1. AN OVERVIEW OF WXMAXIMA The value of x may be itself if no other value has been assigned – x is x, or x is, e.g., 10 (from the input x:10). An atom can be a name (a charactersymbol likeV, x andr above), a string enclosed in quotation marks (e.g., "volume" and "radius"), or a numeral such as an integer or decimal number like 1, -5, 3.14159, etc. Expressions in Maxima not consisting of atoms are termed “non-atomic” and can be represented as op(a1, . . . , an), where op is an operator and (a1, . . . , an) are its n arguments. This format is also used internally by Maxima, including the basic arithmetic operations such as addition, sub- traction, multiplication and division which are input conventionally using the symbols + - /. These are “seen” by Maxima in the form op(a,b) – for ex- ample 1+2 is represents op(1,2), where "op" is the appropriate operation for addition. Similar operators are used for function evaluation, e.g., in connection with trigonometric and special functions. Morecomplexmathematicalexpressionsmayinvolvecombinationsofnames, literal numerals, and operators. Literal numerals include constants with special Maxima names such as %piand %e. As listed above, in Maxima objects arealso expressions. Example 1.3.1. A list a1, . . . , an of n objects is an object expression. These can be created with the operation (oplist) = and arguments. In the case of a matrix object, which also is an expression, we have ( op = matrix ): matrix(list((a1,1), (a1,2),. . . , (a1,n)) , . . . , list((am,1), (am,2),. . . , (am,n))) These arguments are non-atomic, they are list object expressions each of which may or may not be composed of atoms. The value of these expressions is the list object or the resulting matrix object. Observation 1.3.2. While all expressions have a value, the value of an ex- pression may be lost unless the expression is assigned a name using the the : operator. Merely entering an expression as Maxima input will result in the display of the value of the expression (unless suppressed), and then the object and its value passes out of existence. Sometimes this is okay, for example when Maxima is being used as a symbolic calculator. However, Maxima has a built-in feature that mitigates this issue significantly. The special Maxima name % is assigned the value of the last entered expres- sion and may be used like any name assigned a value. Of course, the value of % changes with each new expression entered as input. The values of each en- tered expression are saved in the special names prefixed as %o with a sequential numeral for each line of output These %o names (e.g, %o1, %o2, ..., %on) may be used in Maxima expressions as names with the values of the displayed output. The downside to the frequent use of this feature is that these generic names generatedbyMaximahavelittle ifanyliteralsignificance. Onecaneasilyrecog- nizethatV meansvolumeandr meansradius,butwhatdoes%(%o7-%o5)/%o3 signify?1.3. EXPRESSIONS 15 Programming constructs are also expressions. A code block is represented internallytoMaximaasanexpressionwithanoperatorandarguments. Hence,a conditionalstatement(ifathenbelseifcthend)isrepresentedasif (a, b, c, d) and a loop (for a in L do S) as mdoin(a, L, S). Maxima has two functions to help evaluate what kind an expression is. The function atom(expr)takes an expressionas an argumentand indicates whether this is simply atomic. The function op(expr) returns the overall operation of an expression if it is not simply atomic. Expressions of this class have values which vary according to the type of programming construct. For example, the value of a loop expression may be “done” while the value of a block expression is the value of the last argument listed. Example 1.3.3. Maxima expressions 1. Atoms are symbols, strings, and numbers. Below, we have a various of these grouped into a list: (%i9) a, foo, foo_bar, "Hello, world", 42, 17.29; 2. Mathematical expressions (%i10) a + b + c, a b c, foo = bar, ab cd; These may simply be combinations of atoms and operators or may also be relations between expressions. For example foo = bar is considered to be a mathematical expression. This expression does not say that foo is equal to bar, instead it is merely a logical relation between (in this case two atoms) the names foo and bar. The relation between the two names holds only when their values are the same, resulting in the value “true” and otherwise “false”. 3. Object Expressions – Lists and matrices The elements of a list or matrix can be any kind of expression, even another list or a vector/matrix. (%i11) L:a, b, c, %pi, %e, 1729, 1/(ad - bc); This input is a list object expression assigned to the nameL. The elements of this list are all atoms except the last which is a mathematical expression. Now, look at the input. (%i12) L2:a, b, c, %pi, %e, 1729, 1/(ad - bc);16 CHAPTER 1. AN OVERVIEW OF WXMAXIMA This is a different list object expression assigned to the name L2. The last element is itself a list object consisting of two atoms, another list object and a mathematical expression. These objects result in index names being created when assigned to a name. The values are accessed by appending brackets to the object name: (%i13) L7; which returns the seventh element of the list L. Similarly, (%i14) L23; returns the third element of the list L2, which is in itself a list. The assignment (%i15) M:matrix (%pi, 17, 29, %e);   π 17 defines the matrix M = . It is also possible to assign matrices 29 e with elements consisting of submatrices: (%i16) M2:matrix (%pi, 17, ad - bc, matrix (1, a, b, 7), %e);   1 a The submatrix on the second row, first column can be references b 7 with the command: (%i18) M221; Example 1.3.4. Programming constructs These are expressions such as x : y which means assign y to x; the value of the assignment expression is the value of y. There is probably no better example of the difference between an expression and its value than this object. This expression is always non-atomic, but its value is atomic if the value of y is atomic. The block operation groups several expressions, and evaluates them one af- ter another; the value of the block operation expression is the value of the last expression of the block. Try to guess the value of the expression below before entering it as input. (%i19) ("a block", a:42) - ("another block", b:17);1.3. EXPRESSIONS 17 We observe that this expression is the difference between the values of two block expressions. The string atoms that are the first argument of each block do noth- ing. They are unassigned atoms and they pass out of existence after the value of the statement is displayed. Their purpose is to merely serve as arguments to demonstrate a block expression. This input does two things in one statement. First, it assigns 42 to the namea and 17 to the name b, and then it performs the difference operation using the value of these assigment statements as arguments. However, an assignment is not itself an operation. Entering op(a:42)results in an error message. This is because Maxima “sees” a:42 as an atom. The input atom(a:42) and the value is true. (a:42) - (b:17) is merely a mathematical expression with two atoms as arguments. The value of this expression is 25. If you input op((a:42) - (b:17)) the result is +. This peculiarity is due to the fact that Maxima is true to mathematics in the sense that subtraction is defined in terms of the sum of a and the additive inverse of b – a−b means by definition a+(−b). The result of (%i20) a, b; illustrates that although the string atoms of the block expressions were lost, and the block expressions themselves are gone, the names a and b have values that persist. This is a list expression object formed using the atoms a and b as arguments with values 42 and 17 respectively. Consider (%i21) block (a, a: 42, a2 - 1600) + block (b, b: 5, %pib); This is a Maxima block programming construct object expression formed using two block operations ( op = block) with the arguments as shown. Notice that the block operation returned the value of a2 - 1600 + block (b, b: 5, %pib) , where the last term in this argument was also a block operation. It returned a 2 value of %pi5 – this was added to the 164 from the result of 42 −1600 = 164 5 to yield the final output of π +164. Moreover (%i22) (if a 1 then %pi else %e) + (if b 0 then 1/2 else 1/7); shows two programming object expressions as arguments to the addition opera- tion. The characteristic operation of this expression is addition – op = +. The 1 arguments are the two if operations that result in the two values π and that are 7 the addendi of the total expression. Note that the arguments to the if operations (op is if) may be relational mathematical expressions – (a 1) and (b 0). These are evaluated as arguments in this case. What is interesting to note is that because the overall operator of this expression is +, this is a mathematical expression in the end. The values of the op = if expressions are atomic – π 1 and . The expressions themselves are non-atomic. 718 CHAPTER 1. AN OVERVIEW OF WXMAXIMA 1.3.1 Utility Functions These functions demonstrate how Maxima works and we have already seen ex- amples of their use. The function op(expr) returns the overall (or character- istic) operator of a expression while args(expr) returns the arguments, and atom(expr) tells whether an expression is an atom. Example 1.3.5. Lets try the following: (%i23) op(p + q); The result of this is “+”. When an expression contains more than one operator, the outermost of these is obtained: (%i24) op(p + q pq); Similarly when we have nested functions; the outer function is picked up: (%i25) op(sin (p + q)); We can also pick up the operator of a function defined in the same expression, e.g., (%i26) op(foo (p, q) := p - q); gives the assignment operator “:=”. The corresponding utility for picking up function arguments is the function args, try (%i27) args(p + q); giving q,p. A composite expression like (%i28) args(p + q pq); yields q+p,pq. A curiosity is revealed when we try (%i29) args(foo (p, q)); for the function defined above. It turns out that Maxima interprets subtraction as addition of the corresponding number with opposite sign. In this case the result is p,-q. As already noted, the function atom returns “true” for an expression being purely atomic and false otherwise, e.g., (%i30) atom(p); (%i31) atom(p + q); (%i32) atom(sin (p + q));1.3. EXPRESSIONS 19 1.3.2 Expression Construction Thesinglequotetells Maximato“construct” anexpressionbutsuppresses“eval- uation” of the expression. It is important to note the difference between the assignment operator :, evaluation and the single quote. This is illustrated in the following Example 1.3.6. Consider the results of the following inputs. (%i33) x:2+3; (%i34) x; (%i35) ’x; (%i36) op(x); (%i37) op(’x); (%i38) x;atom(x); (%i39) ’x;atom(’x); The results of the above show that the value of an expression and its constructed value may be different even if both are atoms. Example 1.3.7. Consider the assignment (%i40) x:if p q then p else q; In this case, x itself is the assigned expression, while the single quote results in just “x”. Compare the results of the following: (%i41) op(x); (%i42) op(’x); So, there is a difference between value and constructed value also for non-atomic expressions. Observe that ’x is atomic but ’(if p q then p else q) is not. The former does not return an operator as already seen and the latter returns the operator“if”. Theexpressionusingtheifprogrammingconstructisconstructed as an argument to op, but it is not evaluated – it remains a non-atomic expres- sion. Thus the characteristic operation of this expression is op = if. In a situation where p and q are atoms with certain values, the value of the expres- sion (if p q then p else q) is different from its constructed value: (%i43) p:3;q:%pi;(if p q then p else q);’(if p q then p else q); Now, we consider a block programming construct

Advise: Why You Wasting Money in Costly SEO Tools, Use World's Best Free SEO Tool Ubersuggest.