UBC Home Page -
UBC Home Page -
UBC Home Page UBC Home Page -
-
-
News Events Directories Search UBC myUBC Login
-
- -
=> => =>
  Mathematica FAQ  
Home
Events
People
Research
Graduate
Undergrad
Courses
Alumni
Internal
Computing Resources
Email
FAQ
Home Directory
Lab Overview
Lab Schedule
LaTeX
Mathematica
Printers
Scanners
Secure Login
Security
Site Licenses
SysAdmins
Unix Help
Web Publishing
Windows Software
Links

Quick Links:
About Us
Contacts
Events Calendar
Employment
Newsletter
Outreach Programs
Affiliated Research Sites
P&A at UBC cIRcle

General Mathematica questions? Check out Wolfram's websites: Mathematica Home Page and MathWorld.

Use the Help Browser. It has information on virtually everything in Mathematica. It may be slow, but it will help.
Also, a demonstration notebook is available. To save this file, hold the shift key down then click on the link.


Having trouble printing?

Mathematica prints to a file by default. If your printout does not appear, check to make sure that you are printing to LPR in the print window.
Look at: printing from mathematica for more details on how to do this.
Do not type "lpr file.nb"! It will print around fifty pages of gibberish. Print the file.nb.ps file only.


My file worked yesterday, why isn't it working today?

Did you reprocess the file after you loaded it? Mathematica does not remember what you typed yesterday, even after you load the file. Each line has to be reprocessed each time Mathematica is restarted. Each time you load, you should also select Kernel->Evaluation->EvaluateNotebook before you add anything new. If you only want the contents of one section, highlight the appropriate cell brackets on the right of the screen with the mouse, and hit shift-return.


Why do some functions like ErrorListPlot or Regress not work sometimes?

A lot of Mathematica functions come from extra packages (ie: Graphics`Graphics`) that need to be loaded before you use the function. This keeps Mathematica from being even more bloated than it already is. If you use the function before you have loaded the package, Mathematica creates a new variable with the name of the function. Unforunately, when you try to load the package after this, Mathematica experiences a conflict between the newly loaded function, and the variable of the same name. It prints an error message and the function loses.

You have two options to fix this. Instead of using Clear["Global`*"] at the start before loading packages, use Remove["Global`*"]. Alternately, you can reset Mathematica completely by quitting the kernel.

Recommendation: Instead of starting your notebooks with Clear["Global`*"], use Remove["Global`*"]. Reprocessing the notebook will cure this problem most of the time. NB: On the first use, it will give a warning that there are no variables to remove. This is only a warning; Mathematica is not unhappy.


How do I fit a curve to only part of my data?

The Regress/Fit functions don't have a means to fit only on a specified portion of the data you give it. You need to make a new data set containing only the data that you want to fit. You can use the Take command to grab the appropriate portion. You can look up how to use Take in the help browser.


How do I draw X and Y error bars in my graph?

X error bars are not as easy as Y error bars. Load this notebook into Mathematica for a demonstration of how it can be done. To save this file, choose File->Save As after clicking on link.


My notebook has become corrupted and won't load!

Sometimes there have been problems with the Mathematica cache files, not your notebook itself. Quit mathematica completely; go to your xterm window (your command line) and type:
mathematica -clean &
This clears the cache before starting. If you are still having the problem, check your disk quota. If you are over your quota, your notebook itself is likely corrupted. Talk to the Computer Lab TA, they can often fix your file; you might lose some of the stuff you saved, but most of your file will survive.


Problem: Mouse will not focus on windows in Mathematica

Sometimes the mouse will not focus in Mathematica when you click on a particular window. This problem can be solved my making sure that the NumLock key on the keyboard is switched off.


How can I run Mathematica from physics on my PC at home?

Windows answer: In order to display any windows over a remote connection, you need Cygwin, a free Linux-like environment for Windows. Click on the Cygwin link for instructions on installing and using Cygwin to display X programs on your windows-based PC.

You will also need to download extra fonts in order for Mathematica to display properly. Unzip and copy the Math30 directory to the appropriate directory. Then use Xutil to add the directories to the font path.

Linux answer: First, you need to download the mathematica fonts. Untar them and move the PCF directory to /usr/lib/X11/fonts. Before you ssh to physics, you need to give the command:

xset fp+ /usr/X11R6/lib/X11/fonts/PCF/
on your PC to add the PCF directory to your font path.

