# Dr Richard Greenaway

Size: px
Start display at page:

Transcription

1 SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 3 Creating, Organising & Processing Data Dr Richard Greenaway

2 3 Creating, Organising & Processing Data In this Workshop the matrix type is introduced which is the basic type in MATLAB. You will be shown how to create and manipulate matrices and arithmetic operations will be covered in detail. Before looking at the matrix we will study how to manipulate complex numbers. 3.1 Complex Numbers As we have already seen, the symbols i and j by default represent the imaginary number represent a complex number in MATLAB as follows, thus we can z = 2 + 5j In keeping with engineering practice we will use j. Note however that MATLAB always returns i in answers. Alternatively you can create a complex value using the complex function. >> z = complex(2,5) z = i >> You can add, subtract, multiply and divide complex numbers just as you would real numbers. >> z1 = 3-4j z1 = i >> z2 = 1 - j z2 = i >> z1 + z i There are various functions available for operating on complex numbers, some of which are listed in Table 3-1. real imag conj abs angle Function Description Returns the real part of a complex number. Returns the imaginary part of a complex number. Returns the complex conjugate. Returns the magnitude of a complex number. Returns the argument (phase angle) of the complex number. Table 3-1 4PAM1008 Engineering Mathematics Page 3.2

3 Recall that a complex number,, can be represented in polar form as where and ( ) The magnitude, R, can be obtained directly using the abs function and likewise θ can be obtained using angle. >> z = 4 + 7j z = i >> R = abs(z) R = >> theta = angle(z) theta = >> z = R*exp(i*theta) z = i >> You could of course calculate the argument using the inverse tangent (atan function) but angle will always be correct regardless of the quadrant in which the value lies in the complex plane. Exercise Given that and, calculate the following. i) ii) iii) iv) 2. For i) Determine 4PAM1008 Engineering Mathematics Page 3.3

4 De Moivre's theorem states that ii) Convert the value z to exponential form and recalculate using De Moivre's theorem. 3. A circuit with a resistor and inductor in series has total impedance given by Where R is the resistor value and L is the inductance. If an AC current of frequency f Hz is driving the load, the voltage as measured across the two components will be out of phase with the current by an amount θ, equal to the phase angle (argument) of z. i) Determine the phase of the output voltage when ii) Convert the angle to degrees iii) Confirm the result by calculating the angle directly from the equation, ( ) where is the imaginary part and is the real part. 3.2 Matrices The most basic MATLAB data structure is the matrix: a two-dimensional, rectangularly shaped data structure capable of storing multiple elements of data in an easily accessible format. These data elements can be numbers, characters, logical states of true or false, or even other MATLAB structure types. MATLAB uses these two-dimensional matrices to store single numbers and linear series of numbers as well. In these cases, the dimensions are 1-by-1 and 1-by-n respectively, where n is the length of the numeric series. That is, the simple variables you have encountered so far such as x = 10 can be considered as a 1 x 1 matrix. MATLAB also supports data structures that have more than two dimensions. These data structures are referred to as arrays in the MATLAB documentation. We will not cover arrays in this course. We will first discuss how to create, access and manipulate matrices and then cover how operators and functions operate on matrices Creating Matrices 4PAM1008 Engineering Mathematics Page 3.4

5 Constructing a Simple Matrix The simplest way to create a matrix in MATLAB is to use the matrix constructor operator, []. Create a row in the matrix by entering elements (shown as E below) within the brackets. Separate each element with a comma or space: row = [E1, E2,..., Em] or row = [E1 E2... Em] For example, to create a one row matrix of five elements, type >> [ ] To start a new row, terminate the current row with a semicolon: [row1; row2;...; rown] This example constructs a 3 row, 5 column (or 3-by-5) matrix of numbers. Note that all rows must have the same number of elements: [ ; ; ] Exercise 3-2 Create the following matrix. [ ] Generating a Numeric Sequence You will often have need to create a numeric sequence, a vector of equally spaced values, for instance creating a the x-values for a function you wish to evaluate over a range and plot. The colon operator (first:last) generates a 1-by-n matrix (or vector) of sequential numbers from the first value to the last. The default sequence is made up of incremental values, each 1 greater than the previous one: 10: The numeric sequence does not have to be made up of positive integers. It can include negative numbers and fractional numbers as well: 4PAM1008 Engineering Mathematics Page 3.5

6 -2.5: You can change the step value by using the following extended syntax. first:step:last To generate a series of numbers from 10 to 50, incrementing by 5, use 10:5: You can increment by noninteger values. This example increments by 0.2: 3:0.2: To create a sequence with a decrementing interval, specify a negative step value: 9:-1: Exercise Create a vector between -30 and 50 in steps of Create a vector between 0 and in steps of π/ Using Specialised Matrix Functions There are a number of functions provided for generating matrices, some of which are listed in Table 3-3 zeros ones eye magic rand Function Description Create a matrix or array of all zeros. Create a matrix or array of all ones. Create a matrix with ones on the diagonal and zeros elsewhere. Create a square matrix with rows, columns, and diagonals that add up to the same number. Create a matrix or array of uniformly distributed random numbers. Table 3-2 >> rand(5) 4PAM1008 Engineering Mathematics Page 3.6

7 Concatenating Matrices It is simple to concatenate matrices wither row-wise or column-wise using the semi-colon operator or comma operator in the same manner as they are used to construct a matrix. Note the use of square brackets since we are creating a new matrix. >> % Concatenate two matrices row-wise >> ones(1,5) >> B = rand(3,5) B = >> C = [A;B] C = >> % Concatenate two matrices column-wise >> D = [1; 2; 3; 4;] D = >> E = zeros(4,2) E = >> F = [D,E] F = PAM1008 Engineering Mathematics Page 3.7

