In[25]:= | x=4 |
Out[25]= |
![]() |
In[26]:= | x==4 |
Out[26]= |
![]() |
In[27]:= | x==5 |
Out[27]= |
![]() |
In[28]:= | x |
Out[28]= |
![]() |
from which we see that the result of x==y is either "True" or
"False". Contrast this with the symbol which is used to assign a
value to a symbol.
Now we introduce the Solve function for solving equations. the syntax can be seen from the following examples:
In[29]:= | Solve[4x + 8 == 0, x] |
Out[29]= |
![]() |
In[30]:= | Solve[x^2 + 2x - 7 == 0, x] |
Out[30]= |
![]() |
In[31]:= | N[%] |
Out[31]= |
![]() |
In[32]:= | Solve[a x^2 + b x + c == 0, x] |
Out[32]= |
![]() |
where both numerical and symbolic solutions may be obtained. We
can also find more complicated problems, such as
In[33]:= | Solve[{x^2 + y^2 == 1, x + 3 y == 0}, {x, y}] |
Out[33]= |
![]() |
In[34]:= | x/.% |
Out[34]= |
![]() |
In[35]:= | y/.%% |
Out[35]= |
![]() |
in which we should note the syntax for solving systems of equations by
grouping things in braces, , and for extracting parts of the
solution. Note also how the different, distinct solutions are grouped
together.
Unfortunately there are equations which Mathematica cannot solve so simply, but which with a little help it could do so. One very useful command in this context is Eliminate, used as follows
In[36]:= | Eliminate[{a x + y == 0, 2 x + (1 - a) y == 1}, y] |
Out[36]= |
![]() |
In[37]:= | Solve[%, x] |
Out[37]= |
![]() |
Often Mathematica is unable to solve a problem in a single step but can
do so if the user guides it through the steps. This is
particularly the case when an equation may have unphysical solutions
which can be ignored. The user can recognise the physically important
solutions and concentrate on those.