NSolve
詳細とオプション
- 系 expr は以下の任意の論理結合でよい.
-
lhs==rhs 等しい lhs!=rhs 等しくない lhs>rhs または lhs>=rhs 不等式 expr∈dom 領域指定 {x,y,…}∈reg 領域指定 ForAll[x,cond,expr] 全称記号 Exists[x,cond,expr] 存在記号 - NSolve[{expr1,expr2,…},vars]とNSolve[expr1&&expr2&&…,vars]は等価である.
- 単一の変数または変数のリストを指定することができる.
- NSolveは,次の形式の規則によって解を与える.
-
{} 解がない {{x->solx,y->soly,…},…} 複数の解 {{}} 解集合は全次元である - 指定された変数が1つの場合,ある方程式で特定の根が1より大きい重複性を示すときにはNSolveは相当する解の複数のコピーを返す.
- NSolve[expr,vars]は,デフォルトで,不等式に代数的に現れる数量は実数値であるが,その他の数量は複素数値であると仮定する.
- NSolve[expr,vars,Reals]では,変数,パラメータ,定数,関数のすべての値が実数に限られる.
- NSolve[expr&&vars∈Reals,vars,Complexes]は変数の実数値について解くが,関数の値は複素数値でもよい.
- NSolve[…,x∈reg,Reals]は,x を領域 reg 内に制限する.Indexed[x,i]を使って異なる座標の x に言及することができる.
- NSolveは主として線形方程式と整方程式を扱う.
- 使用可能なオプション
-
MaxRoots Automatic 返す根の最大数 Method Automatic 使用されるべきメソッド RandomSeeding 1234 乱数生成器のシード VerifySolutions Automatic 解を確かめるかどうか WorkingPrecision Automatic 計算に使われる精度 - Methodの可能な設定値には,"EndomorphismMatrix","Homotopy","Monodromy","Symbolic"がある. »
例題
すべて開く すべて閉じる例 (6)
NSolve[x ^ 5 - 2x + 3 == 0, x]NSolve[x ^ 5 - 2x + 3 == 0, x, Reals]NSolve[x ^ 1000000 - 2x + 3 == 0, x, MaxRoots -> 3]NSolve[{x ^ 2 + y ^ 3 == 1, 2x + 3y == 4}, {x, y}]NSolve[{x ^ 2 + y ^ 3 == 1, 2x + 3y == 4}, {x, y}, Reals]NSolve[{x, y}∈InfiniteLine[{{0, 0}, {2, 1}}] && {x, y}∈Circle[], {x, y}]Graphics[{{Blue, InfiniteLine[{{0, 0}, {2, 1}}], Circle[]}, {Red, Point[{x, y}] /. %}}]スコープ (48)
一変数複素方程式 (10)
NSolve[x ^ 5 - 2x + 17 == 0, x]NSolve[x ^ 3 - 1.234x + 5.678 == 0, x]NSolve[(x ^ 2 - 1)(x ^ 4 - 1) == 0, x]NSolve[x ^ 1234567 + 9x ^ 2 + 7x - 1 == 0, x, MaxRoots -> 5]NSolve[Sqrt[x] + 3x ^ (1 / 3) == 5, x]NSolve[Sin[x] == 1 / 3, x]NSolve[Sin[x] == 1 / 3, x, MaxRoots -> Infinity]NSolve[5 == x 2 ^ (x ^ 2), x, MaxRoots -> 3]NSolve[Sin[E ^ x] - Cos[2 x] == 1 && -1 ≤ Re[x] ≤ 1 && -1 ≤ Im[x] ≤ 1, x]NSolve[Gamma[x] - Log[x] == I / 2 && Abs[x - 2] < 3 / 2, x]NSolve[Cos[Exp[x]] == 3 Exp[-x] + 1 && 0 ≤ Re[x] ≤ 1, x]NSolve[Cos[Exp[x]] == 3 Exp[-x] + 1 && 0 ≤ Re[x] ≤ 1, x, MaxRoots -> Infinity]NSolve[BesselJ[2, x]x - 2 ^ x == 3, x]多変数の複素方程式系 (9)
NSolve[{x + 2y + 3z == 4, 3x + 4y + 5z == 6, 7x + 9y + 8z == 10}, {x, y, z}]NSolve[1.23 x + 2.34 y + 3.45 z == 4.56 && 5.67x + 6.78y + 7.89z == 8.9 && 9.01x + 0.12y + 1.23z == 2.34, {x, y, z}]NSolve[x + 2y + 3z == 4 && 3x + 4y + 5z == 6 && 6x + 7y + 8z == 9, {x, y, z}]NSolve[x + 2y + 3z == 4 && 3x + 4y + 5z == 6 && 6x + 7y + 8z == 0, {x, y, z}]NSolve[x ^ 2 + y ^ 2 == 1 && x ^ 3 + 2y ^ 3 == 3, {x, y}]NSolve[x ^ 10000 == y ^ 2 + 2y + 1 && y ^ 10000 == z ^ 2 + 2z + 1 && z ^ 10000 == x ^ 2 + 2 x + 1, {x, y, z}, MaxRoots -> 5]NSolve[x ^ 2 + y ^ 2 + z ^ 2 == 1 && x y z == 2, {x, y, z}]NSolve[Sqrt[x y] == Sqrt[x + y] && Sqrt[x] - y ^ (1 / 3) == 1, {x, y}]NSolve[Sin[x + y] == x y + 1 && Cos[x - y] == AiryAi[x y] + 2, {x, y}]NSolve[3 ^ x ^ 2 == 7 && x ^ 2 - y ^ 3 == 4, {x, y}, MaxRoots -> 5]一変数実方程式 (11)
NSolve[x ^ 5 - 2x + 1 == 0, x, Reals]NSolve[(x ^ 2 - 1)(x ^ 4 - 1) == 0, x, Reals]NSolve[Sqrt[x] + 3x ^ (1 / 3) == 5, x, Reals]NSolve[Abs[x] ^ 2 - x + UnitStep[x] == 9, x, Reals]NSolve[E ^ x - x == 7, x, Reals]NSolve[ 27^2x - 1^(1/(x)) == Sqrt[9^2x - 1], x, Reals]NSolve[AiryBi[1 - x ^ 2] == 0 && 2 < x < 3, x, Reals]NSolve[900 < AiryAiZero[2t + 1] ^ 2 < 1000, t, Reals]NSolve[E ^ (2E ^ x) - Log[x ^ 2 + 1] - 20x == 11, x, Reals]NSolve[x ^ 1000000 - 2x ^ 777777 + 3x ^ 12345 + 9x ^ 67 - 10 == 0, x, Reals]NSolve[2x ^ (123451 / 67890) - x ^ 2 + 4Sqrt[x] - 4x - 9 / 8 == 0, x, Reals]NSolve[x ^ Pi - x ^ x ^ Sqrt[2] - Sqrt[3]x + 2 ^ (1 / 3) == 0, x, Reals]NSolve[10Sin[Tan[E ^ -x ^ 2]] - x == 3, x, Reals]NSolve[2Sin[Exp[x]] - Cos[Pi x] == 3 / 2 && -1 < x < 1, x, Reals]NSolve[Cos[x] - BesselJ[5, x] == 1 / 2 && 0 ≤ x ≤ 10, x]多変数実方程式系と実不等式系 (9)
NSolve[2 x + 3y - 5z == 1 && 3x - 4y + 7z == 3 && x + y - z == 8, {x, y, z}, Reals]NSolve[x y == z ^ 2 - x && x y z == 2 && x ^ 2 + y ^ 2 + z ^ 2 == 5, {x, y, z}, Reals]NSolve[Exists[x, x ^ 2 + a x + b == 0 && 2 x + a == 0 && a ^ 2 + x b ^ 2 == 1], {a, b}, Reals]NSolve[ForAll[x, Exists[y, a x ^ 2 + b y ^ 2 - 3y == 1 && y < 0 && a y - y == b + 1]], {a, b}, Reals]NSolve[Sqrt[x + 2y] - 3x + 4y == 5 && x + y ^ (1 / 3) == 2, {x, y}, Reals]NSolve[Max[x ^ 2, 1 - y ^ 3] == Min[y ^ 2, x] + 7y && x + UnitStep[4 - y] == 5, {x, y}, Reals]NSolve[Sin[x + y] == 1 / 2 && E ^ x - y == 1 && x ^ 2 ≤ 10, {x, y}, Reals]NSolve[ 3^x - 2^2y == 77 && Sqrt[3^x] - 2^y == 7, {x, y}, Reals]NSolve[E ^ x y ^ 3 + Log[x]y == 1 && x y + E ^ x / x == 10, {x, y}, Reals]NSolve[Exists[a, a x ^ 2 + Sinh[x ^ 2 + 1]a ^ 2 == 1 && x ^ 2 - a ^ 2 == 1], x, Reals]NSolve[Sin[x - Cos[x]] y ^ 3 - x == 1 && x ^ 2 + y ^ 2 == 1, {x, y}, Reals]NSolve[Exists[y, y ^ 3 - Cos[x] y + 2 x ^ 2 Sin[x ^ 2 - 1] == 0 && x ^ 2 + y ^ 2 == 2], x, Reals]NSolve[y ^ 3 - BesselJ[2, x + 2] y - y - 3 x == -2 && x ^ 2 ≤ 1 && x y - x ^ 2 + y ^ 2 == 3, {x, y}, Reals]NSolve[Exists[y, y ^ 4 - Gamma[x + 2] y - y - 3 ArcSin[x / 3] == 1 && x ^ 2 + y ^ 3 == 1 && 0 < x < 2], x, Reals]混合変数領域の系 (1)
幾何学領域 (8)
Subscript[ℛ, 1] = Circle[];
Subscript[ℛ, 2] = Line[{{-2, 1}, {1, -2}}];NSolve[{x, y}∈Subscript[ℛ, 1] && {x, y}∈Subscript[ℛ, 2], {x, y}]Graphics[{{Blue, Subscript[ℛ, 1], Subscript[ℛ, 2]}, {Red, Point[{x, y}] /. %}}]Subscript[ℛ, 1] = Sphere[];
Subscript[ℛ, 2] = InfinitePlane[{{0, 0, 0}, {0, 1, 0}, {1, 0, 1}}];NSolve[2 x y == z^2 && {x, y, z}∈Subscript[ℛ, 1] && {x, y, z}∈Subscript[ℛ, 2], {x, y, z}, Reals]Show[{ContourPlot3D[2 x y == z^2, {x, -1.2, 1.2}, {y, -1.2, 1.2}, {z, -1.2, 1.2}, Mesh -> None, ContourStyle -> Opacity[0.5]], Graphics3D[{{Opacity[0.5], Green, Subscript[ℛ, 1]}, {Opacity[0.5], Yellow, Subscript[ℛ, 2]}, {PointSize[Large], Red, Point[{x, y, z} /. %]}}]}]ℛ = ImplicitRegion[a + 2 b - 3 c ≥ 1 && a b c == 7, {a, b, c}];NSolve[y^2 + x z == 1 && x + y == z ^ 2 && {x, y, z}∈ℛ, {x, y, z}, Reals]ℛ = ParametricRegion[{s + t, s - t, s t}, {s, t}];NSolve[x y == z && x + 2 y + 3 z == 1 && {x, y, z}∈ℛ, {x, y, z}, Reals]Subscript[ℛ, 1] = Disk[{0, 0}, 2];
Subscript[ℛ, 2] = Circle[{1, 1}, 2];
Subscript[ℛ, 3] = RegionIntersection[Subscript[ℛ, 1], Subscript[ℛ, 2]];NSolve[x^2 == x y + 1 && {x, y}∈Subscript[ℛ, 3], {x, y}, Reals]Show[{ContourPlot[x^2 == x y + 1, {x, -2, 3}, {y, -2, 3}], Graphics[{{Opacity[0.5], Yellow, Subscript[ℛ, 1]}, {Green, Subscript[ℛ, 2]}, {Red, Point[{x, y} /. %]}}]}]Subscript[ℛ, 1] = Circle[];
Subscript[ℛ, 2] = InfiniteLine[{{-2, 0}, {0, t}}];
Subscript[ℛ, 3] = Circle[{1, 1}, {2t, t}];
Subscript[ℛ, 4] = RegionIntersection[Subscript[ℛ, 1], Subscript[ℛ, 2], Subscript[ℛ, 3]];NSolve[{x, y}∈Subscript[ℛ, 4], {t, x, y}, Reals]Graphics[{{Blue, Subscript[ℛ, 1], Subscript[ℛ, 2], Subscript[ℛ, 3]}, {Red, Point[{x, y}]}} /. %]円が指定された点を含むような,パラメータ
,
,
の値を求める:
Subscript[ℛ, 1] = Circle[{a, b}, r];
Subscript[ℛ, 2] = Circle[{a + 1, b}, r];
Subscript[ℛ, 3] = RegionIntersection[Subscript[ℛ, 1], Subscript[ℛ, 2]];NSolve[({0, 1} | {0, -1})∈Subscript[ℛ, 3], {a, b, r}, Reals]Show[{Graphics[{{Blue, Subscript[ℛ, 1]}, {Green, Subscript[ℛ, 2]}, {Red, Point[{{0, 1}, {0, -1}}]}} /. %]}]ℛ = RegionIntersection[Circle[], Line[{{-2, -1}, {1, 2}}]];NSolve[x∈ℛ, x]ℛ = Sphere[];NSolve[x.{1, 2, 3} == 0 && x.{-3, -2, -1} == 0 && x∈ℛ, x]一般化と拡張 (1)
オプション (10)
MaxRoots (4)
NSolve[x ^ 12345 + x + 1 == 0, x, MaxRoots -> 3]NSolve[x ^ 1000 == y + 1 && y ^ 1000 == z + 1 && z ^ 1000 == x + 1, {x, y, z}, MaxRoots -> 3]NSolve[Sin[x + y] == 2 && Cos[x - y] == 3, {x, y}, MaxRoots -> 5]NSolveは,デフォルトのAutomatic設定ではすべての解を与えないかもしれない:
NSolve[Sin[x] == 1 / 2, x]MaxRootsInfinityとすると,NSolveはすべての解を求めようとする:
NSolve[Sin[x] == 1 / 2, x, MaxRoots -> Infinity]Method (4)
NSolve[x ^ 2 + 2y ^ 2 == 3 && x ^ 3 - 4x y == 5, {x, y}]NSolve[x ^ 2 + 2y ^ 2 == 3 && x ^ 3 - 4x y == 5, {x, y}, Method -> "EndomorphismMatrix"]NSolve[x ^ 2 + 2y ^ 2 == 3 && x ^ 3 - 4x y == 5, {x, y}, Method -> "Homotopy"]NSolve[x ^ 2 + 2y ^ 2 == 3 && x ^ 3 - 4x y == 5, {x, y}, Method -> "Monodromy"]NSolve[x ^ 2 + 2y ^ 2 == 3 && x ^ 3 - 4x y == 5, {x, y}, Method -> "Symbolic"]この系には
個の根があるが,これは,Bernstein-Khovanskii-Kushnirenkoの定理で与えられた
の境界よりも厳密には少ない:
syst = t1^2 + t2^2 + t3^2 - 12t1 - 68 == 0 && t4^2 + t5^2 + t6^2 - 12t5 - 68 == 0 && t7^2 + t8^2 + t9^2 - 24 t8 - 12t9 + 100 == 0 && t1 t4 + t2 t5 + t3 t6 - 6 t1 - 6t5 - 52 == 0 && t1 t7 + t2 t8 + t3 t9 - 6 t1 - 12t8 - 6t9 + 64 == 0 && t4 t7 + t5 t8 + t6 t9 - 6t5 - 12t8 - 6t9 + 32 == 0 && 2t2 + 2t3 - t4 - t5 - 2 t6 - t7 - t9 + 18 == 0 && t1 + t2 + 2t3 + 2t4 + 2t6 - 2t7 + t8 - t9 - 38 == 0 && t1 + t3 - 2t4 + t5 - t6 + 2t7 - 2t8 + 8 == 0;
vars = {t1, t2, t3, t4, t5, t6, t7, t8, t9};デフォルトで使われる"Homotopy"法は,いくつかの根の複数のコピーを返す:
(sols = NSolve[syst, vars])//Length//AbsoluteTimingUnion[sols, SameTest -> (Norm[(vars /. #1) - (vars /. #2)] < 10 ^ -6&)]//Lengthこの場合は"Monodromy"法の方が速く,根の複数のコピーも返さない:
NSolve[syst, vars, Method -> "Monodromy"]//Length//AbsoluteTimingNSolve[Sin[x + y] + Cos[x - y] == 1 && Sin[x - y] + Cos[x + y] == 2, {x, y}, Method -> "Monodromy"]NSolve[Sin[x + y] + Cos[x - y] == 1 && Sin[x - y] + Cos[x + y] == 2, {x, y}, Method -> "Symbolic"]Methodオプションは,"NSolveOptions"群からシステムオプションをローカルに設定するために使うこともできる:
"NSolveOptions" /. SystemOptions[]デフォルトで,NSolveは劣決定複合系をスライスする超平面を導入する:
NSolve[x ^ 2 + y ^ 2 == 1, {x, y}]Method->{"UseSlicingHyperplanes"->False}とすると,NSolveはパラメトリック解を返す:
NSolve[x ^ 2 + y ^ 2 == 1, {x, y}, Method -> {"UseSlicingHyperplanes" -> False}]VerifySolutions (1)
NSolveは,非等価変換を使って得られた解を検証する:
funs = {Sqrt[x + Sqrt[x]] - 2, y ^ 9 - y - 2 x ^ (1 / 7) - 3};
eqns = And@@Thread[funs == 0];
sol1 = NSolve[eqns, {x, y}];VerifySolutions->Falseでは,NSolveは解の検証は行わない:
sol2 = NSolve[eqns, {x, y}, VerifySolutions -> False];VerifySolutions->Falseで返される解の中には,正しくないものもある:
Length /@ {sol1, sol2}sol3 = Select[sol2, Chop[funs /. #, 10 ^ -8] == {0, 0}&];sol3 === sol1WorkingPrecision (1)
デフォルトで,NSolveは機械精度計算を用いて厳密な方程式の解を求める:
NSolve[x ^ 5 + 2 x + 7 == 0, x]NSolve[x ^ 5 + 2 x + 7 == 0, x, WorkingPrecision -> 50]アプリケーション (17)
幾何学 (11)
pts = NSolve[x ^ 2 + y ^ 2 == 1 && y - 2x ^ 2 + 3 / 2 == 0, {x, y}]Show[{ContourPlot[{x ^ 2 + y ^ 2 == 1, y - 2x ^ 2 + 3 / 2 == 0}, {x, -1.5, 1.5}, {y, -1.5, 1.5}], Graphics[{Red, PointSize[Medium], Point[{x, y} /. pts]}]}]InfiniteLine[{0,0},{1,1}]とInfiniteLine[{{0,1},{1,0}}]の交点を求める:
line1 = InfiniteLine[{0, 0}, {1, 1}];
line2 = InfiniteLine[{{0, 1}, {1, 0}}];sol = NSolve[{x, y}∈line1∧{x, y}∈line2, {x, y}]Graphics[{{Lighter[Blue, 0.5], line1, line2}, {Red, Point[{x, y} /. sol]}}, Axes -> True, ImageSize -> Small]InfiniteLine[{0,0},{1,1}]とCircle[{0,0},1]の交点を求める:
line = InfiniteLine[{0, 0}, {1, 1}];
circle = Circle[{0, 0}, 1];sol = NSolve[{x, y}∈line∧{x, y}∈circle, {x, y}]Graphics[{{Lighter[Blue, 0.5], line, circle}, {Red, Point[{x, y} /. sol]}}, ImageSize -> Small]lines = InfiniteLine /@ RandomReal[1, {5, 2, 2}];BooleanCountingFunctionを使って,厳密に2つの条件が真であることを表明する:
sol = NSolve[{x, y}∈BooleanRegion[BooleanCountingFunction[{2}, 5], lines], {x, y}]Graphics[{{Lighter[Blue, 0.5], lines}, {Red, PointSize[Medium], Point[{x, y} /. sol]}}]円Circle[{1/3 Cos[k 2π/5],1/3 Sin[k 2π/5]}]で,ペアの円ごとの交点を k=0,…,4について求める:
circles = Table[Circle[{1 / 3 Cos[k 2π / 5], 1 / 3 Sin[k 2π / 5]}], {k, 0, 4}];sol = NSolve[{x, y}∈BooleanRegion[BooleanCountingFunction[{2}, 5], circles], {x, y}]Graphics[{{Lighter[Blue, 0.5], circles}, {Red, PointSize[Medium], Point[{x, y} /. sol]}}]InfiniteLine[{{-1,1,1},{1,1,1}}]とInfinitePlane[{{2,0,0},{0,2,0},{0,0,2}}]の交点を求める:
line = InfiniteLine[{{-1, 1, 1}, {1, 1, 1}}];
plane = InfinitePlane[{{2, 0, 0}, {0, 2, 0}, {0, 0, 2}}];sol = NSolve[{{x, y, z}∈line, {x, y, z}∈plane}, {x, y, z}]Graphics3D[{{Opacity[0.5], line, plane}, {Red, PointSize[Large], Point[{x, y, z} /. sol]}}, Axes -> True, PlotRange -> {{-2, 2}, {-2, 2}, {-2, 2}}]InfiniteLine[{{-1,1,1},{1,1,1}}]とSphere[{0,0,0},3]の交点を求める:
line = InfiniteLine[{{-1, 1, 1}, {1, 1, 1}}];
sphere = Sphere[{0, 0, 0}, 3];sol = NSolve[{{x, y, z}∈line, {x, y, z}∈sphere}, {x, y, z}]Graphics3D[{{Opacity[0.5], line, sphere}, {Red, PointSize[Large], Point[{x, y, z} /. sol]}}, PlotRangePadding -> 0.5]InfiniteLine[{{-1,1/3,1/2},{1,1/3,1/2}}]とTetrahedron[{{0,0,0},{1,0,0},{0,1,0},{0,0,1}}]の境界の交点を求める:
line = InfiniteLine[{{-1, 1 / 3, 1 / 2}, {1, 1 / 3, 1 / 2}}];
tet = RegionBoundary@Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}];sol = NSolve[{x, y, z}∈RegionIntersection[line, tet], {x, y, z}]Graphics3D[{{Opacity[0.5], line, Tetrahedron[{{0, 0, 0}, {1, 0, 0}, {0, 1, 0}, {0, 0, 1}}]}, {Red, PointSize[Medium], Point[{x, y, z} /. sol]}}, PlotRangePadding -> 0.2]planes = InfinitePlane /@ RandomReal[1, {3, 3, 3}];sol = NSolve[{x, y, z}∈RegionIntersection@@planes, {x, y, z}]Graphics3D[{{Opacity[0.5], planes}, {Red, PointSize[Medium], Point[{x, y, z} /. sol]}}, PlotRangePadding -> 0.1]球Sphere[{1/3 Cos[k 2π/3],1/3 Sin[k 2π/3],0}]の交点を k=0,1,2について求める:
spheres = Table[Sphere[{1 / 3 Cos[k 2π / 3], 1 / 3 Sin[k 2π / 3], 0}], {k, 0, 2}];sol = NSolve[{x, y, z}∈RegionIntersection@@spheres, {x, y, z}]Graphics3D[{{Opacity[0.5], spheres}, {Red, PointSize[Large], Point[{x, y, z} /. sol]}}]ランダムな10の平面のうち,厳密に3平面のすべての交点を求める:
planes = InfinitePlane /@ RandomReal[{-1, 1}, {10, 3, 3}];BooleanCountingFunctionを使って厳密に3つのことが真となる条件を求める:
sol = NSolve[{x, y, z}∈BooleanRegion[BooleanCountingFunction[{3}, 10], planes], {x, y, z}];//QuietGraphics3D[{{Opacity[0.3], planes}, {Red, PointSize[Medium], Point[{x, y, z} /. sol]}}, PlotRange -> {{-1, 1}, {-1, 1}, {-1, 1}}]化学 (1)
reactionpolys = {50 + Subscript[x, 1] - Subscript[x, 4] - (4 Subscript[x, 2] Subscript[x, 4]/125) - (Subscript[x, 2] Subscript[x, 5]/50) - (99 Subscript[x, 6]/100) + Subscript[x, 7], -(9/200) Subscript[x, 3] Subscript[x, 5] + 15 (50 - Subscript[x, 4] - Subscript[x, 6]) + Subscript[x, 8], -(4/125) Subscript[x, 2] Subscript[x, 4] - (1/50) Subscript[x, 4] (350 - Subscript[x, 2] - Subscript[x, 3] + Subscript[x, 4] + Subscript[x, 5]) + 16 (50 - Subscript[x, 4] - Subscript[x, 6]) + (101 Subscript[x, 6]/100), Subscript[x, 1] - (Subscript[x, 2] Subscript[x, 5]/50) - (9 Subscript[x, 3] Subscript[x, 5]/200) - (11 Subscript[x, 5] (350 - Subscript[x, 2] - Subscript[x, 3] + Subscript[x, 4] + Subscript[x, 5])/10000) + Subscript[x, 7] + (43/500) (100 - Subscript[x, 1] - Subscript[x, 5] - Subscript[x, 7] - Subscript[x, 8]) + Subscript[x, 8], (1/50) Subscript[x, 4] (350 - Subscript[x, 2] - Subscript[x, 3] + Subscript[x, 4] + Subscript[x, 5]) - (101 Subscript[x, 6]/100), (9 Subscript[x, 3] Subscript[x, 5]/200) - (273 Subscript[x, 8]/250), (Subscript[x, 2] Subscript[x, 5]/100) - Subscript[x, 7] + (23 Subscript[x, 8]/250), -(3 Subscript[x, 1]/2) + (Subscript[x, 2] Subscript[x, 5]/100)};
vars = Variables[reactionpolys];変数は化学種の量を表すため,すべての成分が負ではない実数値の解に興味がある:
nonnegSolutions[polys_, vars_, meth_ : Automatic] := Module[
{solns, realsolns},
solns = vars /. NSolve[polys, vars, Method -> meth];
realsolns = Select[solns, FreeQ[#, Complex]&];
Select[realsolns, Apply[And, Map[# >= 0&, #]]&]
]nonnegsolns = nonnegSolutions[reactionpolys, vars]見かけの多重度はAutomaticメソッドの成果物であり,高速になる傾向があるが,多重度が誇張される場合がある:
nonnegSolnsE = nonnegSolutions[reactionpolys, vars, "EndomorphismMatrix"]力学 (3)
Gough-Stewart平行の自由度6のプラットフォームの順運動学:
eqns = {t1^2 + t2^2 + t3^2 - 12t1 - 68, t4^2 + t5^2 + t6^2 - 12t5 - 68, t7^2 + t8^2 + t9^2 - 24 t8 - 12t9 + 100, t1 t4 + t2 t5 + t3 t6 - 6 t1 - 6t5 - 52, t1 t7 + t2 t8 + t3 t9 - 6 t1 - 12t8 - 6t9 + 64, t4 t7 + t5 t8 + t6 t9 - 6t5 - 12t8 - 6t9 + 32, 2t2 + 2t3 - t4 - t5 - 2 t6 - t7 - t9 + 18, t1 + t2 + 2t3 + 2t4 + 2t6 - 2t7 + t8 - t9 - 38, t1 + t3 - 2t4 + t5 - t6 + 2t7 - 2t8 + 8};
vars = {t1, t2, t3, t4, t5, t6, t7, t8, t9};
Length[solns = NSolve[eqns, vars]]この解集合は複数の解があるとするが,複数のコピーを削除する:
Union[solns, SameTest -> (Norm[(vars /. #1) - (vars /. #2)] < 10 ^ -6&)]//LengthLength[NSolve[eqns, vars, Method -> "Monodromy"]]カメラの姿勢推定手順から生じる4変数の6つの方程式の過剰決定系を設定する:
coords = {{1, 2, 1.49071, 4}, {1, 3, .400000, 8}, {1, 4, .894427, 4}, {2, 3, 1.49071, 4}, {2, 4, .666667, 8}, {3, 4, .894427, 4}};
vars = Array[x, 4];
polys = MapThread[x[#1] ^ 2 + x[#2] ^ 2 - #3 * x[#1] * x[#2] - #4&, Transpose[coords]]realsols = NSolve[polys[[1 ;; 4]], vars, Reals]各解について,解の接続による最初の4つの残差は小さいが,最後の2つは無視できない:
residuals = polys /. realsols次に,残差の二乗和を最小化するための開始点として使用して各解を完成させる:
newsols = Map[FindMinimum[polys.polys, Transpose[{vars, (vars /. #)}]]&, realsols]平面内の2本の無質量ケーブルによって吊り下げられた重りの静的平衡を表す連立方程式:
polys = {-1 + (3 ct1/4) + (7 ct2/5) - (9 ct3/10), (1/8) + (3 st1/4) + (7 st2/5) - (9 st3/10), (3 ct1/4) + (3 ct2/5) + (st2/5) - x, -(ct2/5) + (3 st1/4) + (3 st2/5) - y, ct1 f1 + ct3 f3, -1 + f1 st1 + f3 st3, ct1 t1 - x, st1 t1 - y0, 1 + ct3 t3 - x, -(1/8) + st3 t3 - y0, -1 + ct1^2 + st1^2, -1 + ct2^2 + st2^2, -1 + ct3^2 + st3^2};
vars = Variables[polys];
Length[solns = NSolve[polys == 0, vars]]各実数値の解は他とは異なる平衡位置に対応する.このような解は6つある:
realsols = Union[Cases[vars /. solns, {_Real..}], SameTest -> (Norm[#1 - #2] <= 10 ^ -9&)]経済 (1)
経済学に生じる縮小された8次元系.精度を高めるためにデフォルト以外の方法を使用する:
eqns = {x1 + x1 * x2 + x2 * x3 + x3 * x4 + x4 * x5 + x5 * x6 + x6 * x7 - 1 * u8,
x2 + x1 * x3 + x2 * x4 + x3 * x5 + x4 * x6 + x5 * x7 - 2 * u8,
x3 + x1 * x4 + x2 * x5 + x3 * x6 + x4 * x7 - 3 * u8,
x4 + x1 * x5 + x2 * x6 + x3 * x7 - 4 * u8,
x5 + x1 * x6 + x2 * x7 - 5 * u8,
x6 + x1 * x7 - 6 * u8,
x7 - 7 * u8,
x1 + x2 + x3 + x4 + x5 + x6 + x7 + 1};
vars = {x1, x2, x3, x4, x5, x6, x7, u8};
Length[solns = NSolve[eqns, vars, Method -> "Monodromy"]]Cases[vars /. solns, {_Real..}]差分方程式 (1)
des = {a[n + 1] == b[n] ^ 2 * a[n] - 3 * c[n] - 1, b[n + 1] == a[n] * c[n] ^ 2 - 2 * b[n - 1] + 1, c[n + 1] == a[n - 1] - b[n - 2]};RSolveは解の解析的な形を求められない:
RSolve[des, {a, b, c}, n]rep = {a[_] :> a, b[_] :> b, c[_] :> c};
asymp = des /. repこれを解き,漸近的で可能な(初期条件に依存する)実漸近値を与える :
desolns = NSolve[asymp, {a, b, c}];
Select[desolns, MatchQ[{a, b, c} /. #, {_Real..}]&]特性と関係 (8)
polys = {x ^ 2 + y ^ 2 - 1, 2x + 3y - 4};
NSolve[Thread[polys == 0], {x, y}]polys /. %NSolveは{}で空の解すなわち解の不在を表す:
NSolve[x == 1 && x == 2, x]NSolveは{{}}でユニバーサル解,つまりすべての点が方程式を満足することを表す:
NSolve[x == x, x]一変数の整方程式について,NSolveはその多重度によって解を繰り返す:
NSolve[(x - 1) ^ 2(x - 2) ^ 3 == 0, x]NSolve[(x ^ 4 - 1)(x ^ 4 - 4) == 0, x]NSolve[(x ^ 4 - 1)(x ^ 4 - 4) == 0, x, Reals]NSolveは置換規則によって解を表す:
NSolve[{x ^ 2 + y ^ 2 == 1, x ^ 3 - y ^ 3 == 2}, {x, y}]NSolveValuesは解の値を与える:
NSolveValues[{x ^ 2 + y ^ 2 == 1, x ^ 3 - y ^ 3 == 2}, {x, y}]NSolveは大域的方程式ソルバである:
NSolve[{x ^ 2 + y ^ 3 == 1, x ^ 4 + y ^ 4 == 2}, {x, y}]FindRootは局所的方程式ソルバである:
FindRoot[{x ^ 2 + y ^ 3 == 1, x ^ 4 + y ^ 4 == 2}, {{x, 1}, {y, -1}}]NSolveは近似結果を与える:
NSolve[{x ^ 2 + y ^ 2 == 1, x + y ^ 2 == 2}, {x, y}]Solveを使って厳密解を得る:
Solve[{x ^ 2 + y ^ 2 == 1, x + y ^ 2 == 2}, {x, y}]FindInstanceを使って厳密解の例を得る:
FindInstance[{x ^ 2 + y ^ 2 == 1, x + y ^ 2 == 2}, {x, y}]NDSolveを使って微分方程式を数値的に解く:
NDSolve[{y''[x] == -y[x], y[0] == 0, y'[0] == 1}, y[x], {x, 0, 7}]Plot[y[x] /. %[[1]], {x, 0, 7}]考えられる問題 (7)
poly = Expand[Product[x - i, {i, 30}]];NSolve[poly == 0, x]WorkingPrecisionを高くすると,より正確な結果が生成される:
NSolve[poly == 0, x, WorkingPrecision -> 20]eqns = {x ^ 2 + y ^ 2 == 1, x ^ 3 - 2x y == 2};
sols = NSolve[eqns, {x, y}]eqns /. solsNorm /@ ({x ^ 2 + y ^ 2 - 1, x ^ 3 - 2x y - 2} /. sols)WorkingPrecisionを高くすると,許容度の低い解が得られる:
sols = NSolve[eqns, {x, y}, WorkingPrecision -> 25]({x ^ 2 + y ^ 2 - 1, x ^ 3 - 2x y - 2} /. sols)多項式系解集合が無限の場合,NSolveは解集合とランダムな超平面との交点を与える:
NSolve[x ^ 2 + y ^ 2 == 1, {x, y}]NSolve[x ^ 2 + y ^ 2 + z ^ 2 == 1, {x, y, z}]ContourPlotとContourPlot3Dを使って解の実部を見る:
ContourPlot[x ^ 2 + y ^ 2 == 1, {x, -1, 1}, {y, -1, 1}]ContourPlot3D[x ^ 2 + y ^ 2 + z ^ 2 == 1, {x, -1, 1}, {y, -1, 1}, {z, -1, 1}]NSolveは,デフォルトで,実際の数よりも多くの解を主張することができる:
polys = {9 * y2 ^ 2 - 5.656854249492381 * y2 + z2, x3 ^ 2 + y3 ^ 2 + z3 ^ 2 - 1, x4 ^ 2 + y4 ^ 2 + z4 ^ 2 - 1, y5 ^ 2 + z5 ^ 2 - 0.888888888888889, x3 - 2.828427124746190 * y2 * x3 + y2 * y3 + z2 * z3 - 1 / 3, x3 * x4 + y3 * y4 + z3 * z4 - 1 / 3, 1 / 3 * x4 + y4 * y5 + z4 * z5 - 1 / 3, 8 / 3 - 2.828427124746190 * y2 + x3 + x4, y2 + y3 + y4 + y5 + 0.8888888888888889, z2 + z3 + z4 + z5};
vars = {x3, x4, y2, y3, y4, y5, z2, z3, z4, z5};
Length[solns = NSolve[polys, vars]]Length[Union[vars /. solns, SameTest -> (Norm[#1 - #2] < 10 ^ -9&)]]Length[NSolve[polys, vars, Method -> "Monodromy"]]Length[NSolve[polys, vars, Method -> "EndomorphismMatrix"]]polys = {-1 + a + b + c + d, -2772 a^2 - 4620 a b - 1980 b^2 - 3960 a c - 3465 b c - 1540 c^2 - 3465 a d - 3080 b d - 2772 c d - 1260 d^2 + 13860 r, 926640 a^3 + 2432430 a^2 b + 2116400 a b^2 + 617760 b^3 + 2230800 a^2 c + 3848130 a b c + 1684800 b^2 c + 1731600 a c^2 + 1526525 b c^2 + 462000 c^3 + 2108106 a^2 d + 3603600 a b d + 1573000 b^2 d + 3211065 a c d + 2836680 b c d + 1287000 c^2 d + 1474200 a d^2 + 1310400 b d^2 + 1192464 c d^2 + 368550 d^3 + 16216200 a r + 14414400 b r + 13513500 c r + 12972960 d r, 213840 a^2 + 374220 a b + 162800 b^2 + 343200 a c + 296010 b c + 133200 c^2 + 324324 a d + 277200 b d + 247005 c d + 113400 d^2 + 332640 a lambda + 277200 b lambda + 237600 c lambda + 207900 d lambda + 831600 mu + 1247400 r, 486486 a^2 + 846560 a b + 370656 b^2 + 769626 a c + 673920 b c + 305305 c^2 + 720720 a d + 629200 b d + 567336 c d + 262080 d^2 + 720720 a lambda + 617760 b lambda + 540540 c lambda + 480480 d lambda + 2162160 mu + 2882880 r, 2230800 a^2 + 3848130 a b + 1684800 b^2 + 3463200 a c + 3053050 b c + 1386000 c^2 + 3211065 a d + 2836680 b d + 2574000 c d + 1192464 d^2 + 3088800 a lambda + 2702700 b lambda + 2402400 c lambda + 2162160 d lambda + 10810800 mu + 13513500 r, 2108106 a^2 + 3603600 a b + 1573000 b^2 + 3211065 a c + 2836680 b c + 1287000 c^2 + 2948400 a d + 2620800 b d + 2384928 c d + 1105650 d^2 + 2702700 a lambda + 2402400 b lambda + 2162160 c lambda + 1965600 d lambda + 10810800 mu + 12972960 r};
vars = {r, a, b, c, d, lambda, mu};
Length[solmach = NSolve[polys, {r, a, b, c, d, lambda, mu}, Method -> "EndomorphismMatrix"]]Length[solbig = NSolve[polys, {r, a, b, c, d, lambda, mu}, Method -> "EndomorphismMatrix", WorkingPrecision -> 100]]Map[Max, Abs[polys /. solmach[[1 ;; 4]]]]Map[Max, Abs[polys /. solbig[[1 ;; 4]]]]残差の差にもかかわらず,2つの解はMachinePrecision精度におけるすべての桁が一致する:
(vars /. solmach[[1 ;; 4]]) - (vars /. solbig[[1 ;; 4]])領域としてRealsを指定すると,NSolveは解の近傍で関数が実数値ではない解は求めないかもしれない:
f = (x ^ 2 - 7 x + 11) ^ (x ^ 2 - 13 x + 42) - 1;NSolve[f == 0, x, Reals]Plot[{Abs[f], Im[f]}, {x, 1.5, 7.5}, PlotLegends -> "Expressions"]NSolve[f == 0 && Element[x, Reals], x]NSolveはすべての解を与えないことがある:
NSolve[Cos[x] == x, x]NSolve[Cos[x] == x, x, MaxRoots -> 100]//Lengthおもしろい例題 (1)
roots = NSolve[Sin[z + Sin[z + Sin[z]]] == Cos[z + Cos[z + Cos[z]]] && -3 < Re[z] < 3 && -3 < Im[z] < 3, z, MaxRoots -> Infinity];ListPlot[{Re[z], Im[z]} /. roots, PlotLabel -> TraditionalForm[Sin[z + Sin[z + Sin[z]]] == Cos[z + Cos[z + Cos[z]]]]]テクニカルノート
履歴
1991 で導入 (2.0) | 2014 で更新 (10.0) ▪ 2024 (14.0)
テキスト
Wolfram Research (1991), NSolve, Wolfram言語関数, https://reference.wolfram.com/language/ref/NSolve.html (2024年に更新).
CMS
Wolfram Language. 1991. "NSolve." Wolfram Language & System Documentation Center. Wolfram Research. Last Modified 2024. https://reference.wolfram.com/language/ref/NSolve.html.
APA
Wolfram Language. (1991). NSolve. Wolfram Language & System Documentation Center. Retrieved from https://reference.wolfram.com/language/ref/NSolve.html
BibTeX
@misc{reference.wolfram_2026_nsolve, author="Wolfram Research", title="{NSolve}", year="2024", howpublished="\url{https://reference.wolfram.com/language/ref/NSolve.html}", note=[Accessed: 31-October-2026]}
BibLaTeX
@online{reference.wolfram_2026_nsolve, organization={Wolfram Research}, title={NSolve}, year={2024}, url={https://reference.wolfram.com/language/ref/NSolve.html}, note=[Accessed: 31-October-2026]}