正在加载图片...
4 MATLAB can be used as a scientific calculator,combining several operations in one expression.The computation of the expression is based on well-known mathe matical rules.In particular,some operations are performed before others,based on precedence rules Precedence Operator Parentheses (round brackets) Exponentiation.left to right Multiplication and division.left to right Addition and subtraction.left to right If you want to know the result of the operation (2+[5*3/(7-5)]3)you have to type >(2+(5*3/(7-5)^2)/3) <ENTER> ans、 3.2500 In this example.MATLAB first calculates (7-5)=2.then it squares 22=4.ther it performs the multiplication5*3=15(multiplication left to right).and then divides the result by the previously computed result,i.e.,15/4=3.75.The result in brackets is divided by 3 (3.75/3=1.25)and then added to 2,giving the result.Note that in MATLAB,parentheses are always given by round brackets. MATLAB was developed for scientists,and for this reason you can find built-in operations and functions that are more advanced than the ones we have just looked at.Consider ing MATLAB as a sort of scientific calculator,you can engage the cosine buttor simply by typing: >c03(36) <ENTER> ans -0.1280 Other common functions are reported in the following table.Type the operation after the>>prompt followed by Enter: MATLAB answer Meaning of the operation cos(12) ans=0.8439 Cosine of the element in parentheses 1nt12) n8=-0.5366 Sine of the element in parentheses tan(4) ns=1.1578 Tangent of the element in parentheses exp(3) ans=20.0855 Exponential of the element in parentheses 1og10) n=23026 Natural logarithm of the element in parentheses 1og10(12】 an$=1.0792 Base-10 logarithm of the element in parentheses We will see in the rest of the book the possibility using many other functions Just to introduce some:statistical function functions,fund tions for in ation and last but not least,you own custom-crea ated fur4 1 Basic Operations MATLAB can be used as a scientifi c calculator, combining several operations in one expression. The computation of the expression is based on well-known mathe￾matical rules. In particular, some operations are performed before others, based on precedence rules, which are given in the following table: Precedence Operator 1 Parentheses (round brackets) 2 Exponentiation, left to right 3 Multiplication and division, left to right 4 Addition and subtraction, left to right If you want to know the result of the operation {2+[5*3/(7−5) 2 ]/3} you have to type: >> (2+(5*3/(7-5)^2)/3) <ENTER> ans = 3.2500 In this example, MATLAB fi rst calculates (7−5) = 2, then it squares 2^2 = 4, then it performs the multiplication 5*3 = 15 (multiplication left to right), and then divides the result by the previously computed result, i.e., 15/4 = 3.75. The result in brackets is divided by 3 (3.75/3 = 1.25) and then added to 2, giving the result. Note that in MATLAB, parentheses are always given by round brackets. MATLAB was developed for scientists, and for this reason you can fi nd built-in operations and functions that are more advanced than the ones we have just looked at. Considering MATLAB as a sort of scientifi c calculator, you can engage the “cosine button” simply by typing: >> cos(36) <ENTER> ans = -0.1280 Other common functions are reported in the following table. Type the operation after the >> prompt followed by Enter: To TYPE after prompt >> followed by Enter MATLAB answer Meaning of the operation cos(12) ans= 0.8439 Cosine of the element in parentheses sin(12) ans= −0.5366 Sine of the element in parentheses tan(4) ans= 1.1578 Tangent of the element in parentheses exp(3) ans= 20.0855 Exponential of the element in parentheses log(10) ans= 2.3026 Natural logarithm of the element in parentheses log10(12) ans= 1.0792 Base-10 logarithm of the element in parentheses We will see in the rest of the book the possibility using many other functions. Just to introduce some: statistical functions, interpolation functions, linear-algebraic functions, functions for images and sound elaboration, and last but not least, your own custom-created functions!
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有