MATLAB: Does trapz yield infinity

trapz

Hi there…
Why does the following code yield infinity
x = 0:0.001:1;
ytDiff = 1./(2*(x).^(1/2));
ArcEq = sqrt(1+ytDiff.^2);
s = trapz(x,ArcEq)
when the actual value should be s = 1.4789!?
Thanks!

Best Answer

Because that function approaches infinity at x=0, and you have included that endpoint of the interval explicitly. Try this instead:
x = 0.001:0.001:1;
ytDiff = 1./(2*(x).^(1/2));
ArcEq = sqrt(1+ytDiff.^2);
s = trapz(x,ArcEq)