8 >> Accessing Elements You can access a single element in an array using the following notation A(row,column) >> [2 6 9; 4 2 8; 3 5 1] >> A(2,3) To access multiple elements we us the colon operator. Subscript expressions involving colons refer to portions of a matrix. The expression A(1:m, n) refers to the elements in rows 1 through m of column n of matrix A. A colon on its own specifies the whole row or column. >> A(:,2) The indexing syntax used above to return parts of a matrix can also be used for selectively assigning values to an existing matrix. For instance. >> 1: >> A(2:4) = 0 4PAM1008 Engineering Mathematics Page 3.8

9 You can remove a row or column by assigning an 'empty' matrix - []. >> rand(4) >> A(2,:) = [] Exercise Create a 9 x 9 matrix of random numbers. 2. Set the central 3x3 square elements to zero. 3. Create a 9 x 1 vector of ones. 4. Replace the 8th column with this vector. 5. Reduce the matrix to a 7 x 7 by removing the outer columns and rows. The result should look something like this Other Matrix Operations Here are some other useful matrix operations. 4PAM1008 Engineering Mathematics Page 3.9

10 Transpose A matrix can be transposed simply using the apostrophe operator. >> [ 1 2 3; 4 5 6; 7 8 9] >> B = A' B = Flip a Matrix The flipud and fliplr functions can be used to flip a matrix horizontally or vertically. >> [ 1 2 3; 4 5 6; 7 8 9] >> B =flipud(a) B = Functions and Matrices One of the powerful features of MATLAB is the way functions handle inputs of vectors and matrices. Consider for example the standard trigonometric functions sin, cos etc. In MATLAB, as in all generic languages, if you pass a value to the function it will return the associated result of the specified operation. However if you pass a matrix, the function will return a matrix of the same size containing the results calculated for all the input values. Consider calculating the sine of 3 values. Here is how you would do it in the C programming language. double result [3]; double vector [3] = { 0.01, /2, }; for (int i = 0 ; i<3 ;i++) { result[i] = sin(vector[i]); } In MATLAB it takes just one line 4PAM1008 Engineering Mathematics Page 3.10

11 >> sin([0.001 pi/2 pi]) Now consider functions which operate on multiple values by default. To calculate the average of a set of values we use the mean function and pass a vector containing those values. >> a = rand(1,10) a = >> mean(a) Now, in the case where the input is a matrix the behaviour is different from that of functions like sin. mean does not calculate the average of all the values but treats each column as a separate vector. >> rand(10,5) >> mean(a) This columnwise behaviour occurs frequently. Another example is data plotting, where if you pass a matrix to the plot function, it will treat each column in the matrix as a separate data set. Thus if you pass an n x 3 matrix to plot you will get a graph with 3 lines plotted. Here is an example. 4PAM1008 Engineering Mathematics Page 3.11

12 Example. 3-1 >> % Create the values of theta for which we sill calculate sine and cosine >> x = 0:0.1:2*pi; >> % Transpose it to make it a column vector >> x = x'; >> % Calculate sine and cosine for those angles and put the results in an n x 2 matrix >> result = [sin(x), cos(x) ]; >> % plot the sine and cosine curves against angle >> plot(x,result) The plot should look like this Fig. 1 The result from Example. 3-1 Exercise 3-5 Calculate ( ) ( ) for at intervals of 0.1 radians. Plot the results. You must use the sin and plot functions only once. HINT After you create the numeric sequence you must convert it from a row of numbers to a column of numbers using the transpose operator. 4PAM1008 Engineering Mathematics Page 3.12

13 3.4 Arithmetic Operations You have already used arithmetic operators when dealing with single values. We will now generalise their use to matrices. You should begin to see how powerful MATLAB is at processing data and how easy it is to operate on complete data sets without the need for traditional loop constructs used in generic programming languages Addition and Subtraction Two matrices of the same size can be added or subtracted. The operation is done on an element by element basis. You can also add a scalar to a matrix. >> ones(3) >> B = A + 4 B = >> C = eye(3) C = >> D = B + C D = Multiplication The multiply operator, *, we have seen earlier in fact implements a matrix multiply operation. That is, the product of an m p matrix A with an p n matrix B is an m n matrix C whose entries are And in general, So, in MATLAB, 4PAM1008 Engineering Mathematics Page 3.13

14 >> [ 1 2 3; 4 5 6] >> B = [1 2 ; 3 4 ; 5 6] B = >> A*B >> B*A Remember, the inner matrix dimensions must agree. That is, the number of columns in the left operand must equal the number of rows in the right operand. >> [ ; ] >> B = [1 2 ; 3 4 ; 5 6] B = >> A * B??? Error using ==> mtimes Inner matrix dimensions must agree. 4PAM1008 Engineering Mathematics Page 3.14

15 3.4.3 Division (Solving Systems of Linear Equations) Recall that we can use matrices to solve systems of linear equations. The following equations can be represented in matrix form as The general form for a system of linear equations is * + * + * + which can be solved as follows. In MATLAB we could solve the equation set above as follows. >> [1 3 ; 3-2] >> b = [7 ; -12] b = 7-12 >> inv(a)*b However, there is a quicker way to do this without explicitly determining the inverse matrix and that is to carry out a matrix left division using the back-slash operator. >> [1 3 ; 3-2] >> b = [7 ; -12] b = PAM1008 Engineering Mathematics Page 3.15

16 >> u = A\b u = -2 3 Functionally, A\B corresponds to inv(a)*b. Exercise 3-6 Solve the following equations Explain this answer 4. Explain this answer 5. Repeat question 4 by calculating the inverse explicitly Matrix Power Since, for example The power operator simply does a matrix multiply of a matrix by itself n times where n is the exponent. 4PAM1008 Engineering Mathematics Page 3.16

