How to use Maxima if then else

Viewed 2314

does anyone know how to use standard if then else structure in Maxima syntax when you need more than one instruction after then and else??? Like a block in a standard computer language??? Thanks leon

1 Answers

You can put multiple expressions into block(...) or (...). The difference is that block allows local variables, e.g. block([a, b], a: ..., b: ...).

For both block(...) and (...), the result value is whatever was evaluated last. When there aren't any control structures such as if, the last expression in the block(...) or (...) is evaluated last. Otherwise, the result of the block(...) or (...) is whatever is the result of control structure. See also return.

Example:

if x < 4
    then block([y], print("Hi, x is less than 4"), y: 2*x, y - 1)
    else (print("I guess x >= 4"), x^3 - 10);
Related