You are on page 1of 15

Lab Name: To perform partitioning of Matrices using MATLAB with insight about partitioned

Matrices application in Computational Fluid Dynamics (CFD), Mathematical Modeling of Physical


systems and Matrix calculations of High-speed Computers.

Course title: Control Engineering (Lab) Total Marks: 20


Practical No. 3 Date of experiment performed:
Course teacher/Lab Instructor: Engr.Syed M kashif Shah Date of marking:
Student Name:
Registration no:

Marking Evaluation Sheet

Knowledge Domain Taxonomy Contribution Max. Obtained


components level marks marks

1. Student is aware
with requirement Set (P2) 3
and use of apparatus
involved in Experiment.
Psychomotor
2. Student has conducted the
experiment by practicing 70%
the hands-on skills as per
Instructions. Guided Response 11
3. Student has achieved (P3)
required accuracy in
performance.

4. Student is aware of discipline


& safety rules and followed Affective Receiving (A1) 2
the rules during experiment. 20%

5. Student has responded well


Respond (A2) 2
and contributed affectively in
Respective lab activity
6. Student familiar with Comprehension
partitioning of matrices using Cognitive 10% 2
(C2)
matlab and mathematical
modelling of physical
systems.

Total 20

Signed by Course teacher/ Lab


Instructor

Page 1 of 15
EXPERIMENT # 3

To perform partitioning of Matrices using MATLAB with insight about partitioned


Matrices application in Computational Fluid Dynamics (CFD), Mathematical Modeling
of Physical systems and Matrix calculations of High-speed Computers.
PRE LAB TASK

Objective:
1. To be familiar with Matrix Partitioning with insight about Partitioned (Block) Matrix
appearance in most modern applications of Linear Algebra such as Computational Fluid
Dynamics (CFD), Mathematical Modeling of Physical systems and Matrix calculations of
High-speed Computers.
2. To be familiar with basics of Matrix Partitioning with MATLAB.
Theory:

1. Introduction to Matrix Partitioning

A key feature of work on matrices has been the ability to regard a matrix A as a list of column
vectors rather than just a rectangular array of numbers. This point of view has been so useful
that we wish to consider other partitions of A, indicated by horizontal and vertical dividing
rules, as in Example 1 below.

In Linear algebra, a block matrix or a partitioned matrix is a matrix that is interpreted as having
been broken into sections called blocks or submatrices. Intuitively, a matrix interpreted as a
block matrix can be visualized as the original matrix with a collection of horizontal and vertical
lines, which break it up, or partition it, into a collection of smaller matrices. Any matrix may
be interpreted as a block matrix in one or more ways, with each interpretation defined by how
its rows and columns are partitioned.

1.1 Example 1:
The Matrix

1.2 Applications:
Partitioned matrices appear in most modern applications of linear algebra because the
notation highlights essential structures in matrix analysis, as in the application of
partitioned matrix on aircraft design given below.

Page 2 of 15
1.2.1 Computers Model in Aircraft Design /Computational Fluid Dynamics
(CFD):
To design the next generation of commercial and military aircraft, engineers at
Boeing’s Phantom Works use 3D modeling and computational fluid dynamics
(CFD). They study the airflow around a virtual airplane to answer important design
questions before physical models are created. This has drastically reduced design
cycle times and cost—and linear algebra plays a crucial role in the process.
The virtual airplane begins as a mathematical “wireframe” model that exists only
in computer memory and on graphics display terminals. (Model of a Boeing 777 is
shown.) This mathematical model organizes and influences each step of the design
and manufacture of the airplane— both the exterior and interior. The CFD analysis
concerns the exterior surface.

Although the finished skin of a plane may seem smooth, the geometry of the surface
is complicated. In addition to wings and a fuselage, an aircraft has nacelles,
stabilizers, slats, flaps, and ailerons. The way air flows around these structures
determines how the plane moves through the sky. Equations that describe the
airflow are complicated, and they must account for engine intake, engine exhaust,
and the wakes left by the wings of the plane. To study the airflow, engineers need
a highly refined description of the plane’s surface.

A computer creates a model of the surface by first superimposing a three-


dimensional grid of “boxes” on the original wire-frame model. Boxes in this grid
lie either completely inside or completely outside the plane, or they intersect the
surface of the plane. The computer selects the boxes that intersect the surface and
subdivides them, retaining only the smaller boxes that still intersect the surface. The
subdividing process is repeated until the grid is extremely fine. A typical grid can
include more than 400,000 boxes.

The process for finding the airflow around the plane involves repeatedly solving a
system of linear equations Ax=b that may involve up to 2 million equations and
variables. The vector b changes each time, based on data from the grid and solutions
of previous equations. Using the fastest computers available commercially, a
Phantom Works team can spend from a few hours to several days setting up and
solving a single airflow problem. After the team analyzes the solution, they may
make small changes to the airplane surface and begin the whole process again.
Thousands of CFD runs may be required.

The Applied Linear Algebra (ALA) lab presents two important concepts that assist
in the solution of such massive systems of equations:

Partitioned matrices: A typical


