I am using the "integrate" function to plot the integral of sin(x) [which is -cos(x)]. When I plot the integral it should plot from -1 to 1 but instead it is shifting the integral from 0 to 2. In the code below I show what I did. The @myFunInt is the following
function fval = myFunInt(x)fval = sin(x);end
and the main code is
cleara=0; % lower limit
b=30; % upper limit
n=1000; % subintervals
h = (b-a)/n; % Spacing
x = 0:30;int = zeros(1,n+1);for j = 0:n x_j=a+j*h; % x values are being allocated in the empty array
x(:,j+1)=x_j; fun = @myFunInt; y=integral(fun,a,x(:,j+1)); int(:,j+1)=y;endplot(x,int);
Note that this code works with any other function exept than integrading cos(x) and -sin(x).
Thank you for your input.
Best Answer