Part 10
Mathematical functions

Subjects covered...

	^
	PI, EXP, LN, SIN, COS, TAN, ASN, ACS, ATN

This section deals with the mathematics that the +3 can handle. Quite
possibly you will never have to use any of this at all, so if you find
it too heavy going, don't be afraid of skipping it. It covers the
operation ^ (raising to a power), the functions EXP and LN, and the
trigonometrical functions SIN, COS, TAN and their inverses ASN, ACS
and ATN.


^ and EXP

You can raise one number to the power of another. This means 'multiply
the first number by itself the second number of times'. This is
normally shown by writing the second number just above and to the
right of the first number; but obviously this would be difficult on a
computer so we use the symbol ^ instead. For example, the powers of 2
are...

2^1 equals 2
                                                      2
2^2 equals 2x2 equals 4 (2 squared, normally written 2 )
                                                      3
2^3 equals 2x2x2 equals 8 (2 cubed, normally written 2 )
                                                                        4
2^4 equals 2x2x2x2 equals 16 (2 to the power of four, normally written 2 )

...and so on.

Thus, at its most elementary level, a^b means 'a multiplied by itself
b times', but obviously this only makes sense if b is a positive whole
number. To find a definition that works for other values of b, we
consider the rule...

a^(b+c) equals a^b x a^c

(Notice that we give ^ a higher priority than multiplication and
division so that when there are several operations in one expression,
^ is evaluated before '*' and '/'). You should not need much
convincing that this works when b and c are both positive whole
numbers, but if we decide that we want it to work even when they are
not, then we find ourselves compelled to accept that...

a^0 equals 1
a^(-b) equals 1/a ^ b
a^(1/b) equals the bth root of a, which is to say, the number that you
	to multiply by itself b times to get a

...and...

a^(b x c) equals (a^b)^c

If you have never seen any of this before then don't try to remember
it straight away, just remember that...

a^(-1) equals 1/a

...and...

a^(1/2) equals SQR a

...and maybe when you are familiar with these, the rest will begin to
make sense.

Experiment with all this by trying this program...

	10 INPUT a,b,c
	20 PRINT a*(b+c),a^b*a^c
	30 GO TO 10

Of course, if the rule we gave earlier is true, then each time round,
the two numbers that the +3 prints out will be equal. (Note - because
of the way the computer works out ^, the number on the left, 'a' in
this case, must never be negative.)

A rather typical example of what this function can be used for is that
of compound interest. Suppose you keep some of your money in a
building society and they give 15% interest per year. Then after one
year you will have not just the 100% that you had anyway, but also the
15% interest that the building society has given you, making
altogether 115% of what you had originally. To put it another way, you
have multiplied your sum of money by 1.15, and this is true however
much you had there in the first place. After another year, the same
will have happened again, so that you will then have 1.15 x 1.15, or
in other words, 1.15 ^ 2, or in other words, 1.3225 times your
original sum of money. In general then, after y years, you will have
1.15 ^ y times what you started out with.

If you try the command...

	FOR y=0 TO 100: PRINT y,10*1.15^y: NEXT y

...you will see that even starting off from just #10, it all mounts up
quite quickly, and what's more, it gets faster and faster as time goes
on (though you might still find that it doesn't keep up with
inflation).

This sort of behaviour, where after a fixed interval of time some
quantity multiplies itself by a fixed proportion, is called
exponential growth, and it is calculated by raising a fixed number to
the power of the time.

Suppose you did this...

	10 DEF FN a(x)=a^x

Here, 'a' is more or less fixed, by LET statements - its value will
correspond to the interest rate, which changes only every so often.

There is a certain value for 'a' that makes the function 'FN a' look
especially pretty to the trained eye of a mathematician, and this
value is called e. The +3 has a function called EXP defined by...

	EXP x is equal to e^x

Unfortunately, e itself is not an especially pretty number; it is an
infinite non-recurring decimal. You can see its first few decimal
places by typing...

	PRINT EXP 1

...because 'EXP 1' is equal to e^1 which is equal to e. Of course,
this is just an approximation. You can never write down e exactly.


LN

The inverse of an exponential function is a logarithmic function - the
logarithm (to base a) of a number x is the power to which you'd have
to raise a to get the number x, and this is written loga x [no it
isn't, but I can't show it any better. :-/]. Thus by definition,
a^loga x is equal to x; and it is also true that log (a^x) is equal to
x.

