MATLAB: Not sure how to write this script using if,else if

piece wise defined function

Consider the piece wise function
F(t) = {t^2e^2. -8<=t<=-2
2t+1. -2<t<=4
Cos(3t)sin(6t). 4<t<=8
Write a matlab script that calculates f(t) for any supplies legal value for t, and plot the function over the interval [-8,8] if the user chooses to.
Requirements:
  1. – the user must supply the value of t at which the function is evaluated
  2. – script must generate an error message if the value of t is outside the interval [-8,8]
  3. – calculated f value must be displayed using 3 digits after decimal point

Best Answer

Hint:
function ft = F(t)
if -8 <= t && t <= 2
ft = t^2 * exp(2);
elseif
You finish it. And to ask the user in your main, calling routine use questdlg() and call F(t) for values of t in that range....
message = sprintf('Do you want to plot F(t) over [-8,8]?');
reply = questdlg(message, 'Plot?', 'Yes', 'Yes', 'No');
if strcmpi(reply, 'Yes')
for t = -8 : 0.1 : 8
f(t) = F(t);
end
plot(
Again, try to finish it.