CFD system of equations has a
“sparse” coefficient matrix with
mostly zero entries. Grouping the
variables correctly leads to a
partitioned matrix with many zero
blocks. This Lab introduces such
matrices and describes some of
their applications.

Page 3 of 15
Matrix factorizations: Even when written with partitioned matrices, the system of
equations is complicated. To further simplify the computations, the CFD software
at Boeing uses what is called an LU factorization of the coefficient matrix. Next
Lab discusses LU and other useful matrix factorizations.

1.2.2 Mathematical Models of a Physical system:

When a matrix A appears in a mathematical model of a physical system such as an


electrical network, a transportation system, or a large corporation, it may be natural
to regard A as a partitioned matrix. For instance, if a microcomputer circuit board
consists mainly of three VLSI (very large-scale integrated) microchips, then the
matrix for the circuit board might have the general form

The submatrices on the “diagonal” of A—namely, A11, A22, and A33—concern


the three VLSI chips, while the other submatrices depend on the interconnections
among those microchips.

1.2.3 Matrix calculations of High-speed Computers:

1. When matrices are too large to fit in a computer’s high-speed memory,


partitioning permits the computer to work with only two or three submatrices
at a time. For instance, one linear programming research team simplified a
problem by partitioning the matrix into 837 rows and 51 columns. The
problem’s solution took about 4 minutes on a Cray supercomputer.
2. Some high-speed computers, particularly those with vector pipeline
architecture, perform matrix calculations more efficiently when the algorithms
us partitioned matrices.
3. Professional software for high-performance numerical linear algebra, such as
LAPACK, makes intensive use of partitioned matrix calculations.

2. Matrix Partitioning with MATLAB:


One can use MATLAB to perform Matrix Partitioning. In order to accomplish this task following
function or commands and programming concepts of MATLAB Environment need to be known.
1. Creating Matrix in MATLAB
2. Matrix Addition and Subtraction in MATLAB
3. Vector Products and Transpose in MATLAB
4. Multiplying Matrices in MATLAB
5. Identity Matrix in MATLAB
6. Matrix inverse in MATLAB
7. Use of Colon, “:” in MATLAB
8. Array Indexing in MATALB
9. Multidimensional Arrays in MATALAB
10. Getting Input Value with Text Indication in MATLAB.
All of these commands are discussed in section 2.1.
2.1 Getting Started with MATLAB for Matrices Partitioning:
1. MATLAB has many functions that create different kind of matrices, for example you
can create a symmetric matrix with entries based on Pascal's triangle using ‘A =
pascal(3)’. You can create an asymmetric magic square matrix, which has equal row

Page 4 of 15
and column sums using ‘B=magic(3)’. Another example is a 3-by-2 rectangular matrix
of random integers using ‘C=randi(10,3,2)’; In this case the first input to randi describes
the range of possible values for the integers, and the second two inputs describe the
number of rows and columns.

A column vector is an m-by-1 matrix, a row vector is a 1-by-n matrix, and a scalar is a
1-by-1 matrix. To define a matrix manually, use square brackets [ ] to denote the
beginning and end of the array. Within the brackets, use a semicolon ; to denote the end
of a row. In the case of a scalar (1-by-1 matrix), the brackets are not required. For
example, these statements produce a column vector, a row vector, and a scalar:

U = [3; 1; 4]
V=[2 0 -1] or [2, 0, -1]
S= 7

2. Addition and subtraction of matrices and arrays is performed element-by-element, or


elementwise. For example, adding A to B and then subtracting A from the result
recovers B:

Note: Addition and subtraction require both matrices to have compatible dimensions.
If the dimensions are incompatible, an error results.

3. A row vector and a column vector of the same length can be multiplied in either
order. The result is either a scalar, called the inner product, or a matrix, called the
outer product:

