Why isn't my integration using Trapezoidal Rule working?
3 views (last 30 days)
Show older comments
Kimberly Kepke
on 15 May 2016
Edited: Kimberly Kepke
on 15 May 2016
Hi,
I am a newbie at matlab and was wondering why the following code was not working. The problem is asking me to integrate using trapezoidal rule/method for this function.

The code I wrote was:
x = pi/4:2:pi/3; y = x./((sin(x)).^2); z = trapz(x, y);
When I run the code, I get the following errors:
Error in trapz (line 43) y = permute(y,perm);
Error in assignmenttesting (line 3) z = trapz(x, y);
Please help
0 Comments
Accepted Answer
Roger Stafford
on 15 May 2016
The problem lies in the line
x = pi/4:2:pi/3;
It has only one point and 'trapz' is not happy with that. Try something like
x = linspace(pi/4,pi/3,100);
to get 100 points.
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!