17 3.5 Element-wise (Array) Arithmetic Operations When operating on matrices there are other forms of arithmetic operation which are of importance, in particular operations which act on the elements of a matrix or vector individually, known in MATLAB as array operations Array Multiplication (the Hadamard Product) Array multiplication (known as the Hadamard Product) is used extensively in MATLAB. This is the entrywise product of two matrices of the same size, or of a matrix and a scalar. The Hadamard product of A and B is where, In MATLAB we use the dot-star operator : '.*' to compute this product. >> [1 2 ;3 4] >> A.*A This operator is particularly useful in MATLAB because it allows us to do an element-by-element multiply of data in a single command. That is we can generate multiple data points for complex functions which are the product of two or more other functions in one line of code Array Division The division equivalent of array multiplication is exactly what you would expect. If matrix A is divided by matrix B, the result is a matrix of the same size where each element is the result of dividing the corresponding elements of A by B. >> a = ones(1,5) a = >> b = 1:5 b = >> a./b 4PAM1008 Engineering Mathematics Page 3.17

18 Array Power Finally, array power can be used to raise individual elements of a matrix to powers. The exponent can be a scalar in which case all elements of the matrix are raised to the same power or a matrix of the same size as the operand in which case each element of the matrix is raised to the power of the value in the corrrsponding element of the exponent matrix. >> a = ones(1,4)*2 a = >> b = 1:4 b = >> a.^b Now try the following exercises. Exercise 3-7 Consider the following function. ( ) ( ) ( ) Generate values for the given function at intervals of between 0 and and plot the resulting data following the steps below. 1. Generate a vector of theta values at the specified interval and over the specified range for N=6. (section ) 2. Determine y for all values of theta. Since y is the product of two functions, ( ) ( ). To calculate ( ) we must evaluate ( ) and ( ) and then take the product and do this for each value of θ. Thus you use the array product. Similarly, you must use the array power operator to calculate 3. Now plot the function using the plot command. Type help plot to see how to use it. 4PAM1008 Engineering Mathematics Page 3.18

19 3.6 Relational Operations and Logical Vectors Relational operators compare operands quantitatively, using operators like "less than" and "not equal to." The following table provides a summary. < Less than <= Less than or equal to > Greater than >= Greater than or equal to == Equal to ~= Not equal to Table 3-3 Logical operators return a logical true or false represented as 1 and 0 respectively as illustrated in the example below. >> 3 > 6 0 >> 3 < 6 1 The answer generated is not the integer value 1 but the logical value 1. A value of type logical can only have two states, either 1 (true) or 0 (false). When applied to a matrix or vector a relational operator works on an element-by-element basis. >> a = 1:5 a = >> b = ones(1,5)*3 b = >> a > b PAM1008 Engineering Mathematics Page 3.19

20 That is, a > b is false for the first three elements and true for the last two. What makes this type of operation so powerful is that logical vectors can be used to index elements in a matrix, thus we can find data within a data set (a vector or matrix) which conform to some relational test. An example should make this clear. >> x = 0 : pi/20 : 3*pi; % Generate theta values >> y = sin(x); >> neg = y < 0; % find all values of sin(x) less than 0 >> y(neg) = 0; % set all those values to 0 >> plot(x,y); The result looks like this The operation y<0 returns a logical vector with 1s in elements corresponding to values in the y vector less than zero and 0s in all the other elements. This vector is stored as the variable neg. When neg is used to index y (as in y(neg)), it indexes all elements in y less than zero, and so y(neg)= 0 replaces all negative values with zero. We can reduce the number of steps required to do the above exercise to 4 as follows. Exercise 3-8 Carry out the following steps. >> x = 0 : pi/20 : 3*pi; >> y = sin(x); >> y = y.* (y > 0); >> plot(x,y) 4PAM1008 Engineering Mathematics Page 3.20

21 Can you see how that works? Do it yourself and look at the output from each step. You can break down the operations in any way you want. For instance, look at what y>0 does by typing it on its own and then do the array multiply. Here is an exercise to try. Exercise Plot the graph of between and. Define angles x at intervals of. theta = -3/2*pi : pi/100 : 3/2*pi; y = tan(theta); plot(theta,y); If you've done it correctly you should get a plot that looks like this. 6 x It doesn't look much like a tan θ curve unfortunately, why is that? Well as θ approaches odd-multiples of π/2, tan θ approaches ±. Look at the y-axis and you'll see that the peak values are huge. The structure of the curve is lost. To solve this problem we need to locate the values of tan θ that are very large (negative and positive) and replace them with zeros. 2. Replace the values of y which are greater than some arbitrary large number (it's not crucial, but look at the plot above) by zero and then re-plot the graph. We can do this as follows. Locate all values less than our 'arbitrary' large number. 4PAM1008 Engineering Mathematics Page 3.21

22 result = (abs(y) < 1e10); The vector result will have ones where the (absolute) value of y is less than and zeros elsewhere. So if we multiply y by this vector, that should get rid of the large values. You don't have to split the task, you can remove the large values from y in a single line. Try that now and then re-plot the data. If you get it right it should look like this PAM1008 Engineering Mathematics Page 3.22

23 Exercise 3-10 We are going to plot a function known as the sinc function which has the following form. 1. Define theta values between -3π/2 and 3π/2 in steps of π/10. theta = -3/2*pi : pi/10 : 3/2*pi; 2. Now create the sinc function. Remember you have use array division. y = sin(theta)./theta; 3. Now plot the result using the plot function. plot(theta,y) Notice that the curve has no value at theta = 0. That's because. which, as far as MATLAB is concerned, is undefined 1. MATLAB handles it very well, in such a situation it returns the special value NaN (not-a-number) which is ignored when plotting, hence the gap in the plot. We nevertheless have a missing value, so how can we deal in general with problems like this? 1 It is evident from the curve of course that is defined which can be proven from L'Hôpital's rule which states that if ( ) ( ) then ( ) ( ) ( ) ( ) and therefore ( ) 4PAM1008 Engineering Mathematics Page 3.23

