Why does trapz yield infinity

9 views (last 30 days)
David
David on 25 Apr 2014
Answered: David on 25 Apr 2014
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!

Accepted Answer

the cyclist
the cyclist on 25 Apr 2014
Edited: the cyclist on 25 Apr 2014
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)

More Answers (1)

David
David on 25 Apr 2014
Of course... And it works!
Thank you very much!

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!