Mathematical Functions
Mathematical Functions
Function Description
Returns the absolute value of x. For example, abs(5) = 5,
abs(0) = 0, and abs(–4) = 4. Geometrically, abs(x) is the
distance between x and 0 on the number line. Similarly,
abs(x – y) is the distance between x and y on the on the
number line.
Returns the largest integer that is less than or equal to x. For
example, floor(2.1) = 2, floor(2.9) = 2, floor(–2.1) = –3.
2 Mathematical Functions
Trigonometric Functions
The basic trigonometric functions of an acute angle (one smaller than 90°)
in terms of the sides of a right triangle are defined in Figure 1. These func-
tions are simply names given to ratios that can be formed by the three sides
of a right triangle.
opposite
sin(θ) =
hypotenuse
se
adjacent te nu
cos(θ) = po opposite
hy
hypotenuse
θ
opposite
tan(θ) =
adjacent adjacent
As an example, let’s say that we want to find the length of the shadow
cast by a building 50 meters high when the sun is 20 degrees above the hori-
zon, as illustrated in Figure 2.
50 m
20°
x
Figure 2: We can use trigonometry to find the length of a cast shadow.
50
tan ( 20 ) =
x
50
x=
tan 20
Mathematical Functions 3
We can then calculate and display x using the following command:
Logarithmic Functions
The base-10 logarithm, log(x), is the inverse function of 10x . That is, if
log(x) = y, then x = 10y. An example of the use of the base-10 logarithm is
the decibel (or dB) scale, which measures the loudness of sound. If I is the
intensity of sound in watts per square meter, then the sound level in deci-
bels is given by the following:
(
Sound level = 10 log I × 1012 dB )
For example, if the sound intensity is 10 –10 watts per square meter, we
can find the sound level in dB using the following blocks:
ln ( 2 )
Half-life = ,
k
4 Mathematical Functions
The number e is the value that satisfies ln(e) = 1, and the exponential
function, exp(x) = ex , is the inverse of ln(x). That is, if ln(x) = y, then x = ey.
This function appears in many scientific formulas such as those modeling
population growth, compound interest, radioactive decay, heat transfer,
and so on.
As an example, let’s assume that the number of people in a city with an
initial population of 1,000 is expected to grow according to this formula:
To find the number of people after 10 years, we can re-create the for-
mula with Scratch commands and replace t with 10:
x y = e y ln x , x > 0.
For example, if you want to find 64, you can use the following block:
Mathematical Functions 5