Ubuntu/Kubuntu answer:

  1. First, you need to download the mathematica fonts. Untar the this file in the /usr/local/share/fonts directory (you will end up with three new sub-directories, AFM, Type1, and X.
     sudo cd /usr/local/share/fonts
     sudo wget http://www.phas.ubc.ca/computer/mathematica/Mathematica4.0_FontsForUbuntu.tar.gz
     sudo tar zxf Mathematica4.0_FontsForUbuntu.tar.gz
              
  2. Edit /etc/X11/xorg.conf and add the following lines to the "Files" section:
    Section "Files"
      FontPath    "/usr/local/share/fonts/AFM"
      FontPath    "/usr/local/share/fonts/Type1"
      FontPath    "/usr/local/share/fonts/X"
    EndSection
  3. Restart the X server by pressing Alt-Ctrl-Backspace (will log you out) or restart your system.

Re: persistent xorg.conf in Ubuntu 9.10 Karmic /etc/X11/xorg.conf is used if it exists, it just isnt created by default.
sudo Xorg -configure
will try to generate an xorg.conf for you if you want it but if you need to add options you can just create an empty xorg.conf file yourself and add those options to it if you like

Wolfram Tutorial: Mathematica Fonts on Unix and Linux

Dealing with fonts under Unix and Linux can sometimes be tricky. The important issues in dealing with fonts in Mathematica are presented in this tutorial for your convenience.

Font Formats

The Mathematica front end supports BDF, TrueType, and Type1 fonts. These fonts are automatically installed by MathInstaller during installation.

Font Installation

All machines that display the front end must have access to the fonts included with Mathematica. If the Mathematica process is running on a remote machine and the front end is displayed on the local machine, the X server on the local machine must know where to find the Mathematica fonts. To do this, add the Mathematica fonts to the local font path by running a command like the following on the local machine.
xset fp+ /usr/local/Wolfram/Mathematica/7.0/SystemFiles/Fonts/Type1; xset fp rehash
Be sure to execute
xset fp rehash
to make the fonts available to the local X server.

For optimal onscreen performance, Type1 fonts should appear before BDF fonts in the font path.

Hence, $InstallationDirectory/SystemFiles/Fonts/Type1 should appear before $InstallationDirectory/SystemFiles/Fonts/BDF.

You can check the order of the font path by executing the command
xset q
Note: TrueType fonts are automatically loaded and do not require an xset command.

Font Servers

You may prefer not to install local copies of the Mathematica fonts on all machines. You can instead set up a font server with all the necessary Mathematica fonts. The other machines on the network can then find the fonts as needed by reading them from the Mathematica directory on the font server. Consult your operating system's documentation for further information.

Common Font Errors

On some systems, the font path is limited in length, and it is possible to receive xset: bad font path element errors even if the fonts are available to the server. In this case, try reordering the font path and adding the directories for the Mathematica fonts earlier in the path. The directory $InstallationDirectory/SystemFiles/Fonts/Type1 must be listed before $InstallationDirectory/SystemFiles/Fonts/BDF on the font path for optimal onscreen performance.

Fonts and Printing

When the X front end prints a notebook, it uses AFM files for the font metrics needed for printing. If you want to print using a particular font not included with Mathematica, you will need the AFM files for the font. These files are installed in either $InstallationDirectory/Configuration/Fonts/AFM, /usr/lib/AFM, or /usr/lib/afm. Fonts are normally downloaded to the printer by the front end when printing. You may be able to download the fonts and store them on the printer. See the documentation and programs that came with your printer for more information.

GhostScript

If you want to view Mathematica graphics using GhostScript, you need to make GhostScript aware of the Mathematica fonts. For more information, contact Technical Support by sending email to support@wolfram.com, or visit support.wolfram.com/mathematica/graphics/export/ghostscript.html.


How do I setup Mathematica batchfiles that I can let run overnight?

The UNIX versions of Mathematica can run batch files by executing:
math < {infile} > {outfile}
where infile is a text file composed of the necessary Mathematica input commands, and outfile is the file that is written by Mathematica which contains the evaluations of each of the input commands. It is sometimes useful to make the first line in the infile:
AppendTo[$Echo, "stdout"]
,so that input lines will also be included in the output file. (This information also appears on page 30 of the Getting Started with Mathematica Under UNIX and X guide.)

To run this batch job in the background, execute:

nohup nice +19 math < {infile} > {outfile} &
,which will continue running the batch job in the background even after you logout of your UNIX session.

If you have Mathematica commands stored in a notebook that you would like to transfer to your infile, you can use one of Mathematica's Front End features to help you.

  1. Select the cell or set of cells that contain the commands you wish to be written to the infile text file.
  2. These cells will be defined as initialization cells by clicking on Cell->Cell Properties->Initialization_Cell in the menu bar.
  3. Now Mathematica can generate a text file by clicking on File->Save_As_Special...->Package_Format
A dialog box will appear prompting you to give the file a name and location. You can use this Package Format file as the infile for your Mathematica batch job.

NOTES: The Mathematica method for appending output to a file is to use the form:

expression >>> output.file
To make sure that your output is in a form that is readable by Mathematica (and hence convertable into other forms, like Matlab), add what is advised above:
InputForm[ expression ] >>> output.file
Be sure to use >>> , not >>, as Mathematica syntax defines >> as a file overwrite, not an append.


Other problems?

Quitting the kernel can cure a number of odd problems that you may encounter. It doesn't fix everything, but it is worth a try. Generally, if you are still getting the problem, it is because of a bug/typo in your code.