This talk gives an overview of some programs that can take the tedium out of mathematical calculations. They perform calculations such as differentiation, integration, solving nonlinear equations, ODEs and PDEs, Taylor series expansions, plotting functions, and so on. We will concentrate on three programs that are available at ISU: Matlab, Mathematica, and Maple.
Mathematica is designed to provide symbolic answers, that is, to solve problems in closed form. It can also solve these problems numerically, to arbitrary precision, but gives no detail on how that is done. It is not well suited for extensive numerical computations.
Mathematica is available on four of the machines in the lab in Carver 449 (δ1 through δ4; from the front of the room, they are the leftmost machines in the front row). I also found an old copy on machine ca400w1 (version 2, as opposed to version 5 in the lab).
Maple is also mainly a symbolic calculator. It is very similar to Mathematica, but poorly supported at ISU. It is available on Project Vincent in directory /afs/iastate.edu/public/maplevr6/bin as either maple (text interface) or xmaple (X windows interface). From machine isua1, the command "add maple" had the desired effect. From machine ca400w1 the "add" did not work, but I was able to start maple from its afs directory. There are also directories maplevr4 and maplevr5 (presumably versions 4 and 5, and the current version is 6). The help files are missing, so you are on your own.
Matlab is designed primarily to provide numerical answers. It can perform some symbolic computations, by internally calling Maple, but its symbolic capabilities are limited compared to the other two. The numerical algorithms used are described in detail in the documentation, and for many operations there is a choice of different algorithms. Matlab is available on all machines in the department.
Matlab is also available on Project Vincent, but they let their site license lapse several years ago. You can get to version 6, installed in 2000, by attach matlab6. The current version available in the Math Department is version 7.
| Mathematica | Maple | Matlab | |
| Main Application | symbolic | symbolic | numeric |
| Support and Availability | few copies around, but up-to-date; public copies are for Windows XP only | available for several types of workstations (including Linux PC); out of date, missing help files | available everywhere; widely used by faculty and in classes; up to date |
| Output formatting | mathematical typesetting | text-based or mathematical typesetting (depending on whether you invoke maple or xmaple) | text-based only |
| Save work in internal format | yes | yes | yes |
| Save/print a transcript of your work | text, TeX, HTML, MathML | text, TeX, HTML | text only |
| Save formulas as | TeX, Fortran, C | TeX (supposedly also Fortran and C, but I couldn't get it to work) | TeX, Fortran, C |
| Interface to other programs | ?? | ?? | Fortran, C, Maple, Excel, lab instruments, ... |
| Plot | yes | yes | yes |
| Calculate values of special functions (Bessel functions, error function, hypergeometric functions, etc.) | yes | yes | yes |
We want to integrate (x+1)/(x^2+x+1), either as an indefinite integral or as a definite integral from 0 to 1. For the definite integral, also state the answer as a decimal with 30 digits.
In[2]:= |
> int((x+1)/(x^2+x+1),x); > int((x+1)/(x^2+x+1),x=0..1); > evalf[30](%); |
Matlab is primarily a numerical calculator. We do the definite integral numerically first, then the symbolic integral.
| >> help quad QUAD Numerically evaluate integral, adaptive Simpson quadrature. Q = QUAD(FUN,A,B) tries to approximate the integral of function FUN from A to B to within an error of 1.e-6 using recursive adaptive Simpson quadrature. The function Y = FUN(X) should accept a vector argument X and return a vector result Y, the integrand evaluated at each element of X. ... See also quadv, quadl, dblquad, triplequad, @, trapz. >> f = inline('(x+1)./(x.^2+x+1)') >> syms x |
We want to find the Taylor series for sin(e^x-1) around the point x=0 up to the x^5 term, and also the expansion of the central finite difference approximation to the first derivative.
In[11]:= Out[11]= In[13]:= Out[13]= In[14]:= Out[14]= In[15]:= Out[15]= |
> series(sin(exp(x)-1),x=0,5); > term1 := series(f(x+h),h=0,4); > term2 := series(f(x-h),h=0,4); > s := (term1 - term2)/(2*h); > simplify(s); > expand(s); > combine(s); > collect(s,h); > normal(s); |
The last example shows why I tried to learn Maple two or three times, and gave up every time: I just could not convince Maple to simplify the result in the form that I wanted.
>> taylor(sin(exp(x)-1),5) >> syms f x h |
We want to solve the ODE y' = y+1, with or without the initial condition y(0)=1.
(I accidentally used the initial condition y(0)=0 here)
In[8]:= Out[8]= In[9]:= Out[9]= |
> dsolve(D(y)(x) = y(x)+1, y(x)); > dsolve({D(y)(x) = y(x)+1,y(0)=1}, y(x)); |
We do the numerical solution first, then the symbolic solution.
>> yprime = inline('y+1','t','y') >> dsolve('Dy = y+1') |
We want to plot the function 1/x + e^x over the interval [0.1, 3].
In[17]:= Out[17]= |
> plot(1/x+exp(x),x=0.1..3); |
>> x = linspace(0.1,3);
|
These are the default figures for all programs. I am sure you can add labels, change the axis limits, etc.
Mathematica and Maple saved the figures as gif files by default. I am sure you can save them in a variety of other formats as well. For inclusion into TeX documents, you should save them as .eps files (encapsulated Postscript). Matlab needs to be told the format explicitly (this one is a .jpg file), but it can handle a lot of different formats, including .eps and .epsc (color Postscript).
You can convert a single formula to Fortran code, C code, or TeX code, for cutting and pasting into a program or TeX document.
In[21]:= Out[21]= In[22]:= Out[22]//FortranForm= 1 + (1 + x**2)*Sec(x) In[23]:= Out[23]//TeXForm= \left(x^2+1\right) \sec (x)+1 In[24]:= Out[24]//CForm= 1 + (1 + Power(x,2))*Sec(x) |
> s := 1 + (x^2+1)/cos(x); > fortran(s); > latex(s);
1+{\frac {{x}^{2}+1}{\cos(x)}}
> C(s); |
The Fortran output form is listed in the manual, but it did not work on the version of Maple I tried. The syntax for the C form was just a guess on my part, which also did not work.
>> syms x 2 >> fortran(s) |
Last Updated: March 7, 2006