CHAPTER (2)
Download
1 / 19

CHAPTER (2) - PowerPoint PPT Presentation


  • 68 Views
  • Uploaded on

CHAPTER (2). MATRIX OPERATIONS. Matrix Algebra with MATLAB. MATRIX is a two-dimensional, rectangular shaped data structure capable of storing multiple elements of data in an easily accessible format. These data elements can be numbers, characters, logical states of true or false.

loader
I am the owner, or an agent authorized to act on behalf of the owner, of the copyrighted work described.
capcha
Download Presentation

PowerPoint Slideshow about ' CHAPTER (2)' - erica-sullivan


An Image/Link below is provided (as is) to download presentation

Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author.While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server.


- - - - - - - - - - - - - - - - - - - - - - - - - - E N D - - - - - - - - - - - - - - - - - - - - - - - - - -
Presentation Transcript

CHAPTER (2)

MATRIX OPERATIONS

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • MATRIX is a two-dimensional, rectangular shaped data structure capable of storing multiple elements of data in an easily accessible format. These data elements can be numbers, characters, logical states of true or false.

  • MATLAB is a matrix-based computing environment. All of the data that you enter into MATLAB is stored in the form of a matrix or a multidimensional array. Even a single numeric value like 100 is stored as a matrix.

    • >> A=100;

    • >> whos A

    • Name Size Bytes Class

    • A 1x1 8 double

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • The simplest way to create a matrix in MATLAB is to use the matrix constructor operator, [ ].

  • Entering a Matrix

MATLAB Format

  • >> A = [2 -3 5; -1 4 5]

  • A =

  • 2 -3 5

  • -1 4 5

Eng. Mohamed EltaherEng.Ahmed Ibrahim


MATLAB Format

  • >> x = [1 4 7] or >> x = [1, 4, 7]

  • x =

  • 1 4 7

  • Entering a Column Vector in MATLAB

MATLAB Format

  • >> x = [1; 4; 7];

  • or

  • >> x = [1 4 7]'

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • MATLAB has a number of functions that create different kinds of matrices.

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • Dimensions of the Matrix

  • These functions return information about the shape and size of a matrix.

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • Matrix addition and subtraction with MATLAB are achieved in the same manner as with scalars provided that the matrices have the same size. Typical expressions are shown below.

  • >> C = A + B

  • >> D = A - B

  • MATLAB has many error messages that indicate problems with operations. If the matrices have different sizes, the message is

    • ??? Error using ==> 

    • Matrix dimensions must agree.

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • Addition

    • Commutative: A+B=B+A

    • Associative: (A+B)+C=A+(B+C)

  • Subtraction

    • By adding a negative matrix

Eng. Mohamed EltaherEng.Ahmed Ibrahim


Eng. Mohamed EltaherEng.Ahmed Ibrahim


Eng. Mohamed EltaherEng.Ahmed Ibrahim


Example: -

Given a matrix

»mat=[1 2 -3;-3 -1 1;1 -1 1];

  • Calculate the rank of a matrix

    »r=rank(mat);

    the number of linearly independent rows or columns

    Calculate the determinant

    »d=det(mat); mat must be square !

    if determinant is nonzero, matrix is invertible

  • Get the matrix inverse

    »E=inv(mat);

Eng. Mohamed EltaherEng.Ahmed Ibrahim


Two vectors:

Inner product = scalar

  • Vector Products

Inner product XTY is a scalar

(1xn) (nx1)

Outer product = matrix

  • Outer product XYT is a matrix

    (nx1) (1xn)

Eng. Mohamed EltaherEng.Ahmed Ibrahim


Example:-

  • >> u = [3; 1; 4];

  • >> v = [2 0 -1];

  • >> x = v*uscalar

    • x =

    • 2

  • >> X = u*vmatrix

  • >> X =

    • 6 0 -3

    • 2 0-1

    • 8 0 -4

Eng. Mohamed EltaherEng.Ahmed Ibrahim


>> A=ones(2);

>> A.^2

ans =

1 1

1 1

>> A=ones(2);

>> A^2

ans =

2 2

2 2

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • The Transpose Operationinterchanges aij and aji. MATLAB uses the apostrophe operator (') to perform a complex conjugate transpose, and uses the dot-apostrophe operator (.') to transpose without conjugation. For matrices containing all real elements, the two operators return the same result.

  • The example matrix A is symmetric, so A' is equal to A. But B is not symmetric:

  • >>B = magic(3);

  • >>X = B'

  • Transposition turns a row vector into a column vector:

  • >>v = [2 0 -1];

  • >>x = v'

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • >>z = [1+2i 7-3i 3+4i; 6-2i 9i 4+7i]

  • >>z'

  • ans =

    • 1.0000 - 2.0000i 6.0000 + 2.0000i

    • 7.0000 + 3.0000i 0 - 9.0000i

    • 3.0000 - 4.0000i 4.0000 - 7.0000i

  • The unconjugated complex transpose, where the complex part of each element retains its sign, is denoted by z.':

  • >>z.'

  • ans =

  • 1.0000 + 2.0000i 6.0000 - 2.0000i

  • 7.0000 - 3.0000i 0 + 9.0000i

  • 3.0000 + 4.0000i 4.0000 + 7.0000i

Eng. Mohamed EltaherEng.Ahmed Ibrahim


  • Sets of Linear Equation transposes the vector or matrix, but also converts each complex element to its complex conjugate. That is, the sign of the imaginary part of each complex element changes. So if

  • One of the most important problems in technical computing is the solution of systems of simultaneous linear equations. For example, consider the set of equations:-

  • The less favorable, but more straightforward method is to take

  • The preferable solution is found using the matrix left-division operator

The residual error can be computed by

Eng. Mohamed EltaherEng.Ahmed Ibrahim


Example:- transposes the vector or matrix, but also converts each complex element to its complex conjugate. That is, the sign of the imaginary part of each complex element changes. So if

Given a system of linear equations

x+2y-3z=5

-3x-y+z =-8

x- y+ z =0

Solution

  • »A=[1 2 -3;-3 -1 1;1 -1 1];

  • »b=[5;-8;0];

    and solve with a single line of code!

    »x=A\b;

    x is a 3x1 vector containing the values of x, y, and z. the residual will be »res=A*x-b;

Eng. Mohamed EltaherEng.Ahmed Ibrahim


Example:- transposes the vector or matrix, but also converts each complex element to its complex conjugate. That is, the sign of the imaginary part of each complex element changes. So if

Use MATLAB to solve the simultaneous equations below.

Solution

  • »A=[??????];

  • »b=[???? ];

    and solve with a single line of code!

    »x=A\b;

  • Or » x = inv(A)*b

  • Eng. Mohamed EltaherEng.Ahmed Ibrahim


    ad