# JMathLabTutorial:Transformations

# Transformations

Symbolic transformations can be done by specifying "syms x" keyword in front of your code. It can be commented out if x no need to be a symbolic value.

It is possible to define variables whose value is a function. In this case the function's name must be preceded by the character

```
$
```

to suppress evaluation. These variables can be used like the function they stand for. For example, who dislikes the built-in function **realpart(x)** name can shorten:

## Substitution

Parts of an expression may be replaced by other expressions using **subst(a,b,c)**: a is substituted for b in c. This is a powerful function with many uses. First, it may be used to insert numbers for variables, in the example $3$ for $x$ in der formula [math]2\sqrt{x} \dot e^{-x^2}[/math].

Second, one can replace a symbolic variable by a complex term. The expression is automatically updated to the canonical format. In the following example [math]z^3+2[/math] is inserted for x in [math]x^3+2x^2+x+7[/math].

Finally, the term b itself may be a complex expression (in the example [math]z^2+1[/math]). jMathLab then tries to identify this expression in c (example: [math]\frac{z\cdot x^3}{\sqrt{z^2+1}})[/math]. This is accomplished by solving the equation a = b for the symbolic variable in b (example: "z"), and inserting the solution in c. This does not always succeed, or there may be several solutions, which are returned as a vector.

## Simplifying and Collecting Expressions

The function **trigrat(expression)** applies a series of algorithms to expression.

** All numbers are transformed to exact format.**
** Trigonometric functions are expanded to complex exponentials.**
** Addition theorems for the exponentials are applied.**
** Square roots are calculated and collected.**
** Complex exponentials are back transformed to trigonometric functions.**

It is often required to apply float(expression) to the final result.

And with 2 variables, x,y

trigexpand(expression) expands trigonometric expressions to complex exponentials. It is the first step of the function trigrat above.