Mathematica and the Wolfram language on Raspberry Pi

Arguments

An argument is a parameter passed into a function. These parameters always directly follow the function in square brackets. For the Print example, the argument is:

["Hello world!"]

And for the N function example, the argument is:

[1/3]

Some functions do not require arguments, but the large majority do, so it is important to read up about the particular function you are working with and find out exactly how to use it. For information on how to use a function and what arguments it will accept, you can type the function into the notebook window, preceded by a question mark. For instance, if you wanted more information on the Print function, you type

?Print

and press Shift+Enter to see information about the function (Example A).

If you are looking for a function but can't remember the full name, you can use this question mark notation to find it. Say, for example, you know that the function you are looking for begins with Print, but you can't remember the rest. You can type

?Print*

and press Shift+Enter. You will be presented with a list of functions that start with the word Print (Example B).

You can then click on any of these functions, and Mathematica will bring up a description of what it does, so you can determine whether it is the one you are thinking about before you use it in your program (Example C).

You can also look for functions ending in a particular word by putting the asterisk in front of the function name ?*Print. Alternatively, you can search for information about functions from the online documentation center on the Wolfram website [3]. A quick way to access the documentation center within Mathematica is to click on Help  | Online Documentation.

Strings

The string data type (integers and floating-point numbers are other data types) is present in practically every programming language. A string is usually a sequence of characters typically used to display or use text within a program; however, it is possible to define strings that contain only numbers as well.

In Mathematica, as in most programming languages, a string is defined by placing text in quotation marks. If you do not put a string in quotation marks, Mathematica will probably try to evaluate it as either a variable or a function, and this will likely cause errors within your code.

In the preceding example, "Hello world!" is a string. In Mathematica, because of its ability to work as a multiparadigm language with natural text input, you don't need the quotation marks; however, I highly recommend getting into the habit early on of enclosing your strings in quotation marks because this prudent practice will likely save you some grief in the future.

Buy this article as PDF

Express-Checkout as PDF

Pages: 2

Price $2.95
(incl. VAT)

Buy Raspberry Pi Geek

SINGLE ISSUES
 
SUBSCRIPTIONS
 
TABLET & SMARTPHONE APPS
Get it on Google Play

US / Canada

Get it on Google Play

UK / Australia

Related content