필터 지우기
필터 지우기

Is possible to integrate numerical data using quadrature method?

조회 수: 3 (최근 30일)
University Glasgow
University Glasgow 2023년 3월 17일
편집: John D'Errico 2023년 3월 18일
I have attached the numerical data.
xi = linspace(-0.3, 0.3, 201);
u = linspace(0, 3, 201);
I used trap method:
Dv(ixi, iu) = trapz(Dvv1(:));
Please is possible to apply methods like quadrature etc?

답변 (1개)

John D'Errico
John D'Errico 2023년 3월 17일
편집: John D'Errico 2023년 3월 18일
TRAPZ already is a quadrature method!!!!!
TRAPZ is an implementation of trapezoidal integration, i.e., QUADRATURE. Where do you think the name comes from?
load Dvv1_400N.mat
plot(Dvv1)
Looking at that data, you seriously don't want to use anything that is higher order then trapezoidal integration. Higher order integration methods would actually exacerbate any noise in your data.
If your data were well behaved, nice and smooth, then there are schemes one can use. For example,
x = linspace(0,pi,6);
y = sin(x);
plot(x,y,'-o')
The integral under that curve is of course 2. trapz is not terrible, within approximately 3% of the solution.
truth = 2;
trapz(x,y)
ans = 1.9338
100*(ans - truth)/truth
ans = -3.3117
You can simply use a spline here though too.
spl = spline(x,y);
diff(fnval(fnint(spl),[0,pi]))
ans = 2.0013
100*(ans - truth)/truth
ans = 0.0631
As you can see, this result is accurate to roughly 0.06%, so 50 times better. But this is a nice, smoooth, well-behaved function. things get bad when the function is complicated and noisy.
Just use trapz.
  댓글 수: 4
John D'Errico
John D'Errico 2023년 3월 17일
편집: John D'Errico 2023년 3월 18일
Again, a higher order rule is a terribly bad idea for wildly oscilatory data. Anything that will try to be a better integration method, will also implicitly assume the function is well behaved, that your function must be differentiable. Noisy things like that are best integrated using a low order method. ( actually once did a simulation of exactly that. I showed that if you consider the uncertainty in your estimate of the integral, it gets worse when higher order rules are used.
Maybe I need to explain. You CANNOT use an adaptive quadrature rule (like integral) on data. You CAN interpolate the data, then integrate the interpolant. But this is often a bad idea. The typical higher order rules one can use are effectively the integral of a local polynomial interpolant. (They are normally called Newton-Cotes rules. Simpson's rule is the next step up after trapezoidal rule in that family.)
The problem is, when you pass a polynomial through data like yours, the polynomial will oscillate wildly. The integral of that polynomial, since it now has wild swings in it, ends up being complete crap. You would see similar behavior if you use a spline to interpolate the data, then integrate the spine. Again, a spline on data like yours will oscillate far beyond the swings in your data.
There is only one option that may be mildly acceptable, if you use pchip to interpolate the data, then integrate the pchip interpolant. (Use fnint to do so.) This is because pchip is designed not to oscillate. But the difference will probably be marginal.
Just use trapz.
Torsten
Torsten 2023년 3월 18일
You'd better work first on the code from which you got the Dvv1 results in the plot. They don't look very trustworthy.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Numerical Integration and Differentiation에 대해 자세히 알아보기

제품


릴리스

R2022b

Community Treasure Hunt

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

Start Hunting!

Translated by