next up previous index
Next: Functions Up: Algebra Previous: Fractions

Substitutions

We can always substitute  values for x and y in

\begin{displaymath}\frac{x^2 + xy + y^2}{1 + x + y}
\end{displaymath}

using ev in Maxima, eval in Maple, and ReplaceAll in Mathematica. Here is the Maxima example:
\begin{figure}
\begin{tex2html_preform}\begin{verbatim}(C23) a;
2 2
Y + X Y + ...
..., x=1, y=2);
7
(D24) -
4
(C25)\end{verbatim}\end{tex2html_preform}\end{figure}

You can also use a Maxima function at in this context, which works much like the Maple function eval discussed below:
\begin{figure}
\begin{tex2html_preform}\begin{verbatim}(C34) at(a, [x=1, y=2]);
7
(D34) -
4
(C35)\end{verbatim}\end{tex2html_preform}\end{figure}

Function at takes only one argument after the expression to be evaluated. If you want to evalute a multivariable expression at some multidimensional point, you have to give its coordinates as a list.

In Maple value assignments must be presented to function eval as one argument too. If you have several variables to assign values too, wrap them into a list. Maple's list syntax is the same as in Maxima.

\begin{figure}
\begin{tex2html_preform}\begin{verbatim}> a;
2 2
x + y x + y
-...
...> eval(a, [x=1, y=2]);
7/4>\end{verbatim}\end{tex2html_preform}\end{figure}

In Mathematica there is a function ReplaceAll, which in this context does what ev does in Maxima and what eval does in Maple. It's syntax is more like that of eval, that is, if you have multi-variable assignments, you have to wrap them into a list first. Lists in Mathematica are built using $\{$ and $\}$:

\begin{figure}
\begin{tex2html_preform}\begin{verbatim}In[3]:= a2 2
x + x y ...
...y->2}]7
Out[4]= -
4In[5]:=\end{verbatim}\end{tex2html_preform}\end{figure}

Mathematica can also use a special shorthand notation here to accomplish the same task:
\begin{figure}
\begin{tex2html_preform}\begin{verbatim}In[7]:= a2 2
x + x y ...
... -> 2}7
Out[8]= -
4In[9]:=\end{verbatim}\end{tex2html_preform}\end{figure}

The notation /. is equivalent to calling ReplaceAll. It derives from the following mathematical notation:

\begin{displaymath}\frac{x^2 + x y + y^2}{1 + x + y}\biggr\vert_{x = 1, y = 2}
\end{displaymath}

Although tricks like this are quite neat from the user point of view, we will avoid them at this stage, since our aim here is to demonstrate how Maxima, Maple and Mathematica resemble each other.


next up previous index
Next: Functions Up: Algebra Previous: Fractions
Zdzislaw Meglicki
2001-02-26