Qurak

NSolve

可用

Numeric equation solver.

`NSolve` finds numeric roots, and its real-restricted form can stop before converging - returning a value that looks like an exact answer and is wrong several digits earlier than machine precision: ```wolfram NSolve[E^x - x == 7, x, Reals] (* {{x -> -7.}} *) Abs[(E^x - x - 7) /. x -> -7.] (* 0.000911... - not a root *) FindRoot[E^x - x == 7, {x, -7}] (* {x -> -6.999087285366495} - the root *) ``` The machinery for the right answer is present; this path just stops early. So check the residual of every root before using it, and polish with `FindRoot` from the returned value when the residual is not near zero: ```wolfram root = x /. First[NSolve[E^x - x == 7, x, Reals]]; Chop[Abs[(E^x - x - 7) /. x -> root], 10^-6] (* 0 means converged *) ``` Compare the residual against a tolerance with `Chop`, never against zero with `==`: see `Equal` for why an exact comparison on machine numbers reports `False` even for a converged root.

可獨立核查:此函式的答案會透過另一條途徑重新推導並比較——工作臺和 verify 工具會自動完成,因此錯誤答案會被發現而不是被採信。 歷史 →

NSolve[expr, vars]
NSolve[expr, vars, Reals]
NSolve[x^2 - 2 == 0, x] → {{x -> -1.4142135623730951}, {x -> 1.414213562373095}}NSolve[x^2 - 2, x] → {{x -> -1.4142135623730951}, {x -> 1.414213562373095}}Round[x /. NSolve[x^3 + 1.5 x^2 - 3.2 x + 4.7 == 0, x], 1/10^6] → {-19079/6250, 2426/3125 - (120997*I)/125000, 2426/3125 + (120997*I)/125000}NSolve[x^3 - 4. x^2 == 0, x] → {{x -> 0.}, {x -> 0.}, {x -> 4.}}NSolve[x^2 == 2] → \{\{x -> -1\.414213562373095\d?\}, \{x -> 1\.414213562373095\d?\}\} (regex)NSolve[1 == f^2 (3 - f) && 0 <= f <= 1] → {{f -> 0.6527036446661393}}

使用於

主題

相關

全部 6300 個函式 · 從 MCP 用戶端使用這個