Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.

Slides:



Advertisements
Similar presentations
Introduction to arrays
Advertisements

Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
1.5 Elementary Matrices and a Method for Finding
CSE 1301 Lecture 6B More Repetition Figures from Lewis, “C# Software Solutions”, Addison Wesley Briana B. Morrison.
Chapter 8 and 9 Review: Logical Functions and Control Structures Introduction to MATLAB 7 Engineering 161.
Lecture 5 Review Programming Program Structures Comparison Repetition: looping or iteration Conditional execution: branching Bubble Sort.
CIS 101: Computer Programming and Problem Solving Lecture 7 Usman Roshan Department of Computer Science NJIT.
Introduction to MATLAB
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
Linear Algebra and Matrices
Copyright © Cengage Learning. All rights reserved. 7.6 The Inverse of a Square Matrix.
1 Chapter 3 Matrix Algebra with MATLAB Basic matrix definitions and operations were covered in Chapter 2. We will now consider how these operations are.
Chapter 7 Matrix Mathematics Matrix Operations Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
EPSII 59:006 Spring Topics Using TextPad If Statements Relational Operators Nested If Statements Else and Elseif Clauses Logical Functions For Loops.
Chapter 4 MATLAB Programming Combining Loops and Logic Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
MATLAB and SimulinkLecture 11 To days Outline  Introduction  MATLAB Desktop  Basic Features  Branching Statements  Loops  Script file / Commando.
Chapter 10 Review: Matrix Algebra
Creating scalars, vectors, matrices Ex1 & 2. Dot Product & Cross Product Ex3. Plotting Graphs Ex4. Conversion Table Ex5. Plotting functions Finishing Ex4.
Needs Work Need to add –HW Quizzes Chapter 13 Matrices and Determinants.
Matrices. Given below is a record of all the types of books kept in a class library. TypeFictionGeneral Malay2547 Chinese4072 English8085.
REVIEW 2 Exam History of Computers 1. CPU stands for _______________________. a. Counter productive units b. Central processing unit c. Copper.
TH EDITION LIAL HORNSBY SCHNEIDER COLLEGE ALGEBRA.
Copyright © 2013, 2009, 2005 Pearson Education, Inc. 1 5 Systems and Matrices Copyright © 2013, 2009, 2005 Pearson Education, Inc.
Matrix Entry or element Rows, columns Dimensions Matrix Addition/Subtraction Scalar Multiplication.
ADVANCED EV3 PROGRAMMING LESSON
4.6 Matrix Equations and Systems of Linear Equations In this section, you will study matrix equations and how to use them to solve systems of linear equations.
A Brief Introduction to Matlab Laila Guessous Dept. of Mechanical Engineering Oakland University.
Lecture 4. RAM Model, Space and Time Complexity
ENGR 1320 Final Review - Programming Major Topics: – Functions and Scripts – Vector and Matrix Operations in Matlab Dot product Cross product – Plotting.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
Matlab Basics Tutorial. Vectors Let's start off by creating something simple, like a vector. Enter each element of the vector (separated by a space) between.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
CMPS 1371 Introduction to Computing for Engineers CONDITIONAL STATEMENTS.
Chapter 4 Review: Manipulating Matrices Introduction to MATLAB 7 Engineering 161.
PHP Logic. Review: Variables Variables: a symbol or name that stands for a value – Data types ( Similar to C++ or Java): Int, Float, Boolean, String,
1 Computer Programming (ECGD2102 ) Using MATLAB Instructor: Eng. Eman Al.Swaity Lecture (4): Control Flow (Chapter 2)
Review for Exam2 Key Ideas 1. Key Ideas: Boolean Operators (2 > 3) || (3 < 29.3) A.True B.False C.Impossible to determine (22 > 3) && (3 > 29.3) A.True.
What does C store? >>A = [1 2 3] >>B = [1 1] >>[C,D]=meshgrid(A,B) c) a) d) b)
Linear algebra: matrix Eigen-value Problems Eng. Hassan S. Migdadi Part 1.
Scientific Computing General Least Squares. Polynomial Least Squares Polynomial Least Squares: We assume that the class of functions is the class of all.
Introduction to Matlab Module #4 Page 1 Introduction to Matlab Module #4 – Programming Topics 1.Programming Basics (fprintf, standard input) 2.Relational.
Chapter 4 Controlling Execution CSE Objectives Evaluate logical expressions –Boolean –Relational Change the flow of execution –Diagrams (e.g.,
Recap Saving Plots Summary of Chapter 5 Introduction of Chapter 6.
Lecture 2 Conditional Statement. chcslonline.org Conditional Statements in PHP Conditional Statements are used for decision making. Different actions.
ES 240: Scientific and Engineering Computation. Chapter 8 Chapter 8: Linear Algebraic Equations and Matrices Uchechukwu Ofoegbu Temple University.
Lecture 26: Reusable Methods: Enviable Sloth. Creating Function M-files User defined functions are stored as M- files To use them, they must be in the.
Matlab Programming for Engineers
Chapter 8: MuPAD Programming I Conditional Control and Loops MATLAB for Scientist and Engineers Using Symbolic Toolbox.
8.2 Operations With Matrices
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
General Computer Science for Engineers CISC 106 Lecture 13 - Midterm Review James Atlas Computer and Information Sciences 10/02/2009.
1 Lecture 3 Post-Graduate Students Advanced Programming (Introduction to MATLAB) Code: ENG 505 Dr. Basheer M. Nasef Computers & Systems Dept.
Controlling Program Flow with Decision Structures.
Chapter 4 MATLAB Programming MATLAB Troubleshooting Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display.
Why Repetition? Read 8 real numbers and compute their average REAL X1, X2, X3, X4, X5, X6, X7, X8 REAL SUM, AVG READ *, X1, X2, X3, X4, X5, X6, X7, X8.
IST 210: PHP LOGIC IST 210: Organization of Data IST210 1.
Finishing up Chapter 5. Will this code enter the if statement? G=[30,55,10] if G
4 - Conditional Control Structures CHAPTER 4. Introduction A Program is usually not limited to a linear sequence of instructions. In real life, a programme.
Matrices IB Mathematics SL. Matrices Describing Matrices Adding Matrices.
Computer Application in Engineering Design
Repetition Structures Chapter 9
Matlab Training Session 4: Control, Flow and Functions
L9Matrix and linear equation
Selection By Ramin && Taimoor
Use of Mathematics using Technology (Maltlab)
Logical Operations In Matlab.
Communication and Coding Theory Lab(CS491)
Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn.
Matlab Basics.
REPETITION Why Repetition?
Presentation transcript:

Vectors and Matrices In MATLAB a vector can be defined as row vector or as a column vector. A vector of length n can be visualized as matrix of size 1xn or nx1.

Vectors and Matrices Matrices can be of different sizes, either square matrices of size NxN or rectangular NxM. Note that vectors are special case of matrices.

Some Special Vectors and Matrices

Matrix Calculations Addition Multiplication Inverse

Solving Simultaneous Equations Ax=b A=matrix of coefficients, x = vector of variables, b = vector of values. In matrix form the above system and its solution can be written as In MATLAB we write as x = inv(A)*b

Loops Two different types of loops exist in MATLAB. for and while Their structure is as shown here

for loop A simple for loop to calculate and display squares of numbers from 1 to 5.

for loop (contd.) We can write the same for loop with some change. Now we are saving the results in a vector named ‘result’. Note that the squared values will be saved in the ‘result’ vector. The vector must be initialized before assigning any value to it. Note that this is the case for vectors and matrices only. We don’t need to initialize scalars in MATLAB.

for loop (contd.) The control index of the for loop shown in the previous slides was incremented by ‘1’. We can increment the control index by any arbitrary value as required. In the following example odd numbers from 1 to 9 are printed.

while loop While loop continue to execute if the given condition is true. A condition is true if it is not equal to ‘0’. A simple while loop to display numbers from 1 to 10 is shown here. In this while loop at each iteration the value of ‘i’ is incremented after the value is printed.

Logical Operators AND, OR, and INVERT logical operations can be performed in MATLAB. The symbols used for these operators are ‘&&’, ‘||’, and ‘~’ respectively for AND, OR, and INVERT. A logical operation always results in a ‘1’ or ‘0’.

Some more logical operators Other logical operators in MATLAB include Note that the results of these operations are also either ‘1’ or ‘0’. <Less than >Greater than ==Equal to <=Less than or equal to >=Greater than or equal to ~=Not equal to

Examples: logical operations Lets say, a=1, b=2, and c=1. Then, A<b results in TRUE I.e. ‘1’ A>b results in FALSE I.e. ‘0’ A==b results in FALSE I.e. ‘0’ A==c results in TRUE I.e. ‘1’ A==c && a<=b results in ‘1’. Several examples can be used to show the usage of these operators.

while loop revisited Now we can show the usage of these logical operations in the while loop as condition. Say a=1, then the following code results in the execution of loop until the condition a<b gets FALSE.

if statement if statement checks whether the condition given to it is TRUE or FALSE. If the condition evaluates to TRUE the are executed otherwise not. Unlike the for and while loops the inside the if statement are executed only once.

if-else statement If-else is used if we want to perform two different tasks depending upon the condition is TRUE or FALSE.

We wish to use “if” and “else” statement to decide upon if the input integer is an odd or an even number. The Matlab code for the purpose is shown below:

Functions in Matlab Functions are actually computer routines(programs) to perform specific task. Matlab is rich in built-in function A function is called, user gives specific input(s) to the function, which generates the required output(s).

Example of built-in functions Our objective is to calculate mean or average of certain vector ‘x’. We call the built in function “mean” of Matlab and give ‘x’ as an input to the function. The mean is calculated and is stored in variable ‘y’.

We can also built our own functions and call them when required. The functions are the m-files. For example for a given quadratic equation we wish to calculate the roots of equation. So we build our own function “call” and use the quadratic formula to solve for x1 and x2.

In our main program the function is called and the inputs ‘a’, ‘b’ and ‘c’ are given to the function which calculates the required roots

Plotting in Matlab Matlab uses “plot” command to plot the curves with different line style and colors Example follows:

Thank You