Help us understand the problem. What is going on with this article?

中点則(数値積分)

More than 1 year has passed since last update.

中点則とは

  • 数値積分の解法の一つ
  • 関数$f(x)$において、微小区間$[x_0,x_1]$内の関数値は、区間の中点での関数値で一定であると仮定する

qiita-integer-3.png

算法

区間$[a,b]$を小区間に$n$等分し、刻幅$h$と分点$x_i$を次のようにする。
$$ h=\frac{b-a}{n}\ ,\ \ x_i=a+\frac{2i+1}{2}h\ ,\ (i=0,1,\cdots,n-1) $$

積分の近似値は、
$$ \int_a^bf(x)=\sum_{i=0}^{n-1}hf(x_i) $$

サンプルコード

$f(x)=\sqrt{1-x^2}$において、区間$[0,1]$の定積分の値を求めるプログラム。
分割数は4。
解析解は$\pi/4$です。

midpoint_rule.c
#include<stdio.h>
#include<math.h>

double f (double x) {
  return sqrt(1-x*x);
}

/* 中点則(区間[a,b]をn分割) */
double midpoint_rule (double a, double b, int n) {
  double h;
  int i;
  double x, value=0;

  h = (b - a) / n;   // 区間幅の計算
  for (i = 0; i < n; i++) {
    x = a + h*(2*i + 1)/2;   // 分点の計算
    value += f(x);
  }
  value = value*h;
  return value;
}

int main (void) {
  printf("Analytical solution: %f\n", M_PI/4);
  printf("Numerical solution : %f\n", midpoint_rule(0, 1, 4));
  return 0;
}

実行結果

Analytical solution: 0.785398
Numerical solution : 0.795982

特徴

  • 全区間の誤差
    $$ E=\frac{h^2(b-a)}{24}f^{\prime\prime}(\xi)\ ,\ \ \ (a<\xi<b) $$

  • 分割数を倍にすると誤差は$1/4$に減少

  • 上記の$\xi$は、台形則のとは違うので、中点則の方が誤差が小さいことを表しているわけではない

Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした