MATLAB: How to make a function that returns the difference between the passed function’s max and min value given a range of the independent variable

functionplotplotting

I was given the task to develop a function M-file that returns the difference between the passed function's maximum and minimum value given a range of the independent variable. In addition, I have to make the function generate a plot of the function for range. I was given three instances to test my M-file.
a.) f(t) = 8e^(-0.25t)sin(t – 2) , from t=0 to 6pi
b.) f(x) = e^(4x)sin(1/x) , from x =0.01 to 0.02
c.) The built in humps function from x = 0 to 2
I found the exact problem on Chegg, but it provides absolutely no explanation of the code and I would really like to be able to understand this problem. I hope someone can help!

Best Answer

Hint: You need to use * for when you multiply, and use exp() for e^, and you can use linspace() to get a bunch of values for t between some starting and stopping values.
t=linspace(0,6*pi, 1000); % Get 1000 values of t
f = 8 * exp(-0.25*t).*sin(t - 2);
plot(t, f);
grid on;
I'm assuming you know how to use min() and max() and how to subtract the values they return.
Related Question