# Getting started with tomSym

Jump to navigationJump to search

We believe that the best way to learn is to try it out ourself. The easiest way to use TOMSYM is to give commands directly at the MATLAB prompt. Unless you put a semicolon at the end of the line, the results will be displayed as soon as you hit the "enter" key. This guide provides several examples that you can try. The code that you should type into MATLAB is preceeded by the prompt >> , and MATLAB's response appears below it, as in this example:

```>> toms a b % Create two symbolic objects
>> a + b    % Add them together

ans = tomSym(1x1):

a+b

```

Any text after a percent sign (%) is a comment, and has no effect on the result.

### Installation

TomSym is part of TOMLAB, which is available for Windows (32bit/64bit), Linux (32bit/64bit) and Mac OS X (64bit).

TOMLAB can be downloaded from the website http://tomopt.com and the download page also contains a link to the installation manual which explains the rest of the installation process.

### Examples

The tomSym installation contains a directory named examples. This contains a number of ready-made examples of optimization problems solved using TOMSYM, and might serve as a source of inspiration.

### Getting help

For help on any specific TOMSYM command, you can always type help followed by the command name at the MATLAB prompt. You can also look for help in the FAQ section of this guide.

Finally, you are always welcome to ask us directly, via the support form on our website: http://tomopt.com

## Introduction to TOMSYM

TOMSYM is a symbolic package, meaning that it deals with symbols, rather than numbers. A tomSym object can be a simple symbol (a name) or it can be a mathematical expression involving many simple symbols.

```>> a = tom('a') % Create a scalar symbol

a = tomSym(1x1):

a

>> f = cos(a)/a

f = tomSym(1x1):

(1/a)*cos(a)

```

In this example, a is a simple symbol, and f is an expression.

TOMSYM expressions can be used in calculations in much the same way as normal Matlab variables, and the result of the calculations will be new TOMSYM expressions. It is, for example, possible to add 2 to the expression we already defined:

```>> f = f+2

f = tomSym(1x1):

(1/a)*cos(a)+2

```

In optimization, it is often useful to compute the derivative of a function. TOMSYM supports symbolic derivatives via the derivative function.

```>> g = derivative(f,a)

g = tomSym(1x1):

-(cos(a)*((1/a)*(1/a)))-(1/a)*sin(a)

```

TOMSYM objects can be converted into numeric values by substituting values for the symbols it contains.

```>> subs(g,a==2)

ans =

-0.3506
```