The following matlabreg summary lists and briefly describes


142 Chapter 4 Manipulating MATLAB® Matrices

MATLAB® SUMMARY

The following MATLAB® summary lists and briefly describes all of the special char-acters, commands, and functions that were defined in this chapter.

Special Characters

: colon operator

... ellipsis, indicating continuation on the next line

[] empty matrix

Commands and Functions

meshgrid maps vectors into a two-dimensional array

zeros creates a matrix of zeros

ones creates a matrix of ones

diag extracts the diagonal from a matrix

fliplr flips a matrix into its mirror image, from left to right

flipud flips a matrix vertically

magic creates a "magic" matrix

KEY TERMS

elements magic matrices subscripts

index numbers mapping 

PROBLEMS

Manipulating Matrices

4.1 Create the following matrices, and use them in the exercises that follow:

(a) Create a matrix called d from the third column of matrix a.

(b) Combine matrix b and matrix d to create matrix e, a two-dimensional matrix with three rows and two columns.

(c) Combine matrix b and matrix d to create matrix f, a one-dimensional matrix with six rows and one column.

(d) Create a matrix g from matrix a and the first three elements of matrix c, with four rows and three columns.

(e) Create a matrix h with the first element equal to a1,3, the second ele-ment equal to c1,2, and the third element equal to b2,1.

PDF processed with CutePDF evaluation edition www.CutePDF.com

Problems 143

4.2 Load the file thermo_scores.dat provided by your instructor, or enter the matrix at the top of page 137 and name it thermo_scores. (Enter only the numbers.)

(a) Extract the scores and student number for student 5 into a row vector named student_5.

(b) Extract the scores for Test 1 into a column vector named test_1.

(c) Find the standard deviation and variance for each test.

(d) Assuming that each test was worth 100 points, find each student's final total score and final percentage. (Be careful not to add in the student number.)

(e) Create a table that includes the final percentages and the scores from the original table.

(f) Sort the matrix on the basis of the final percentage, from high to low (in descending order), keeping the data in each row together. (You may need to consult the help function to determine the proper syntax.)

4.3 Consider the following table:

Time Thermocouple 1 Thermocouple 2 Thermocouple 3

(a) Create a column vector named times going from 0 to 24 in 2-hour increments.

(b) Your instructor may provide you with the thermocouple temperatures in a file called thermocouple.dat, or you may need to create a matrix named thermocouple yourself by typing in the data.

(c) Combine the times vector you created in part (a) with the data from thermocouple to create a matrix corresponding to the table in this problem.

(d) Recall that both the max and min functions can return not only the maximum values in a column, but also the element number where those values occur. Use this capability to determine the values of times at which the maxima and minima occur in each column.

4.4 Suppose that a file named sensor.dat contains information collected from a set of sensors. Your instructor may provide you with this file, or you may need to enter it by hand from the following data:

Each row contains a set of sensor readings, with the first row containing values collected at 0 seconds, the second row containing values collected at 1.0 seconds, and so on.

