Sei sulla pagina 1di 2

MIE 124

HW 2

You will submit three files for this assignment. Turn in a single m-file script containing problems
1,2,3 and 5 and two separate m-files of functions containing parts A and B of problem 4. The script
should be called “yourinitials_hw2_1.m”, the part A function should be called
“yourinitials_hw2_A.m”, and the part B function should be called “yourinitials_hw2_B.m”.

1. Make a 3x100 matrix. For row 1, the first 99 elements should be equally spaced values starting at 9 and
ending at 999, and the 100th element should be the sum of the first 99 elements. For row 2, generate
random integers with an equal probability of being between 1 and 100 (without randi). In row 3, the
values should be the square root of the integers from 1 to 100.

2. Create two 3x5 matrices, with Matrix A having [1-5] in the top row, [6-10] in the second row, etc. and
Matrix B having [1-3] in the first column, [4-6] in the second column, etc. Print these matrices to the
workspace.

Use the “zeros” function to create a third 3x5 matrix called C. Then:
• The first element in each row of the matrix C (i.e. the first column) is the difference between the
first element in each corresponding row of Matrices B and A. So, the element of Matrix B minus
the corresponding element of Matrix A.
• The second element in each row of the matrix (C) is the sum of the second element in each
corresponding row of Matrices A and B. So, the element of Matrix B plus the corresponding
element of Matrix A.
• The third element in each row of the matrix (C) is the product of the third element in each
corresponding row of Matrices A and B. So, the element of Matrix B times the corresponding
element of Matrix A.
• The fourth element in each row of the matrix (C) is the quotient of the fourth element in each
corresponding row of Matrices B and A. So, the element of Matrix A divided by the corresponding
element of Matrix B.
• The fifth element in each row of the matrix (C) is equal to the second element in that row.
Print this Matrix to the workspace

3. You are searching for a used car to buy. You are comparing the same model and year of a car, and are
given different prices depending how many miles are on the car. Find the mean, median, and range of the
mileage and prices of the cars, and create separate variables for each of these values (6 total). Then make
a 6x1 vector listing the dollars/mileage ratio from best to worst.
Car Mileage Price in Dollars

1 62,800 8,260

2 82,500 6,660

3 111,100 3,970

4 127,880 2,840

5 92,350 4,790

6 76,650 7,550
4. A. Create a function with an input that is the volume of a sphere, and with outputs that are the
radius and surface area of the sphere.
B. Create a function with an input that is the surface area of a cube, and outputs the volume and
side length of the cube.

5. Create a 10x3 matrix to display Tom Brady’s Touchdowns and Passing Yards trends for the past 10
years. Each row represents a year, the second element in each row will be his TDs and the third element
will be his Passing Yards (PYs) for that year.

Year TD’s Passing Yards

2016 28 3554

2015 36 4770

2014 33 4109

2013 25 4343

2012 34 4827

2011 39 5235

2010 36 3900

2009 28 4398

2008 0 76

2007 50 4806

Enter this data into a 10x3 matrix. Use the plot function to create two separate line graphs
showing the trends over the course of Tom Brady’s career. Change the line style of the plot (--
,:,etc.), make the touchdowns plot blue, and the passing yards plot red, and put an x on the max
value. Then, print the mean and median of his Touchdowns and Passing Yards to the
workspace. Be sure to label all axis and title the graphs.

Potrebbero piacerti anche