W2Q1: Raise a number to a power Description ---------------------------------------------------------- *Make a vector* |v| *whose entries are powers of 2, beginning with the _zeroth_ power, and ending with the _eight_ power.* Solution Template ---------------------------------------------------- v=; Reference Solution --------------------------------------------------- v=2.^[0:8]; Visible Tests -------------------------------------------------------- Hidden Tests --------------------------------------------------------- run('solution'); s=2.^[0:8]; assert(isequal(s,v)); W2Q2: Plot a direction vector Description ---------------------------------------------------------- *You have measured a direction and want to draw an arrow of unit length that makes an angle* |adeg| *of 60 degrees _measured clockwise from the vertical_ axis . If the base of the arrow starts at the origin of the coordinate system, calculate the _vertical_ coordinate* |y| *and the _horizontal_ coordinate* |x| *of the _tip_ of the arrow.* Solution Template ---------------------------------------------------- adeg=60; y=; x=; Reference Solution --------------------------------------------------- adeg=60; y=cos(adeg/180*pi); x=sin(adeg/180*pi); Visible Tests -------------------------------------------------------- Hidden Tests --------------------------------------------------------- run('solution'); assessVariableEqual('y',cos(adeg/180*pi),'AbsoluteTolerance',1e-10) assessVariableEqual('x',sin(adeg/180*pi),'AbsoluteTolerance',1e-10) W2Q3: Element-multiply two vectors Description ---------------------------------------------------------- *Two vectors* |a| *and* |b| *are of equal length. Multiply them together on an element-by-element basis. The result* |c| *is of the same length, and has a generic entry that is the product of the corresponding elements in the vectors* |a| *and* |b|. Solution Template ---------------------------------------------------- % Do not change the variable names below a=[1 2 3 4 5]; b=[6 7 8 9 0]; % Write your answer here below c=; Reference Solution --------------------------------------------------- a=[1 2 3 4 5]; b=[6 7 8 9 0]; c=a.*b; Visible Tests -------------------------------------------------------- Hidden Tests --------------------------------------------------------- run('solution'); assert(isequal(a.*b,c)); W2Q4: Make a matrix of a defined size Description ---------------------------------------------------------- *Two variables* |m| *and* |n| *denote the numbers of rows and columns of a certain matrix* |A| *that you wish to build. For values* |m| *and* |n| *of your choice, construct the matrix* |A| *and fill it entirely with entries that are* _Not-a-Number_. Solution Template ---------------------------------------------------- m=4; n=7; A=; Reference Solution --------------------------------------------------- m=4; n=7; A=nan(m,n); Visible Tests -------------------------------------------------------- Hidden Tests --------------------------------------------------------- run('solution'); assert(isequal(size(A,1),m)) assert(isequal(size(A,2),n)) assert(isequal(all(isnan(A(:))),1)) W2Q5: Element-divide two matrices Description ---------------------------------------------------------- *You measured an array of numbers* |a| *that you want to compare to an expected array of numbers* |b| *in a relative sense. Form the ratio of the elements in* |a| *to the corresponding elements in* |b|, *subtract 1, multiply by 100, and use* |abs| *on the result, in that order. You will have a vector with the magnitude of the relative mismatches in per cent. Use* |round| *to round to the nearest integer and collect the results in a vector* |cv| *whose mean* |mc| *you also compute using* |mean|. Solution Template ---------------------------------------------------- % Do not change the two lines below a=[1.1 1.8 2.7 4.4]; b=[1.0 2.0 3.0 4.0]; % Your solution starts below cv=; mc=; Reference Solution --------------------------------------------------- a=[1.1 1.8 2.7 4.4]; b=[1.0 2.0 3.0 4.0]; cv=round(abs((a./b-1)*100)); mc=mean(c); Visible Tests -------------------------------------------------------- Hidden Tests --------------------------------------------------------- run('solution'); assessVariableEqual('cv',repmat(10,size(cv)),'AbsoluteTolerance',1e-10) assessVariableEqual('mc',10,'AbsoluteTolerance',1e-10)