Answer:
Complete Matlab code with explanation and output results is given below
Step-by-step explanation:
The given piece-wise function is
f(x) = eˣ⁻¹¹ for x ≤ 5
-2x - 1 for 5 < x ≤ 10
x/(x - 11) for x > 10 and x ≠ 11
A function f(x) is created using if else statements to select piece-wise functions with corresponding ranges. Also the last function is undefined at x = 11 therefore, it shows error whenever we enter x = 11.
Matlab Code:
function y=f(x)
if x==11
fprintf("sorry! f(x) is not defined at x=11")
else if x <= 5
y = exp(x-11);
else if x > 5 & x <= 10
y = (-2.*x) - 1;
else if x > 10
y = x/(x - 11);
end
end
end
end
end
Output:
f(4)
ans = 9.1188e-04
f(5)
ans = 0.0025
f(5.5)
ans = -12
f(10)
ans = -21
f(11)
sorry! f(x) is not defined at x=11
f(12)
ans = 12
output is tested for a wide range of inputs and the program is returning correct output values.