Azzera filtri
Azzera filtri

Value of trapz shrinking to zero

3 visualizzazioni (ultimi 30 giorni)
Allan Andre do Nascimento
Dear Matlab community,
I am calculating an index with trapz and I am having some strange results. This index gets a solution from an ode and makes use of trapz. The strange thing is that depending on the number of points generated by the ode, the trapz value decreases indefinetly (the bigger the number of points the smaller the value of trapz). A decrease could be expected if the trapezoids approximating the function were "bigger" that the real functon, but as the number of points increased, trapz value should approximate a fixed value (which is the real value of trapz). Furthermore trapz is calculating the area based only on positive numbers, thus the area should not go to zero.... Could someone please help me with that?
  6 Commenti
John D'Errico
John D'Errico il 1 Ago 2016
This is always the best way to solve a problem - by thinking it out, making a conjecture about the problem. When I have a problem like this, once I have some conjecture as to the reason, there is usually a way I can test the validity of my conjecture.
For example, use a finer interval. Or use a better interpolant. The default for interp1 is a piecewise linear interpolation. However you can also use various spline options for interp1, which will generally yield a higher accuracy to approximate a smooth function.
Allan Andre do Nascimento
Thank you very much for the help John! I am thinking about defining the internal step in tspan. Like this, I will have the internal answers calculated by ode in a pre-defined interval and number of points, which can give me a better accuracy than interp1 ,which is just a linear interpolation performed from the internal data provided by ode (please correct me if I am wrong).

Accedi per commentare.

Risposte (0)

Community Treasure Hunt

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

Start Hunting!

Translated by