Skip to content

Instantly share code, notes, and snippets.

@wakusei-meron-
Last active September 30, 2015 06:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save wakusei-meron-/3ba806b41e7eac6e0e07 to your computer and use it in GitHub Desktop.
Save wakusei-meron-/3ba806b41e7eac6e0e07 to your computer and use it in GitHub Desktop.
ニュートン法とは何か??ニュートン法で解く方程式の近似解 ref: http://qiita.com/PlanetMeron/items/09d7eb204868e1a49f49
\begin{aligned}
f'(x_1)&=\frac{\Delta y}{\Delta x} \\
&=\frac{f(x_1)}{x_1 - x_2} \\
\Leftrightarrow x_1-x_2&=\frac{f(x_1)}{f'(x_1)} \\
\therefore x_2 &=x_1 - \frac{f(x_1)}{f'(x_1)}
\end{aligned}
\begin{aligned}
x_3 &=x_2 - \frac{f(x_2)}{f'(x_2)}
\end{aligned}
\begin{aligned}
x^2 &= 2 \\
x^2-2 &= 0 \\
f(x) &= 0 \hspace{1em} (\therefore f(x) = x^2 - 2)
\end{aligned}
\begin{aligned}
x_{n+1} &= x_n - \frac{f(x_n)}{f'(x_n)} \\
&= x_n - \frac{x_{n}^2-2}{2x_n}
\end{aligned}
\begin{aligned}
x_2 &= x_1 - \frac{x_{1}^2-2}{2x_1} \\
&= 5 - \frac{5^2 -2 }{2 \times 5} \\
&= 2.7
\end{aligned}
\begin{aligned}
x_3 &\risingdotseq 1.720 \\
x_4 &\risingdotseq 1.441 \\
x_5 &\risingdotseq 1.414
\end{aligned}
# 適当な初期値の設定
x = 5.0
while True:
# ニュートン法による新しいxを求める
x2 = x - (x * x - 2) / (x * 2)
# 計算後の値が誤差の範囲内になったら計算終了
if abs(x2 - x) < 0.0001:
break
# 計算後の値をxとして計算を繰り返す
x = x2
# 計算結果の表示
print(x)
\begin{aligned}
x_{n+1} &=x_n - \frac{f(x_n)}{f'(x_n)}
\end{aligned}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment