3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

数値積分 > ガウス積分 / gaussian quadrature > 5点の積分例

Last updated at Posted at 2015-04-13

ガウス積分という積分方法について。

概要

積分のポイントは以下のテーブルとして用意されている。
Gaussian Quadrature Weights and Abscissae

計算でもWeights and Abscissaeを求めることができるはず。
sunilさんのページにgaus_leg.cとしてweightsとabscissaeを計算するコードがある。
但し、gaus_leg.c内の関数gauleg()で得られるweight w[]とabscissa x[]はインデックスが1から使う点に注意。

サンプルコード

例として5点のガウス積分を実装してみた。
積分式は以下のものとした。

\int_{-1}^{1}{\pi}dr = [\pi r]^{1}_{-1} = 2\pi
sample-gauss.c
# include <stdio.h>
# include <math.h>

# define IDX_WEI (0)
# define IDX_ABS (1)
# define NUM_ITEMS (5)

double cf[NUM_ITEMS][2] =
{
// weight, abscissa
{0.5688888888888889,	0.0000000000000000},
{0.4786286704993665,	-0.5384693101056831},
{0.4786286704993665,	0.5384693101056831},
{0.2369268850561891,	-0.9061798459386640},
{0.2369268850561891,	0.9061798459386640	}
};

static double myFunc(double x_)
{
	const double pi=acos(-1.0);
	return pi;
}

int main(void)
{
	double d0, xx, yy, weight;
	int idx;

	d0 = 0.0;
	for(idx=0; idx<NUM_ITEMS; idx++) {
		xx = cf[idx][IDX_ABS];
		weight = cf[idx][IDX_WEI];
		yy = myFunc(xx);
		d0 += (weight * yy);
	}

	printf("%lf\n", d0); // 2pi
}
実行結果
$ gcc sample-gauss.c -lm
$ ./a.out
6.283185
3
4
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
4

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?