MathematicalOperations
Pascal can do many mathematical operations. They are all relatively simple and easy to remember.
The first thing to remember is that pascal uses `:=` not `=` to assign a value to a variable.
e.g. `int := 3;`

Basic mathematical operators

``` Addition ...................... x := y + z; Subtraction ................... x := y - z; Multiplication ................ x := y * z; Division ...................... x := y / z; Integer division .............. x := y div z; Modulo arithmetic ............. x := y mod z;```

Integer Division: One integer is divided by another and the integer part of the result is returned.

Modulo Arithmetic (Remainder Arithmetic): `x := y mod z;`
The above finds the remainder of y/z and puts it into x.

These mathematical operations are pretty self explanatory.

Mathematical functions

SQR

Syntax:

`SQR(Real Variable)`

Explanation:
SQR returns the square of the real variable that is passed to it, pretty simple really.

Example:
`x := SQR(y)`;
This finds the square of y and puts the result in x.

SQRT

Syntax:

`SQRT(Real Variable)`

Explanation:
SQRT returns the square root of the real variable that is passed to it, pretty simple really.

Example:
`x := SQRT(y)`;
This finds the square root of y and puts the result in x.

SIN

Syntax:

`SIN(Real variable)`

Explantation:
SIN returns the sin of the number that is passed to it. Unfortunately this is in radians(stupid radians).
2*pi radians is equal to 360 degrees, so to convert from degrees to radians it is degrees/180 * pi,
and from radians to degrees it is radians/pi * 180. It is a bit of a hassle but nevermind.

Example:
`x := SIN`(y);
This finds the sin of y(radians) and puts the value in x.

COS

Syntax:

`COS(Real variable)`

Explantation:
COS returns the cos of the number that is passed to it. This is also in radians. If you want to know how to convert

Example:
`x := COS(y)`;
This finds the cos of y(radians) and puts the value in x.

ARCTAN

Syntax:

`ARCTAN(Real variable)`

Explantation:
ARCTAN returns the inverse tanget of the number that is passed to it.
It returns the angle in radians (gasp).

Example:
`x := ARCTAN(y);`
This finds the inverse tangent, in radians, of y and puts the value in x.

Finding TANGENT

To find tanget just divide sin(Y) by cos(Y).
e.g ` x := sin(y)/cos(y);` finds the tangent of y and puts it in x (remember radians).

Finding INVERSE SIN/COS

To find INVERSE SIN or INVERSE COS do the following...
INVERSE SIN = ARCTAN(y/sqrt(1-sqr(y)))
INVERSE COS = ARCTAN(sqrt(1-sqr(x))/x)

So `x := arctan(y/sqrt(1-sqr(y)));` finds the inverse sin of y and puts it in x.
So `x := arctan(sqrt(1-sqr(x))/x);` finds the inverse cos of y and puts it in x.

Previous Lesson(Basic I/O)    Main menu    Next Lesson(Procedures)