# Chapter 7. Variables

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 (e.g. 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

The easiest way to create a known variable is to store the current result. This can be done by clicking the 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. The name is used in expressions (e.g. var_1 + 5 if the variable is named var_1), while the descriptive name is shown as title in menus. Variables in the Temporary category disappears when Qalculate! is closed.

Known variables can also be created from scratch by selecting FileNewVariable or by clicking in the variable manager. The value is entered in the text field below the name. Any mathematical expression is allowed as value (e.g. π m or sin(2) + ln(3)). The value can be specified as exact or approximate using the check button below the value field. It is possible to specify multiple names, and various properties of these names, using the button.

Alternatively values can be stored in variables using the save() function, or the associated :=/= operators (e.g. save(v1, 5) or v1:=5, save(v1, ln(5)+2,,,1) or v1=ln(5)+2).

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 selected.

Edit a variable by clicking in the variable manager, or using the context menu (right-click) of the corresponding menu item in the menu of the .

The special ( right-click) variable is updated using the classic ( right-click), (( middle-click), ( right-click), and ( middle-click) operations.

## 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 in the variable manager to edit a matrix/vector variable, but to create a new, select FileNewMatrix or FileNewVector.

In this dialog, name, category and descriptive name are typed in as usual, but instead of a single value field, multiple values are entered using a table. The number of rows and columns are selected using the controls above the table. In a vector this only determines how many cells that are shown in the table and empty cells will be ignored. For matrices, each cell 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 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.

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.