Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

matlab question es | Shared ENGR1721 2018 S1 Semester Break (Week 2) 16 April-22

ID: 2086962 • Letter: M

Question


matlab question

es | Shared ENGR1721 2018 S1 Semester Break (Week 2) 16 April-22 April mid-semester Exam Write a function, called formula, to evaluate f y) for any two values x and lassume two values are always provided), where the function fxyis as follows f(x. y) xly if x and y are greater than or equal to 0, f (x, y)-xy 2 if x is greater than or equal to 0 and y is less than 0, f(x. y)-xA2y if x is less than O and y is greater than or equal to 0 and f (x y)HXA2ty12 if x and y are less than 0. Make sure you 'end' your function. Examples: formula(1, 2) ans 0.5 formula(-1, 2) ans -0.5 formula(1, -2) ans-4 formula(-1, -2) ans 2 Answer: (penalty regime: 0, 0, 96) %write your 'formula, function here, don't forget to 'end' it 2 function ans formula (x,y) 5 elseif x>-0 88 yxe ans-xy 2; 8 ans x 2/y 9 e1seifx®3/?"2; 10 end 11 end 12 Type here to search

Explanation / Answer

Matlab Code:

function s=formula(x,y)
if x>=0 && y>=0
s=x/y;
elseif x>=0 && y<0
s=x*y^2;
elseif x<0 && y>=0
s=x^2/y;
elseif x<0 && y<0
s=x^(-2)*y^2;
end
end

Note:

In example(4) they given,

formula(-1,-2) = -2 , which is not possible with given equations.. it may be error in equation or in example. check it.