0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

いろんなアルゴリズム"00.00.00.0c"

Last updated at Posted at 2025-05-04

立ち位置・仕様

  • いろんなアルゴリズムをコピペできるように記録するのみ
  • 最適化が目的でない
  • たまにメモとして解説を残す
  • 最低限でまとめる
  • データを抽出しやすいように個別のIDを付与
  • あるアルゴリズムにおいて、他のアルゴリズムが登場する際にはそのIDを付与
  • IDは16進数表記
  • なるべく最低限なパッケージで実装
  • なるべく特殊なオブジェクト型は使用しない

TargetID

00.00.00.0c

ReferenceID

ニュートン・ラフソン法

  • 微分可能関数 $f$ が $f(x)=0$の解、つまり根を求めるための反復的手法
  • 一元n次方程式で実行可能
def NewtonRaphsonMethod(func, derivative, x1, step):
	# func : 元の関数
	# derivative : 導関数
	# args : 初期値
	# step : 反復回数
	xn = x1
	for _ in range(step):
		xn = xn - func(xn)/derivative(xn)
	return xn

使用方法

def func(x):
	return (x-3)**2 - 1

def derivative(x): # 事前に導関数を計算する必要
	return 2*(x-3)

if __name__ == '__main__':
	x = NewtonRaphsonMethod(func, derivative, 8, 10)
	print('y=0となるとき、xは{}'.format(x)) # 4 (初期値によっては2)
0
0
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
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?