上海交通大学交大密西根 联合学院一 ◆ UM-SJTU Joint Institute 1Ua日 181t ■ University of Michigan Shanghal Jiao Tong University Calculating with MatLab Direct calculation,ans the default variable for answer,you can name a variable and do arithmetic calculation as in a calculator >>1+2*3 >>X=1+2*3 >>4*X ans X = ans 7 7 28.0000 Table 1.1:Basic arithmetic operators SYMBOL OPERATION EXAMPLE Addition 2+3 Subtraction 2-3 Multiplication 2*3 Division 2/3
Calculating with Calculating with MatLab • Direct calculation, ans the default variable for answer, you can name a variable and do arithmetic calculation as in a calculator
上海交通大学交大密西根 联合学院一 ◆ 1811 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Started with MatLab Overwrite a variable >> t=5; >>t= t+1 t 6 ·Error message >>X= 10; >>5x ???5x I Error:Unexpected MATLAB expression. ·Precedence >>(1+2)*3 ans 9
Started with Started with MatLab • Overwrite a variable • Error Message • Precedence
上海交通大学交大密西根 联合学院· UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Started with MatLab Display format:Inside MatLab,there is only one date type:double,has 15 digits accuracy >format short >> format long >x=-163.6667 >>x=-1.636666666666667e+002 Get Help,type help command after > 。 Hold the display:putting“;”at the end of a command,will hold display Clear working space:“clear”or“clear all''will erase all the defined variables
Started with Started with MatLab • Display format: Inside MatLab, there is only one date type: double, has 15 digits accuracy • Get Help, type help command after >> • Hold the display: putting “;” at the end of a command, will hold display • Clear working space: “clear” or “clear all” will erase all the defined variables
上海交通大学交大密西根 ·联合学院一 181 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Math Functions in MatLab cos(x) Cosine abs(x) Absolute value sin(x) Sine sign(x) Signum function tan(x) Tangent max (x) Maximum value acos(x) Arc cosine min(x) Minimum value asin(x) Arc sine ceil(x) Round towards +oo atan(x) Arc tangent floor(x) Round towards -o exp(x) Exponential round(x) Round to nearest integer sqrt (x) Square root rem(x) Remainder after division log(x) Natural logarithm angle(x) Phase angle 1og10(x) Common logarithm conj(x) Complex conjugate
Math Functions in Math Functions in MatLab
上海交通大学交大密西根 联合学院一 ◆] 1811 UM-SJTU Joint Institute University of Michigan Shanghal Jiao Tong University Predefined constants in MatLab Table 2.2:Predefined constant values pi The number,=3.14159... i,j The imaginary unit i,v-1 Inf The infinity,o NaN Not a number
Predefined constants in Predefined constants in MatLab