In: Mechanical Engineering
Write a script le using conditional statements to evaluate the following function, assuming that the scalar variable x has a value. The function is
Y = ex+1 for x < -1, y = 2 + cos(πx) for -1 ≤ x ≤ 5, and y = 10(x - 5) + 1 for x ≥ 5. Use your le to evaluate y for x = -5, x = 3, and x = 15, and check the results by hand.
Matlab script file for following function is to evaluate x = -5
x = -5;
if x < -1
y = exp(x + 1);
elseif x < 5
y = 2 + cos(pi*x);
else
y = 10*(x - 5) + 1;
end
Output: y = 0.0183
Matlab script file for following function is to evaluate x = 3
x = 3;
if x < -1
y = exp(x + 1);
elseif x < 5
y = 2 + cos(pi*x);
else
y = 10*(x - 5) + 1;
end
output: y = 1
Matlab script file for following function is to evaluate x = -15
x = -15;
if x < -1
y = exp(x + 1);
elseif x < 5
y = 2 + cos(pi*x);
else
y = 10*(x - 5) + 1;
end
output: y = 101
Output: y = 0.0183
output: y = 1