Roots of a function: Difference between revisions

->Mathematica
No edit summary
(->Mathematica)
Line 166:
 
By itself (i.e. unless specifically asked to do so), Maple will only perform exact (symbolic) operations and not attempt to do any kind of numerical approximation.
 
=={{header|Mathematica}}==
 
There are multiple obvious ways to do this in Mathematica.
 
===Solve===
This requires a full equation and will perform symbolic operations only:
In[1]:= Solve[x^3-3*x^2+2*x==0,x]
Out[1]= {{x->0},{x->1},{x->2}}
 
===NSolve===
This requires merely the polynomial and will perform numerical operations if needed:
In[2]:= NSolve[x^3 - 3*x^2 + 2*x , x]
Out[2]= {{x->0.},{x->1.},{x->2.}}
(note that the results here are floats)
 
===FindRoot===
This will numerically try to find one(!) local root from a given starting point:
In[3]:= FindRoot[x^3 - 3*x^2 + 2*x , {x, 1.5}]
Out[3]= {x->0.}
In[4]:= FindRoot[x^3 - 3*x^2 + 2*x , {x, 1.1}]
Out[4]= {x->1.}
(note that there is no guarantee which one is found).
 
===FindInstance===
This finds a value (optionally out of a given domain) for the given variable (or a set of values for a set of given variables) that satisfy a given equality or inequality:
In[5]:= FindInstance[x^3 - 3*x^2 + 2*x == 0, x]
Out[5]= {{x->0}}
 
===Reduce===
This will (symbolically) reduce a given expression to the simplest possible form, solving equations and performing substitutions in the process:
In[6]:= Reduce[x^3 - 3*x^2 + 2*x == 0, x]
Out[6]= x==0||x==1||x==2
(note that this doesn't yield a "solution" but a different expression that expresses the same thing as the original)
 
=={{header|Perl}}==
Anonymous user