# Lesson 03: MATLAB Matrices

## Objectives

• To understand and manipulate matrices
• To learn how to extract data from matrices
• To learn how to create and use special matrices

## Background

When you use MATLAB to solve some complicated problems, you will find that you may need to create some small matrices, combine them into large matrices, extract data from the matrices, or create very large matrices.

## Questions

1. Create the following matrices, and use them in the exercises that follow:
$$A = \left[ {\begin{array}{ccccccccccccccc} {15}&3&{22}\\ 3&8&5\\ {14}&3&{82} \end{array}} \right]$$
$$B = \left[ {\begin{array}{ccccccccccccccc} 1\\ 5\\ 6 \end{array}} \right]$$
$$C = \left[ {\begin{array}{ccccccccccccccc} {12}&{18}&5&2 \end{array}} \right]$$
1. Create a matrix called D from the third column of matrix A.
2. Combine matrix B and matrix D to create matrix E, a two-dimensional matrix with three rows and two columns.
3. Combine matrix B and matrix D to create matrix F, a one-dimensional matrix with six rows and one column.
4. Create a matrix G from matrix A and the first three elements of matrix C, with four rows and three columns.
5. Create a matrix H with the first element equal to A1,3, the second element equal to C1,2, and the third element equal to B2,1.
2. Create a 6×6 magic matrix.
1. What is the sum of each of the rows?
2. What is the sum of each of the columns?
3. What is the sum of each of the diagonals?
3. The ideal gas law,  $$Pv = RT$$, describes the behavior of many gases. When solved for v (the specific volume, m3 /kg), the equation can be written
$$v = \frac{{RT}}{P}$$
Find the specifi c volume for air, for temperatures from 100 to 1000 K and for pressures from 100 kPa to 1000 kPa. The value of R for air is 0.2870 kJ/(kg K).
In this formulation of the ideal gas law, R is different for every gas. There are other formulations in which R is a constant, and the molecular weight of the gas must be included in the calculation. You’ll learn more about this equation in chemistry classes and thermodynamics classes. Your answer should be a two-dimensional matrix.
© 2024 Air Supply Information Center (Air Supply BBS)