资源预览内容
第1页 / 共661页
第2页 / 共661页
第3页 / 共661页
第4页 / 共661页
第5页 / 共661页
第6页 / 共661页
第7页 / 共661页
第8页 / 共661页
第9页 / 共661页
第10页 / 共661页
亲,该文档总共661页,到这儿已超出免费预览范围,如果喜欢就下载吧!
资源描述
1,Chapter 1 MATLAB Primer,This introductory chapter is relatively short and has as its main objective the introduction of MATLAB to the reader. This early introduction has the purpose of familiarizing the reader with the basic operations of MATLAB so that the program may be used throughout the book to support the mathematical analysis.,2,Desktop Layout,The screen shown on the next slide is based on Version7, Release 14. The Student Version of MATLAB comes with the Symbolic Mathematics Toolbox and the program Simulink. All examples in the text should work with the Student Version,3,4,Prompt,MATLAB automatically inserts the prompt at the beginning of each line in the Command Window of the Professional Version. The corresponding prompt for the Student Version is EDU. We will assume the shorter prompt of the Professional Version throughout the text and the presence of the prompt on a line will alert the reader to the fact that a MATLAB command and possible results will follow.,5,Command Window,The Command Window may be used on an interactive basis by simply typing in the commands after for the Professional Version or after EDU for the Student Version on a line-by-line basis. Depress Enter on the keyboard after each line is entered, and any results generated by the command will immediately appear on the screen unless the addition of a semicolon has suppressed the display or unless the command is part of a sequence.,6,Notational Conventions,In the MATLAB examples, we will usually display the results exactly as they appear on the screen. This means that the type style will be different from the standard mathematical style in the remainder of the book, but the symbols should be perfectly clear. Standard mathematical notation includes italicized symbols with subscripts and/or superscripts but MATLAB notation will be non-italicized without subscripts or superscripts.,7,Command Window versus M-files,The Command Window will allow you to work in a manner similar to that of a calculator. You can enter a command and see the numerical results immediately. The important thing is that it is interactive. This is in contrast to the writing of M-files, which is performed in a different window. An M-file is a form of computer program.,8,Clear Commands,Clearing the screen: clcClearing all variables: clearClearing a variable x: clear x,9,Spacing,Blank spaces between distinct sections of a command line may be used to avoid a “crowded” appearance provided that they dont disrupt a particular command function or number. Thus, x=5 , x = 5, and x = 5 are all acceptable. However, if the number is 51, you will get an error message if you try to put a space between the 5 and the 1. Likewise a variable x1 cannot be expressed as x 1.,10,Basic Arithmetic Operations,In many of the slides that follow, basic arithmetic operations will be employed using simple numbers to illustrate the manner in which the command window can be used in much the same way as a calculator. To save space on the slides, many of the blank lines that appear on the computer screen will be eliminated.,11,Entering Numbers, 5 ans =5 x = 5 x =5 y = 3 y =3,12,Addition and Subtraction, z1 = 5 + 3 z1 =8 z1 = x + y z1 =8 z2 = y - x z2 =-2,13,Checking on the Variables, whos Name Size Bytes Classx 1x1 8 double arrayy 1x1 8 double arrayz1 1x1 8 double arrayz2 1x1 8 double arrayThis information may also be found in the Current Directory window.,14,Multiplication,Multiplication is performed by placing an asterisk (*) between the numbers. z3 = 5*3 z3 =15 z3 = x*y z3 =15,15,Division,Division of x by y is performed as follows: z4 = x/y z4 =1.6667An alternate form is as follows: z4 = yx z4 =1.6667,16,Exponentiation,Exponentiation is performed by using the symbol (). z5 = x2 z5 =25,17,Suppressing the Listing of Results,If it is desired to perform a computation and not show it on the screen, the command should be followed by a semicolon (;). For example, z6 = yx; The value is in memory and may be seen by entering the variable name. z6 z6 =243,18,Entering in Exponential Form,A microwave frequency of 15 GHz (1 GHz = 109 Hz) may be entered as f = 15e9 f =1.5000e+010 Boltzmanns constant k = 1.38x10-23 J/K may be entered as k = 1.38e-23 k =1.3800e-023,19,Square Root, z7 = sqrt(x) z7 =2.2361,20,Hierarchy,Without parentheses, the normal hierarchy of arithmetic operations is exponentiation, multiplication, division, addition, and subtraction. Parentheses may be used to change the order. When in doubt, it is prudent to add parentheses to ensure that the order is performed properly. The process of placing parentheses within parentheses is called nesting.,21,Consider the algorithm shown below.,1. Add 3 to x. 2. Square the result of step 1. 3. Multiply the result of step 2 by 6. 4. Add 8 to the result of step 3. 5. Take the square root of step 4 and the value obtained is y.,
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号