Sie sind auf Seite 1von 6

MATLAB TUTORIAL FOR BEGINNERS

WHAT IS MATLAB?

Matlab is an interactive program for numerical computation and data visualization; it is used extensively by control engineers for analysis and design. There are many different toolboxes available which extend the basic functions of Matlab into different application areas. Matlab is supported on Unix, Macintosh, and Windows environments; a student version of Matlab is available for personal computers. For more information on Matlab, contact the Mathworks.

WHY MATLAB?

MATLAB is relatively easy to learn MATLAB code is optimized to be relatively quick when performing matrix operations MATLAB may behave like a calculator or as a programming language MATLAB is interpreted, errors are easier to fix.

WHAT MATLAB IS NOT (Limitations of MATLAB)

MATLAB is NOT a general purpose programming language. MATLAB is an interpreted language (making it for the most part slower than a compiled language such as C++) MATLAB is designed for scientific computation and is not suitable for some things (such as parsing text).

MATLAB IS A MATRIX CALCULATOR !

MATrix + LABoratory = MATLAB

MATRICES

What is a matrix? A matrix is a an arrangement of rows and columns, Like this

One can see that this has 3 rows and 3 columns i.e. it is a 3 by 3 matrix.

FOR MATLAB EVERYTHING IS A MATRIX !

Question: Is scalar number 5 a matrix for MATLAB? Answer: Yes number 5 is a 1 by 1 matrix. Creating a matrix is as easy as making a vector, using semicolons (;) to separate the rows of a matrix. If we type

A= [1 2 3; 4 5 6; 7 8 9]

Matlab will receive a matrix A in workspace. If we do A+Enter MATLAB will give what is stored in A. One area in which MATLAB excels is matrix computation. We can easily find the transpose of the matrix 'A'.

B = A'

Now let's multiply these two matrices together. Note again that MATLAB doesn't require you to deal with matrices as a collection of numbers. MATLAB knows when you are dealing with matrices and adjusts your calculations accordingly.

C=A*B

Let's find the inverse of a matrix ..

X = inv(A)

.. and then illustrate the fact that a matrix times its inverse is the identity matrix.

I = inv(A) * A

MATLAB has functions for nearly every type of common matrix calculation.

SOME BASIC MATRIX OPERATIONS Hands On

MATRIX OPERATIONS IN MATLAB It is possible to perform operations and commands on matrices. The following MATLAB operations are important. Multiplication

Matrix

Size

(m rows and n columns) i= 1,2, m j= 1,2, n

j= 1,2, n k= 1,2, p

i= 1,2, m k= 1,2, p (product of and )

where

= ai1 b1k + ai2 b2k + + ain bnk

So,

Product of the matrices

and

can only be formed if the sizes of

and

are . If may or

compatible: the number of columns of exists, may or may not exist. If .

must be equal to the number of rows of as well as exist, then

may not be equal to

Within MATLAB, the matrix product of

and

is always defined if either

or

is a

number. Multiplication of a matrix by a number (scalar multiplication) results in multiplication of all matrix elements by that number. The symbol for matrix multiplication in MATLAB is *, i.e.,

>> A*B

ADDITION AND SUBTRACTION

Addition

>> A+B

and Subtraction:

>> A-B

of two matrices

and

is performed by addition and subtraction of the separate elements

of the matrix. In MATLAB, these operations are defined if the sizes of the matrices are the same or if one of the matrices is a scalar. In the latter case the scalar is added to or subtracted from every element of the matrix.

RAISING TO A POWER The command

>> A^p

raises the matrix multiplication of

to the

power. If

is a positive integer,

is calculated by repeated

by itself. The matrix

needs to be square (i.e., the number of rows is equal

to the number of columns) to be able to perform this operation.

TRANSPOSITION Let be an matrix. , is the matrix with .

Then the transpose of , denoted by

In MATLAB, the command transpose(A) or A' (the latter only for real valued matrices) calculates the

transpose of the matrix . To give an example:

>> [1 2 3]'

forms the column matrix: >> 1 2 3 If the matrix contains complex, non-real, elements, then the command A' does not only with respect to the diagonal, but it also takes the complex conjugate of with respect to the diagonal,

reflect the matrix

every element. If you only want to calculate the reflection of you can do this with the command A.'.

Das könnte Ihnen auch gefallen