You may well already know how to use base 10 logarithms for doing
multiplications; these are called common logarithms. The +3 has a
function LN which calculates logarithms to the base e; these are
called natural logarithms. To calculate logarithms to any other base,
you must first divide the natural logarithm by the natural logarithm
of the base, i.e. loga x is equal to 'LN x/LN a'.


PI

Given any circle, you can find its perimeter (the distance around its
edge - often called its circumference) by multiplying its diameter
(width) by a number called pi [they use the symbol, but I can't]. Pi
(pronounced pi) is the Greek equivalent of the English letter p, and
it is used because it stands for perimeter.

Like e, pi is an infinite non-recurring decimal - it starts off as
3.1415927. The word PI on the +3 is taken as standing for this number.
Try...

	PRINT PI


SIN COS and TAN, ASN ACS and ATN

These trigonometrical functions measure what happens when a point
moves round a circle. Here is a circle of radius 1 ('1 what?' you may
ask - it doesn't matter, as long as we keep to the same unit all the
way through) and a point moving round it. The point started at the '3
o'clock' position, and then moved round in an anti-clockwise
direction.

                                  | y-axis
                                  |
                                  |     <-__
                               ___|___      --_   distance moved
                           __--   |   -+__     -_   around circle = a
                         _-       |   /   -_     \
                        /         |  /      \     \
                       /          | /        \     |
                      |           |/          |    |
            ----------+-----------+-----------+-----------
                      |           |           |\     x-axis
                      :\          |          /  \
                      : \_        |        _/    \
                      :   --__    |    __--       \
                      :       ----+----             starting
                      :           |                 position
                      <-radius=1 ->
                                  |
                                  |

             [picture slightly altered to save my sanity]


We have also drawn in two lines called axes through the centre of the
circle. The one through 3 o'clock is called the x-axis, and the one
through 12 o'clock is called the y-axis.

To specify where the point is, you say how far it has moved round the
circle from its 3 o'clock starting position: let us call this distance
a. We know that the circumference of the circle is 2pi (because its
radius is 1 and its diameter is thus 2), so when it has moved a
quarter of the way round the circle, a is equal to pi/2; when it has
moved halfway round, a is equal to pi; and when it has moved the whole
way round, a is equal to 2pi.

Given the curved distance round the edge - a, two other distances you
might like to know are how far the point is the right of the y-axis,
and how far it is above the x-axis. These are called, respectively,
the cosine and sine of a. The functions COS and SIN on the +3 will
calculate these.

                                  | y-axis
                                  |
                    cosine of a = COS a <-__
                               ___|_|_      --_   a
                           __--   |_v_-+__     -_
                         _-       |   /|  -_     \
                        /         |  / |    \     \
                       /          | /  |<-+  \     |
                      |           |/   |  |   |    |
            ----------+-----------+-------|---+-----------
                      |           |       |   |\     x-axis
                      :\ sine of a = SIN a   /  \
                      : \_        |        _/    \
                      :   --__    |    __--       \
                      :       ----+----             starting
                      :           |                 position
                      <-radius=1 ->
                                  |
                                  |

Note that if the point goes to the left of the y0axis, then the cosine
becomes negative, and if the point goes below the x-axis, the since
becomes negative.

Another property is that once a has got up to 2pi, the point is back
where it started and the sine and cosine start taking the same values
all over again, i.e. SIN (a+2*PI) equals SIN a, and COS (a+2*PI)
equals COS a.

The tangent of a is defined as being the sine divided by the cosine;
the corresponding function on the +3 is called TAN.

Sometimes we need to work these functions out in reverse, finding the
value of a that has given some cosine or tangent. The functions to do
this are called arcsine (ASN on the +3), arc-cosine (ACS) and
arctangent (ATN).

In the diagram of the point moving round the circle, look at the
radius joining the centre to the point. You should be able to see that
the distance we have called a (the distance that the point has moved
round the edge of the circle) is a way of measuring the angle through
which the radius has moved away from the x-axis. When a is equal to
pi/2, the angle is 90 degrees; when a is equal to pi the angle is 180
degrees, and so on, round to when a is equal to 2pi, and the angle is
360 degrees. You might just as well forget about degrees, and measure
the angle in terms of a alone; we say then that we are measuring the
angle in radians. Thus pi/2 radians is equal to 90 degrees and so on.

You must always remember that on the +3, the functions SIN, COS, etc.
use radians and not degrees. To convert degrees to radians, divide by
180 and multiply by pi; to convert back from radians to degrees, you
divide by pi and multiply by 180.
[Back] [Contents] [Next]