This document discusses programming concepts in MATLAB including conditional statements, loops, and logical operators. It provides examples of how to:
- Use if, elseif, and else conditional statements to execute different sections of code depending on conditions.
- Implement for loops to repeat a block of code a specified number of times.
- Employ logical operators like & (AND), | (OR), and ~ (NOT) to combine relational expressions and conditionally execute code.
- Compare values, arrays, and scalars using relational operators like <, >, ==, ~=, etc. and logical indexing.
The examples demonstrate how to control program flow and selectively run sections of MATLAB code.
This chapter discusses mathematical operations with arrays in MATLAB. It covers topics such as addition, subtraction, multiplication, and division of arrays. Array operations can be performed elementwise or using matrix multiplication. Built-in functions like mean, max, and sort can be used to analyze array properties. Random number generation functions rand, randn and randi are also introduced.
The document defines various types of matrices including row vectors, column vectors, submatrices, square matrices, triangular matrices, diagonal matrices, identity matrices, zero matrices, and diagonally dominant matrices. It provides examples of each type of matrix. It also discusses when two matrices are considered equal, which is when they have the same size and corresponding elements are equal.
1. The document discusses various types and operations of matrices including transpose, similarity, inverse, and determinant of matrices.
2. It also discusses using matrices to solve systems of linear equations by finding the inverse of the coefficient matrix or calculating the determinant.
3. The key matrix concepts covered are matrix notation, types of matrices, matrix addition/subtraction, multiplication, and using matrices to represent and solve linear systems.
This document provides an introduction to algebraic operations in MATLAB, including scalar calculations using basic arithmetic operators and order of operations, and matrix calculations such as addition, subtraction, multiplication, and transposition. It also discusses special matrices like identity matrices that can be created with functions like eye(), and zeros and ones matrices that can be made with functions like zeros() and ones().
Matrices can be added, subtracted, and multiplied according to certain rules.
- Matrices can only be added or subtracted if they are the same size. The sum or difference of matrices A and B yields a matrix C of the same size.
- Matrices can be multiplied by a scalar. Multiplying a matrix A by a scalar k results in a new matrix kA where each element is multiplied by k.
- Matrix multiplication allows combining information from two matrices but has specific rules regarding the dimensions of the matrices.
The document discusses various types of matrices:
- Row and column matrices are matrices with only one row or column respectively.
- A square matrix has the same number of rows and columns.
- A diagonal matrix has non-zero elements only along its main diagonal.
- An identity matrix has ones along its main diagonal and zeros elsewhere.
- A scalar matrix has all elements along its main diagonal multiplied by a scalar.
- A null matrix has all elements equal to zero.
The document also discusses properties such as the transpose of a matrix, symmetric matrices, and how to add, subtract and multiply matrices.
The history and development of matrix theory is summarized as follows:
1) The term "matrix" was introduced in 1850 by James Joseph Sylvester to describe rectangular arrays of numbers or expressions arranged in rows and columns.
2) The founder of modern matrix theory is considered to be Arthur Cayley, who in the 1850s introduced concepts such as inverse matrices and matrix multiplication.
3) Important developments in matrix theory continued throughout the 19th and 20th centuries, including the discovery by Arthur Cayley and William Hamilton of unique properties of matrices.
System of linear algebriac equations nsmRahul Narang
The document discusses systems of linear algebraic equations and methods for solving them numerically. It introduces systems of linear equations in matrix form Ax = b and describes elementary row operations that can transform the matrix A. It then explains Gaussian elimination and Gauss-Jordan elimination methods for solving systems of linear equations by transforming the augmented matrix into reduced row echelon form. Finally, it briefly describes Jacobi and Gauss-Seidel iterative methods as well as applications of linear algebra in computer science fields like statistical learning, image manipulation, and physics.
This chapter discusses mathematical operations with arrays in MATLAB. It covers topics such as addition, subtraction, multiplication, and division of arrays. Array operations can be performed elementwise or using matrix multiplication. Built-in functions like mean, max, and sort can be used to analyze array properties. Random number generation functions rand, randn and randi are also introduced.
The document defines various types of matrices including row vectors, column vectors, submatrices, square matrices, triangular matrices, diagonal matrices, identity matrices, zero matrices, and diagonally dominant matrices. It provides examples of each type of matrix. It also discusses when two matrices are considered equal, which is when they have the same size and corresponding elements are equal.
1. The document discusses various types and operations of matrices including transpose, similarity, inverse, and determinant of matrices.
2. It also discusses using matrices to solve systems of linear equations by finding the inverse of the coefficient matrix or calculating the determinant.
3. The key matrix concepts covered are matrix notation, types of matrices, matrix addition/subtraction, multiplication, and using matrices to represent and solve linear systems.
This document provides an introduction to algebraic operations in MATLAB, including scalar calculations using basic arithmetic operators and order of operations, and matrix calculations such as addition, subtraction, multiplication, and transposition. It also discusses special matrices like identity matrices that can be created with functions like eye(), and zeros and ones matrices that can be made with functions like zeros() and ones().
Matrices can be added, subtracted, and multiplied according to certain rules.
- Matrices can only be added or subtracted if they are the same size. The sum or difference of matrices A and B yields a matrix C of the same size.
- Matrices can be multiplied by a scalar. Multiplying a matrix A by a scalar k results in a new matrix kA where each element is multiplied by k.
- Matrix multiplication allows combining information from two matrices but has specific rules regarding the dimensions of the matrices.
The document discusses various types of matrices:
- Row and column matrices are matrices with only one row or column respectively.
- A square matrix has the same number of rows and columns.
- A diagonal matrix has non-zero elements only along its main diagonal.
- An identity matrix has ones along its main diagonal and zeros elsewhere.
- A scalar matrix has all elements along its main diagonal multiplied by a scalar.
- A null matrix has all elements equal to zero.
The document also discusses properties such as the transpose of a matrix, symmetric matrices, and how to add, subtract and multiply matrices.
The history and development of matrix theory is summarized as follows:
1) The term "matrix" was introduced in 1850 by James Joseph Sylvester to describe rectangular arrays of numbers or expressions arranged in rows and columns.
2) The founder of modern matrix theory is considered to be Arthur Cayley, who in the 1850s introduced concepts such as inverse matrices and matrix multiplication.
3) Important developments in matrix theory continued throughout the 19th and 20th centuries, including the discovery by Arthur Cayley and William Hamilton of unique properties of matrices.
System of linear algebriac equations nsmRahul Narang
The document discusses systems of linear algebraic equations and methods for solving them numerically. It introduces systems of linear equations in matrix form Ax = b and describes elementary row operations that can transform the matrix A. It then explains Gaussian elimination and Gauss-Jordan elimination methods for solving systems of linear equations by transforming the augmented matrix into reduced row echelon form. Finally, it briefly describes Jacobi and Gauss-Seidel iterative methods as well as applications of linear algebra in computer science fields like statistical learning, image manipulation, and physics.
This document defines matrices and determinants, including examples and types of matrices. It describes how to add, subtract, and multiply matrices, and defines determinants and Cramer's rule. Cramer's rule is used to solve a 3x3 system of equations. The relationship between matrices and determinants is that determinants are uniquely related to square matrices but not vice versa, and determinants are used to calculate inverses.
The document discusses determinants and their properties. It defines determinants as representing single numbers obtained by multiplying and adding matrix elements in a special way. It then provides formulas for calculating determinants of matrices of order 1, 2 and 3. It also outlines several properties of determinants, such as how interchanging rows/columns, multiplying rows by constants, and adding rows affects the determinant. Finally, it discusses how determinants are used to determine whether systems of linear equations are consistent or inconsistent.
This document defines and provides examples of different types of matrices:
- Matrices are arrangements of elements in rows and columns represented by symbols.
- Types include row matrices, column matrices, square matrices, null matrices, identity matrices, diagonal matrices, scalar matrices, triangular matrices, transpose matrices, symmetric matrices, skew matrices, equal matrices, and algebraic matrices.
- Algebraic matrix operations include addition, subtraction, and multiplication where the matrices must be of the same order.
Matrices can be added, subtracted, and multiplied under certain conditions.
Addition and subtraction require matrices to be the same size.
Matrix multiplication requires the number of columns of the first matrix to equal the number of rows of the second matrix.
Matrices can also be multiplied by scalars.
1. This document discusses methods for solving linear algebraic equations and operations involving matrices. It covers topics such as matrix definitions, types of matrices, matrix operations, representing equations in matrix form, and methods for solving systems of linear equations including graphical methods, determinants, Cramer's rule, elimination, Gauss-Jordan, LU decomposition, and calculating the matrix inverse.
2. Key matrix operations include addition, multiplication, and rules for inverting a matrix. Methods for solving systems of equations include graphical techniques, determinants, Cramer's rule, elimination, Gauss, Gauss-Jordan, and LU decomposition.
3. LU decomposition involves writing a matrix as the product of a lower and upper triangular matrix, which can
The document provides information about matrices, including:
1) Matrices can reduce complex systems of equations to simple expressions and are well-suited to computers.
2) A matrix is a set of numbers arranged in rows and columns, with specified dimensions.
3) There are several types of matrices including column/row vectors, rectangular, square, diagonal, identity, null, triangular, and scalar matrices.
4) Matrix operations include addition, subtraction, and multiplication according to specific rules like the distributive property. Not all matrices can be multiplied together.
This document provides an overview of MATLAB, including what it is, its features, toolboxes, applications, and how to perform various tasks. MATLAB is a numerical computing environment and programming language used for algorithm development, data analysis, and visualization. It allows matrix operations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. The document describes MATLAB's various components, data types, commands, and how to work with matrices, arrays, plots, and other mathematical functions. It also outlines uses of MATLAB in domains like signal processing, control systems, image processing, and more.
Here are the key steps to find the eigenvalues of the given matrix:
1) Write the characteristic equation: det(A - λI) = 0
2) Expand the determinant: (1-λ)(-2-λ) - 4 = 0
3) Simplify and factor: λ(λ + 1)(λ + 2) = 0
4) Find the roots: λ1 = 0, λ2 = -1, λ3 = -2
Therefore, the eigenvalues of the given matrix are -1 and -2.
This document provides an overview of matrices and basic matrix operations. It discusses what matrices are, how to perform operations like addition, multiplication, and taking the transpose. It also covers special types of matrices like diagonal, triangular, and identity matrices. It explains how to calculate the determinant of a 2x2 matrix and find the inverse of a 2x2 matrix using the determinant. The goal is for the reader to understand matrices, common operations, and how to calculate the determinant and inverse of a 2x2 matrix after reviewing this material.
The document defines matrices and provides examples of different types of matrices. It discusses key concepts such as rows, columns, dimensions, entries, addition, subtraction, and multiplication of matrices. It also covers special matrices like identity matrices, inverse matrices, transpose of matrices, and using matrices to solve systems of linear equations. The document is a comprehensive overview of matrices that defines fundamental terms and concepts.
Arrays in c unit iii chapter 1 mrs.sowmya jyothiSowmya Jyothi
1. Arrays allow storing multiple values of the same data type under a single variable name. There are one-dimensional, two-dimensional, and multidimensional arrays.
2. One-dimensional arrays use a single subscript to store elements, two-dimensional arrays use two subscripts for rows and columns, and multidimensional arrays can have three or more dimensions.
3. Arrays can be initialized at compile-time by providing initial values, or at run-time by assigning values with a for loop or other method.
A matrix is a rectangular arrangement of numbers organized in rows and columns. The order of a matrix refers to the number of rows and columns it contains. Entries are the individual numbers within the matrix. Basic matrix operations include addition, subtraction, scalar multiplication, and multiplication. To add or subtract matrices, they must be the same order, while scalar multiplication multiplies each entry of the matrix by the scalar.
This document provides an introduction to basic matrix operations including addition, subtraction, scalar multiplication, and matrix multiplication. It defines matrices and how to perform basic arithmetic on matrices. It also introduces the concept of matrix equations and using matrix multiplication to solve systems of linear equations. Key points covered include:
- How to add and subtract matrices by adding or subtracting the corresponding entries
- Scalar multiplication involves multiplying each entry of a matrix by a scalar number
- Matrix multiplication involves multiplying rows of one matrix with columns of another, with the constraint that the number of columns of the first matrix must equal the number of rows of the second matrix.
- Matrix multiplication is not commutative in general.
This document provides an overview of matrices and matrix operations. It begins by stating the objectives of understanding matrix characteristics, applying basic matrix operations, knowing inverse matrices up to 3x3, and solving simultaneous linear equations up to 3 variables. It then defines what a matrix is, discusses matrix dimensions and types of matrices. The document outlines various matrix operations including addition, subtraction, multiplication and scalar multiplication. It provides examples of how to perform these operations. It also covers the transpose of a matrix and inverse matrices.
A matrix is a rectangular array of numbers arranged in rows and columns. The dimensions of a matrix are written as the number of rows x the number of columns. Each individual entry in the matrix is named by its position, using the matrix name and row and column numbers. Matrices can represent systems of equations or points in a plane. Operations on matrices include addition, multiplication by scalars, and dilation of points represented by matrices.
The document defines and provides examples of different types of matrices, including:
- Square matrices, where the number of rows equals the number of columns.
- Rectangular matrices, where the number of rows does not equal the number of columns.
- Row matrices, with only one row.
- Column matrices, with only one column.
- Null or zero matrices, with all elements equal to zero.
- Diagonal matrices, with all elements equal to zero except those on the main diagonal.
The document also discusses transpose, adjoint, and addition of matrices.
1) A matrix is a rectangular array of numbers arranged in rows and columns. The dimensions of a matrix are specified by the number of rows and columns.
2) The inverse of a square matrix A exists if and only if the determinant of A is not equal to 0. The inverse of A, denoted A^-1, is the matrix that satisfies AA^-1 = A^-1A = I, where I is the identity matrix.
3) For two matrices A and B to be inverses, their product must result in the identity matrix regardless of order, i.e. AB = BA = I. This shows that one matrix undoes the effect of the other.
This document provides an overview of operators, control flows, and plotting in MATLAB. It discusses various types of operators in MATLAB including arithmetic, relational, logical, and special operators. It also covers conditional statements like if/elseif/else and switch/case statements for controlling program flow. Additionally, it describes loops in MATLAB including for and while loops as well as loop control statements like break and continue. Finally, it discusses various plotting functions in MATLAB for 2D and 3D plotting and provides examples of how to manipulate plots using command lines and the GUI.
This document provides an overview of MATLAB, including its uses, features, and basic programming concepts. MATLAB is a numerical computing environment and programming language that allows matrix manipulations, data visualization, algorithm development, and interfacing with other languages. It has a comprehensive set of built-in functions for mathematical and technical computing. The document discusses MATLAB's programming constructs like scripts, functions, operators, decision making statements, and loops. It also covers basic data types like vectors and matrices.
This document defines matrices and determinants, including examples and types of matrices. It describes how to add, subtract, and multiply matrices, and defines determinants and Cramer's rule. Cramer's rule is used to solve a 3x3 system of equations. The relationship between matrices and determinants is that determinants are uniquely related to square matrices but not vice versa, and determinants are used to calculate inverses.
The document discusses determinants and their properties. It defines determinants as representing single numbers obtained by multiplying and adding matrix elements in a special way. It then provides formulas for calculating determinants of matrices of order 1, 2 and 3. It also outlines several properties of determinants, such as how interchanging rows/columns, multiplying rows by constants, and adding rows affects the determinant. Finally, it discusses how determinants are used to determine whether systems of linear equations are consistent or inconsistent.
This document defines and provides examples of different types of matrices:
- Matrices are arrangements of elements in rows and columns represented by symbols.
- Types include row matrices, column matrices, square matrices, null matrices, identity matrices, diagonal matrices, scalar matrices, triangular matrices, transpose matrices, symmetric matrices, skew matrices, equal matrices, and algebraic matrices.
- Algebraic matrix operations include addition, subtraction, and multiplication where the matrices must be of the same order.
Matrices can be added, subtracted, and multiplied under certain conditions.
Addition and subtraction require matrices to be the same size.
Matrix multiplication requires the number of columns of the first matrix to equal the number of rows of the second matrix.
Matrices can also be multiplied by scalars.
1. This document discusses methods for solving linear algebraic equations and operations involving matrices. It covers topics such as matrix definitions, types of matrices, matrix operations, representing equations in matrix form, and methods for solving systems of linear equations including graphical methods, determinants, Cramer's rule, elimination, Gauss-Jordan, LU decomposition, and calculating the matrix inverse.
2. Key matrix operations include addition, multiplication, and rules for inverting a matrix. Methods for solving systems of equations include graphical techniques, determinants, Cramer's rule, elimination, Gauss, Gauss-Jordan, and LU decomposition.
3. LU decomposition involves writing a matrix as the product of a lower and upper triangular matrix, which can
The document provides information about matrices, including:
1) Matrices can reduce complex systems of equations to simple expressions and are well-suited to computers.
2) A matrix is a set of numbers arranged in rows and columns, with specified dimensions.
3) There are several types of matrices including column/row vectors, rectangular, square, diagonal, identity, null, triangular, and scalar matrices.
4) Matrix operations include addition, subtraction, and multiplication according to specific rules like the distributive property. Not all matrices can be multiplied together.
This document provides an overview of MATLAB, including what it is, its features, toolboxes, applications, and how to perform various tasks. MATLAB is a numerical computing environment and programming language used for algorithm development, data analysis, and visualization. It allows matrix operations, plotting of functions and data, implementation of algorithms, creation of user interfaces, and interfacing with programs in other languages. The document describes MATLAB's various components, data types, commands, and how to work with matrices, arrays, plots, and other mathematical functions. It also outlines uses of MATLAB in domains like signal processing, control systems, image processing, and more.
Here are the key steps to find the eigenvalues of the given matrix:
1) Write the characteristic equation: det(A - λI) = 0
2) Expand the determinant: (1-λ)(-2-λ) - 4 = 0
3) Simplify and factor: λ(λ + 1)(λ + 2) = 0
4) Find the roots: λ1 = 0, λ2 = -1, λ3 = -2
Therefore, the eigenvalues of the given matrix are -1 and -2.
This document provides an overview of matrices and basic matrix operations. It discusses what matrices are, how to perform operations like addition, multiplication, and taking the transpose. It also covers special types of matrices like diagonal, triangular, and identity matrices. It explains how to calculate the determinant of a 2x2 matrix and find the inverse of a 2x2 matrix using the determinant. The goal is for the reader to understand matrices, common operations, and how to calculate the determinant and inverse of a 2x2 matrix after reviewing this material.
The document defines matrices and provides examples of different types of matrices. It discusses key concepts such as rows, columns, dimensions, entries, addition, subtraction, and multiplication of matrices. It also covers special matrices like identity matrices, inverse matrices, transpose of matrices, and using matrices to solve systems of linear equations. The document is a comprehensive overview of matrices that defines fundamental terms and concepts.
Arrays in c unit iii chapter 1 mrs.sowmya jyothiSowmya Jyothi
1. Arrays allow storing multiple values of the same data type under a single variable name. There are one-dimensional, two-dimensional, and multidimensional arrays.
2. One-dimensional arrays use a single subscript to store elements, two-dimensional arrays use two subscripts for rows and columns, and multidimensional arrays can have three or more dimensions.
3. Arrays can be initialized at compile-time by providing initial values, or at run-time by assigning values with a for loop or other method.
A matrix is a rectangular arrangement of numbers organized in rows and columns. The order of a matrix refers to the number of rows and columns it contains. Entries are the individual numbers within the matrix. Basic matrix operations include addition, subtraction, scalar multiplication, and multiplication. To add or subtract matrices, they must be the same order, while scalar multiplication multiplies each entry of the matrix by the scalar.
This document provides an introduction to basic matrix operations including addition, subtraction, scalar multiplication, and matrix multiplication. It defines matrices and how to perform basic arithmetic on matrices. It also introduces the concept of matrix equations and using matrix multiplication to solve systems of linear equations. Key points covered include:
- How to add and subtract matrices by adding or subtracting the corresponding entries
- Scalar multiplication involves multiplying each entry of a matrix by a scalar number
- Matrix multiplication involves multiplying rows of one matrix with columns of another, with the constraint that the number of columns of the first matrix must equal the number of rows of the second matrix.
- Matrix multiplication is not commutative in general.
This document provides an overview of matrices and matrix operations. It begins by stating the objectives of understanding matrix characteristics, applying basic matrix operations, knowing inverse matrices up to 3x3, and solving simultaneous linear equations up to 3 variables. It then defines what a matrix is, discusses matrix dimensions and types of matrices. The document outlines various matrix operations including addition, subtraction, multiplication and scalar multiplication. It provides examples of how to perform these operations. It also covers the transpose of a matrix and inverse matrices.
A matrix is a rectangular array of numbers arranged in rows and columns. The dimensions of a matrix are written as the number of rows x the number of columns. Each individual entry in the matrix is named by its position, using the matrix name and row and column numbers. Matrices can represent systems of equations or points in a plane. Operations on matrices include addition, multiplication by scalars, and dilation of points represented by matrices.
The document defines and provides examples of different types of matrices, including:
- Square matrices, where the number of rows equals the number of columns.
- Rectangular matrices, where the number of rows does not equal the number of columns.
- Row matrices, with only one row.
- Column matrices, with only one column.
- Null or zero matrices, with all elements equal to zero.
- Diagonal matrices, with all elements equal to zero except those on the main diagonal.
The document also discusses transpose, adjoint, and addition of matrices.
1) A matrix is a rectangular array of numbers arranged in rows and columns. The dimensions of a matrix are specified by the number of rows and columns.
2) The inverse of a square matrix A exists if and only if the determinant of A is not equal to 0. The inverse of A, denoted A^-1, is the matrix that satisfies AA^-1 = A^-1A = I, where I is the identity matrix.
3) For two matrices A and B to be inverses, their product must result in the identity matrix regardless of order, i.e. AB = BA = I. This shows that one matrix undoes the effect of the other.
This document provides an overview of operators, control flows, and plotting in MATLAB. It discusses various types of operators in MATLAB including arithmetic, relational, logical, and special operators. It also covers conditional statements like if/elseif/else and switch/case statements for controlling program flow. Additionally, it describes loops in MATLAB including for and while loops as well as loop control statements like break and continue. Finally, it discusses various plotting functions in MATLAB for 2D and 3D plotting and provides examples of how to manipulate plots using command lines and the GUI.
This document provides an overview of MATLAB, including its uses, features, and basic programming concepts. MATLAB is a numerical computing environment and programming language that allows matrix manipulations, data visualization, algorithm development, and interfacing with other languages. It has a comprehensive set of built-in functions for mathematical and technical computing. The document discusses MATLAB's programming constructs like scripts, functions, operators, decision making statements, and loops. It also covers basic data types like vectors and matrices.
Chapter 3:Programming with Java Operators and StringsIt Academy
Exam Objective 4.5 Given an algorithm as pseudo-code, develop code that correctly applies the appropriate operators, including assignment operators (limited to: =, +=, -=), arithmetic operators (limited to: +, -, *, /, %, ++, --), relational operators (limited to: <,><=,>, >=, ==, !=), logical operators (limited to: !, &&, ||), to produce a desired result. Also, write code that determines the equality of two objects or two primitives.
The document discusses Java operators including assignment, arithmetic, relational, logical, and bitwise operators. It provides examples and explanations of how each operator works, the order of operations, and error conditions. Key points covered include arithmetic promotions, equality comparisons of primitives versus objects, short-circuit logical operators, and using operators to manipulate strings.
Chapter 3 : Programming with Java Operators and StringsIt Academy
Exam Objective 4.5 Given an algorithm as pseudo-code, develop code that correctly applies the appropriate operators, including assignment operators (limited to: =, +=, -=), arithmetic operators (limited to: +, -, *, /, %, ++, --), relational operators (limited to: <,><=,>, >=, ==, !=), logical operators (limited to: !, &&, ||), to produce a desired result. Also, write code that determines the equality of two objects or two primitives.
This document describes an assignment to write a Matlab function that transforms a matrix A and vector b into upper triangular form to solve simultaneous equations. Students are provided with 6 example matrices A and vectors b to test their function on. They must return the solution vector x, transformed matrix A', and vector b'. The function must include error checking to ensure valid input dimensions.
This document provides an overview of relational algebra and calculus, database normalization, and queries. It defines common relational algebra operations like selection, projection, join, etc. It explains database normalization forms like 1NF, 2NF, 3NF and their advantages. It also covers functional dependencies, integrity constraints, and different types of queries including subqueries and nested subqueries.
This document discusses operators and expressions in C++. It begins by defining operators as symbols that represent operations and operands as the objects involved in those operations. It then covers various types of operators in C++ like arithmetic, relational, logical, and conditional operators. It provides examples of using each operator and notes order of precedence. The document also discusses expressions, noting they are combinations of operators, constants, and variables. It provides examples of integer, real, relational, and logical expressions. Finally, it discusses mathematical functions available in the C++ standard library header file math.h that can be used in arithmetic expressions.
This document provides an introduction to MATLAB for people working in marketing. It explains that MATLAB is useful for analyzing large or complex datasets, as it can handle data more efficiently than Excel. The document demonstrates how to use MATLAB through a example of modeling mobile app subscription prices and demand based on survey data. Key functions and operations in MATLAB like vectors, matrices, element referencing, basic math operations, plotting, and linear regression are covered. The example shows how to estimate a linear pricing model that fits the sample data well.
OCA Java SE 8 Exam Chapter 2 Operators & Statementsİbrahim Kürce
Operators in Java include unary, binary, and ternary operators that perform operations on operands. Binary operators like arithmetic, relational, and logical operators follow an order of precedence unless overridden by parentheses. Statements in Java include if-then, if-then-else, switch, while, do-while, for, and more to control program flow. The if-then statement and if-then-else statement evaluate conditions and execute code blocks conditionally. The switch statement compares a value to multiple case labels and executes the corresponding code block.
Operators in C++ represent specific tasks or operations that are applied to operands. There are several types of operators including arithmetic, relational, logical, increment/decrement, and conditional operators. Arithmetic operators perform basic math operations like addition, subtraction, multiplication, and division on operands. Relational operators compare operands and return true or false based on the comparison. Logical operators combine relational expressions and include logical AND, logical OR, and logical NOT. The increment/decrement operators increment or decrement operands by 1. The conditional operator returns one of two results based on a condition. Precedence rules determine the order in which operations are performed.
1. The document discusses logical operators and functions in MATLAB. It describes element-wise and short-circuit logical operators like &, |, ~, &&, and ||.
2. Various logical functions are also covered, including find to find indices of non-zero elements, all to check if all elements are non-zero, and any to check if any elements are non-zero.
3. Functions are also described to represent true and false values using true and false, convert numeric values to logical using logical, and check if a variable is logical using islogical.
The document provides an overview of various Excel functions organized into different categories such as mathematical functions, statistical functions, lookup and date functions, and financial functions. It describes high-level functions like SUM, AVERAGE, VLOOKUP, and DATE as well as more specialized functions like MOD, GCD, MEDIAN, and DATEDIF. For each function, it provides the syntax and examples of usage to calculate or look up values based on supplied arguments. The document serves as a reference for understanding the variety of calculations that can be performed using functions in Excel.
chap 2 : Operators and Assignments (scjp/ocjp)It Academy
The document provides an overview of operators in Java, including:
- Unary operators like increment, decrement, negation, boolean complement and cast
- Arithmetic operators like multiplication, division, modulo and their behavior during errors
- Relational operators like comparison and instanceof
- Equality operators like == and !=
- Logical operators like &&, || and conditional operator ?: and their short-circuit behavior
- Bitwise and boolean operators like &, |, ^, AND, OR
- Assignment operators like += and their evaluation order from right to left
Logical vectors in MATLAB compare elements of vectors and return a logical vector with the same size where each element indicates whether the comparison is true (1) or false (0). Logical vectors can be used to create discontinuous graphs by multiplying a vector by a logical vector that filters out negative values. They can also avoid division by zero errors by replacing zeros with a small nonzero value like eps. Common logical functions for vectors include any(), which returns 1 if any element is nonzero, and all(), which returns 1 only if all elements are nonzero.
The document provides an overview of various Excel functions organized into categories including:
1. Mathematical functions such as ROUND, MOD, INTEGER, GCD, and LOG functions.
2. Statistical functions such as COUNT, AVERAGE, MAX, MEDIAN, and financial functions such as NPV, PV, PMT.
3. Lookup functions including VLOOKUP, HLOOKUP, MATCH to find data in tables or perform lookups.
4. Date and time functions like DATE, TIME, TODAY, NOW and DATEDIF to work with dates and times.
5. Text functions including LEFT, RIGHT, MID, UPPER, LOWER, LEN to manipulate
On if,countif,countifs,sumif,countifs,lookup,v lookup,index,matchRakesh Sah
This document provides information and examples for various Excel functions including text, logical, lookup, and match functions. It discusses the TRIM and CLEAN functions for removing spaces and characters from text strings. It also covers the IF, AND, OR functions for logical evaluations and provides truth tables and nested formula examples. Lookup functions like VLOOKUP, HLOOKUP, INDEX and MATCH are explained for retrieving values or positions from a table. Various examples demonstrate how to use operators, wildcards and cell references with these functions.
This document discusses operators in object-oriented programming and Java. It covers assignment, arithmetic, compound assignment, increment/decrement, relational/equality, logical, conditional, comma, and bitwise operators. It also discusses type casting and the sizeof operator. Examples are provided for each operator. The document concludes with exercises involving using various operators to calculate wages and convert mathematical formulas into Java code.
The document discusses logical operators in MATLAB - AND, OR, and NOT. It explains that they work on arrays element-by-element, returning arrays with 1s and 0s to represent true and false. AND requires both elements to be non-zero to return true, OR returns true if either element is non-zero, and NOT flips the values. Examples are given to illustrate each logical operator.
This chapter covers two-dimensional (2D) plots in MATLAB. It discusses various plot commands like plot, fplot, and errorbar that can be used to create basic and specialized 2D plots. It also describes how to format plots by adding labels, titles, legends, text annotations and grids. Plots with logarithmic and polar axes as well as histograms are demonstrated. The chapter shows how to create multiple plots on the same figure using subplots or in separate figure windows.
The chapter discusses inputting and managing data in MATLAB. It covers the MATLAB workspace, using script files to input data, displaying and saving output, and exchanging data with other programs. The key points are:
1) MATLAB stores variables in the workspace during a session and script files can access these variables. The workspace window allows viewing and editing variables.
2) Script files can input data by assigning values in the file, command window, or prompting the user.
3) The disp and fprintf commands display output, with fprintf offering more formatting control. Fprintf can write to files or the screen.
4) The save command saves workspace variables to a file, while load retrieves stored data
This document discusses creating and manipulating arrays in MATLAB. It covers:
- Creating one-dimensional arrays (vectors) using known values, spacing, or number of elements.
- Creating two-dimensional arrays (matrices) by specifying rows and ensuring each row has the same number of columns.
- Basic array commands like zeros, ones, and eye to create arrays filled with zeros, ones, or an identity matrix.
- Transposing arrays with the ' operator.
- Accessing and assigning values to individual elements or ranges of elements using indexing and colon notation.
- Adding elements to existing arrays by assigning values to undefined indices or appending rows/columns.
This chapter discusses starting MATLAB and working in the command window. It introduces MATLAB windows like the command window, figure window, editor window, etc. It describes how to do basic arithmetic and define scalar variables in MATLAB. Functions for elementary math operations, trigonometric functions, and managing variables are also introduced.
The document provides guidance on how to write an effective CV or resume. It defines what a CV and resume are, as well as the key differences between them. It then outlines the main sections that should be included in a CV, such as contact information, career objective, work experience, education, skills, and references. Tips are provided about what information to include under each section and how to structure and format the CV to make it easy for employers to read. The document also discusses different types of CVs, such as chronological, functional, and hybrid CVs, and their advantages and disadvantages.
The document discusses the history and types of black holes. John Michel and Pierre-Simon Laplace first proposed the idea of invisible stars, or black holes, in the late 1790s. Einstein later predicted black holes in his general relativity theory of 1915. There are two main types: miniature black holes created during the Big Bang and supermassive black holes with masses equal to billions of suns. The central singularity is a point of infinite density where physics breaks down, surrounded by the event horizon from within nothing, not even light, can escape.
UI5con 2024 - Keynote: Latest News about UI5 and it’s EcosystemPeter Muessig
Learn about the latest innovations in and around OpenUI5/SAPUI5: UI5 Tooling, UI5 linter, UI5 Web Components, Web Components Integration, UI5 2.x, UI5 GenAI.
Recording:
https://www.youtube.com/live/MSdGLG2zLy8?si=INxBHTqkwHhxV5Ta&t=0
Artificia Intellicence and XPath Extension FunctionsOctavian Nadolu
The purpose of this presentation is to provide an overview of how you can use AI from XSLT, XQuery, Schematron, or XML Refactoring operations, the potential benefits of using AI, and some of the challenges we face.
What is Augmented Reality Image Trackingpavan998932
Augmented Reality (AR) Image Tracking is a technology that enables AR applications to recognize and track images in the real world, overlaying digital content onto them. This enhances the user's interaction with their environment by providing additional information and interactive elements directly tied to physical images.
Using Query Store in Azure PostgreSQL to Understand Query PerformanceGrant Fritchey
Microsoft has added an excellent new extension in PostgreSQL on their Azure Platform. This session, presented at Posette 2024, covers what Query Store is and the types of information you can get out of it.
GraphSummit Paris - The art of the possible with Graph TechnologyNeo4j
Sudhir Hasbe, Chief Product Officer, Neo4j
Join us as we explore breakthrough innovations enabled by interconnected data and AI. Discover firsthand how organizations use relationships in data to uncover contextual insights and solve our most pressing challenges – from optimizing supply chains, detecting fraud, and improving customer experiences to accelerating drug discoveries.
A Study of Variable-Role-based Feature Enrichment in Neural Models of CodeAftab Hussain
Understanding variable roles in code has been found to be helpful by students
in learning programming -- could variable roles help deep neural models in
performing coding tasks? We do an exploratory study.
- These are slides of the talk given at InteNSE'23: The 1st International Workshop on Interpretability and Robustness in Neural Software Engineering, co-located with the 45th International Conference on Software Engineering, ICSE 2023, Melbourne Australia
Neo4j - Product Vision and Knowledge Graphs - GraphSummit ParisNeo4j
Dr. Jesús Barrasa, Head of Solutions Architecture for EMEA, Neo4j
Découvrez les dernières innovations de Neo4j, et notamment les dernières intégrations cloud et les améliorations produits qui font de Neo4j un choix essentiel pour les développeurs qui créent des applications avec des données interconnectées et de l’IA générative.
SOCRadar's Aviation Industry Q1 Incident Report is out now!
The aviation industry has always been a prime target for cybercriminals due to its critical infrastructure and high stakes. In the first quarter of 2024, the sector faced an alarming surge in cybersecurity threats, revealing its vulnerabilities and the relentless sophistication of cyber attackers.
SOCRadar’s Aviation Industry, Quarterly Incident Report, provides an in-depth analysis of these threats, detected and examined through our extensive monitoring of hacker forums, Telegram channels, and dark web platforms.
Microservice Teams - How the cloud changes the way we workSven Peters
A lot of technical challenges and complexity come with building a cloud-native and distributed architecture. The way we develop backend software has fundamentally changed in the last ten years. Managing a microservices architecture demands a lot of us to ensure observability and operational resiliency. But did you also change the way you run your development teams?
Sven will talk about Atlassian’s journey from a monolith to a multi-tenanted architecture and how it affected the way the engineering teams work. You will learn how we shifted to service ownership, moved to more autonomous teams (and its challenges), and established platform and enablement teams.
Revolutionizing Visual Effects Mastering AI Face Swaps.pdfUndress Baby
The quest for the best AI face swap solution is marked by an amalgamation of technological prowess and artistic finesse, where cutting-edge algorithms seamlessly replace faces in images or videos with striking realism. Leveraging advanced deep learning techniques, the best AI face swap tools meticulously analyze facial features, lighting conditions, and expressions to execute flawless transformations, ensuring natural-looking results that blur the line between reality and illusion, captivating users with their ingenuity and sophistication.
Web:- https://undressbaby.com/
E-Invoicing Implementation: A Step-by-Step Guide for Saudi Arabian CompaniesQuickdice ERP
Explore the seamless transition to e-invoicing with this comprehensive guide tailored for Saudi Arabian businesses. Navigate the process effortlessly with step-by-step instructions designed to streamline implementation and enhance efficiency.
Measures in SQL (SIGMOD 2024, Santiago, Chile)Julian Hyde
SQL has attained widespread adoption, but Business Intelligence tools still use their own higher level languages based upon a multidimensional paradigm. Composable calculations are what is missing from SQL, and we propose a new kind of column, called a measure, that attaches a calculation to a table. Like regular tables, tables with measures are composable and closed when used in queries.
SQL-with-measures has the power, conciseness and reusability of multidimensional languages but retains SQL semantics. Measure invocations can be expanded in place to simple, clear SQL.
To define the evaluation semantics for measures, we introduce context-sensitive expressions (a way to evaluate multidimensional expressions that is consistent with existing SQL semantics), a concept called evaluation context, and several operations for setting and modifying the evaluation context.
A talk at SIGMOD, June 9–15, 2024, Santiago, Chile
Authors: Julian Hyde (Google) and John Fremlin (Google)
https://doi.org/10.1145/3626246.3653374
UI5con 2024 - Boost Your Development Experience with UI5 Tooling ExtensionsPeter Muessig
The UI5 tooling is the development and build tooling of UI5. It is built in a modular and extensible way so that it can be easily extended by your needs. This session will showcase various tooling extensions which can boost your development experience by far so that you can really work offline, transpile your code in your project to use even newer versions of EcmaScript (than 2022 which is supported right now by the UI5 tooling), consume any npm package of your choice in your project, using different kind of proxies, and even stitching UI5 projects during development together to mimic your target environment.
Takashi Kobayashi and Hironori Washizaki, "SWEBOK Guide and Future of SE Education," First International Symposium on the Future of Software Engineering (FUSE), June 3-6, 2024, Okinawa, Japan
Hand Rolled Applicative User ValidationCode KataPhilip Schwarz
Could you use a simple piece of Scala validation code (granted, a very simplistic one too!) that you can rewrite, now and again, to refresh your basic understanding of Applicative operators <*>, <*, *>?
The goal is not to write perfect code showcasing validation, but rather, to provide a small, rough-and ready exercise to reinforce your muscle-memory.
Despite its grandiose-sounding title, this deck consists of just three slides showing the Scala 3 code to be rewritten whenever the details of the operators begin to fade away.
The code is my rough and ready translation of a Haskell user-validation program found in a book called Finding Success (and Failure) in Haskell - Fall in love with applicative functors.
Essentials of Automations: The Art of Triggers and Actions in FMESafe Software
In this second installment of our Essentials of Automations webinar series, we’ll explore the landscape of triggers and actions, guiding you through the nuances of authoring and adapting workspaces for seamless automations. Gain an understanding of the full spectrum of triggers and actions available in FME, empowering you to enhance your workspaces for efficient automation.
We’ll kick things off by showcasing the most commonly used event-based triggers, introducing you to various automation workflows like manual triggers, schedules, directory watchers, and more. Plus, see how these elements play out in real scenarios.
Whether you’re tweaking your current setup or building from the ground up, this session will arm you with the tools and insights needed to transform your FME usage into a powerhouse of productivity. Join us to discover effective strategies that simplify complex processes, enhancing your productivity and transforming your data management practices with FME. Let’s turn complexity into clarity and make your workspaces work wonders!
E-commerce Application Development Company.pdfHornet Dynamics
Your business can reach new heights with our assistance as we design solutions that are specifically appropriate for your goals and vision. Our eCommerce application solutions can digitally coordinate all retail operations processes to meet the demands of the marketplace while maintaining business continuity.
1. Chapter 6
Programming in MATLAB
MATLAB An Introduction with Applications, 5th Edition
Dr. Amos Gilat
The Ohio State University
2. 6.0
In this chapter will study how to
make MATLAB programs run
sections of code
• If something is true
• While something is true
• For a certain number of times
2
3. 6.0
Will also learn how to run different
sections of code depending on
• The value of a variable
• Which particular condition is true
• What combination of conditions is true
– If this and that are true
– If this or that is true, etc.
• What relationship two things have
– For example, one is less than the other;
greater than; equal to; not equal to; etc.
3
4. 6.1 Relational and Logical Operators
Relational operator:
• Can't put space between operators that have
two characters
• "Not equal to" is "~=", not "!=" as in C or C++
• "Equal to" comparison is two equal signs (==),
not one.
– Remember, "=" means "assign to" or "put into"
4
5. 6.1 Relational and Logical Operators
• Result of comparing with a relational
operator is always "true" or "false"
– If "true", MATLAB gives the comparison a
value of one (1)
– If "false", MATLAB gives the comparison a
value of zero (0)
This may be different than convention
in other programming languages. For
example, C gives an expression that is
false a value of zero, but it can give a
true expression any value but zero,
which you can't assume will be one
5
6. 6.1 Relational and Logical Operators
When comparing arrays
• They must be the same dimensions
• MATLAB does an elementwise
comparison
• Result is an array that has same
dimensions as other two but only
contains 1's and 0's
6
7. 6.1 Relational and Logical Operators
When comparing array to scalar
• MATLAB compares scalar to every
member of array
• Result is an array that has same
dimensions as original but only
contains 1's and 0's
7
8. 6.1 Relational and Logical Operators
Example
>> x=8:12
x = 8 9 10 11 12
>> x>10
ans = 0 0 0 1 1
>> x==11
ans = 0 0 0 1 0
>> x>=7
ans = 1 1 1 1 1
8
9. 6.1 Relational and Logical Operators
It helps to picture in your mind that the result
of a logical comparison
1. Is a vector
2. Has a 0 or 1 corresponding to each original
element
>> x=8:12
x = 8 9 10 11 12
>> x>10
ans = 0 0 0 1 1
9
T I P
10. 6.1 Relational and Logical Operators
If results of relational comparison
stored in a vector, can easily find the
number of elements that satisfy that
comparison, i.e., that are true, by using
sum command, which returns sum of
vector elements
• Works because elements that are true
have value of one and false elements
have value zero
10
T I P
11. 6.1 Relational and Logical Operators
EXAMPLE
How many of the numbers from 1-20
are prime?
• Use MATLAB isprime command, which
returns true (1) is number is prime and
false (0) if it isn't
>> numbers = 1:20;
>> sum( isprime(numbers) )
ans =
8
11
T I P
12. 6.1 Relational and Logical Operators
Can mix relational and arithmetic
operations in one expression
• Arithmetic operations follow usual
precedence and always have higher
precedence than relational operations
• Relational operations all have equal
precedence and evaluated left to right
12
T I P
13. 6.1 Relational and Logical Operators
A logical vector or logical array is a
vector/array that has only logical
1's and 0's
• 1's and 0's from mathematical operations
don't count
• 1's and 0's from relational comparisons do
work
• First time a logical vector/array used in
arithmetic, MATLAB changes it to a
numerical vector/array
13
14. 6.1 Relational and Logical Operators
Can use logical vector to get actual values
that satisfy relation, not just whether or
not relation satisfied. Doing this is called
logical indexing or logical subscripting
• Do this by using logical vector as index in
vector of values. Result is values that satisfy
relation, i.e., values for which relationship
are 1
• NOTE – technique doesn't quite work with arrays.
Won't discuss that case further
14
15. 6.1 Relational and Logical Operators
EXAMPLE
What are the numbers from 1-10 that are
multiples of 3?
>> numbers = 1:10
numbers = 1 2 3 4 5 6 7 8 9 10
>> multiples = rem( numbers, 3 ) == 0
multiples = 0 0 1 0 0 1 0 0 1 0
>> multiplesOf3 = numbers(multiples)
multiplesOf3 =
3 6 9
15
16. 6.1 Relational and Logical Operators
Example
Think of numbers(multiples) as pulling
out of numbers all elements that have a 1 in
the corresponding element of multiples
numbers = 1 2 3 4 5 6 7 8 9 10
multiples = 0 0 1 0 0 1 0 0 1 0
numbers(multiples) = 3 6 9
16
17. 6.1 Relational and Logical Operators
EXAMPLE
What are the prime numbers from 1-20?
>> numbers = 1:20;
>> numbers( isprime(numbers) )
ans =
2 3 5 7 11 13 17 19
Logical indexing is particularly useful when
used with logical operators, discussed next
17
18. 6.1 Relational and Logical Operators
Logical operators:
Boolean logic is a system for combining
expressions that are either true of false.
• MATLAB has operators and commands
to do many Boolean operations
• Boolean operations in combination with
relational commands let you perform
certain types of computations clearly
and efficiently
18
19. 6.1 Relational and Logical Operators
A truth table defines the laws of Boolean
logic. It gives the output of a logical
operation for every possible combination of
inputs. The truth table relevant to MATLAB
is
19
20. 6.1 Relational and Logical Operators
In words, the truth table says
• AND is true if both inputs are true,
otherwise it is false
• OR is true if at least one input is true,
otherwise it is false
• XOR (exclusive OR) is true if exactly one
input is true, otherwise it is false
• NOT is true if the input is false,
otherwise it is false
20
21. 6.1 Relational and Logical Operators
An arithmetic operator, e.g., + or -, is a
symbol that causes MATLAB to perform an
arithmetical operation using the numbers
or expressions on either side of the symbol
Similarly, a logical operator is a character
that makes MATLAB perform a logical
operation on one or two numbers or
expressions
21
22. 6.1 Relational and Logical Operators
MATLAB has three logical operators: &, |, ~
• a&b does the logical AND operation on a and b
• a|b does the logical OR operation on a or b
• ~a does the logical NOT operation on a
• Arguments to all logical operators are numbers
– Zero is "false"
– Any non-zero number is "true"
• Result (output) of logical operator is a logical one
(true) or zero (false)
22
23. 6.1 Relational and Logical Operators
When using logical operator on arrays
• They must be the same dimensions
• MATLAB does an element-wise evaluation of
operator
• Result is an array that has same dimensions
as other two but only contains 1's and 0's
(not only operates on one array so the
first point is irrelevant)
23
24. 6.1 Relational and Logical Operators
When operating with array and scalar
• MATLAB does element-wise operation
on each array element with scalar
• Result is an array that has same
dimensions as original but only contains
1's and 0's
24
25. 6.1 Relational and Logical Operators
Can combine arithmetic, relational
operators, and logical operators. Order
of precedence is
25
26. 6.1 Relational and Logical Operators
EXAMPLE
Child – 12 or less years
Teenager – more than 12 and less than 20 years
Adult – 20 or more years
>> age=[45 47 15 13 11]
age = 45 47 15 13 11
26
27. 6.1 Relational and Logical Operators
EXAMPLE
Who is a teenager?
>> age=[45 47 15 13 11];
>> age>=13
ans = 1 1 1 1 0
>> age<=19
ans = 0 0 1 1 1
>> age>=13 & age<=19
ans = 0 0 1 1 0
27
These mark the two teenagers
28. 6.1 Relational and Logical Operators
EXAMPLE
>> age=[45 47 15 13 11]
age = 45 47 15 13 11
Who is not a teenager?
>> ~(age>=13 & age<=19)
ans = 1 1 0 0 1
Who is an adult or a child?
>> age>19 | age<13
ans = 1 1 0 0 1
28
29. 6.1 Relational and Logical Operators
Built-in logical functions:
MATLAB has some built-in functions or
commands for doing logical operations and
related calculations. Three are equivalent
to the logical operators
• and(A,B) – same as A&B
• or(A,B) – same as A|B
• not(A) – same as ~A
29
30. 6.1 Relational and Logical Operators
MATLAB also has
other Boolean
functions
30
31. 6.2 Conditional Statements
A conditional statement is a command
that allows MATLAB to decide whether
or not to execute some code that
follows the statement
• Conditional statements almost always
part of scripts or functions
• They have three general forms
– if-end
– if-else-end
– if-elseif-else-end
31
32. 6.2.1 The if-end Structure
A flowchart is a diagram that shows the
code flow. It is particularly useful for
showing how conditional statements
work. Some common flowchart
symbols are
• represents a sequence of commands
• represents an if-statement
• shows the direction of code
execution
32
33. 6.2.1 The if-end Structure
If the conditional expression is true,
MATLAB runs the lines of code that are
between the line with if and the line
with end. Then it continues with the
code after the end-line 33
34. 6.2.1 The if-end Structure
If the conditional expression is false,
MATLAB skips the lines of code that are
between the line with if and the line with
end. Then it continues with the code after
the end-line 34
35. 6.2.1 The if-end Structure
The conditional expression is true if it
evaluates to a logical 1 or to a non-zero
number. The conditional expression is false
if it evaluates to a logical 0 or to a
numerical zero 35
36. 6.2.2 The if-else-end Structure
if-else-end structure lets you execute
one section of code if a condition is true and
a different section of code if it is false.
EXAMPLE - answering your phone
if the caller is your best friend
talk for a long time
else
talk for a short time
end
36
37. 6.2.2 The if-else-end Structure
Fig. 6-2 shows the code and the
flowchart for the if-else-end
structure
37
38. 6.2.3 The if-elseif-else-end Structure
if-elseif-else-end structure lets you
choose one of three (or more) sections of code
to execute
EXAMPLE - answering your phone
if the caller is your best friend
talk for a long time
elseif the caller is your study-mate
talk until you get the answer to the hard problem
else
say you'll call back later
end
38
39. 6.2.3 The if-elseif-else-end Structure
Can have as many elseif statements as you want
EXAMPLE
if the caller is your best friend
talk for a long time
elseif the caller is a potential date
talk for a little bit and then set a time to meet
elseif the caller is your study-mate
talk until you get the answer to the hard problem
elseif the caller is your mom
say you're busy and can't talk
else
have your room-mate say you'll call back later
end
39
40. 6.2.3 The if-elseif-else-end Structure
Fig. 6-3 shows the code and the flowchart for
the if-elseif-else-end structure
40
41. 6.2.3 The if-elseif-else-end Structure
Can omit else statement
• In this case, if no match to if- or
elseif-statements, no code in
structure gets executed
41
42. 6.3 The switch-case Statement
if-elseif-else-end structure
gets hard to read if more than a few
elseif statements. A clearer
alternative is the switch-case
structure
• switch-case slightly different
because choose code to execute
based on value of scalar or string, not
just true/false
42
43. 6.3 The switch-case Statement
Concept is
switch name
case 'Bobby'
talk for a long time
case 'Susan'
talk for a little bit and then set a time to meet
case 'Hubert'
talk until you get the answer to the hard problem
case 'Mom'
say you're busy and can't talk
otherwise
have your room-mate say you'll call back later
end
43
45. 6.3 The switch-case Statement
switch evaluates
switch-expression
–If value is equal to
value1, executes
all commands up to
next case,
otherwise,
or end statement, i.e., Group 1
commands, then executes code after
end statement
–If value is equal to value2, same as
above but Group 2 commands only
–Etc. 45
46. 6.3 The switch-case Statement
• If switch-expression not
equal to any of values in
case statement,
commands after
otherwise executed. If
otherwise not present,
no commands executed
• If switch expression matches more than one
case value, only first matching case executed
46
47. 6.3 The switch-case Statement
Comparisons of text strings are case-
sensitive. If case values are text strings,
make all values either lower case or upper
case, then use upper or lower
command to convert switch expression
caller = lower( name );
switch caller
case 'bobby'
some code
case 'susan'
some code
case 'mom'
some code
end
47
T I P
48. 6.4 Loops
A loop is another method of flow
control. A loop executes one set of
commands repeatedly. MATLAB has
two ways to control number of times
loop executes commands
• Method 1 – loop executes commands a
specified number of times
• Method 2 – loop executes commands as
long as a specified expression is true
48
49. 6.4.1 for-end Loops
A for-end loop (often called a for-
loop) executes set of commands a
specified number of times. The set of
commands is called the body of the
loop
49
50. 6.4.1 for-end Loops
• The loop index variable can have any
variable name (usually i, j, k, m, and n
are used)
– i and j should not be used when working
with complex numbers. (ii and jj are good
alternative names)
50
Body of loop
51. 6.4.1 for-end Loops
1. Loop sets k to f,
and executes
commands between
for and the end commands,
i.e., executes body of loop
2. Loop sets k to f+s, executes body
3. Process repeats itself until k > t
4. Program then continues with commands
that follow end command
• f and t are usually integers
• s usually omitted. If so, loop uses
increment of 1
51
Body of loop
52. 6.4.1 for-end Loops
• Increment s can be negative
– For example, k = 25:–5:10 produces four
passes with k = 25, 20, 15, 10
• If f = t, loop executes once
• If f > t and s > 0, or if f < t and
s < 0, loop not executed
52
Body of loop
53. 6.4.1 for-end Loops
• If values of k, s, and t are such that k cannot
be equal to t, then
– If s positive, last pass is one where k has largest
value smaller than t
• For example, k = 8:10:50 produces five passes with
k = 8, 18, 28, 38, 48
– If s is negative, last pass is one where k has
smallest value larger than t
53
Body of loop
54. 6.4.1 for-end Loops
• In the for command k can also be assigned
specific value (typed in as a vector)
– For example: for k = [7 9 –1 3 3 5]
• In general, loop body should not change value
of k
• Each for command in a program must have
an end command
54
Body of loop
55. 6.4.1 for-end Loops
• Value of loop index variable (k) not
displayed automatically
– Can display value in each pass (sometimes
useful for debugging) by typing k as one of
commands in loop
• When loop ends, loop index variable (k)
has value last assigned to it
55
Body of loop
56. 6.4.1 for-end Loops
EXAMPLE
Script
for k=1:3:10
k
x = k^2
end
fprintf('After loop k = %dn', k);
56
Output
k = 1
x = 1
k = 4
x = 16
k = 7
x = 49
k = 10
x = 100
After loop k = 10
57. 6.4.1 for-end Loops
Can often calculate something
using either a for-loop or
elementwise operations.
Elementwise operations are:
• Often faster
• Often easier to read
• More MATLAB-like
GENERAL ADVICE – use
elementwise operations when you
can, for-loops when you have to
57
T I P
58. 6.4.2 while-end Loops
while-end loop used when
• You don't know number of loop iterations
• You do have a condition that you can test and
stop looping when it is false. For example,
– Keep reading data from a file until you reach the
end of the file
– Keep adding terms to a sum until the difference
of the last two terms is less than a certain
amount
58
59. 6.4.2 while-end Loops
1. Loop
evaluates
conditional-expression
2. If conditional-expression is true,
executes code in body, then goes
back to Step 1
3. If conditional-expression is false,
skips code in body and goes to code
after end-statement
59
60. 6.4.2 while-end Loops
The conditional expression of a while-
end loop
• Has a variable in it
– Body of loop must change value of variable
– There must be some value of the variable that
makes the conditional expression be false
60
62. 6.4.2 while-end Loops
If the conditional expression never
becomes false, the loop will keep
executing... forever! The book calls this
an indefinite loop, but more commonly
referred to as an infinite loop. Your
program will just keep running, and if
there is no output from the loop (as if
often the case), it will look like MATLAB
has stopped responding
62
63. 6.4.2 while-end Loops
Common causes of indefinite loops:
• No variable in conditional expression
distance1 = 1;
distance2 = 10;
distance3 = 0;
while distance1 < distance2
fprintf('Distance = %dn',distance3);
end
63
distance1 and distance2
never change
64. 6.4.2 while-end Loops
Common causes of indefinite loops:
• Variable in conditional expression never
changes
minDistance = 42;
distanceIncrement = 0;
distance = 0;
while distance < minDistance
distance=distance+distanceIncrement;
end
64
Typo – should be 10
65. 6.4.2 while-end Loops
Common causes of indefinite loops:
• Wrong variable in conditional expression
changed
minDistance = 42;
delta = 10;
distance = 0;
while distance < minDistance
minDistance = minDistance + delta;
end
65
Typo – should be distance
66. 6.4.2 while-end Loops
Common causes of indefinite loops:
• Conditional expression never becomes false
minDistance = 42;
x = 0;
y = 0;
while -sqrt( x^2+y^2 ) < minDistance
x = x + 1;
y = y + x;
end
66
Typo – shouldn't be
any negative sign
67. 6.4.2 while-end Loops
If your program gets caught in an
indefinite loop,
• Put the cursor in the Command
Window
• Press CTRL+C
67
T I P
68. 6.5 Nested Loops and Nested Conditional Statements
If a loop or conditional statement is
placed inside another loop or
conditional statement, the former are
said to be nested in the latter.
• Most common to hear of a nested loop,
i.e., a loop within a loop
– Often occur when working with two-
dimensional problems
• Each loop and conditional statement must
have an end statement
68
70. 6.6 THE break AND continue COMMANDS
The break command:
• When inside a loop (for and while), break
terminates execution of loop
– MATLAB jumps from break to end command
of loop, then continues with next command
(does not go back to the for or while
command of that loop).
– break ends whole loop, not just last pass
• If break inside nested loop, only nested
loop terminated (not any outer loops)
70
71. 6.6 The break and continue Commands
–break command in script or function
file but not in a loop terminates
execution of file
–break command usually used within a
conditional statement.
• In loops provides way to end looping if some
condition is met
71
72. 6.6 The break and continue Commands
EXAMPLE
Script
while( 1 )
name = input( 'Type name or q to quit: ', 's' );
if length( name ) == 1 && name(1) == 'q'
break;
else
fprintf( 'Your name is %sn', name );
end
end
72
Output for inputs of "Greg", "quentin", "q"
Type name or q to quit: Greg
Your name is Greg
Type name or q to quit: quentin
Your name is quentin
Type name or q to quit: q
>>
Trick – "1" is always true so it makes loop iterate forever!
If user entered only one
letter and it is a "q", jump
out of loop
Otherwise print name
Only way to exit loop!
73. 6.6 The break and continue Commands
The continue command:
Use continue inside a loop (for- and while-)
to stop current iteration and start next iteration
– continue usually part of a conditional
statement. When MATLAB reaches continue it
does not execute remaining commands in loop
but skips to the end command of loop and then
starts a new iteration
73
74. 6.6 The break and continue Commands
EXAMPLE
for ii=1:100
if rem( ii, 8 ) == 0
count = 0;
fprintf('ii=%dn',ii);
continue;
end
% code
% more code
end
74
Every eight iteration reset
count to zero, print the
iteration number, and skip
the remaining
computations in the loop