Is possible to integrate numerical data using quadrature method?
4 ビュー (過去 30 日間)
古いコメントを表示
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?
0 件のコメント
回答 (1 件)
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)
100*(ans - truth)/truth
You can simply use a spline here though too.
spl = spline(x,y);
diff(fnval(fnint(spl),[0,pi]))
100*(ans - truth)/truth
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
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
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.
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!