Wolfram Computation Meets Knowledge

When do I use FindRoot instead of NSolve?

Like Solve, NSolve is designed primarily for solving polynomial equations.

In[1]:= NSolve[4 - r^2 == r, r]
Out[1]= {{r -> -2.56155}, {r -> 1.56155}}

The algebraic methods available in NSolve cannot handle general equations with transcendental functions—for example:

In[2]:= NSolve[4 Cos[r] == r, r]
  NSolve::nsmet: This system cannot be solved with the methods available to NSolve.
Out[2]= NSolve[4 Cos[r] == r, r] 

FindRoot uses numerical methods for starting at an initial value for the independent variable and locating a solution:

In[3]:= fr = FindRoot[ 4 Cos[r] == r, {r, 1}]
Out[3]= {r -> 1.25235}  

Verify that the returned value solves the equation:

In[4]:= (4 Cos[r] - r) /. fr // Chop
Out[4]= 0

FindRoot finds one solution per evaluation. To obtain further solutions with FindRoot, initial values need to be chosen sufficiently close to the other root locations:

In[5]:= Plot[ 4 Cos[r] - r, {r, -2 Pi, 2 Pi}]

4Cos[r] - r , 3 roots

In[6]:= FindRoot[ 4 Cos[r] == r, {r, -4}]
Out[6]= {r -> -3.5953}

In[7]:= FindRoot[ 4 Cos[r] == r, {r, -2}]
Out[7]= {r -> -2.13333}

See also the tutorial on numerical equation solving.

该文档是否有帮助?

任何建议?

非常感谢您的反馈!

提交

联系支持团队

从账单到产品激活,以及任何技术相关内容,无论您遇到任何问题,我们都在此为您提供帮助。

1-800-WOLFRAM (+1-217-398-0700 美国境外用户)

客服支持

周一至周五
8am–5pm 美国中部时区

  • 产品注册或激活
  • 预售信息和订单
  • 安装帮助和首次启动

高级技术支持 (面向特定用户)

周一至周四
8am–7pm 美国中部时区

周五
8:30–10am & 11am–5pm 美国中部时区

  • 优先技术支持
  • Wolfram 专家助理专员
  • Wolfram 语言编程帮助
  • 高级安装支持