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.

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)

 Respuesta aceptada

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.)

Más respuestas (0)

Categorías

Preguntada:

el 21 de Mayo de 2016

Respondida:

el 21 de Mayo de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by