MATLAB: Numerical integration Error in size of elements

integration

Hi all
I have a function to integrate , the problem is , for any amount of x that contains zero , the size of g matrix becomes one smaller , like x : 1×19 and g :1×18 , what happens to g when I calculate it's square root ??? what changes the dimension ? since this integration needs that x and g be of the same dimension
x=[-p/2:1:p/2];
f= c*sin(a/p*x);
g=sqrt(1+(diff(f)).^2);
integ=trapz(x,g)

Best Answer

Because diff will reduce the length of g , use
integ=trapz(x(1:end-1),g)