    Next: Example: Functions Up: Operators and Functions Previous: Operators and Functions

### Exercise 1 (Numbers and Operators)

Calculate the following mathematical expressions:  Solution:

>> 3.23*(14-2^5)/(15-(3^3-2^3))
ans = 14.535
>> 4.5e-23/0.0000013
ans = 3.4615E-17
>> 17.4^((3-2.13^1.2)^0.16)
ans = 13.125
>> 17.23e4/(1.12-17.23e4/(1.12-17.23e4/1.12))
ans = 76919

0

In addition to these arithmetic operators Jasymca provides operators for comparing numbers (< > >= <= == ~=), and for boolean functions ( & | ~ ). Logical true is the number 1, false is 0.

>> 1+eps>1
ans = 1
>> 1+eps/2>1      % defines eps
ans = 0
>> A=1;B=1;C=1;   % semikolon suppresses output.
>> !(A&B)|(B&C) == (C~=A)
ans = 1


The most common implemented functions are the squareroot (sqrt(x)), the trigonometric functions (sin(x), cos(x), tan(x)) and inverses
(atan(x), atan2(y,x)), and the hyperbolic functions (exp(x), log(x)). A large number of additional functions are available, see the list in chapter 4. Some functions are specific to integers, and also work with arbitrary large numbers: primes(Z) expands Z into primefactors, factorial(Z) calculates the factorial function. Modular division is provided by divide and treated later in the context of polynomials.

0

Helmut Dersch
2009-03-15