(a) Read the data file and print the number of sensors and the number of seconds of data contained in the file. (Hint: Use the size function- don't just count the two numbers.)

(b) Find both the maximum value and the minimum value recorded on each sensor. Use MATLAB® to determine at what times they occurred.

(c) Find the mean and standard deviation for each sensor and for all the data values collected. Remember, column 1 does not contain sensor data; it contains time data.

4.5 The American National Oceanic and Atmospheric Administration (NOAA) measures the intensity of a hurricane season with the accumulated cyclone energy (ACE) index. The ACE for a season is the sum of the ACE for each tropical storm with winds exceeding 35 knots (65 km/h). The maximum sustained winds (measured in knots) in the storm are measured or approxi-mated every six hours. The values are squared and summed over the dura-tion of the storm. The total is divided by 10,000, to make the parameter easier to use.

This parameter is related to the energy of the storm, since kinetic energy is proportional to velocity squared. However, it does not take into account the size of the storm, which would be necessary for a true total energy estimate. Reliable

storm data have been collected in the Atlantic Ocean since 1950, and are included here. This data may also be available to you from your instructor as an EXCEL worksheet, ace.xlsx, and was extracted from the Accumulated Cyclone Energy article in Wikipedia. (https://en.wikipedia.org/wiki/Accumulated_ cyclone_energy). It was collected by the National Oceanic and Atmospheric Administration (https://www.aoml.noaa.gov/hrd/tcfaq/E11.html).

(a) Import the data into MATLAB®, and name the array ace_data.

(b) Extract the data from each column, into individual arrays. You should have arrays named

• years

• ace

• tropical_storms

• hurricanes

• major_hurricanes

(c) Use the max function to determine which year had the highest

• ACE value

• Number of tropical storms

• Number of hurricanes

• Number of major hurricanes

(d) Determine the mean and the median values for each column in the array, except for the year.

(e) Use the sortrows function to rearrange the ace_data array based on the ACE value, sorted from high to low.

The data presented in this problem is updated regularly. Similar data is available for the eastern Pacific and central Pacific oceans.

Problems with Two Variables

4.6 The area of a triangle is, area 5 ½ base × height (see Figure P4.6). Find the area of a group of triangles whose base varies from 0 to 10 m and whose height varies from 2 to 6 m. Choose an appropriate spacing for your calcu-lational variables. Your answer should be a two-dimensional matrix.

4.7 A barometer (see Figure P4.7) is used to measure atmospheric pressure and is filled with a high-density fluid. In the past, mercury was used, but because of its toxic properties it has been replaced with a variety of other fluids. The pressure, P, measured by a barometer is the height of the fluid column, h, times the density of the liquid, r, times the acceleration due to gravity, g, or

P 5hrg

This equation could be solved for the height:

P h 5 rg

Find the height to which the liquid column will rise for pressures from 0 to 100 kPa for two different barometers. Assume that the first uses mercury, with a density of 13.56 g/cm3 (13,560 kg/m3) and the second uses water, with a density of 1.0 g/cm3 (1000 kg/m3). The acceleration due to gravity is 9.81 m/s2. Before you start calculating, be sure to check the units in this calculation. The metric measurement of pressure is a pascal (Pa), equal to l kg/m s2. A kPa is 1000 times as big as a Pa. Your answer should be a two-dimensional matrix.

4.8 The ideal gas law, Pv 5 RT, describes the behavior of many gases. When solved for v (the specific volume, m3/kg), the equation can be written

v 5 RT
P

Find the specific 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.

Special Matrices

4.9 Create a matrix of zeros the same size as each of the matrices a, b, and c from Problem 4.1. (Use the size function to help you accomplish this task.)

4.10 Create a 6 3 6 magic matrix.

(a) What is the sum of each of the rows?

(b) What is the sum of each of the columns?

(c) What is the sum of each of the diagonals?

4.11 Extract a 3 3 3 matrix from the upper left-hand corner of the magic matrix you created in Problem 4.9. Is this also a magic matrix?

 

4.12 Create a 5 3 5 magic matrix named a.

(a) Is a times a constant such as 2 also a magic matrix?

(b) If you square each element of a, is the new matrix a magic matrix?

(c) If you add a constant to each element, is the new matrix a magic matrix?

a 2*a (d) Create a 10 3 10 matrix out of the following components (see Figure P4.12):
• The matrix a

• 2 times the matrix a

a^2 a 2 • A matrix formed by squaring each element of a
• 2 plus the matrix a

Is your result a magic matrix? Does the order in which you arrange the com-
Figure P4.12
ponents affect your answer?
Create a matrix out of other
4.13 Albrecht Durer's magic square (Figure 4.8) is not exactly the same as the

matrices.
4 3 4 magic square created with the command magic(4)

(a) Recreate Durer's magic square in MATLAB® by rearranging the columns.

(b) Prove that the sum of all the rows, columns, and diagonals is the same.


Attachment:- Chapter_4_-_Homework.pdf

Request for Solution File

Ask an Expert for Answer!!
MATLAB Programming: The following matlabreg summary lists and briefly describes
Reference No:- TGS01557933

Expected delivery within 24 Hours