24 If we replace the angle 0 with a very small number (ie an approximation to zero) then our function will work. MATLAB provides such a number, eps. eps returns the 'distance' between contiguous floating point numbers as they are represented in MATLAB, the 'resolution' of floating point numbers if you like. 4. Type eps in the command window to see what value it is. 5. Now see what happens when you put this angle into the equation. Calculate, ( ). So now all we have to do is find θ = 0 in our vector of θ values and replace it with eps and recalculate the sinc function. Again, we can do it with logical vectors. 6. In the theta vector replace all occurrences of 0 with eps. theta2 = theta + (theta == 0)*eps; Compare the values in theta2 with those in theta. How does the line above work. 7. Recalculate the sinc function and re-plot it. 3.7 Operator Precedence You can build expressions that use any combination of arithmetic, relational, and logical operators. Precedence levels determine the order in which MATLAB evaluates an expression. Within each precedence level, operators have equal precedence and are evaluated from left to right. The precedence rules for MATLAB operators are shown in this list, ordered from highest precedence level to lowest precedence level: 1. Parentheses () 2. Transpose (.'), power (.^), complex conjugate transpose ('), matrix power (^) 3. Unary plus (+), unary minus (-), logical negation (~) 4. Multiplication (.*), right division (./), left division (.\), matrix multiplication (*), matrix right division (/), matrix left division (\) 5. Addition (+), subtraction (-) 6. Colon operator (:) 7. Less than (<), less than or equal to (<=), greater than (>), greater than or equal to (>=), equal to (==), not equal to (~=) 8. Element-wise AND (&) 9. Element-wise OR ( ) 10. Short-circuit AND (&&) 11. Short-circuit OR ( ) 4PAM1008 Engineering Mathematics Page 3.24

25 3.8 Saving and Reading Data Saving Data Data in the MATLAB workspace can be saved to special files with the extension mat. Typing save on the command line will save all the data to the default file matlab.mat. Alternatively you can save selected variables to a file name of your choice. The following command will save two matrices, A and c to the file test.mat. >> save 'test' A c When you save data to a file it will overwrite any existing file of the same name so you will lose whatever data had been previously saved. If you want to add data to an existing file then use the -append option as follows. >> save 'test' B -append The file test.mat will now contain 3 variables, A, B and c. There are various other ways to export data from MATLAB to formats such as csv, excel files, text files etc Reading Data Data previously saved to mat files can be read back in to the MATLAB workspace using the load function. If the data was saved to the default matlab.mat file then simply type load and all the variables will be restored to the workspace. For other files you must specify the filename. >> load 'test' 4PAM1008 Engineering Mathematics Page 3.25

### Dr Richard Greenaway

SCHOOL OF PHYSICS, ASTRONOMY & MATHEMATICS 4PAM1008 MATLAB 2 Basic MATLAB Operation Dr Richard Greenaway 2 Basic MATLAB Operation 2.1 Overview 2.1.1 The Command Line In this Workshop you will learn how

### MATH (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab

MATH 495.3 (CRN 13695) Lab 1: Basics for Linear Algebra and Matlab Below is a screen similar to what you should see when you open Matlab. The command window is the large box to the right containing the

### A Guide to Using Some Basic MATLAB Functions

A Guide to Using Some Basic MATLAB Functions UNC Charlotte Robert W. Cox This document provides a brief overview of some of the essential MATLAB functionality. More thorough descriptions are available

### Experiment 1: Introduction to MATLAB I. Introduction. 1.1 Objectives and Expectations: 1.2 What is MATLAB?

Experiment 1: Introduction to MATLAB I Introduction MATLAB, which stands for Matrix Laboratory, is a very powerful program for performing numerical and symbolic calculations, and is widely used in science

### Introduction to MATLAB Programming

Introduction to MATLAB Programming Arun A. Balakrishnan Asst. Professor Dept. of AE&I, RSET Overview 1 Overview 2 Introduction 3 Getting Started 4 Basics of Programming Overview 1 Overview 2 Introduction

### Lecture 2: Variables, Vectors and Matrices in MATLAB

Lecture 2: Variables, Vectors and Matrices in MATLAB Dr. Mohammed Hawa Electrical Engineering Department University of Jordan EE201: Computer Applications. See Textbook Chapter 1 and Chapter 2. Variables

### Constraint-based Metabolic Reconstructions & Analysis H. Scott Hinton. Matlab Tutorial. Lesson: Matlab Tutorial

1 Matlab Tutorial 2 Lecture Learning Objectives Each student should be able to: Describe the Matlab desktop Explain the basic use of Matlab variables Explain the basic use of Matlab scripts Explain the

### 1 Introduction to Matlab

1 Introduction to Matlab 1. What is Matlab? Matlab is a computer program designed to do mathematics. You might think of it as a super-calculator. That is, once Matlab has been started, you can enter computations,

### EGR 111 Introduction to MATLAB

EGR 111 Introduction to MATLAB This lab introduces the MATLAB help facility, shows how MATLAB TM, which stands for MATrix LABoratory, can be used as an advanced calculator. This lab also introduces assignment

### Matlab Tutorial. The value assigned to a variable can be checked by simply typing in the variable name:

1 Matlab Tutorial 1- What is Matlab? Matlab is a powerful tool for almost any kind of mathematical application. It enables one to develop programs with a high degree of functionality. The user can write

### Introduction to Matlab. By: Dr. Maher O. EL-Ghossain

