Hi, I actually do not understand what I have done wrong, but the code just gives out an error all the time.
function s=integrate(f,a,b,n)x=0:(n-1);h=(b-a)/n;x=a+h*x;s=0;for i=1:n s=s+f(x(i))*h;endend
For integrate(1,2,3,4) i get the error
Index exceeds the number of array elements (1).
Error in integrate (line 7)
s=s+f(x(i))*h;'
and for f=sin(x)
'Undefined function or variable 'x'.
Best Answer