两个节点复化高斯型求积公式matlab
时间: 2023-07-13 18:35:21 浏览: 174
两个复化的Gauss-Legendre型求积公式及其误差分析 (2011年)
以下是两个节点复化高斯型求积公式的 MATLAB 代码:
1. 对于区间 [a,b],使用两个节点的复化高斯型求积公式:
```matlab
function I = Gauss2(f,a,b)
% Gauss2: 2-node Gauss quadrature
% I = Gauss2(f,a,b): 2-node Gauss quadrature of f(x) over [a,b]
% input:
% f = input funtion
% a,b = integration limits
% output:
% I = integral of f(x) over [a,b]
x = [-0.5773502692, 0.5773502692]; % nodes
w = [1.0, 1.0]; % weights
I = (b-a)/2 * sum(w .* f((b-a)/2 * x + (b+a)/2));
```
2. 对于区间 [a,b],使用两个节点的复化高斯型求积公式,将区间等分为 n 个子区间,每个子区间使用两个节点的复化高斯型求积公式:
```matlab
function I = Gauss2c(f,a,b,n)
% Gauss2c: Composite 2-node Gauss quadrature
% I = Gauss2c(f,a,b,n): Composite 2-node Gauss quadrature of f(x) over [a,b], using n subintervals
% input:
% f = input funtion
% a,b = integration limits
% n = number of subintervals
% output:
% I = integral of f(x) over [a,b]
x = [-0.5773502692, 0.5773502692]; % nodes
w = [1.0, 1.0]; % weights
h = (b-a)/n; % subinterval width
I = 0;
for i = 1:n
I = I + sum(w .* f((h/2) * x + (a+(i-0.5)*h)));
end
I = (b-a)/(2*n) * I;
```
阅读全文