What Is MATLAB lec 1

Information about What Is MATLAB lec 1

Published on July 25, 2014

Author: yatindrapathak3

Source: authorstream.com

Content

What Is MATLAB: What Is MATLAB Presented By Sandeep Gupta PowerPoint Presentation: MATLAB is a high-performance language for technical computing . It integrates computation, visualization, and programming in an easy-to-use environment where problems and solutions are expressed in familiar mathematical notation. Typical uses include: Typical uses include Math and computation Algorithm development Data acquisition Modeling , simulation, and prototyping Data analysis, exploration, and visualization Scientific and engineering graphics Application development, including graphical user interface building Toolboxes: Toolboxes MATLAB features a family of add-on application-specific solutions called toolboxes. Very important to most users of MATLAB, toolboxes allow you to learn and apply specialized technology. Toolboxes are comprehensive collections of MATLAB functions (M-files) that extend the MATLAB environment to solve particular classes of problems. Areas in which toolboxes are available include signal processing, control systems, neural networks, fuzzy logic, wavelets, simulation, and many others. The MATLAB System: The MATLAB System Development Environment The MATLAB Mathematical Function Library The MATLAB Language Graphics The MATLAB Application Program Interface (API) MATLAB Documentation: MATLAB Documentation MATLAB Online Help Desktop Tools and Development Environment Mathematics Programming Graphics 3-D Visualization Creating Graphical User Interfaces External Interfaces MATLAB also includes reference documentation for all MATLAB functions: MATLAB also includes reference documentation for all MATLAB functions Functions — Categorical List — Lists all MATLAB functions grouped into categories •Handle Graphics Property Browser — Provides easy access to descriptions of graphics object properties •External Interfaces Reference — Covers those functions used by the MATLAB external interfaces, providing information on syntax in the calling language, description, arguments, return values, and examples PowerPoint Presentation: The MATLAB online documentation also includes Examples — An index of examples included in the documentation Release Notes — New features and known problems in the current release Printable Documentation — PDF versions of the documentation suitable for printing. To enter matrix, simply type in the Command Window: To enter matrix, simply type in the Command Window A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1] Some Funtions sum, transpose, and diag sum(A) A‘ sum(A')‘ diag (A) sum( diag (A)) sum( diag ( fliplr (A))) Subscripts: Subscripts A(1,4) + A(2,4) + A(3,4) + A(4,4) If you try to use the value of an element outside of the matrix, it is an error. t = A(4,5) Index exceeds matrix dimensions On the other hand, if you store a value in an element outside of the matrix, the size increases to accommodate the newcomer. X = A; X(4,5) = 17 The Colon Operator: The Colon Operator The colon, :, is one of the most important MATLAB operators. It occurs in several different forms. The expression 1:10 To obtain nonunit spacing, specify an increment. For example, 100:-7:50 0:pi/4:pi Subscript expressions involving colons refer to portions of a matrix. : Subscript expressions involving colons refer to portions of a matrix. A(1:k,j) is the first k elements of the jth column of A. So sum(A(1:4,4)) sum(A(:,end)) sum(1:16)/4 The magic Function: The magic Function MATLAB actually has a built-in function that creates magic squares of almost any size. Not surprisingly, this function is named magic. B = magic(4) To make this B into A , swap the two middle columns. A = B(:,[1 3 2 4]) This says, for each of the rows of matrix B, reorder the elements in the order 1,3, 2, 4 Expressions: Expressions •“Variables” •“Numbers” •“Operators” •“Functions” Variables: Variables MATLAB does not require any type declarations or dimension statements. When MATLAB encounters a new variable name, it automatically creates the variable and allocates the appropriate amount of storage. If the variable already exists, MATLAB changes its contents and, if necessary, allocates new storage. For example, num_students = 25 creates a 1-by-1 matrix named num_students and stores the value 25 in its single element. PowerPoint Presentation: Variable names consist of a letter, followed by any number of letters, digits, or underscores. MATLAB is case sensitive; it distinguishes between uppercase and lowercase letters. A and a are not the same variable N = namelengthmax N = 63 The genvarname function can be useful in creating variable names that are both valid and unique. v = genvarname ({'A', 'A', 'A', 'A'}) Numbers: Numbers MATLAB uses conventional decimal notation, with an optional decimal point and leading plus or minus sign, for numbers. Scientific notation uses the letter e to specify a power-of-ten scale factor. Imaginary numbers use either i or j as Operators: Operators + Addition - Subtraction * Multiplication / Division \ Left division (described in “Matrices and Linear Algebra” in the MATLAB documentation) ^ Power ' Complex conjugate transpose ( ) Specify evaluation order Functions: Functions MATLAB provides a large number of standard elementary mathematical functions, including abs, sqrt , exp, and sin. MATLAB also provides many more advanced mathematical functions, including Bessel and gamma functions. Most of these functions accept complex arguments. For a list of the elementary mathematical functions, type help elfun Several special functions provide values of useful constants.: Several special functions provide values of useful constants. PowerPoint Presentation: The function names are not reserved. It is possible to overwrite any of them with a new variable, such as eps = 1.e-6 and then use that value in subsequent calculations. The original function can be restored with clear eps Examples of Expressions You have already seen several examples of MATLAB expressions. Here are a few more examples, and the resulting values.: Examples of Expressions You have already seen several examples of MATLAB expressions. Here are a few more examples, and the resulting values. Working with Matrices: Working with Matrices •“Generating Matrices” •“The load Function” •“M-Files” •“Concatenation” •“Deleting Rows and Columns” PowerPoint Presentation: MATLAB provides four functions that generate basic matrices. Here are some examples. Z = zeros(2,4) R = randn (4,4) The load Function: The load Function The load function reads binary files containing matrices generated by earlier MATLAB sessions, or reads text files containing numeric data. load data.dat M-Files : M-Files You can create your own matrices using M-files, which are text files containing MATLAB code. Use the MATLAB Editor or another text editor to create a file containing the same statements you would type at the MATLAB command line. Save the file under a name that ends in .m. Store the file under the name magik.m . Then the statement Magik reads the file and creates a variable, A, containing our example matrix. Concatenation: Concatenation Concatenation is the process of joining small matrices to make bigger ones. B = [A A+32; A+48 A+16] This matrix is halfway to being another magic square. Its elements are a rearrangement of the integers 1:64. Its column sums are the correct value for an 8-by-8 magic square. sum(B) Deleting Rows and Columns: Deleting Rows and Columns You can delete rows and columns from a matrix using just a pair of square brackets. Start with X = A; Then, to delete the second column of X, use X(:,2) = [] If you delete a single element from a matrix, the result is not a matrix anymore. : If you delete a single element from a matrix, the result is not a matrix anymore. So, expressions like X(1,2) = [] result in an error. However, using a single subscript deletes a single element, or sequence of elements, and reshapes the remaining elements into a row vector. So X(2:2:10) = [] More About Matrices and Arrays: More About Matrices and Arrays This section shows you more about working with matrices and arrays, focusing on •“Linear Algebra” •“Arrays” •“Multivariate Data” •“ Scalar Expansion” •“Logical Subscripting” •“The find Function” Linear Algebra: Linear Algebra Informally, the terms matrix and array are often used interchangeably. More precisely, a matrix is a two-dimensional numeric array that represents a linear transformation. The mathematical operations defined on matrices are the subject of linear algebra. A + A‘ det (A) rref (A) inv(A) eig (A) v = ones(4,1) P = A/34 P^5 poly(A) Arrays: Arrays When they are taken away from the world of linear algebra, matrices become two-dimensional numeric arrays. Arithmetic operations on arrays are done element by element. This means that addition and subtraction are the same for arrays and matrices, but that multiplicative operations are different. MATLAB uses a dot, or decimal point, as part of the notation for multiplicative array operations. The list of operators includes: The list of operators includes A.*A Building Tables: Building Tables Array operations are useful for building tables. Suppose n is the column vector n = (0:9)'; pows = [n n.^2 2.^n] builds a table of squares and powers of 2

Related presentations