Introduction to Matlab By: Dr. Maher O. EL-Ghossain Outline: q What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control

### Lab of COMP 406. MATLAB: Quick Start. Lab tutor : Gene Yu Zhao Mailbox: or Lab 1: 11th Sep, 2013

Lab of COMP 406 MATLAB: Quick Start Lab tutor : Gene Yu Zhao Mailbox: csyuzhao@comp.polyu.edu.hk or genexinvivian@gmail.com Lab 1: 11th Sep, 2013 1 Where is Matlab? Find the Matlab under the folder 1.

### MATLAB Tutorial Matrices & Vectors MATRICES AND VECTORS

MATRICES AND VECTORS A matrix (m x n) with m rows and n columns, a column vector (m x 1) with m rows and 1 column, and a row vector (1 x m) with 1 row and m columns all can be used in MATLAB. Matrices

### Creates a 1 X 1 matrix (scalar) with a value of 1 in the column 1, row 1 position and prints the matrix aaa in the command window.

EE 350L: Signals and Transforms Lab Spring 2007 Lab #1 - Introduction to MATLAB Lab Handout Matlab Software: Matlab will be the analytical tool used in the signals lab. The laboratory has network licenses

### MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MATLAB sessions: Laboratory MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs

### ELEN E3084: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals

ELEN E384: Signals and Systems Lab Lab II: Introduction to Matlab (Part II) and Elementary Signals 1 Introduction In the last lab you learn the basics of MATLAB, and had a brief introduction on how vectors

### Physics 326G Winter Class 2. In this class you will learn how to define and work with arrays or vectors.

Physics 326G Winter 2008 Class 2 In this class you will learn how to define and work with arrays or vectors. Matlab is designed to work with arrays. An array is a list of numbers (or other things) arranged

### PowerPoints organized by Dr. Michael R. Gustafson II, Duke University

Part 1 Chapter 2 MATLAB Fundamentals PowerPoints organized by Dr. Michael R. Gustafson II, Duke University All images copyright The McGraw-Hill Companies, Inc. Permission required for reproduction or display.

### Part #1. A0B17MTB Matlab. Miloslav Čapek Filip Kozák, Viktor Adler, Pavel Valtr

A0B17MTB Matlab Part #1 Miloslav Čapek miloslav.capek@fel.cvut.cz Filip Kozák, Viktor Adler, Pavel Valtr Department of Electromagnetic Field B2-626, Prague You will learn Scalars, vectors, matrices (class

### MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB

MAT 343 Laboratory 1 Matrix and Vector Computations in MATLAB MATLAB is a computer software commonly used in both education and industry to solve a wide range of problems. This Laboratory provides a brief

### Introduction to Matlab

Introduction to Matlab By:Mohammad Sadeghi *Dr. Sajid Gul Khawaja Slides has been used partially to prepare this presentation Outline: What is Matlab? Matlab Screen Basic functions Variables, matrix, indexing

### Arithmetic and Logic Blocks

Arithmetic and Logic Blocks The Addition Block The block performs addition and subtractions on its inputs. This block can add or subtract scalar, vector, or matrix inputs. We can specify the operation

### Chapter 2. MATLAB Fundamentals

Chapter 2. MATLAB Fundamentals Choi Hae Jin Chapter Objectives q Learning how real and complex numbers are assigned to variables. q Learning how vectors and matrices are assigned values using simple assignment,

### Introduction to MATLAB

to MATLAB Spring 2019 to MATLAB Spring 2019 1 / 39 The Basics What is MATLAB? MATLAB Short for Matrix Laboratory matrix data structures are at the heart of programming in MATLAB We will consider arrays

### A very brief Matlab introduction

A very brief Matlab introduction Siniša Krajnović January 24, 2006 This is a very brief introduction to Matlab and its purpose is only to introduce students of the CFD course into Matlab. After reading

### OUTLINES. Variable names in MATLAB. Matrices, Vectors and Scalar. Entering a vector Colon operator ( : ) Mathematical operations on vectors.

1 LECTURE 3 OUTLINES Variable names in MATLAB Examples Matrices, Vectors and Scalar Scalar Vectors Entering a vector Colon operator ( : ) Mathematical operations on vectors examples 2 VARIABLE NAMES IN

### CME 192: Introduction to Matlab

CME 192: Introduction to Matlab Matlab Basics Brett Naul January 15, 2015 Recap Using the command window interactively Variables: Assignment, Identifier rules, Workspace, command who and whos Setting the

### MATLAB Tutorial EE351M DSP. Created: Thursday Jan 25, 2007 Rayyan Jaber. Modified by: Kitaek Bae. Outline

MATLAB Tutorial EE351M DSP Created: Thursday Jan 25, 2007 Rayyan Jaber Modified by: Kitaek Bae Outline Part I: Introduction and Overview Part II: Matrix manipulations and common functions Part III: Plots

### Vectors and Matrices. Chapter 2. Linguaggio Programmazione Matlab-Simulink (2017/2018)

Vectors and Matrices Chapter 2 Linguaggio Programmazione Matlab-Simulink (2017/2018) Matrices A matrix is used to store a set of values of the same type; every value is stored in an element MATLAB stands

### MATLAB Fundamentals. Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University

MATLAB Fundamentals Berlin Chen Department of Computer Science & Information Engineering National Taiwan Normal University Reference: 1. Applied Numerical Methods with MATLAB for Engineers, Chapter 2 &

### ARRAY VARIABLES (ROW VECTORS)

11 ARRAY VARIABLES (ROW VECTORS) % Variables in addition to being singular valued can be set up as AN ARRAY of numbers. If we have an array variable as a row of numbers we call it a ROW VECTOR. You can

### Chapter 1 Introduction to MATLAB

