「旧課程(-2012年度)高等学校数学B/数値計算とコンピューター」の版間の差分
削除された内容 追加された内容
→2分法: Schemeでも実行結果を表示するようにした。 タグ: 2017年版ソースエディター |
→2分法: Pythonも再帰化。受入検査と再帰を分離。受入検査に cllable(func) と left <= right を追加。ラムダ式の評価回数を最小化。 タグ: 2017年版ソースエディター |
||
81 行
;[[Python]]による[https://paiza.io/projects/mslsT2vksLfwnt8HqWmn-A?language=python3 コード例]:<syntaxhighlight lang="python">
def bisection(func, left: float, right: float) -> float:
# Acceptance inspection
assert (callable(func)),"The func is not callable."
assert (type(left) == float),"The left side is not a real number."
assert (type(right) == float),"The right side is not a real number."
# Implementation of core algorithms
def core(f, low: float,
x = (low +
if (abs(fx) <
return x
if fx < 0.0:
low = x
else:
return
return core(func, left, right)
print(bisection(lambda x: x-1, 0.0, 3.0))
100 ⟶ 106行目:
</syntaxhighlight>
;実行結果:<syntaxhighlight lang=text>
0.9999999999417923
1.0000000000291038
</syntaxhighlight>
123 ⟶ 129行目:
1.0000000000291038
</syntaxhighlight>
:このコードも<math>\lambda(x)=x-1</math>、または、<math>\lambda(x)=x^2-1</math>のときに試された。[[Python]]版
==== 台形公式====
|