Download presentation
Presentation is loading. Please wait.
Published byBlaise Phelps Modified over 9 years ago
1
ECE 1304 Introduction to Electrical and Computer Engineering Section 1.1 Introduction to MATLAB
2
MATLAB MATLAB stands for “Matrix Laboratory.” MATLAB was developed for applications involving matrices, linear algebra and numerical analysis. MATLAB has built-in capacity for complex numbers.
3
Commands entered here are executed immediately. This is called an Interactive Session. The commands are recorded in the Command History.
4
Numbers and mathematical operations may be entered directly as if in a calculator. The operation returns a value.
5
MATLAB assigns the value to a built-in variable named ans.
6
Scalar Arithmetic Operators
7
The value assigned to the variable named ans may be used in subsequent calculations.
8
The user may enter the variable name and use the assignment operator = to assign a value. In this case the variable is named “ r.”
9
Variable Names Variable names must begin with a letter and may contain up to 32 characters. The characters may include letters, numbers and the under score character. MATLAB is case sensitive. speed and Speed are two different variable names. Chose variable names that make sense for the problem you are solving. This makes programs easier to read.
10
The Assignment Operator The Assignment Operator = behaves differently than the mathematical equality symbol. MATLAB evaluates the expression on the right hand side of the = operator and then assigns that value to the variable on the left hand side of the operator.
11
The Assignment Operator The expression x + 2 = y is meaningless in MATLAB. The expression y = x + 2 is appropriate. Provided x has been assigned a value. MATLAB will find the value of x + 2 then assign that value to the variable y. If x does not have a value MATLAB will display an error message.
12
Numerical Precision MATLAB uses high precision for all of its calculations (14 decimal decimal places?). By default, results are displayed using 4 decimal places. This format may be changed if the user wishes. Numbers are displayed using exponential notation using e to represent a power of ten. 5.3164 10 2 is displayed as 5.3164e+2
13
If the name of a variable is entered, MATLAB will display the value of the variable.
14
After a variable has been assigned a value, that variable may be used in subsequent calculations. The result is assigned to a new variable named s.
15
MATLAB evaluates this expression as “the new value of s is assigned the old value of s plus 160.”
16
Expressions are evaluated according to a built-in order of precedence for the mathematical operators.
17
Order of Precedence
19
The who operator causes MATLAB to display the names of the variables currently stored in the program. The values of the variables are not displayed.
20
The whos operator causes MATLAB to display the names of the variables, the vector size of each variable, the number of bytes required by each variable, the class of variable (double precision in this case) an if the variable is complex.
21
The clear operator removes all variables from memory. The memory space assigned to those variables is reclaimed. Variables may be cleared by name: clear r clear s
22
The clc operator clears the command window. The clc operator does not clears the memory.
23
The clc only changes the appearance of the Command Window.
24
All variables in MATLAB are vectors (arrays) by default. A scalar is a 1 1 vector (array). The colon operator : is used to generate the elements of a vector (array). The operator is evaluated as first element : increment : final value
25
Think of the vector (array) as a list of numbers all assigned to the variable name t. This vector has one row and nine columns.
26
The whos operator indicates the vector is 1 9 in size (one row, nine columns). The total size is 72 bytes (9 numbers at 8 bytes each).
27
The semi-colon operator ; may be used to suppress MATLAB displaying values on the screen. It serves as an end-of-line indicator.
28
MATLAB has the built-in capacity for complex numbers. A complex number has a real part and an imaginary part. i = j = sqrt(–1) is the imaginary unit. Complex number arithmetic must obey a specific set of rules.
29
Complex number addition.
30
Complex number subtraction.
31
Complex number multiplication.
32
Complex number division.
34
The vector x starts at zero and goes to 10 with an increment of 0.01. The brackets [ ] are used to enclose a vector. The sine operation is performed on each element of the vector x and the results are assigned to a vector y. y has the same number of elements as x.
35
The plot command creates a graph. plot( horizontal axis vector, vertical axis vector ) The xlabel and ylabel commands print labels on the axes. The axis names are inside the quotation marks.
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.