Chapter 7. Variables
Prev |  | Next

# Chapter 7. Variables

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 always contains the most recent result. For multiple results of an equation, this variable contains a vector of solutions (access the first solution using “ans(1)”).

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 7.1. 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 File → Store Result.... Type a name for the variable in the dialog that pops up. The name is used in expressions (e.g. “var_1 + 5” if the variable is named “var_1”). Temporary variables (placed in the “Temporary” category) disappears when Qalculate! is closed.

Known variables can also be created from scratch by selecting File → New → Variable or by clicking New 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)”).

It is possible to specify multiple names, and various properties of these names, by clicking the icon on the right side of the name field.

The second page of the dialog provides fields for entry of descriptive name (shown as title in menus), category, and description.

Figure 7.2. New Variable

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 File → New → Unknown Variable. Instead of a value, an assumed type and sign can then be selected.

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

The special MR (= right-click) variable is updated using the classic MC (AC right-click), MS ((= middle-click), M+ (+ right-click), and M− (DEL 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 Edit in the variable manager to edit a matrix/vector variable, but to create a new, select File → New → Matrix or File → New → Vector.

Figure 7.3. Matrix/Vector Edit Dialog

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.

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 File → Import 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 7.4. 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 File → Export CSV File... or from the variable manager.

Prev |  | Next
Chapter 6. Propagation of Uncertainty and Interval Arithmetic | Home | Chapter 8. Functions