Integrating the following function using trapz method, while choosing a good step value (h = b-a/n ) to get enough accuracy and a fast result.
2 views (last 30 days)
Show older comments
Kimberly Kepke
on 21 May 2016
Answered: Star Strider
on 21 May 2016

Hi guys,
So I am still a newbie at matlab, and I wrote this following code. But I am not sure on the step value I should pick for an accurate and fast result when integrating. Any help would be great, I have been tyring to figure it out for some time now. Thanks!
x = linspace(0,1,0.2);
y = (((sin(x)).^2)./x)-(x.*exp(2))-4;
z = trapz(x, y);
display(z)
0 Comments
Accepted Answer
Star Strider
on 21 May 2016
Please read the documentation on linspace thoroughly.
That should tell you the reason this call to it:
x = linspace(0,1,0.2);
isn’t doing what you believe it is doing.
Choosing the lower limit of ‘x’ to be eps rather than 0 might be worth considering. (You might also want to peruse the documentation for eps.)
0 Comments
More Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!