
Ministry of education and science, youth and sport of Ukraine
National Aviation University
Computer Architecture
Laboratory work 6
Study matrices and arrays manipulating methods and approaches
Prepared by: Student of CSF - 205 Bashuk K.A.
Accepted by: Associate professor
Romanov E.I
Kyiv 2012
Table of contents
1.Task 7
2.Theory 7
Matrices and Magic squares 7
About matrices 7
Entering matrices 7
sum, transpose, and diag 8
Subscripts 9
The Colon Operator 10
The magic Function 10
Expressions 11
Variables 11
Numbers 11
Operators 12
Functions 12
Examples of Expressions 13
3.Conclusion 13
Task
1. Matrices and Magic squares:
About matrices;
Entering matrices;
sum, transpose(‘) and diag;
Subscripts;
The Colon operator;
The magic function.
2. Expressions
Variables;
Numbers;
Operators;
Functions;
Examples of Expressions.
Theory
Matrices and Magic squares
About matrices
In the MATLAB environment, a matrix is a rectangular array of numbers. Special meaning is sometimes attached to 1-by-1 matrices, which are scalars, and to matrices with only one row or column, which are vectors. MATLAB has other ways of storing both numeric and nonnumeric data, but in the beginning, it is usually best to think of everything as a matrix. The operations in MATLAB are designed to be as natural as possible. Where other programming languages work with numbers one at a time, MATLAB allows you to work with entire matrices quickly and easily. A good example matrix, used throughout this book, appears in the Renaissance engraving Melencolia I by the German artist and amateur mathematician Albrecht Dürer.
This image is filled with mathematical symbolism, and if you look carefully, you will see a matrix in the upper right corner. This matrix is known as a magic square and was believed by many in Dürer's time to have genuinely magical properties. It does turn out to have some fascinating characteristics worth exploring.
Entering matrices
The best way for you to get started with MATLAB is to learn how to handle matrices. Start MATLAB and follow along with each example.
You can enter matrices into MATLAB in several different ways:
Enter an explicit list of elements.
Load matrices from external data files.
Generate matrices using built-in functions.
Create matrices with your own functions and save them in files.
Start by entering Dürer's matrix as a list of its elements. You only have to follow a few basic conventions:
Separate the elements of a row with blanks or commas.
Use a semicolon, ; , to indicate the end of each row.
Surround the entire list of elements with square brackets, [ ].
To enter Dürer's matrix, simply type in the Command Window
A = [16 3 2 13; 5 10 11 8; 9 6 7 12; 4 15 14 1]
MATLAB displays the matrix you just entered:
A =
16 3 2 13
5 10 11 8
9 6 7 12
4 15 14 1
This matrix matches the numbers in the engraving. Once you have entered the matrix, it is automatically remembered in the MATLAB workspace. You can refer to it simply as A. Now that you have A in the workspace, take a look at what makes it so interesting.