学習環境
- 数式入力ソフト(TeX, MathML): MathType
- MathML対応ブラウザ: Firefox、Safari
- MathML非対応ブラウザ(Internet Explorer, Google Chrome...)用JavaScript Library: MathJax
オイラーの贈物―人類の至宝eiπ=-1を学ぶ (吉田 武(著)、東海大学出版会)の第Ⅰ部(基礎理論(Basic Theory))、3章(微分(Differentiation))、3.8(関数のグラフを描く)、問題5.を解いてみる。
問題5.
コード(Emacs)
#!/usr/bin/env python3
# -*- coding: utf-8 -*_
import fractions
def newton(x, r=10):
inner = lambda x:fractions.Fraction(2 * x ** 3 + x ** 2 - 1,
3 * x ** 2 + 2 * x - 4)
for i in range(r):
print('x_{0} = {1}'.format(i, float(x)))
x = inner(x)
print()
x = fractions.Fraction(-5, 3)
newton(x)
x = 0
newton(x)
x = fractions.Fraction(5, 3)
newton(x)
入出力結果(Terminal, IPython)
$ ./sample5.py x_0 = -1.6666666666666667 x_1 = -7.481481481481482 x_2 = -5.253561542166176 x_3 = -3.856870541321936 x_4 = -3.0647804042831877 x_5 = -2.7248676719102827 x_6 = -2.654106846739904 x_7 = -2.6510987533831787 x_8 = -2.651093408954031 x_9 = -2.651093408937175 x_0 = 0.0 x_1 = 0.25 x_2 = 0.27358490566037735 x_3 = 0.2738905022655762 x_4 = 0.27389055496421605 x_5 = 0.2738905549642176 x_6 = 0.2738905549642176 x_7 = 0.2738905549642176 x_8 = 0.2738905549642176 x_9 = 0.2738905549642176 x_0 = 1.6666666666666667 x_1 = 1.4396135265700483 x_2 = 1.3812200268652726 x_3 = 1.3772213440738694 x_4 = 1.3772028543676846 x_5 = 1.3772028539729577 x_6 = 1.3772028539729577 x_7 = 1.3772028539729577 x_8 = 1.3772028539729577 x_9 = 1.3772028539729577 $
0 コメント:
コメントを投稿