# Three-Dimensional Mathematica Graphics (Chapter 1)

### Extract from Mathematica Graphics: An Intensive Tutorial

#### by Tom Wickham-Jones

This HTML document is based on Mathematica Graphics: An Intensive Tutorial by Tom Wickham-Jones. It was adapted by Martin Kraus for non-commercial use.

All other product names mentioned are trademarks of their producers.

Copyright 1992 by Wolfram Research, Inc.

All rights reserved. No part of this document may be reproduced, stored in a retrieval system, or transmitted, in any form or by any means, electronic, mechanical, photocopying, recording or otherwise, without the prior written permission of the copyright holder.

## Introduction

### 1.1 Introduction to Mathematica

Mathematica is a computer system which integrates symbolic and numerical mathematics with powerful computer graphics. These are supported by a concise and flexible programming language. This first chapter consists of a brief description of Mathematica as a system and how to use it.

## 1.1 Introduction to Mathematica

Before we start to look at Matheamtica graphics we should first review some basic Mathematica concepts.

Mathematica can be split into two parts: the kernel, which actually performs computations, and the front end, which handles interactions with the user. The kernel contains the same functionality on all the computers that run Mathematica. The front end, on the other hand, is optimized for particular computers and is concerned with system-specific tasks such as on-line editing, graphical display and printing. On many computers, the front end for Mathematica supports sophisticated interactive documents called Notebooks. These consist of an interactive mixture of computations, text and graphics. However the same input commands work on all versions to produce equivalent results.

When you start up a Mathematica kernel you see an input prompt In[num]:=, where num is a positive integer. Your documentation will tell you how to do this, the actual operations may vary from one system to another. With an input prompt you may enter something and ask Mathematica to evaluate it. This is how Mathematica works, you give it input, this is evaluated and the result is returned. We shall now examine a sample session. Enter the text which follow the input prompt.

 In[num] Mathematica is waiting for an input Out[num] the result from Mathematica
 This arithmetic operation evaluates to a result different from the input expression. In[1]:= 2 + 5 Out[1]= 7 There are many built-in mathematical functions. In[2]:= Sin[Sqrt[10.5]] Out[2]= -0.0986171 The ? is a simple and quick way to get help on a function. In[3]:= ?Sin Out[3]= Sin[z] gives the sine of z. The result is a rational number which can not simplify further. In[4]:= 100 50/89 Out[4]= 5000/89 N converts its argument to a real number. The % means the previous result. In[5]:= N[%] Out[5]= 56.1798 You can also refer to a result further back by using the number from Out. In[6]:= N[%1]^2 Out[6]= 49.

### Mathematica Expressions

We have now looked at various forms of arithmetic. The main type of input we have seen is for numbers. Mathematica can of course do much more.

 Numbers Symbols Strings Compound expressions
Some of the different types of Mathematica expressions.
 Assign the number 42 to the symbol a. In[7]:= a = 42 Out[7]= 42 The symbol a evaluates as it was set in the previous input. In[8]:= a Out[8]= 42 A string is put inside double quotes "". In[9]:= "This is a string" Out[9]= This is a string InputForm shows what we would have to enter into Mathematica to get the same result. In[10]:= InputForm[%] Out[10]//InputForm= "This is a string" This is a List. It is a fundamental way to hold a group of objects. In[11]:= expr = {a, b, c, d} Out[11]= {42, b, c, d} This command Table is another way to generate a List. Here i is set to go from 1 to 5 in steps of 1. In[12]:= Table[{i, i^2, i^3}, {i, 5}] Out[12]= {{1, 1, 1}, {2, 4, 8}, {3, 9, 27}, {4, 16, 64}, {5, 25, 125}} FullForm shows how Mathematica actually stores expr. In[13]:= FullForm[expr] Out[13]//FullForm= List[42, b, c, d] The FullForm of expr is List. The Head of an expression is a way to label it. In[14]:= Head[expr] Out[14]//FullForm= List The number of arguments of an expression is given by the Length function. In[15]:= Length[expr] Out[15]= 4 Part returns that component of an expression. In[16]:= Part[expr, 3] Out[16]= c This is identical to the previous input. This is an abbreviated way to refer to Part. A number of Mathematica commands have similar abbreviations. In[17]:= expr[[3]] Out[17]= c

### Mathematica Options

Many Mathematica commands can be altered by the use of options. All of the graphics commands have a number of options which alter the way they behave. To see the options which are available for a Mathematica command one can use Options.

 This shows the options for Plot3D. In[18]:= Options[Plot3D] Out[18]= {AmbientLight -> GrayLevel[0], AspectRatio -> Automatic, Axes -> True, AxesEdge -> Automatic, AxesLabel -> None, AxesStyle -> Automatic, Background -> Automatic, Boxed -> True, BoxRatios -> {1, 1, 0.4}, BoxStyle -> Automatic, ClipFill -> Automatic, ColorFunction -> Automatic, ColorOutput -> Automatic, Compiled -> True, DefaultColor -> Automatic, Epilog -> {}, FaceGrids -> None, HiddenSurface -> True, ImageSize -> Automatic, Lighting -> True, LightSources -> {{{1., 0., 1.}, RGBColor[1, 0, 0]}, {{1., 1., 1.}, RGBColor[0, 1, 0]}, {{0., 1., 1.}, RGBColor[0, 0, 1]}}, Mesh -> True, MeshStyle -> Automatic, Plot3Matrix -> Automatic, PlotLabel -> None, PlotPoints -> 15, PlotRange -> Automatic, PlotRegion -> Automatic, Prolog -> {}, Shading -> True, SphericalRegion -> False, Ticks -> Automatic, ViewCenter -> Automatic, ViewPoint -> {1.3, -2.4, 2.}, ViewVertical -> {0., 0., 1.}, DefaultFont :> \$DefaultFont, DisplayFunction :> \$DisplayFunction, FormatType :> \$FormatType, TextStyle :> \$TextStyle} If there are no options an empty list is returned. In[19]:= Options[Table] Out[19]= {} This shows the default setting for an option. In[20]:= Options[Plot3D, Boxed] Out[20]= {Boxed -> True} This changes the option Boxed for Plot. The actual meaning of these options is discussed later. In[21]:= Plot3D[x^2 + y^2, {x, 0, 1}, {y, 0, 1}, Boxed -> False] Out[21]= - SurfaceGraphics - This changes the default value for an option. The semicolon at the end of the input line suppresses the printing of the result. In[22]:= SetOptions[Plot3D, Boxed -> False]; The default setting has now changed. In[23]:= Options[Plot3D, Boxed] Out[23]= {Boxed -> False} We should change the default back. In[24]:= SetOptions[Plot3D, Boxed -> True];

### Miscellaneous Useful Features

Mathematica runs on many different types of computers. These computers have a number of differences in the way in which they refer to and manipulate files. Mathematica provides commands to work with files in a way that is the same for every computer on which it runs.

 This shows the files which end with the letters dat. In[25]:= FileNames["*dat"] Out[25]= {file.dat, file1.dat} This shows the contents of the file file.dat. If this does not work probably the file does not exist on your system. Use a text editor to make it and insert these numbers. Then try again. In[26]:= !!file.dat 1 1 2 8 3 27 4 64 5 125 6 216 7 343 8 512 This will reenter input line 20. In[27]:= In[20] Out[27]= {Boxed -> True} This retrieves output 20. In[28]:= %20 Out[28]= {Boxed -> True} This is an equivalent way to retrieve output. In[29]:= Out[20] Out[29]= {Boxed -> True}