Chapter 1 Introduction to MATLAB 1.1 What is MATLAB? MATLAB = MATrix LABoratory, the language of technical computing, modeling and simulation, data analysis and processing, visualization and graphics,

### Ordinary Differential Equation Solver Language (ODESL) Reference Manual

Ordinary Differential Equation Solver Language (ODESL) Reference Manual Rui Chen 11/03/2010 1. Introduction ODESL is a computer language specifically designed to solve ordinary differential equations (ODE

### McTutorial: A MATLAB Tutorial

McGill University School of Computer Science Sable Research Group McTutorial: A MATLAB Tutorial Lei Lopez Last updated: August 2014 w w w. s a b l e. m c g i l l. c a Contents 1 MATLAB BASICS 3 1.1 MATLAB

### Programming in Mathematics. Mili I. Shah

Programming in Mathematics Mili I. Shah Starting Matlab Go to http://www.loyola.edu/moresoftware/ and login with your Loyola name and password... Matlab has eight main windows: Command Window Figure Window

### This is a basic tutorial for the MATLAB program which is a high-performance language for technical computing for platforms:

Appendix A Basic MATLAB Tutorial Extracted from: http://www1.gantep.edu.tr/ bingul/ep375 http://www.mathworks.com/products/matlab A.1 Introduction This is a basic tutorial for the MATLAB program which

### AN INTRODUCTION TO MATLAB

AN INTRODUCTION TO MATLAB 1 Introduction MATLAB is a powerful mathematical tool used for a number of engineering applications such as communication engineering, digital signal processing, control engineering,

### Introduction to MatLab. Introduction to MatLab K. Craig 1

Introduction to MatLab Introduction to MatLab K. Craig 1 MatLab Introduction MatLab and the MatLab Environment Numerical Calculations Basic Plotting and Graphics Matrix Computations and Solving Equations

### LAB 1 General MATLAB Information 1

LAB 1 General MATLAB Information 1 General: To enter a matrix: > type the entries between square brackets, [...] > enter it by rows with elements separated by a space or comma > rows are terminated by

### Interactive Computing with Matlab. Gerald W. Recktenwald Department of Mechanical Engineering Portland State University

Interactive Computing with Matlab Gerald W. Recktenwald Department of Mechanical Engineering Portland State University gerry@me.pdx.edu Starting Matlab Double click on the Matlab icon, or on unix systems

### Section 7.6 Graphs of the Sine and Cosine Functions

Section 7.6 Graphs of the Sine and Cosine Functions We are going to learn how to graph the sine and cosine functions on the xy-plane. Just like with any other function, it is easy to do by plotting points.

### A General Introduction to Matlab

Master Degree Course in ELECTRONICS ENGINEERING http://www.dii.unimore.it/~lbiagiotti/systemscontroltheory.html A General Introduction to Matlab e-mail: luigi.biagiotti@unimore.it http://www.dii.unimore.it/~lbiagiotti

### EEE161 Applied Electromagnetics Laboratory 1

EEE161 Applied Electromagnetics Laboratory 1 Instructor: Dr. Milica Marković Office: Riverside Hall 3028 Email: milica@csus.edu Web:http://gaia.ecs.csus.edu/ milica This laboratory exercise will introduce

### FreeMat Tutorial. 3x + 4y 2z = 5 2x 5y + z = 8 x x + 3y = -1 xx

1 of 9 FreeMat Tutorial FreeMat is a general purpose matrix calculator. It allows you to enter matrices and then perform operations on them in the same way you would write the operations on paper. This

### Introduction to Octave/Matlab. Deployment of Telecommunication Infrastructures

Introduction to Octave/Matlab Deployment of Telecommunication Infrastructures 1 What is Octave? Software for numerical computations and graphics Particularly designed for matrix computations Solving equations,

### To start using Matlab, you only need be concerned with the command window for now.

Getting Started Current folder window Atop the current folder window, you can see the address field which tells you where you are currently located. In programming, think of it as your current directory,

### Introduction to MATLAB

Introduction to MATLAB Basics MATLAB is a high-level interpreted language, and uses a read-evaluate-print loop: it reads your command, evaluates it, then prints the answer. This means it works a lot like

### Chapter 1 MATLAB Preliminaries

Chapter 1 MATLAB Preliminaries 1.1 INTRODUCTION MATLAB (Matrix Laboratory) is a high-level technical computing environment developed by The Mathworks, Inc. for mathematical, scientific, and engineering

### What is MATLAB? What is MATLAB? Programming Environment MATLAB PROGRAMMING. Stands for MATrix LABoratory. A programming environment

What is MATLAB? MATLAB PROGRAMMING Stands for MATrix LABoratory A software built around vectors and matrices A great tool for numerical computation of mathematical problems, such as Calculus Has powerful

### Introduction to MATLAB

Introduction to MATLAB Introduction MATLAB is an interactive package for numerical analysis, matrix computation, control system design, and linear system analysis and design available on most CAEN platforms

### \n is used in a string to indicate the newline character. An expression produces data. The simplest expression

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

### Lecture 2. Arrays. 1 Introduction

1 Introduction Lecture 2 Arrays As the name Matlab is a contraction of matrix laboratory, you would be correct in assuming that Scilab/Matlab have a particular emphasis on matrices, or more generally,

### Section 6.2 Graphs of the Other Trig Functions

Section 62 Graphs of the Other Trig Functions 369 Section 62 Graphs of the Other Trig Functions In this section, we will explore the graphs of the other four trigonometric functions We ll begin with the

### MATLAB Tutorial. Digital Signal Processing. Course Details. Topics. MATLAB Environment. Introduction. Digital Signal Processing (DSP)

Digital Signal Processing Prof. Nizamettin AYDIN naydin@yildiz.edu.tr naydin@ieee.org http://www.yildiz.edu.tr/~naydin Course Details Course Code : 0113620 Course Name: Digital Signal Processing (Sayısal

### MATLAB TUTORIAL WORKSHEET

MATLAB TUTORIAL WORKSHEET What is MATLAB? Software package used for computation High-level programming language with easy to use interactive environment Access MATLAB at Tufts here: https://it.tufts.edu/sw-matlabstudent

### MATLAB SUMMARY FOR MATH2070/2970

MATLAB SUMMARY FOR MATH2070/2970 DUNCAN SUTHERLAND 1. Introduction The following is inted as a guide containing all relevant Matlab commands and concepts for MATH2070 and 2970. All code fragments should

### MATLAB: The Basics. Dmitry Adamskiy 9 November 2011

MATLAB: The Basics Dmitry Adamskiy adamskiy@cs.rhul.ac.uk 9 November 2011 1 Starting Up MATLAB Windows users: Start up MATLAB by double clicking on the MATLAB icon. Unix/Linux users: Start up by typing

### MATLAB Constants, Variables & Expression. 9/12/2015 By: Nafees Ahmed

MATLAB Constants, Variables & Expression Introduction MATLAB can be used as a powerful programming language. It do have IF, WHILE, FOR lops similar to other programming languages. It has its own vocabulary

### Matrices. A Matrix (This one has 2 Rows and 3 Columns) To add two matrices: add the numbers in the matching positions:

Matrices A Matrix is an array of numbers: We talk about one matrix, or several matrices. There are many things we can do with them... Adding A Matrix (This one has 2 Rows and 3 Columns) To add two matrices:

### 9 Using Equation Networks

9 Using Equation Networks In this chapter Introduction to Equation Networks 244 Equation format 247 Using register address lists 254 Setting up an enable contact 255 Equations displayed within the Network

### MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED. Christian Daude 1

MATLAB COURSE FALL 2004 SESSION 1 GETTING STARTED Christian Daude 1 Introduction MATLAB is a software package designed to handle a broad range of mathematical needs one may encounter when doing scientific

### MATLAB Basics. Configure a MATLAB Package 6/7/2017. Stanley Liang, PhD York University. Get a MATLAB Student License on Matworks

MATLAB Basics Stanley Liang, PhD York University Configure a MATLAB Package Get a MATLAB Student License on Matworks Visit MathWorks at https://www.mathworks.com/ It is recommended signing up with a student

### Introduction to MATLAB

Introduction to MATLAB The Desktop When you start MATLAB, the desktop appears, containing tools (graphical user interfaces) for managing files, variables, and applications associated with MATLAB. The following

### 2.0 MATLAB Fundamentals

2.0 MATLAB Fundamentals 2.1 INTRODUCTION MATLAB is a computer program for computing scientific and engineering problems that can be expressed in mathematical form. The name MATLAB stands for MATrix LABoratory,

### Introduction to Matlab

Introduction to Matlab Andreas C. Kapourani (Credit: Steve Renals & Iain Murray) 9 January 08 Introduction MATLAB is a programming language that grew out of the need to process matrices. It is used extensively

### Chapter 1 Summary. Chapter 2 Summary. end of a string, in which case the string can span multiple lines.

Chapter 1 Summary Comments are indicated by a hash sign # (also known as the pound or number sign). Text to the right of the hash sign is ignored. (But, hash loses its special meaning if it is part of

### MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences. Introductory remarks

MATLAB Workshop Dr. M. T. Mustafa Department of Mathematical Sciences Introductory remarks MATLAB: a product of mathworks www.mathworks.com MATrix LABoratory What can we do (in or ) with MATLAB o Use like

### Lecturer: Keyvan Dehmamy

MATLAB Tutorial Lecturer: Keyvan Dehmamy 1 Topics Introduction Running MATLAB and MATLAB Environment Getting help Variables Vectors, Matrices, and linear Algebra Mathematical Functions and Applications

### Laboratory 1 Introduction to MATLAB for Signals and Systems

Laboratory 1 Introduction to MATLAB for Signals and Systems INTRODUCTION to MATLAB MATLAB is a powerful computing environment for numeric computation and visualization. MATLAB is designed for ease of use

### Class #15: Experiment Introduction to Matlab

Class #15: Experiment Introduction to Matlab Purpose: The objective of this experiment is to begin to use Matlab in our analysis of signals, circuits, etc. Background: Before doing this experiment, students

### Finding, Starting and Using Matlab

Variables and Arrays Finding, Starting and Using Matlab CSC March 6 &, 9 Array: A collection of data values organized into rows and columns, and known by a single name. arr(,) Row Row Row Row 4 Col Col

### It can be confusing when you type something like the expressions below and get an error message. a range variable definition a vector of sine values

7_april_ranges_.mcd Understanding Ranges, Sequences, and Vectors Introduction New Mathcad users are sometimes confused by the difference between range variables and vectors. This is particularly true considering

### Introduction to MATLAB

Chapter 1 Introduction to MATLAB 1.1 Software Philosophy Matrix-based numeric computation MATrix LABoratory built-in support for standard matrix and vector operations High-level programming language Programming

### ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah)

Introduction ELEC4042 Signal Processing 2 MATLAB Review (prepared by A/Prof Ambikairajah) MATLAB is a powerful mathematical language that is used in most engineering companies today. Its strength lies

### MAT 275 Laboratory 2 Matrix Computations and Programming in MATLAB

MAT 75 Laboratory Matrix Computations and Programming in MATLAB In this laboratory session we will learn how to. Create and manipulate matrices and vectors.. Write simple programs in MATLAB NOTE: For your

### Arrays and Matrix Operations

9 Arrays and Matrix Operations 1 THE PRIMARY MATLAB DATA STRUCTURE As we have previously stated, the basic data element in the MATLAB system is the array. A scalar is represented as a 1 * 1 array that

### Introduction to Matlab

Introduction to Matlab 1 Outline: What is Matlab? Matlab Screen Variables, array, matrix, indexing Operators (Arithmetic, relational, logical ) Display Facilities Flow Control Using of M-File Writing User

### TUTORIAL 1 Introduction to Matrix Calculation using MATLAB TUTORIAL 1 INTRODUCTION TO MATRIX CALCULATION USING MATLAB

INTRODUCTION TO MATRIX CALCULATION USING MATLAB Learning objectives Getting started with MATLAB and it s user interface Learn some of MATLAB s commands and syntaxes Get a simple introduction to use of

### Introduction to MATLAB

ELG 3125 - Lab 1 Introduction to MATLAB TA: Chao Wang (cwang103@site.uottawa.ca) 2008 Fall ELG 3125 Signal and System Analysis P. 1 Do You Speak MATLAB? MATLAB - The Language of Technical Computing ELG

### Operators. Java operators are classified into three categories:

Operators Operators are symbols that perform arithmetic and logical operations on operands and provide a meaningful result. Operands are data values (variables or constants) which are involved in operations.

### Digital Image Analysis and Processing CPE

Digital Image Analysis and Processing CPE 0907544 Matlab Tutorial Dr. Iyad Jafar Outline Matlab Environment Matlab as Calculator Common Mathematical Functions Defining Vectors and Arrays Addressing Vectors

### MATLAB Tutorial. Mohammad Motamed 1. August 28, generates a 3 3 matrix.

MATLAB Tutorial 1 1 Department of Mathematics and Statistics, The University of New Mexico, Albuquerque, NM 87131 August 28, 2016 Contents: 1. Scalars, Vectors, Matrices... 1 2. Built-in variables, functions,

### Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017

Part V Appendices c Copyright, Todd Young and Martin Mohlenkamp, Department of Mathematics, Ohio University, 2017 Appendix A Glossary of Matlab Commands Mathematical Operations + Addition. Type help plus

### Math 3 Coordinate Geometry Part 2 Graphing Solutions

Math 3 Coordinate Geometry Part 2 Graphing Solutions 1 SOLVING SYSTEMS OF EQUATIONS GRAPHICALLY The solution of two linear equations is the point where the two lines intersect. For example, in the graph

### EGR 111 Functions and Relational Operators

EGR 111 Functions and Relational Operators This lab is an introduction to writing your own MATLAB functions. The lab also introduces relational operators and logical operators which allows MATLAB to compare

### Introduction to MATLAB Practical 1

Introduction to MATLAB Practical 1 Daniel Carrera November 2016 1 Introduction I believe that the best way to learn Matlab is hands on, and I tried to design this practical that way. I assume no prior

### University of Alberta

A Brief Introduction to MATLAB University of Alberta M.G. Lipsett 2008 MATLAB is an interactive program for numerical computation and data visualization, used extensively by engineers for analysis of systems.

### Matlab Tutorial. Get familiar with MATLAB by using tutorials and demos found in MATLAB. You can click Start MATLAB Demos to start the help screen.

University of Illinois at Urbana-Champaign Department of Electrical and Computer Engineering ECE 298JA Fall 2015 Matlab Tutorial 1 Overview The goal of this tutorial is to help you get familiar with MATLAB

### Introduction to Matlab

What is Matlab? Introduction to Matlab Matlab is software written by a company called The Mathworks (mathworks.com), and was first created in 1984 to be a nice front end to the numerical routines created

### LAB 2 VECTORS AND MATRICES

EN001-4: Intro to Computational Design Tufts University, Department of Computer Science Prof. Soha Hassoun LAB 2 VECTORS AND MATRICES 1.1 Background Overview of data types Programming languages distinguish

### Introduction to Scientific and Engineering Computing, BIL108E. Karaman

USING MATLAB INTRODUCTION TO SCIENTIFIC & ENGINEERING COMPUTING BIL 108E, CRN24023 To start from Windows, Double click the Matlab icon. To start from UNIX, Dr. S. Gökhan type matlab at the shell prompt.

### A brief introduction to SCILAB

A brief introduction to SCILAB SCILAB is a powerful and versatile package for mathematical modelling and an excellent tool for solving a wide range of engineering problems. SCILAB supports simple interactive

### Mathematical Operations with Arrays and Matrices

Mathematical Operations with Arrays and Matrices Array Operators (element-by-element) (important) + Addition A+B adds B and A - Subtraction A-B subtracts B from A.* Element-wise multiplication.^ Element-wise

### PART 1 PROGRAMMING WITH MATHLAB

PART 1 PROGRAMMING WITH MATHLAB Presenter: Dr. Zalilah Sharer 2018 School of Chemical and Energy Engineering Universiti Teknologi Malaysia 23 September 2018 Programming with MATHLAB MATLAB Environment

### How to learn MATLAB? Some predefined variables

ECE-S352 Lab 1 MATLAB Tutorial How to learn MATLAB? 1. MATLAB comes with good tutorial and detailed documents. a) Select MATLAB help from the MATLAB Help menu to open the help window. Follow MATLAB s Getting

### STAT/MATH 395 A - PROBABILITY II UW Winter Quarter Matlab Tutorial

STAT/MATH 395 A - PROBABILITY II UW Winter Quarter 2016 Néhémy Lim Matlab Tutorial 1 Introduction Matlab (standing for matrix laboratory) is a high-level programming language and interactive environment

### LAB 1: Introduction to MATLAB Summer 2011

University of Illinois at Urbana-Champaign Department of Electrical and Computer Engineering ECE 311: Digital Signal Processing Lab Chandra Radhakrishnan Peter Kairouz LAB 1: Introduction to MATLAB Summer