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 客户端使用