Documente Academic
Documente Profesional
Documente Cultură
09-Feb-13
Arithmetic Operations
Variables, Assignment, Expressions
Outline
Variables Assignment Statements Arithmetic Operators Built-in MATLAB Functions
Arithmetic Operations
09-Feb-13
MATLAB Desktop
Current Directory Workspace Browser The prompt Function Browser
Help Browser
What are the usages of these items? Try it and take notes
Command Window
User Input (What you typed) Calculation Results (What MATLAB computed from your statement)
Arithmetic Operations
09-Feb-13
Variables
Variable: a named space for storing a value radius area Valid names start with a letter, can contain digits. Use meaningful variable names. MATLAB is case sensitive (area and Area are different)
Assignment Statement
Variable: a named space for storing a value sum Assignment: putting a value into a variable Assignment operator: = An assignment statement: r= 2*4.5 Expression on Right Hand Side is evaluated before the assignment operation
Arithmetic Operations
09-Feb-13
Assignment Statement
Expression on rhs is evaluated before the assignment operation Examples:
x= 2*3.14 y= 1+x z= 4^2 cos(y)
Scalar vs Array
Scalar: indicates a variable that holds only a single value at a time.
This is compared to an array, which holds many values at once
B = [1.0 2.0 3.0] creates a 1 x 3 row array/vector length(vec): Returns length (# of elements) of vector length(B) returns 3
Arithmetic Operations
09-Feb-13
Operators
+ * / \ ^ Addition Subtraction Multiplication Division (divided by e.g., 10/5 is 2) Division (divided into e.g., 5\10 is 2) Exponentiation (e.g., 5^2 is 25)
Operators Precedence
() ^ *,/,\ +, parentheses exponentiation negation multiplication and division addition and subtraction
Arithmetic Operations
09-Feb-13
(2 x + 3 y ) 2 a= ; 3z + 5
Etter/Ingber
Arithmetic Operations
09-Feb-13
Functions Examples
Evaluate the following expressions (do it by hand then test it on MATLAB): 1. 2. 3. 4. 5. 6. floor(-2.6) abs(-10*2.5) floor(ceil(10.8)) rem(10,3) round(10.4) fix(10.4) ceil(-2.6) abs(-2^5) ceil(floor(10.8)) rem(3,10) round(10.6) fix(10.6)
Arithmetic Operations