Solve
Usage Message: Solve[eqns, vars] attempts to solve an equation or set of equations for the variables vars.
Solve[eqns, vars, elims] attempts to solve the equations for vars, eliminating the variables elims.
Attributes[Solve] = {Protected} Options: InverseFunctions
-> Automatic MakeRules
-> False Method
-> 3 Mode
-> Generic Sort
-> True VerifySolutions
-> Automatic WorkingPrecision
-> Infinity Related Symbols: Eliminate
FindRoot
GroebnerBasis
LinearSolve
NSolve
NRoots
Reduce
Root
Roots
Notes: The result from Solve is returned as a list of solutions, where each solution is a list of rules. This structure is used to accommodate equations that have more than one solution, and solutions that are described by more than one rule. For example:
In[1]:= Solve[{2 x + y - 2 == 0, x^2 + y == 10}, {x, y}]
Out[1]= {{y -> -6, x -> 4}, {y -> 6, x -> -2}}
For consistency this same structure is used even if there only one solution, and that solution consists of a single rule:
In[2]:= Solve[2 x + 3 == 9, x]
Out[2]= {{x -> 3}}
The rules that are returned by Solve can be used just like rules from any other calculation. For example, here is a method for assigning the value of x from the third solution of x^3+x^2-17x+15==0 as the value of x2:
In[3]:= sol = Solve[x^3+x^2-17x+15==0, x]
Out[3]= {{x -> -5}, {x -> 1}, {x -> 3}}
In[4]:= x2 = x /. sol[[3]]
Out[4]= 1
In[5]:= x2
Out[5]= 3
For other examples of using the results from Solve, see
http://support.wolfram.com/mathematica/kernel/features/usingrulesolutions.html.
The
Solve
function is designed primarily for solving polynomial equations (equations in which all of the exponents are positive integers). A useful suggestion in case of difficulty is to look for ways to rearrange your equations so that they are polynomial equations. For example, instead of solving the equations
In[6]:= Solve[{2/x +2/y -3 == 0, 3/(x + y) - 1 == 0}, {x, y}]
Out[6]= {{x -> 1, y -> 2}, {x -> 2, y -> 1}}
it is slightly easier for Solve to handle the following equivalent equations, which are obtained from the previous equations by combining terms over a common denominators:
In[7]:= Solve[{Numerator[Together[2/x +2/y -3]] == 0,
Numerator[Together[3/(x + y) - 1]] == 0}, {x, y}]
Out[7]= {{x -> 1, y -> 2}, {x -> 2, y -> 1}}
Equations that are not polynomial equations are typically solved by converting them into polynomial equations, or by identifying variables in which the equations are polynomial equations, and constructing a result after solving for those variables. For example, the following equation is solved by first solving for Sin[x], and then using inverse functions to get values for x:
In[8]:= Solve[Cos[x]^2 - 4 Cos[x] + 3 == 0, x]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
Out[8]= {{x -> 0}, {x -> -ArcCos[3]}, {x -> ArcCos[3]}}
Known Bugs: Inexact Numbers (Version 3.0.0 only) There is an error in the Solve function in the initial release of
Version 3.0 (Version 3.0.0, $ReleaseNumber
0) that will cause it to return incorrect results for certain equations that contain both inexact numbers and symbolic constants. This error has
been corrected for Version 3.0.1 ( $ReleaseNumber
1). One workaround for this error is to replace the inexact numbers with exact numbers. You can either do this manually, or using a
function such as Rationalize
. Here is a typical example, first showing the correct result, and then showing an incorrect result. The only difference between the two inputs is that the exact numerical coefficient 2 in the first input has been replaced by the inexact number 2.0 in the second input.
In[1]:= Solve[x^2 + x - 2 (p + q) == 0, x]
-1 - Sqrt[1 + 8 p + 8 q] -1 + Sqrt[1 + 8 p + 8 q]
Out[1]= {{x -> ------------------------}, {x -> ------------------------}}
2 2
In[2]:= Solve[x^2 + x - 2.0 (p + q) == 0, x]
Out[2]= {{x -> -2.}, {x -> 1.}}
Quartic Equations There is an error in the Roots
function in Mathematica Version 3.0 for a special class of quartic polynomials. Since Solve uses Roots
, this error can affect the results from Solve for the same class of quartic polynomials. For more information, see the notes for Roots
. Parasitic Solutions When solving non-polynomial equations, the Solve function will often modify the equations in ways that introduce solutions that were not solutions of the original equations. There are a few examples of equations in which these extra solutions, called parasitic solutions, are not properly rejected. Here are two examples of this behavior in Version 3.0 of Mathematica. Both examples return correct solutions as well as parasitic solutions.
In[1]:= Solve[{x + y == 1, b^(x + y) (1 + y^2 + x y - 2 y) == 0}, {x, y}]
InverseFunction::ifun:
Warning: Inverse functions are being used. Values may be lost for
multivalued inverses.
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
Out[1]= {{x -> 0, y -> 1}, {x -> 1, y -> 0},
1 1
> {x -> 1 - ----------------, y -> ----------------}}
Infinity Infinity
2 + ------------ 2 + ------------
Sign[Log[b]] Sign[Log[b]]
In[2]:= Solve[Cos[t/2 + b/2] + Sin[t/2 + b/2] == 0, t]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
3 Pi Pi Pi 3 Pi
Out[2]= {{t -> -b - ----}, {t -> -b - --}, {t -> -b + --}, {t -> -b + ----}}
2 2 2 2
It is usually possible in these examples to get a correct result by rearranging the equations, or by setting the VerifySolutions
option to True
. In the first example above, the factor b^(x + y) can be dropped, since this factor will never be zero, after which the solution is correct.
In[3]:= Solve[{x + y == 1, (1 + y^2 + x y - 2 y) == 0}, {x, y}]
Out[3]= {{x -> 0, y -> 1}}
In the second example, a correct result can be obtained by making a small change to the form of the input.
In[4]:= Solve[Cos[(t + b)/2] + Sin[(t + b)/2] == 0, t]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
Pi 3 Pi
Out[4]= {{t -> -b - --}, {t -> -b + ----}}
2 2
In some examples the parasitic solutions will be dropped if you set the VerifySolutions
option to True
:
In[5]:= Solve[Sin[t] (Cos[(t + b)/2] + Sin[(t + b)/2]) == 0, t]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
3 Pi Pi Pi
Out[5]= {{t -> 0}, {t -> -b - ----}, {t -> -b - --}, {t -> -b + --},
2 2 2
3 Pi
> {t -> -b + ----}}
2
In[6]:= Solve[Sin[t] (Cos[(t + b)/2] + Sin[(t + b)/2]) == 0, t,
VerifySolutions -> True]
Solve::ifun: Inverse functions are being used by Solve, so some solutions may
not be found.
Pi 3 Pi
Out[6]= {{t -> 0}, {t -> -b - --}, {t -> -b + ----}}
2 2
Setting the VerifySolutions
option to True
will not, however, cause parasitic solutions to be rejected in all examples.
Additional Online Documentation:
Mathematica 3.0
http://documents.wolfram.com/v3/RefGuide/Solve.html
Mathematica 4.0
http://documents.wolfram.com/v4/RefGuide/Solve.html
Questions or comments? Send email to support@wolfram.com.
| |