# JMathLabTutorial:3 Arithmetic

# Arithmetic

First, we will learn how to print a variable which keeps a number. In our example, the variable "x" is assigned to 1000

Click [Output] to see what you are just printed on the screen. Numbers are entered in the usual computer format: with optional decimal point and decimal exponent following the letter e (or E). The numbers 5364 and [math]-1.723478265342 10^{12}[/math] should be entered likeThe basic arithmetic operations are marked with the usual symbols (+ - * / ) . Exponention is performed with the accent character (^). Multiplication and division precede addition and subtraction; any order of evaluation can be forced by parenthesis.

+ | addition |

- | subtraction |

* | multiplication |

/ | division |

\ | left division |

^ | power |

' | conjugate transpose |

## Relations.

The relational operators

< | less than |

> | greater than |

<= | less than or equal |

>= | greater than or equal |

== | equal |

~= | not equal. |

Note that "=" is used in an assignment statement while "==" is used in a relation. Relations may be connected or quantified by the logical operators

& | and |

| | or |

~ | not. |

When applied to scalars, a relation is actually the scalar 1 or 0 depending on whether the relation is true or false.

Logical true is the number 1, false is 0.

Example:

Also, eps is defined:

Most of the time these will be stored as floating point data (double, IEEE standard 754). They are rounded to 5 significant digits for display, but for calculations the full precision of this format is always preserved (15-16 decimal digits). By switching the format (format long) all significant places are displayed.

As an extension it offers the command format Base Number, which is used to display numbers in a system with arbitrary Base with any Number of significant digits. To display numbers with $15$ digits in the binary system we type:

Using format short returns the display mode to default (short decimal). It should be emphasized, that none of the format commands influences the internal representation and accuracy of floating point numbers.Numbers, which are entered without decimal point and exponent, and which are larger than <m>10^{15}</m> are stored as exact rational data type. These numbers are internally represented as quotient of two variable length integers (java data type BigInteger), which allows you to perform calculations without any rounding errors. In the first case of the following example a floating point number is generated, in the second case an exact rational:

10000000000000001. 10000000000000001

Each floating point number Z can be converted to an exact number using the command rat(Z). The conversion is accomplished by continued fraction expansion with an accuracy determined by the variable ratepsilon (default: $10^{-8}$).

The rat() function is a part of symbolic calculation; in such cases we will need to specify "syms". You can comment it out, but the code should contain the keyword to let the engine know that we are interested in symbolic evaluation.Operations between exact and floating point numbers always lead to the promotion of floating point numbers. Calculations can be performed without rounding errors by rationalizing just the first number.

Conversely, the command float(Z) converts numbers into floating point format. Both commands also work for composite data types, like polynomials and matrices, whose coefficients are transformed in one step. Irrational function values of exact numbers and constants like pi remain non-evaluated until the float-command is issued.

You can also use comments in the output:

Imaginary numbers are marked with an immediately following i or j. This will work even if the predefined variables i and j have been overwritten.