# Marks consider the m atlab function contained in the

• 79
• 100% (1) 1 out of 1 people found this document helpful

This preview shows page 10 - 16 out of 79 pages.

4. [4 marks] Consider the MATLABfunction contained in the filefunc1.m.function [z,zx,zy] = func1(x,y)% [z,zx,zy] = func1(x,y)if x+2*y<2if y-x<=1z=5*x-3*y; zx=5; zy=-3;elsez=2*x-4*y; zx=2; zy=-4;endelsez=3*x-y; zx=3; zy=-1;end(a) What values ofZ,Zx, andZyare returned by the following function invocation?
(b) What values ofZ,Zx, andZyare returned by the following function invocation?
MATH 2070U/2072UTest 1Instructor: D.A. AruliahWeek 3, 2008Name (last name, first name):Student Number:InstructionsBefore starting,read over the entire test carefully.Please verify that the test has 5 pages.You may use a calculator and a pen or pencil.Test written in pencil are not elegible for regrading.Laptops, cellphones, and pagers are not permitted.Have your student card on your desk.There are 4 questions on this test and a total of 20 marks.There are 45 minutes for the test.Questions do not carry equal weight so use your time wisely.Show as much work as needed to fully answer the questions.Write your answers as neatly as possible in the test itself.You are expected to comply with the UOIT rules for academic conduct.Q:1234TotalMks:844420
MATH 2070U/2072UTest 1Page 2 of 51. [8 marks] Write in the space provided the output you would expect in an interactive MATLABsessionas a result of entering the given statements.For numerical values returned, assumeformat short, i.e., numerical values displayed roundedto 5 decimal digits.If the expression fails to evaluate, writeERRORwith a short comment addressing the reason whythe statement will not execute.(a)-10+5*6-7/8-2(a)(b)a = 4:2:11(b)(c)a = [2,-1,0];b = [1,5,-3];4*a - b(c)(d)a = [3,-8,-6];b = [-2,-5-,-1];a .*b(d)(e)a = [8,-6,-5,1];b = [5;6;-1];a ./ b(e)(f)a = [5,3,6];b = [3,2,-1];a .ˆ b(f)(g)a = [-10,-9,-7,3];b = [5,3,-7,1];a <= b(g)(h)a = -4:2;3*a.ˆ2(h)
MATH 2070U/2072UTest 1Page 3 of 52. [4 marks] Consider the functionfdefined by the formulaf(x) = (3x5-2x3+ 2) tan2πx3.Write a MATLABscript in the space provided that produces a plot of the functionfsampled at 200points uniformly spaced over the interval[-1,1]. Your script should use a MATLABanonymous func-tion to evaluatefandfshould be vectorised to allow arrays as input.
MATH 2070U/2072UTest 1Page 4 of 53. [4 marks] Write a MATLABfunctionmysumto compute the sumNXk=13kk2-2k+ 2given a positive integerN >0. Assume the input to the function is always a single positive integer andthe output is a single real number (i.e., do not worry about testing input arguments or accepting arraysas input).Assuming the function definition line for them-filemysum.mis as given below, fill in the rest of thefunction file in the space beneath.
MATH 2070U/2072UTest 1Page 5 of 5
• • • 