Skip to content

Commit

Permalink
Merge pull request #1 from lauraclay/master
Browse files Browse the repository at this point in the history
Minor layout/typo edits
  • Loading branch information
bennuttall committed Jun 13, 2014
2 parents a45aa40 + 62b6002 commit e4468fe
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 48 deletions.
14 changes: 7 additions & 7 deletions README.md
@@ -1,18 +1,18 @@
# Getting Started with Mathematica
# Getting started with Mathematica

An introduction to using Mathematica on Raspberry Pi

## About Mathematica

Mathematica is a computational programming tool used in science, maths, computing and engineering first released in 1988. It is proprietary software that you can use for free on the Raspberry Pi and has been bundled with Raspbian and NOOBS since late 2013. Read the announcement on the Raspberry Pi blog: [The Wolfram Language and Mathematica on Raspberry Pi, for free](http://www.raspberrypi.org/the-wolfram-language-and-mathematica-on-raspberry-pi-for-free/).
Mathematica is a computational programming tool used in science, maths, computing, and engineering; it was first released in 1988. It is proprietary software that you can use for free on the Raspberry Pi, and it has been bundled with Raspbian and NOOBS since late 2013. Read the announcement on the Raspberry Pi blog: [The Wolfram Language and Mathematica on Raspberry Pi, for free](http://www.raspberrypi.org/the-wolfram-language-and-mathematica-on-raspberry-pi-for-free/).

![](images/3d-plot.png)

If your SD card was updated since late 2013 then you should have Mathematica and Wolfram pre-installed and should see their icons on the Raspbian desktop:
If your SD card was updated since late 2013, then you should have Mathematica and Wolfram pre-installed and should see their icons on the Raspbian desktop:

![](images/icons.png)

or find the programs in your applications menu under *Education*.
You can also find the programs in your applications menu under *Education*.

## Installation

Expand All @@ -23,13 +23,13 @@ sudo apt-get update
sudo apt-get install wolfram-engine
```

Note this is a 200MB download so may take some time.
Note this is a 200MB download, so it may take some time.

## Requirements

With Mathematica installed you should be able to follow the exercises along.
With Mathematica installed you should be able to follow along with the exercises.

The advanced worksheet features the use of some advanced mathematics (matrices). There is also one example of using GPIO, so for that you'll need basic input and outputs such as a tactile button and an LED.
The advanced worksheet features the use of some advanced mathematics (matrices). There is also one example of using GPIO, so for that you'll need basic input and outputs, such as a tactile button and an LED.

## Worksheets

Expand Down
62 changes: 30 additions & 32 deletions worksheet1.md
@@ -1,18 +1,16 @@
## Getting Started with Mathematica
# Getting started with Mathematica

# Mathematica & the Wolfram Language
## Mathematica & the Wolfram Language

Mathematica is a computational programming tool used in science, maths, computing and engineering first released in 1988. It is proprietary software that you can use for free on the Raspberry Pi and has been bundled with Raspbian and NOOBS since late 2013.

## Mathematica
## Starting Mathematica

Double click the `Mathematica` icon on the Desktop or open it from the applications menu to start. You'll see a splash screen with the red mathematica logo while the program loads:
Double-click the `Mathematica` icon on the Desktop or open it from the applications menu to start. You'll see a splash screen with the red Mathematica logo while the program loads:

![](images/splash.png)

Once loaded, you'll see two windows:

The Wolfram information dialogue:
Once loaded, you'll see two windows. The Wolfram information dialogue:

![](images/info.png)

Expand All @@ -28,19 +26,19 @@ The Wolfram information dialogue shows web links to:

These links will open in the web browser on the Raspberry Pi, provided you're connected to the internet.

### Programming in Mathematica
## Programming in Mathematica

Click in to the notebook window and enter:
Click inside the notebook window and enter:

```
Print["Hello world"]
```

and hit `Shift + Enter` and it will run the command and print "Hello world" to the screen like so:
Press `Shift + Enter`; it will run the command and print "Hello world" to the screen like so:

![](images/hello-world.png)

You can perform mathematical calculations such as:
You can perform mathematical calculations, for example:

```
In[2]:= 2 + 2
Expand All @@ -56,15 +54,15 @@ In[4]:= 1024 * 32
Out[4]= 32768
```

#### Notebook Editing
### Notebook editing

You can revisit a previously entered command by clicking it or moving the edit cursor with the keyboard, then delete, edit or add something and hit `Shift + Enter` to execute the new command in its place.
You can revisit a previously entered command by clicking it or moving the edit cursor with the keyboard. You can then delete, edit, or add something and press `Shift + Enter` to execute the new command in its place.

You can save a notebook and come back to it later, send it to a friend, post it online or even hand it in as your homework! Just go to `File > Save As` in the notebook window.
You can save a notebook and come back to it later, send it to a friend, post it online, or even hand it in as your homework! Just go to `File > Save As` in the notebook window.

When you open up a saved notebook all the previous entries will be shown, including all the inputs and outputs, and you can execute each cell again with `Shift + Enter` or all at once by selecting `Evaluation > Evaluate Notebook` from the menu.
When you open up a saved notebook, all the previous entries will be shown, including all the inputs and outputs. You can execute each cell again with `Shift + Enter`, or all at once by selecting `Evaluation > Evaluate Notebook` from the menu.

#### Variables
### Variables

You can store the results of calculations in variables:

Expand All @@ -77,9 +75,9 @@ area = Pi * radius^2;

Note the semicolon at the end of each line suppresses the output being printed.

##### Symbolic values
#### Symbolic values

Note the use of the built-in symbol `Pi` which contains a symbolic value of Pi. This means that if you pass it in to an equation the reference to the true value of *Pi* is preserved, not converted to decimal and rounded:
Note the use of the built-in symbol `Pi` which contains a symbolic value of Pi. This means that if you pass it into an equation the reference to the true value of *Pi* is preserved, not converted to decimal and rounded:

```
In[19]:= Pi
Expand All @@ -99,17 +97,17 @@ In[5]:= N[Pi]
Out[5]: 3.14159
```

The default number of significant figures given is 6, but more can be given by specifying in the second argument:
The default number of significant figures given is 6, but more can be given by specifying the number in the second argument:

```
In[6]:= N[Pi, 10]
Out[6]: 3.141592654
```

Note this is the number of figures, not decimal places, so the 3 is included in the count, leaving 9 decimal places.
Note this is the number of figures, not decimal places; so the 3 is included in the count, leaving 9 decimal places.

#### Lists
### Lists

You can store collections of data in a list:

Expand All @@ -118,7 +116,7 @@ nums = {1, 2, 3, 5, 8}
people = {"Alice", "Bob", "Charlotte", "David"}
```

##### Range
#### Range

The `Range` function can be used to produce a list of numbers:

Expand All @@ -140,7 +138,7 @@ Table[i ^ 2, {i, nums}] (*Squares of the items in the list nums*)

#### Looping

You can run a loop a number of times, or over the items in a list with `Do`:
You can run a loop a number of times, or over the items in a list, with `Do`:

```
Do[Print["Hello"], {10}] (*Print "Hello" 10 times*)
Expand All @@ -150,15 +148,15 @@ Do[Print[i], {i, 3, 5}] (*Print the numbers 1 to 5, in steps of 2*)
Do[Print[i ^ 2], {i, nums}] (*Print the square of each item in the list nums*)
```

#### Function Help
### Function help

You can get usage help for a function by prepending the function name with a question mark (`?`) and hitting `Shift + Enter`:
You can get usage help for a function by preceding the function name with a question mark (`?`) and pressing `Shift + Enter`:

![](images/sqrt.png)

#### Function Search
#### Function search

You can also search for functions by entering part of the function name to find matches. Just start with a (`?`) add an asterisk (`*`) as a wildcard:
You can also search for functions by entering part of the function name to find matches. Just start with a (`?`) and add an asterisk (`*`) on the end as a wildcard:

```
In[15]:= ?Device*
Expand All @@ -174,7 +172,7 @@ In[16]:= ?*Close*

![](images/function-search2.png)

#### Comments
### Comments

As seen in earlier examples, you can leave comments (notes that are ignored in the program) in scripts by using brackets (`(` & `)`) and asterisks (`*`):

Expand All @@ -184,17 +182,17 @@ Print["Hello"] (*Print "Hello" to the screen*)

## Wolfram command line access

You can also access the Wolfram language from the command line by entering `wolfram` in the termina, or double clicking the Wolfram Desktop icon. This will give a text-only (non-graphical) programming environment with the `In[x]` / `Out[x]` style interface but without interactive notebook functionality. The Mathematica functions will still work as expected:
You can also access the Wolfram language from the command line by entering `wolfram` in the terminal, or double-clicking the Wolfram Desktop icon. This will give a text-only (non-graphical) programming environment with the `In[x]` / `Out[x]` style interface, but without interactive notebook functionality. The Mathematica functions will still work as expected:

![](images/command-line.png)

You'll find the command line interface faster to use due to the lack of graphical processing required to run the notebook, but without the interactivity and graphical pretty printing.
You'll find the command line interface faster to use due to the lack of graphical processing required to run the notebook, however it lacks the graphical interface's interactivity and pretty printing.

To exit, hit `Ctrl + D`.
To exit, press `Ctrl + D`.

### Running scripts with Wolfram

You can write a program and save it as a normal file (usually with a `.m` or `.wl` file extension) and execute the script from the command line by adding the `-script` flag.
You can write a program, save it as a normal file (usually with a `.m` or `.wl` file extension), and execute the script from the command line by adding the `-script` flag.

To run `test.m`:

Expand Down
18 changes: 9 additions & 9 deletions worksheet2.md
@@ -1,6 +1,6 @@
# Getting Started with Mathematica - Advanced Worksheet
# Getting started with Mathematica - advanced worksheet

## List Operations
## List operations

You can apply an operation or function to all items in a list:

Expand All @@ -18,13 +18,13 @@ In[23]:= Sqrt[{1, 2, 3, 4, 5}]
Out[23]: {1, Sqrt[2], Sqrt[3], 2, Sqrt[5]}
```

Note in the last example the square roots of `1` and `4` were given exactly as they yield integer values but the square roots of `2`, `3` and `5`, which are irrational, are given symbolically.
Note that in the last example the square roots of `1` and `4` were given exactly, as they yield integer value; however the square roots of `2`, `3` and `5`, which are irrational, are given symbolically.

## Matrices

One of the most useful additional components of a mathematical programming language is the ability to do [matrix](https://en.wikipedia.org/wiki/Matrix_(mathematics)) operations. Of course, Mathematica has these available.

To create a matrix, first enter the values as a list of lists, making sure the dimensions are rectangular, i.e. `n x m` where `n` and `m` are integers:
To create a matrix first enter the values as a list of lists, making sure the dimensions are rectangular, i.e. `n x m` where `n` and `m` are integers:

```
m = {{1, 2}, {3, 4}, {5, 6}};
Expand Down Expand Up @@ -66,21 +66,21 @@ Graphics3D[{Opacity[.8], Glow[RGBColor[1,0,0]], EdgeForm[White], Lighting -> Non

You can access the GPIO pins from Mathematica using the `DeviceWrite` and `DeviceRead` functions.

To access the GPIO pins, you'll need to be running as root, so run `sudo wolfram` from the terminal (this will run the command line `wolfram` environment) or `sudo mathematica &` to run the Mathematica notebook as root.
To access the GPIO pins you'll need to be running as root. To do this, run `sudo wolfram` from the terminal (this will run the command line `wolfram` environment), or `sudo mathematica &` to run the Mathematica notebook as root.

The following command turns GPIO pin 14 (using BCM pin numbering) on:
The following command turns on GPIO pin 14 (using BCM pin numbering):

```
DeviceWrite["GPIO", 14 -> 1]
```

and the following command turns pin 14 off:
The following command turns pin 14 off:

```
DeviceWrite["GPIO", 14 -> 0]
```

You can also read the status of a GPIO input device (to check if a button is pressed, for example) with `DeviceRead`, much the same way:
You can also read the status of a GPIO input device (to check if a button is pressed, for example) with `DeviceRead`, in a similar way:

```
button = DeviceRead["GPIO", 14]
Expand All @@ -94,7 +94,7 @@ Read more about GPIO in general on the [GPIO usage](../gpio/README.md) page.

## Camera

You can take pictures with the camera using the `DeviceRead` function. First, attach your camera as usual. Follow the [camera setup guide](http://www.raspberrypi.org/help/camera-module-setup/).
You can take pictures with the camera using the `DeviceRead` function. First, attach your camera as usual. Follow the [camera setup guide](http://www.raspberrypi.org/help/camera-module-setup/) if needed.

To take a still picture with the camera, type the following command:

Expand Down

0 comments on commit e4468fe

Please sign in to comment.