Integrated trapezoidal and Gauss quadrature

버전 1.0.0 (1.91 KB) 작성자: Lawrence Agbezuge
Use a combined trapezoidal rule and Gauss quadrature to integrate f(x) in the interval x=[a,b]. f(x) is not necessarily equispaced in x.
다운로드 수: 75
업데이트 날짜: 2019/8/25

라이선스 보기

gTrapz.m
Author: Lawrence Agbezuge (2018), Private consultant.

Purpose:
Use a combination of the trapezoidal rule and Gauss quadrature to integrate
f(x) in the interval x=[a,b].
The data for f(x) is provided in tabular or array form as (x,y), and it does not
have to be equally spaced in x.
Between successive data points, a 3-point Gauss quadrature is used.
This makes it possible to obtain reasonably accurate results for the integral
for f(x) when data points are not equally spaced in x.

Usage:
z = gTrapz(x,y)
Input:
(x,y) tabulated data for f(x)
Output:
z (the required approximate integral)

Example: Copy and paste the following code to the command window.

f=@(x) x.*cos(x) + (x.^2).*sin(x);
a=0; b=pi;
x = [a:pi/20:0.2*pi (0.2*pi+pi/50):pi/50:0.8*pi (0.8*pi+pi/20):pi/20:b]; y=f(x);
plot(x,y,'kd-'); xlabel('x'); ylabel('f(x)'); grid
Iapprox = gTrapz(x,y) % obtained by gTrapz
Imatlab = integral(f,a,b) % obtained by Matlab's integral (quad) function

인용 양식

Lawrence Agbezuge (2024). Integrated trapezoidal and Gauss quadrature (https://www.mathworks.com/matlabcentral/fileexchange/72521-integrated-trapezoidal-and-gauss-quadrature), MATLAB Central File Exchange. 검색됨 .

MATLAB 릴리스 호환 정보
개발 환경: R2019a
모든 릴리스와 호환
플랫폼 호환성
Windows macOS Linux
카테고리
Help CenterMATLAB Answers에서 Numerical Integration and Differential Equations에 대해 자세히 알아보기
도움

줌: Numerical Methods

Community Treasure Hunt

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

Start Hunting!
버전 게시됨 릴리스 정보
1.0.0