Practice vector manipulation


Tasks:

Question 1: Practice Vector Manipulation

Write single MATLAB statements to create these vectors from any vector Z. You can use vector Z shown as a sample input. Create a single m-file script (non-function) to containing all the statements. Comment each problem 'a' through 'e' in your m-file.

Z = [4 5 2 8 4 7 2 64 2 57 2 45 7 43 2 5 7 3 3 6523 3 4 3 0 -65 -343];

a) Create a new vector vecA that is the odd numbered elements of Z (not the odd values, the elements with odd indexes).

b) Count how many elements of Z are less than or equal to 10.

c) Create a new vector vecC that is the same as Z except all the odd values of Z are changed to even by adding 1 to them.

d) Write a single MATLAB statement to generate 100 random integers with values -1 or 0 or 1.

e) Create a new vector vecE that contains all the elements of Z that are a multiple of 3

f) Create a new vector vecF that is the same as Z except the first and last elements are swapped and nothing else is changed.

g) Calculate how many elements of Z are within 10 of the max element in Z (include the max element(s) in your count).

h) Create a new vector vecH that has the sum of the first and second elements of Z in the first position of vecH, the sum second and third elements of Z in the second position of vecH, the sum third and fourth elements of Z in the third position of vecH, etc. The last element of vecHis just the last elementof Z.

Question 2: Create m-file functions to solve some basic vector problems in MATLAB.

For each problem complete the following steps:

A) Draw a picture or write pseudocode for solving the problem using composition (you do not have to hand this in)

B) By hand, make an estimate of roughly the scale of the answer (you do not have to hand this in).

C) Write an m-file function to solve the problem.

D) Test your m-file function using MATLAB in "calculator" mode with the diary on to save all your work in a command history file. It is fine to include errors in your command history file, as long as you eventually compute correctly. If you discover mistakes in your program, correct them and execute again. Please format the results to significant digits that are correct for the problem and data given.

How to create a command history file??

>> diary BauerLab6.txt
. . .
>> diary off

Problems:

A) You are asked to determine the most efficient solid shape (defined by the shape with largest ratio of volume to its surface area) for a large hot air balloon. Write a matlab script m-file named Efficient.m (function not necessary) to create a vector containing the ratios of the volume of a sphere to the surface area for a sphere for radius "r" values ranging from 50 to 100 by 2s.

Do the same thing for the volume and surface area of a cube with side length "r" values ranging from 50 to 100 by 2s

Do the same thing for the volume and surface area of a tetrahedron (equilateral triangle based pyramid) with side length "r" values ranging from 50 to 100 by 2s.

Finally, plot the three vectors of ratios on the same graph, x-axis is the "r" vector, y-axis is the ratio of volume to surface area vector. Use different colors or symbols for each plot, label the axes, and add a legend. Which solid shape shape is most efficient (most volume per surface area)?

B) A vector 'v' stores for the letter grades ('A', 'B', 'C', 'D', 'E') for a student's classes for a term. A student can have from 1 to 6 classes. Assume every class is a 3 credit hour class and assume each grade is worth this many grade points. A = 4, B = 3, C = 2, D = 1, E = 0 Write a function call myGPA that has a single vector argument of grades as described above, and calculates and returns the GPA for the term. NO IF STATEMENTS ARE NEEDED, use vector conditions/manipulations) Sample call and result:

>> GPA = myGPA(['B' 'A' 'A' 'C' 'B'])
GPA =
3.2000

Request for Solution File

Ask an Expert for Answer!!
MATLAB Programming: Practice vector manipulation
Reference No:- TGS01246

Expected delivery within 24 Hours