此为 Mathematica 7 文档,内容基于更早版本的 Wolfram 语言
查看最新文档(版本11.2)
Mathematica HowTo
How to | Solve an Equation
Mathematica has many powerful features which enable you to solve many kinds of equations.
You can solve an equation using Solve. Remember to use "Equal" in an equation, not just "=":
In[1]:=
Click for copyable input
Out[1]=
The result is a Rule inside a doubly nested list. The outer list holds all of the solutions and each inner list holds a single solution. Here there are three solutions:
In[2]:=
Click for copyable input
Out[2]=
To solve a system of equations, use a list in the first argument:
In[3]:=
Click for copyable input
Out[3]=
Here there are two solutions to a simultaneous system of equations; each solution set is wrapped in its own list:
In[4]:=
Click for copyable input
Out[4]=
Here the solution expresses one variable in terms of another:
In[5]:=
Click for copyable input
Out[5]=
To use one of these solutions (here the first one is shown), use [[...]] (the short form of Part) to extract it from the list of solutions and use /. (the short form of ReplaceAll) to apply the rule:
In[6]:=
Click for copyable input
Out[6]=
For example, here is a plot of x^2-y^2 for different values of y, assuming that the first solution holds:
In[7]:=
Click for copyable input
Out[7]=
In a system of equations with multiple variables, you can solve for some or all of the variables by using a list in the second argument:
In[8]:=
Click for copyable input
Out[8]=
If the system is underspecified, Mathematica will give an answer in terms of the remaining variables:
In[9]:=
Click for copyable input
Out[9]=
Solve finds what are known as "generic" solutions to equations. These are solutions that do not depend on the variables not specified in the second argument. For example:
In[10]:=
Click for copyable input
Out[10]=
No matter what y is, putting in 0 for x solves the equation. But there is another solution that does depend on y: namely, setting y to 0. Adding y in the second argument makes this solution show up:
In[11]:=
Click for copyable input
Out[11]=
There are other cases in which Solve does not find every solution. For example:
In[12]:=
Click for copyable input
Out[12]=
You can also solve equations by using Reduce:
In[13]:=
Click for copyable input
Out[13]=
The output of Reduce is different from the output of Solve: Reduce outputs a logical expression that is equivalent to the original equation, so it never omits a solution:
In[14]:=
Click for copyable input
Out[14]=
In[15]:=
Click for copyable input
Out[15]=