University of California, Berkeley Department of Mechanical Engineering Fall Semester 2008 Instructors: M. Frenklach, R.. Horowitz E7, Assignment 2 Assigned: Thursday, September 11 2008 Due: 12:00pm, Friday, September 19, 2008.This assignment is an introduction to using arrays, which are the basic building blocks in MATLAB. The ability to represent and handle multiple items in single collections is one of the main strengths of MATLABand it is what makes code-writing very short. As in the previous assignment, turn in the hard copy of your published file to the drop boxes in Etcheverry 1109 and upload the soft copy of your script (the m-file) to Bspace. Do not forget to name your m-file as lastname_firstname_SID_lab02.m Useful MATLABcommands*in this assignment: linspace, length, sort, find, upper, lower, double, char, rem, size, max, min, plot, polyder, polyval, roots, conv, poly1. Using linspace, create the row vector ahaving 9 regularly spaced elements starting with 16 and ending with 48. Then, using the colon notation and transpose, create the column vector bhaving a regular spacing of 0.5, starting with 0.5 and ending with 4.5. Do the following tasks by using the appropriate array operations. i.Divide each element of aby 2. ii.Add 1 to each element of b. iii.Take the third power of each element of a. iv.Divide all elements of aby the corresponding element in b(e.g. element by element division). v.Find the number of elements of ausing the MATLABfunction length.vi.Assign the 5thelement of ato a new variable c. vii.Create a row vector dwhich is composed of the 6th, 4th, 2ndand 5thelements of a. (e.g. the 1stelement of dis the 6thelement of a.) viii.Using the function sort, define the row vector d_sortedthat contains the *Please refer to MATLABhelp to learn how to use the functions introduced in this assignment. Assignment 2 E7 1
has intentionally blurred sections.
Sign up to view the full version.