I’m guessing at what your problem actually says, but the problem may be the ‘a’ and ‘b’ limits. Adding pi to them as a factor, and correcting the definition of mean value:
myfun2 = @(t) 5*sin(t);
a = pi;
b = 3*pi;
t = linspace(a,b,400);
z = myfun2(t);
average = trapz(t,z)./(b-a)
produces:
average =
-95.6651e-018
which is essentially zero to floating-point precision.
The mean value is Integral(f(t),a,b)/(b-a).
