I am trying to write a code for the Midpoint rule given by :
M = \sum_{i=1}^{n}hf(\frac{x_{i-1}+x_{i}}{2})
My MATLAB code is following:
if true function M = mittpunkt(fun,a,b,n)h = (b-a)/n;x = linspace(a,b,n);f = fun(x);M = h*(sum(f(((1:n-1)+(1:n))/2)));end
My error is :
Error using + Matrix dimensions must agree.
If something is wrong I think it must me the index, certainly not the use of a plus sign, right? Thanks
Best Answer