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.

Este artigo foi útil?
Sim
Não

Algum comentário?

Obrigado pelo seu feedback.

Enviar

Entre em contato com o Suporte

Caso tenha alguma dúvida sobre cobrança, ativação ou suporte técnico, estamos a sua total disposição.

1-800-WOLFRAM (+1-217-398-0700 para chamadas internacionais)

Suporte ao consumidor

Segunda–Sexta
8:00–17:00 Horário Central dos EUA

  • Registro ou ativação do produto
  • Informações de pré-venda e pedidos
  • Ajuda com instalação e início

Suporte técnico avançado (para clientes habilitados)

Segunda–Quinta
8:00–19:00 Horário Central dos EUA

FSexta
8:30–10:00 & 11:00–17:00 Horário Central dos EUA

  • Suporte técnico prioritário
  • Assistência com especialistas da Wolfram
  • Ajuda com a programação da Wolfram Language
  • Suporte avançado de instalação