Chapter 5. Variables

Table of Contents

Variable creation/editing
Vectors and Matrices

Variables are used to conveniently store a fixed value/result under a name. Variables can store everything that a result may contain, including numbers, units, variables, unsolved expressions and functions etc.

There two different kinds of variables known and unknown. Known variables represents a fixed value, usually a number, while unknown variables represents a range or type of values (ex. a non-negative integer).

Some common constants that can only be approximately represented by a real number, such as pi and e, are special known variables. They are not fixed but are recalculated each time precision changes, thereby not compromising the arbitrary precision of Qalculate!.

The ans variable, which always contains the last calculated result, is another special and useful variable.

The unknown variables x, y and z are predefined. They cannot be deleted, but changed. By default they use the default assumptions.

For a complete list of available variables see Appendix B, Variable List or the variable manager.

Variable creation/editing

Figure 5.1. Store Result

Store Result

The easiest way to create a known variable is to store the current result. This can be done by clicking the STO button or selecting FileStore Result.... Type a name for the variable in the dialog that pops up and optionally enter a category and descriptive name to keep variables well organized.

Known variables can also be created from scratch by selecting FileNewVariable or by clicking New in the variable manager. The value can then be filled in, in the text field below the name, and specified as exact or approximate.

Figure 5.2. New Variable

New Variable

The dialog for creation of unknown variables are accessed by selecting FileNewUnknown Variable. Instead of a value, an assumed type and sign can then be entered.

Edit a variable by clicking Edit in the variable manager.


Variables stored in the Temporary category will not be saved after the program exit.

Vectors and Matrices

Vectors and matrices are most effectively used stored in a variable. Qalculate! provides separate tools for these variables. They use a different dialog, where each element can be edited separately as in a spreadsheet. As with other variables, click Edit in the variable manager to edit a matrix/vector variable, but to create a new, select FileNewMatrix or FileNewVector.

Figure 5.3. Matrix/Vector Edit Dialog

Matrix/Vector Edit Dialog

In this dialog, name, category and descriptive name are typed in as usual, but instead of a single value entry, the matrix/vector edit dialog has a table of entries. Select number of rows and columns above. In a vector this only determines how many value entries that are shown in the table and empty entries will be ignored. For matrices, each entry in the table is an element in the matrix. It is possible to switch between matrix and vector in the dialog (the menu item selected only determines the initial mode).

Matrices and vectors can also be loaded from data files. These files most be plain text files with values organized in separated rows and columns. Select FileImport CSV File... and a dialog window pops up. First select the file to import and then specify whether if it shall be imported as a matrix or vectors. A name, descriptive name and category can optionally be typed in. If the name field is empty, the file name will be used instead. After that, the row in the file where the data starts should be specified. as well as whether this first row contains column headings. Finally the delimiter, used to separate columns in the file, must be selected. Click OK and variables will be generated from the file. If vectors are to be generated and the file contains more than one column, the name will be used as a subcategory and each variable will add the column heading (or Column 1, Column 2, ...) to the name and the descriptive name.

Figure 5.4. Import CSV Dialog

Import CSV Dialog

The load() function can be used to access a CSV file directly in an expression. The reversed action is also available with export(), or the dialog accessed with FileExport CSV File... or from the variable manager.