FindRoot
詳細とオプション
- 変数の初期値がリストで与えられているとき,変数の値は同じ次元のリストであると解釈される.
- FindRootはSolveから得るのと同じ形式の x, y, … のための代入リストを返す.
- FindRootは,まずすべての変数の値を局所化し,次に記号的となった変数で f を評価し,繰り返して結果を数値的に評価する.
- FindRootは属性HoldAllを持ち,Blockを用いて実質的に変数を局所化する.
- FindRoot[lhs==rhs,{x,x0,x1}]は x0と x1を x の最初の2つの値とし,導関数を用いずに解を求める.
- FindRoot[lhs==rhs,{x,xstart,xmin,xmax}]は,x が xminから xmaxの範囲外に出た場合にこの検索を中止するという条件で,解を求める.
- x の初期値を1つしか指定しなければ,FindRootはニュートン法を用いて解を求める.初期値を2つ指定すると,FindRootは割線法の変形を用いる.
- すべての方程式と初期値が実数の場合,FindRootは実根のみを求める.複素数が含まれる場合は複素根も求める.
- 初期値に0.Iを加えることで,常にFindRootに複素根を求めさせることができる.
- 指定可能なオプション
-
AccuracyGoal Automatic 目標とする確度 EvaluationMonitor None 式が評価されたときに常に評価される式 Jacobian Automatic この系のヤコビ行列式 MaxIterations 100 使用する最大反復回数
Automatic 使用するメソッド PrecisionGoal Automatic 目標とする精度 StepMonitor None ステップを取るたびに常に評価される式 WorkingPrecision MachinePrecision 内部計算に使用する精度 - デフォルト設定ではAccuracyGoalとPrecisionGoalの設定はWorkingPrecision/2である.
- AccuracyGoalの設定で,根の位置の値と根における関数の値の両方の目標確度の桁数を指定する.
- PrecisionGoalの設定で根の位置の値の目標精度桁数を指定する.
- FindRootはAccuracyGoalまたはPrecisionGoalで指定された目標精度(または確度)に達するまで計算を続ける.
- FindRootがMaxIterationsの反復ステップ内で指定された正確さの解が見出せない場合,最近見出した近似解を返す.この場合,この点を初期値としてFindRootを再適用する.
例題
すべて開く すべて閉じる例 (3)
スコープ (4)
FindRoot[{y == Exp[x], x + y == 2}, {{x, 1}, {y, 1}}]FindRoot[{Sin[x + y], Cos[x - y], x ^ 2 + y ^ 2 - z}, {{x, 1}, {y, 0}, {z, 0}}]FindRoot[Zeta[z], {z, 1 / 2 + 14 I}]実数入力に対して方程式が複素数である場合,実数の初期値が複素数の結果を与えていることがある:
FindRoot[(Cos[z + I] - 2)(z + 2), {z, 1}]FindRoot[(Cos[z + I] - 2)(z + 2), {z, -1}]一般化と拡張 (1)
オプション (10)
AccuracyGoal (1)
10 - x /. FindRoot[Sin[x - 10] - x + 10, {x, 0}]10 - x /. FindRoot[Sin[x - 10] - x + 10, {x, 0}, AccuracyGoal -> 4, PrecisionGoal -> 4]10 - x /. FindRoot[Sin[x - 10] - x + 10, {x, 0}, AccuracyGoal -> Infinity, PrecisionGoal -> 8]DampingFactor (1)
EvaluationMonitor (1)
EvaluationMonitorを使って使用された関数評価を追跡記録することができる:
{res, {evx}} = Reap[FindRoot[x ^ 2 == Exp[x], {x, 0}, EvaluationMonitor :> Sow[x]]]Show[Plot[{x ^ 2, Exp[x]}, {x, -1, 0}], ListPlot[{Transpose[{evx, evx ^ 2}], Transpose[{evx, Exp[evx]}]}]]Jacobian (1)
n = 1000;
A = SparseArray[{{i_, i_} -> -2., {i_, j_} /; Abs[i - j] == 1 -> 1.}, {n, n}, 0.];
blackbox[x_ ? VectorQ] := n ^ 2 A.x + x - x ^ 3 - 1;J[x_ ? VectorQ] := Module[{d = 1 - 3 x ^ 2}, n ^ 2 A + SparseArray[{i_, i_} :> d[[i]], {n, n}]]sc = ConstantArray[0., n];
Block[{e = 0}, Timing[FindRoot[blackbox[x], {x, sc}, Jacobian -> J[x], EvaluationMonitor :> e++];e]]指定された関数行列式がなければ,有限差分の計算に余分な評価が行われる:
Block[{e = 0}, Timing[FindRoot[blackbox[x], {x, sc}, EvaluationMonitor :> e++];e]]疎な形式を知っているならば,疎なパターンテンプレートを指定することで評価回数を少なくできる:
sp = SparseArray[{{i_, j_} /; Abs[i - j] ≤ 1 -> _}, {n, n}]Block[{e = 0}, Timing[FindRoot[blackbox[x], {x, sc}, Jacobian -> {"FiniteDifference", Sparse -> sp}, EvaluationMonitor :> e++];e]]さまざまなメソッドが必要とするヤコビ行列式の評価数を調べる:
Block[{j = 0}, FindRoot[blackbox[x], {x, sc}, Jacobian -> {J[x], EvaluationMonitor :> j++}];"Jacobian Evaluations" -> j]Block[{j = 0}, FindRoot[blackbox[x], {x, sc},
Method -> "AffineCovariantNewton", Jacobian -> {J[x], EvaluationMonitor :> j++}];"Jacobian Evaluations" -> j]MaxIterations (1)
Method (2)
メソッドオプションについては制約条件のない最適化も参照されたい.
f[x_] = ArcTan[1000 Cos[x]];
Plot[f[x], {x, 0, 12}, Exclusions -> None]FindRootで使われるステップと評価をモニターする関数を定義する:
monitoredFindRoot[args__] := Module[{s = 0, e = 0, j = 0},
{FindRoot[args, StepMonitor :> s++, EvaluationMonitor :> e++, Jacobian -> {Automatic, EvaluationMonitor :> j++}], "Steps" -> s, "Evaluations" -> e, "Jacobian Evaluations" -> j}]monitoredFindRoot[ArcTan[1000Cos[x]], {x, 1}]ブレント(Brent)法の根の囲い込みには根を囲む2つの初期条件が必要である:
monitoredFindRoot[ArcTan[1000Cos[x]], {x, 1, 2}, Method -> "Brent"]monitoredFindRoot[ArcTan[1000Cos[x]], {x, 1, 2}, Method -> "Secant"]monitoredFindRoot[ArcTan[1000Cos[x]], {x, 1}, Method -> "AffineCovariantNewton"]PrecisionGoal (1)
10 - x /. FindRoot[Sin[x - 10] - x + 10, {x, 0}]10 - x /. FindRoot[Sin[x - 10] - x + 10, {x, 0}, AccuracyGoal -> 4, PrecisionGoal -> 4]10 - x /. FindRoot[Sin[x - 10] - x + 10, {x, 0}, AccuracyGoal -> Infinity, PrecisionGoal -> 8]StepMonitor (1)
f[x_, y_] = {x - 1, 10(y - Cos[2x] + 1)};{res, {stxy}} = Reap[FindRoot[f[x, y], {{x, -1}, {y, -1}}, StepMonitor :> Sow[{x, y}]]]ContourPlot[f[x, y].f[x, y], {x, -1, 1}, {y, -2, 1}, Epilog -> {Red, Map[Point, stxy]}]ステップ(赤)とその評価(緑)を表す.ステップには数回の評価が必要なことがある:
{res, {exy}} = Reap[FindRoot[f[x, y], {{x, -1}, {y, -1}}, EvaluationMonitor :> Sow[{x, y}]]];ContourPlot[f[x, y].f[x, y], {x, -1, 1}, {y, -2, 1}, Epilog -> {{PointSize[0.04], Red, Map[Point, stxy]}, {Green, Map[Point, exy]}}]WorkingPrecision (1)
FindRoot[Cos[x ^ 2] - x, {x, 1}, WorkingPrecision -> 100]Block[{prec = MachinePrecision}, FindRoot[Cos[x ^ 2] - x, {x, 1.0}, WorkingPrecision -> 100, StepMonitor :> If[Precision[x] ≠ prec, prec = Precision[x];Print["Increased precision to ", prec, " at x = ", x];]]]アプリケーション (3)
逆関数の計算 (1)
inv[f_, s_] := Function[{t}, s /. FindRoot[f - t, {s, 1}]]einv = inv[Exp[x], x]これは組込みのLog関数に非常に近い:
Plot[einv[x] - Log[x], {x, 0, 1}, PlotRange -> All]f[a_ ? NumberQ] := Module[{p = 0}, NDSolve[{x''[t] + x[t] + x[t] ^ 3 == 0, x[0] == a, x'[0] == 0}, x, {t, ∞}, Method -> {"EventLocator", "Event" -> x[t], "EventAction" :> Throw[p = t, "StopIntegration"]}];
4p];Plot[f[a], {a, 0, 4}]finv = inv[f[a], a]Plot[finv[s], {s, 3, 6}]境界値問題を解く (2)
x1[s_ ? NumberQ] := First[x[1] /. NDSolve[{x''[t] + x'[t] + x[t] ^ 3 == Sin[4 t], x[0] == 0, x'[0] == s}, x, {t, 0, 1}]]Plot[x1[s], {s, -10, 10}]FindRoot[x1[s], {s, -1, 0}]sol = NDSolve[{x''[t] + x'[t] + x[t] ^ 3 == Sin[4t], x[0] == 0, x'[0] == s} /. %, x, {t, 0, 1}]Plot[x[t] /. sol, {t, 0, 1}]n = 100;f[{u_, v_}] := {v, (1 - u - u ^ 3) / ϵ};eqns = Flatten[Join[{Subscript[u, 0] == 0, Subscript[u, n] == 0}, Table[Thread[{Subscript[u, i], Subscript[v, i]} == {Subscript[u, i - 1], Subscript[v, i - 1]} + (1/2 n)(f[{Subscript[u, i - 1], Subscript[v, i - 1]}] + f[{Subscript[u, i], Subscript[v, i]}])], {i, 1, n}]]];sv = Flatten[Table[{{Subscript[u, i], 0}, {Subscript[v, i], 0}}, {i, 0, n}], 1];froot = FindRoot[eqns /. ϵ -> 0.01, sv];
sol = Table[Subscript[u, i], {i, 0, n}] /. froot;
ListLinePlot[sol]特性と関係 (2)
方程式の多項式系の場合,NSolveはすべての解をFindRootは1つの解を求める:
polysys = Table[Total[RandomInteger[{-9, 9}, 5]RandomChoice[{x, y, z}, 5] ^ RandomInteger[{0, 3}, 5]] == 0, {3}]FindRootは反復法を使って1つの解を求める:
FindRoot[polysys, Transpose[{{x, y, z}, RandomComplex[1 + I, 3]}]]NSolveは直接法を使ってすべての解を求める:
NSolve[polysys, {x, y, z}]パラメータまたは厳密解を含む方程式の場合はSolve,Reduce,FindInstanceのいずれかを使う:
eq = x Exp[2x + a] + 3 == 0;Solveはいくつかの解を返す:
Solve[eq, x]Reduceはすべての解を列挙する:
Reduce[eq, x]FindInstanceは特定の例を求める:
FindInstance[eq, {x, a}, 2]考えられる問題 (3)
FindRoot[Zeta[1 / 2 + I t], {t, 1}]FindRoot[Abs[Zeta[1 / 2 + I t]], {t, 1}]f[x_] := Nest[Sin[# + Sin[2#]]&, x, 20]FindRoot[f[x], {x, 0}]//Timingg[x_ ? NumericQ] := Nest[Sin[# + Sin[2#]]&, x, 20]FindRoot[g[x], {x, 0}]//Timing検索領域を制限しすぎると問題が発生する可能性がある.2つの非線形方程式の解を1/2から始まる[0,1]の領域で求める:
FindRoot[{y == Exp[x], x + y == 2}, {{x, 1 / 2, 0, 1}, {y, 1 / 2, 0, 1}}]テクニカルノート
-
▪
- 数値解析:基本操作 ▪
- 方程式の解法 ▪
- 方程式の数値解法 ▪
- 数値解析による根の探索 ▪
- 制約条件付き最適化 ▪
- 制約条件のない最適化 ▪
- 記号的評価 ▪
- 実装に関するノート: 数値および関連関数
関連するガイド
-
▪
- 方程式の解法 ▪
- 逆関数 ▪
- コードのコンパイル ▪
- 整方程式 ▪
- 記号的なベクトル,行列,配列
履歴
1988 で導入 (1.0) | 2003 で更新 (5.0)
テキスト
Wolfram Research (1988), FindRoot, Wolfram言語関数, https://reference.wolfram.com/language/ref/FindRoot.html (2003年に更新).
CMS
Wolfram Language. 1988. "FindRoot." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2003. https://reference.wolfram.com/language/ref/FindRoot.html.
APA
Wolfram Language. (1988). FindRoot. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/FindRoot.html
BibTeX
@misc{reference.wolfram_2026_findroot, author="Wolfram Research", title="{FindRoot}", year="2003", howpublished="\url{https://reference.wolfram.com/language/ref/FindRoot.html}", note=[Accessed: 11-August-2026]}
BibLaTeX
@online{reference.wolfram_2026_findroot, organization={Wolfram Research}, title={FindRoot}, year={2003}, url={https://reference.wolfram.com/language/ref/FindRoot.html}, note=[Accessed: 11-August-2026]}