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

1 view (last 30 days)
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

Accepted Answer

Image Analyst
Image Analyst on 23 Sep 2014
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.

More Answers (0)

Categories

Find more on Develop Apps Using App Designer in Help Center and File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!