Define an anonymous function
meansin = @(n) ... which computes the mean value of \(\sin(1)\text{,}\) \(\sin(2)\text{,}\) ..., \(\sin(n)\text{.}\) Use it to display the values meansin(n) for n equal to 10, 50, 250, 1870, and 5000. What pattern do you observe?
Answer.
meansin = @(n) mean(sin(1:n));
for n = [10 50 250 1870 5000]
disp(meansin(n))
end
Explanation: this is a reminder that the vector in
for loop does not have to be of the form a:b even though this form is most common. Here the use of a loop avoids having to writedisp(meansin(10)) disp(meansin(50)) disp(meansin(250))
and so on.
It appears that the mean values approach 0 as
n grows. This can be proved mathematically: see the homework section.
