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 have 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*1.15=1.15↑2=1.3225 times your original sum of money. In general, after y years, you will have 1.15↑y times what you started out with.
If you try this 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 is more, it gets faster and faster as time goes on. (Although even so, 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. NextBASIC has a function called EXP defined by:
EXP x=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 doing:
PRINT EXP 1
because EXP 1 = e↑1 = e. Of course, this is just an approximation. You can never write down e exactly.
The inverse of an exponential function is a logarithmic function: the logarithm (to baseₐ) of a number x is the power to which you have to raise a to get the number x, and it is written logₐx. Thus by definition a↑logₐx=x; and it is also true that log(a↑x)=x. You may well already know how to use base₁₀ logarithms for doing multiplications; these are called common logarithms. NextBASIC has a function LN which calculates logarithms to the baseₑ; these are called natural logarithms. To calculate logarithms to any other base, you must divide the natural logarithm by the natural logarithm of the base:
logₐx = LN x/ LN a
Given any circle, you can find its perimeter (the distance round its edge; often called its circumference) by multiplying its diameter (width) by a number called π. (π is a Greek p, and it is used because it stands for the Greek word perimeter. Unlike, what's commonly believed, its pronunciation is the same as in English.)
ZX Spectrum Next User Manual, 3rd Edition (ISBN 978-1-5272-5496-1), written and illustrated by Phoebus R. Dokos. Copyright © 2020-2024 Phoebus Dokos / SpecNext Ltd. Licensed under CC BY-NC-SA 4.0. This is a transcription and can contain errors; check any doubt against the printed page.