Khả dụng
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.
Có thể kiểm tra độc lập: câu trả lời của hàm này được suy ra lại theo một hướng khác rồi so sánh - bàn làm việc và công cụ verify làm việc này tự động, nên câu trả lời sai bị phát hiện thay vì được tin dùng. Lịch sử →