I was trying to find approximate value of function f(x)=Sin(x)
a =0; b =pi; N=20;h = ((b-a)/N);f= sin(x);x=a:h:b;Area= 0;while (a<b) Area = Area +(h/2)*(f(a) + f(a+h)); % using trapezoidal rule
a = a+h; end fprintf('Area = %f', Area);??? Attempted to access f(0); index must be a positive integer or logical. Error in ==> MenuCommands at 16 Area = Area +(h/2)*(f(a) + f(a+h));
Best Answer