Page 5 of 15
MATLAB uses the apostrophe operator (') to perform a complex conjugate transpose,
and 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 = pascal(3) is symmetric, so A' is equal to A. However, B =
magic(3) is not symmetric, so B' has the elements reflected along the main diagonal:

4. Multiplication of matrices is defined in a way that reflects composition of the


underlying linear transformations and allows compact representation of systems of
simultaneous linear equations. The matrix product C = AB is defined when the column
dimension of A is equal to the row dimension of B, or when one of them is a scalar. If
A is m-by-p and B is p-by-n, their product C is m-by-n. The product can actually be
defined using MATLAB for loops, colon notation, and vector dot products

Page 6 of 15
MATLAB uses an asterisk to denote matrix multiplication, as in C = A*B. Matrix
multiplication is not commutative; that is, A*B is typically not equal to B*A:

5. Generally accepted mathematical notation uses the capital letter I to denote identity
matrices, matrices of various sizes with ones on the main diagonal and zeros
elsewhere. These matrices have the property that AI = A and IA = A whenever the
dimensions are compatible.
The original version of MATLAB could not use I for this purpose because it did not
distinguish between uppercase and lowercase letters and ‘i’ already served duty as a
subscript and as the complex unit. So, an English language pun was introduced. The
function eye(m,n) returns an m-by-n rectangular identity matrix and eye(n) returns an
n-by-n square identity matrix.

6. If a matrix A is square and nonsingular (nonzero determinant), then the equations


AX
= I and XA = I have the same solution X. This solution is called the inverse of A and is
denoted A-1. The inv function and the expression A^-1 both compute the matrix
inverse.

Page 7 of 15
7. The colon ‘:’ is one of the most useful operators in MATLAB. It can create vectors,
subscript arrays, and specify for iterations. It has following syntax:

x = j:k , creates a unit-spaced vector x with elements [j,j+1,j+2,...,j+m] where m = fix(k-j).


x = j:i:k ,creates a regularly-spaced vector x using i as the increment between elements.
A(:,n) , is a matrix with the nth column of matrix A.
A(m,:) ,is a matrix the mth row of matrix A.
A(:,:,p) ,is the pth page of three-dimensional array A.
A(:) ,reshapes all elements of A into a single column vector.
A(j:k) , uses the vector j:k to index into A hence its the vector [A(j), A(j+1), ..., A(k)].

8. In MATLAB, there are three primary approaches to accessing array elements based on
their location (index) in the array. These approaches are indexing by position, linear
indexing, and logical indexing. We will discuss Indexing with element position.

e is the element in the 3,2 position (third row, second column) of A.

Page 8 of 15
9. You can create a multidimensional array by creating a 2-D matrix first, and then
extending it. For example, first define a 3-by-3 matrix as the first page in a 3-D array.

Now add a second page. To do this, assign another 3-by-3 matrix to the index value 2
in the third dimension. The syntax A(:,:,2) uses a colon in the first and second
dimensions to include all rows and all columns from the right-hand side of the
assignment.

10. You can get input from user by following command.


X= input (‘input matrix X manually: ‘)
Where ‘X’ is the variable that stores entered value and text indication for getting value
is written in commas that is ‘input matrix X manually: ‘. Full syntax using these is given
above.

Page 9 of 15
LAB SESSION

Lab Task:
1. To be familiar with Matrix Partitioning with MATLAB.
1. To know how to make a program using MATLAB for Matrix Partitioning
Apparatus:
 Laptop
 MATLAB

Experimental Procedure:

1. How to Setup MATLAB:

1. Start-up the Microsoft Windows.


2. Place the software CD into CD ROM drive or use Pin drive to access software folder.
3. Double click on the software folder and double click on ‘setup.exe’ file and run the
setup.
4. Press next until you reach the window which asks for the key.
5. Install the key provided you by Lab instructor.
6. Finally chose Finish and close the installation.

2. Matrix Partitioning with MATLAB:

1. Start MATLAB by double-click on the icon on your desktop. It will open following
different windows in your PC as shown in image.

Fig. 1. MATLAB Startup GUI window

2. Create a 4x4 matrix A in MATLAB command window.

Page 10 of 15
3. Split A into four 2x2 partitioned matrices, say sA1, sA2, sA3 and sA4, using Array
command.
sA1=A(1:2,1:2),sA2=A(1:2,3:4),sA3=A(3:4,1:2),sA4=A(3:4,3:4)

4. Now we split same Matrix A using MATLAB program. For this Purpose, use Editor for
writing command and first Enter a matrix ‘A’ through user input by below command.
A=input('Enter any Matrix: ');

5. Get size of the Matrix A as below

[r,c]=size(A);

6. Ask user to enter Number of rows in splitted matrix.


rs=input('Enter Number of Rows in splitted Matrix: ');

7. Ask user to enter Number of columns in splitted matrix.


cs=input('Enter Number of Rows in splitted Matrix: ');

Page 11 of 15
8. Calculate number of splitted matrix.
nr=floor(r/rs);
nc=floor(c/cs);

9. Now initialize a required splitted Matrix say ‘sA’.


sA(rs,cs,nr*nc)=0;

for i=1:nr
for j=1:nc
sA(:,:,1)=A(1:rs,1:cs);
end
end
10. Now initialize all required splitted Matrix say ‘say sA1, sA2, sA3 and sA4.’ In separate
pages of a 3D multidimensional array Matrix.
sA(rs,cs,nr*nc)=0;
z=1;
for i=1:nr
for j=1:nc
sA(:,:,z)=A((i-1)*rs+1):1:rs*i,((j-1)*cs+1):cs*j);
z=z+1;
end
end
11. Now get all partitioned Matrices by writing ‘sA’ in command window and press
enter.

Observations:
(Follow Similar procedure and partitioned the 4x4 Magic matrix )

Page 12 of 15
LAB REPORT
Prepare the Lab Report below:
TITLE:

OBJECTIVE:

APPARATUS:

PROCEDURE:
(Note: Use all steps you studied in LAB SESSION of this tab to write procedure and
to complete the experiment)

Page 13 of 15
Page 14 of 15
DISCUSSION:

Q1.: How you describe Partitioned Matrix application in Computational Fluid Dynamics
(CFD)?

Q2.: List the three most modern applications of partitioned Matrices?

Conclusion /Summary:

Page 15 of 15

You might also like