How do I find the itegration's order of convergence?

14 visualizzazioni (ultimi 30 giorni)
I want to integrate a function using several different methods. Let's say I'm using Simpson's rule, with the function defined as follows:
function I = simpsons(f,a,b,n)
if numel(f)>1
n=numel(f)-1;
h=(b-a)/n;
I= h/3*(f(1)+2*sum(f(3:2:end-2))+4*sum(f(2:2:end))+f(end));
else
h=(b-a)/n; xi=a:h:b;
I= h/3*(f(xi(1))+2*sum(f(xi(3:2:end-2)))+4*sum(f(xi(2:2:end)))+f(xi(end)));
end
end
The question is, how to check the order of convergence using MATLAB code? I saw similar questions asked around here, but none answered.

Risposte (1)

John D'Errico
John D'Errico il 20 Dic 2020
Modificato: John D'Errico il 20 Dic 2020
Um, you cannot just magically know the order of convergence of something. There is no simple rule where you can look at code and know how it converges. And, well, this is homework, since nobody normally wants to know this, or if they desperately did then they could derive it, or they would just look it up. Wikipedia can be your friend. (Simpson's rule is a closed end Newton-Cotes rule, with three nodes per panel.)
Effectively, you can think of a Newton-Cotes rule as if you interpolate your points with a series of polynomials (did you learn about Lagrange interpolation?) and then integrate them.
I won't do your homework. Sorry. I won't, because you will learn by doing.
In the case of an integration, if you desperately need to solve this, I will give you a very useful hint:
Consider a simple, vaguely Taylor-like polynomial:
P(x) = a0 + a1*x + a2*x^2 + a3*x^3 + a4*x^4 + ...
I'll stop at x^4 for your purpose here. Now, using one panel of Simpson's rule, integrate that polynomial over the interval [0,2*h]. So there are nodes at {0,h,2*h}.
Can you compute the exact integral of that function over the interval?
Finally, compute the DIFFERENCE between your exact integral and what Simpson's rule gives you.
Look carefully at what remains. Does this suggest anything? If you try it, AND show what you tried as a comment on my question, I will be more forthcoming in how I am willing to help you. But you need to do the work.

Categorie

Scopri di più su Numerical Integration and Differential Equations in Help Center e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by