.NET 開発基盤部会 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

詳細

df(x)  yの増量        f(x+h) - f(x)        f(x+h) - f(x)
── = ───  = lim  ──────  = lim  ──────
 dx    xの増量   h→0 (x+h) - (x)     h→0      h

解析的

式の展開によって微分を求める(誤差がない)。

     2
y = x
df(x)  yの増量        (x+h)^2 - x^2        (x^2+2hx+h^2) - (x^2)
── = ───  = lim  ──────  = lim  ──────────
 dx    xの増量   h→0 (x+h) - (x)     h→0           h
 dy         2hx+h^2
── = lim ──── = lim 2x+h  = 2x
 dx    h→0    h      h→0

数値微分

計算によって微分を求める(誤差がある)。

Python実装

"""This is a test program."""

import numpy as np
import matplotlib.pyplot as plt

def numerical_diff(f, x):
    """数値微分"""
    h = 1e-4 # 微小な値hとして1の-4乗を用いる
    return (f(x + h) - f(x - h)) / (2 * h) # 前方差分から中心差分にして誤差減

def function_1(x):
    """f(x)=0.01x^2+0.1x"""
    return 0.01 * x ** 2 + 0.1 * x

X=5
print("X=" + str(X) + " : " + str(numerical_diff(function_1, X)))
X=10
print("X=" + str(X) + " : " + str(numerical_diff(function_1, X)))

X = np.arange(0.0, 20.0, 0.1)
Y = function_1(X)
plt.xlabel("x")
plt.ylabel("f(x)")
plt.plot(X, Y)
plt.show()

Python出力

偏微分

概要

計算

∂y
── = 12x1^2
∂x1  

参考


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS