Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I am new to Mathematica. I have used the WolframAlpha online calculator to find roots of equations (listed under the heading Root in the output generated in response to a submission). When I try to find the roots of the same equation in Mathematica, I receive various errors. I have tried FindRoot and Reduce. Is there a function in Mathematica that corresponds to whatever is generating the Root output in the online WolframAlpha calculator? Thank you.

share|improve this question
2  
Welcome to Mathematica.SE. Please extend your question by adding some examples of the behavior your are seeing from both Mathematica and Wolfram|Alpha. –  Mr.Wizard Feb 22 '12 at 0:29
    
Maybe Roots is what he is looking for. He might also want to use ToRules on the result Roots returns. –  Ted Ersek Feb 22 '12 at 0:41
add comment

2 Answers 2

up vote 3 down vote accepted

The canonical way to solve algebraic equations is to use Solve, e.g.

2 - 4 x - x^2 + 2 x^3 == 0 // Solve[#, x] &
{{x -> 1/2}, {x -> -Sqrt[2]}, {x -> Sqrt[2]}}

The above eqn //Solve[#,x]& is a so called postfix notation.

This is an infix notation: eqn ~ Solve ~ x

and prefix : Solve[ #, x]& @(eqn)

If you want to solve a transcendental equation e.g. x^2 == Cos[x] you can use Solve as well as Reduce, however one should specify the real domain because by default Mathematica working in the complex domain cannot find all solutions.

Reduce[x^2 == Cos[x], x, Reals]
x == Root[{-Cos[#1] + #1^2 &, -0.82413231230252242296}] ||
x == Root[{-Cos[#1] + #1^2 &, 0.82413231230252242296}]
Solve[x^2 == Cos[x], x, Reals]
{{x -> Root[{-Cos[#1] + #1^2 &, -0.82413231230252242296}]},
 {x -> Root[{-Cos[#1] + #1^2 &, 0.82413231230252242296}]}}

If you are interested in numerical values of solutions you could also choose FindRoot, it works like this :

 FindRoot[ x^2 == Cos[x], {x, Pi/6}]
{x -> 0.824132}

In general x0, here Pi/6 is the point where it starts to search a numerical solution.

NSolve also tackles equations numerically:

NSolve[x^2 == Cos[x], x, Reals]

{{x -> -0.824132}, {x -> 0.824132}}

And here I briefly sketch a few samples of using functions which you mentioned :

Roots[ 2 - 4 x - x^2 + 2 x^3 == 0, x]
x == Sqrt[2] || x == -Sqrt[2] || x == 1/2
Root[ 2 - 4 x - x^2 + 2 x^3, #] & /@ Range[3]
{-Sqrt[2], 1/2, Sqrt[2]}
Reduce[ 2 - 4 x - x^2 + 2 x^3== 0, x]
 x == 1/2 || x == -Sqrt[2] || x == Sqrt[2]
share|improve this answer
    
Thank you to both of you (Artes, David). Solve resolved my issue, whereas neither Root, Roots, FindRoots, nor Reduce worked. I will have to read more on these functions to understand their different purposes. –  user001 Feb 22 '12 at 0:39
    
Artes, could you please briefly tell me what the octothorpe and ampersand signify in your expression? After searching briefly, they seem to deal with "pure functions" and I read that # and #n refer to the first and nth variables, respectively. However, in your expression # appears to correspond more to % (output / result). The ampersand is supposed to designate that something is a pure function with variables that can be called using #. Thanks for your clarification. –  user001 Feb 22 '12 at 0:49
    
# is Slot e.g. #2&[a,b,c] yields b, it represents an argument of a pure function, an #n represents n-th argument. & represents function, e.g. (#^2 + # + 1)& is equvalent to Function[w, W^2 + w +1]. –  Artes Feb 22 '12 at 1:01
add comment

Solve may be a good start:

Solve[a x^2 + b x + c == 0, x]
{
    {x -> (-b - Sqrt[b^2 - 4 a c])/(2 a)},
    {x -> (-b + Sqrt[b^2 - 4 a c])/(2 a)}
}

Other functions that are often useful when solving equations are Reduce (find a logical expression for all variables satisfying a statement) and Refine (add constraints on variables, such as being positive)

FindRoot, one of the functions you used, solves numerically only, iterating Newton's method until sufficiently accurate.

Root is, as far as I know, not really meant to find roots, it's much more an abstract representation of the $n$th root of an equation, much like $\sin(10)$ does make sense on its own, without evaluating it to an explcit number. In some cases for example, it may be impossible to calculate the root of an equation explicitly, so Mathematica keeps it as a Root object; however, once you apply numerical functions like N to it, it can still do some useful operations with it.

share|improve this answer
    
Thank you to both of you (Artes, David). Solve resolved my issue, whereas neither Root, Roots, FindRoots, nor Reduce worked. I will have to read more on these functions to understand their different purposes. –  user001 Feb 22 '12 at 0:39
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.