Presentation is loading. Please wait.

Presentation is loading. Please wait.

MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.

Similar presentations


Presentation on theme: "MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU."— Presentation transcript:

1 MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Email:rmadaz1@lsu.edurmadaz1@lsu.edu Dept of Mechanical Engineering LSU

2 Tutorial Outline Session 1: Introduction to MATLAB Session 2: Programming in MATLAB Session 3: Plotting in MATLAB Session 4: Mathematical Applications using MATLAB Session 5: Mathematical Applications using MATLAB (cont.) Session 6: Engineering Applications using MATLAB Session 7: Open for specific problems Department of Mechanical Engineering, LSU

3 Session Outline  Overview of MATLAB  Using the built-in functions  Constants and Variables  Basic Arithmetic Operations  Matrices and Computation  Solving simple equations Department of Mechanical Engineering, LSU

4 What is MATLAB? MATLAB is basically a computing tool for engineers and mathematicians. Features include:  Interactive programming environment  Graphing facilities  Built-in functions  Toolboxes designed for specialized field of applications Department of Mechanical Engineering, LSU

5 Background info about MATLAB  MATLAB is an acronym for Matrix Laboratory  Cleve Moler was the original creator of MATLAB  MATLAB is now a product of Math Works Inc. co- founded by Cleve Moler and Jack Little.  First version of it appeared as early as 1981  Initially written for matrix computations, it contained only 3000 lines of source code written in FORTRAN Department of Mechanical Engineering, LSU

6 What can MATLAB do for you?  Produce effective solutions  Compact the time invested in analysis and development  Reduce project costs  Quickly test and compare multiple alternatives  Modeling and simulation  ……………………………………………….ad infinitum Department of Mechanical Engineering, LSU

7 Getting Started……. Prerequisites:  Basic knowledge of linear algebra  Some computer experience (helpful but not necessary)  Curiosity!!!!! Department of Mechanical Engineering, LSU

8 Basic Arithmetic Operations Addition:a+b Subtraction:a- b Multiplication:a*b Division:a/b Power:a^b Note the symbols being used for the operators. Department of Mechanical Engineering, LSU

9 In MATLAB…. Department of Mechanical Engineering, LSU

10 Naming Constants and Variables  The value of  is stored in MATLAB as pi  The contents of the variable ans change with every answer  Variable names can contain upto 31 characters  Every variable must start off with a letter  When you write the semicolon ‘;’ at the end of the statement the computer will not display the result after you press the return key.  MATLAB is case sensitive. A & a are identified different Department of Mechanical Engineering, LSU

11 In MATLAB…. Department of Mechanical Engineering, LSU

12 Built-in math functions abs(x) absolute value of x Sin(x) sine of x (where x is in radians) asin(x) arcsine of x exp(x) exponential of x log(x) natural logarithm of x log10(x) base 10 logarithm of x sqrt(x) square root of x imag(x) imaginary part of complex number x real(x) real part of the complex number x Department of Mechanical Engineering, LSU

13 In MATLAB….. To get more information about other functions type at command prompt: >>help elfun Department of Mechanical Engineering, LSU

14 Vectors and matrices  An ordered collection of numbers separated by commas or spaces can be defined in MATLAB as an array or vector  Example: A=[1 2 3 4 5] is an array of 1 row and 5 columns  A matrix is defined as an array of n  n elements  The elements of an array are identified by their index  The number of elements of an array can be retrieved using the length function  The addition and subtraction are defined only for arrays of the same length Department of Mechanical Engineering, LSU

15 In MATLAB…. Department of Mechanical Engineering, LSU

16 Vectors and matrices (cont..)  Array of equally spaced elements can be entered by stating the first element, the increment and the last element  When the increment is 1 it can be omitted Department of Mechanical Engineering, LSU

17 Vectors and matrices (cont..)  Array multiplication in MATLAB is indicated by “.*”  For example : A.*B is the product of two arrays  Array division in MATLAB is indicated by “./”  For example : A./B is the quotient of two arrays  We can also raise the elements of the array to the same power by using the operator “.^”  Many built-in functions can be applied to the array by simply using the array name as the argument Department of Mechanical Engineering, LSU

18 In MATLAB…. Department of Mechanical Engineering, LSU

19 Simple plots using arrays Department of Mechanical Engineering, LSU

20 Plot result….. Department of Mechanical Engineering, LSU

21 Row Vectors and Column Vectors  One dimensional arrays can be considered as row vectors  Column vectors are generated by entering an array of numbers separated by semicolons “;”  Row vectors and column vectors can be converted into each other by transposition operation “ ‘ “

22 Department of Mechanical Engineering, LSU In MATLAB….

23 Department of Mechanical Engineering, LSU Defining a matrix  Matrices are defined as two dimensional arrays  Different rows are separated by semi colons or type each row separately and press enter  Any element of a matrix is identified by two indices: the first indicates the row and the second indicates the column

24 Department of Mechanical Engineering, LSU In MATLAB….

25 Department of Mechanical Engineering, LSU Cont…  The number of rows and columns in a matrix is retrieved by size function  We can create a new matrix by putting two matrices besides each other

26 Department of Mechanical Engineering, LSU Cont…  We can also extract a sub matrix out of a matrix

27 Cont… Department of Mechanical Engineering, LSU  We can generate a matrix with the same number of rows and columns as A, with all the elements equal to one, using the command ones  Similarly using the command zeroes we can get all the elements of the matrix as zeroes

28 Department of Mechanical Engineering, LSU Polynomials….  Polynomial is expressed in MATLAB as an array of coefficients, A=[1 2 -4]  The equation is solved by using the function roots(A)  The coefficients of the polynomial can be retrieved from its roots through the function poly()  The value of a polynomial at point x is obtained by function polyval(A,x) where A is the array, the coefficients of the polynomial are stored

29 Department of Mechanical Engineering, LSU In MATLAB….

30 Department of Mechanical Engineering, LSU Complex Numbers

31 Department of Mechanical Engineering, LSU Solving systems of Equations… x 1 + 2x 2 + x 3 = 4 2x 1 + 3x 2 - x 3 = 9 4x 1 - x 2 +2x 3 = 0

32 Department of Mechanical Engineering, LSU In MATLAB….

33 Department of Mechanical Engineering, LSU Looking ahead…. There are several books written on MATLAB where a good Description about the functions is given.  Introduction to MATLAB for Engineers and Scientists Delores M. Etter & David C. Kentucky  A guide to MATLAB: for Beginners and experienced users Brian R. Hunt, Ronald L. Lipsman & JM Rosenberg

34 Department of Mechanical Engineering, LSU Next Session…. Programming in MATLAB :  How to use M Files  Programming functions  Control Structures  Displaying output in different formats

35 Thank You Department of Mechanical Engineering, LSU


Download ppt "MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU."

Similar presentations


Ads by Google