Eng:List of Mathematical Functions Done in Scratch

This page lists ways in which important mathematical functions and formulas can be expressed using the Scratch Operators Blocks. This does not need to be limited to simple or elsewhat useful formulae.

Cone
(((pi) * ((r) * (r))) + ((pi) * ((r) * (l))))



Cylinder
((((2) * (pi)) * ((r) * (r))) + ((2) * ((pi) * ((r) * (h)))))



Ellipse
((pi) * ((a) * (b)))



Circle
Also known as a degenerate ellipse, this is the area of a circle: ((pi) * ((r) * (r)))

Frustum
(((pi) * ((r of bottom circle) + (r of top circle))) * ( [sqrt v] of ((((r of bottom circle) - (r of top circle)) * ((r of bottom circle) - (r of top circle))) + ((h) * (h)))



Möbius Strip
(((4) * (pi)) * ((r) * (w))) w is the distance between the edges, and r is half the distance between two points on opposite sides of the strip

This formula derives from the fact that the Möbius strip is one-sided (non-orientable).

Kite
Here, "d1" and "d2" are the lengths of the two diagonals of the kite:

(((d1) * (d2)) / (2))

Parallelogram
((base) * (height))

Trapezoid/Trapezium
Here, "a" and "b" are the two parallel sides of the trapezoid:

((((a) + (b)) * (h)) / (2))

Regular N-gon
Here, "n" is the number of sides in the polygon:

(((n) * ((side) * ((1) / ([tan v] of ((pi) / (n)))))) / (4))

Sphere
((pi) * ((4) * ((r) * (r))))



Sector of a Circle
This will find the answer in degrees: (((central angle) / (360)) * ((pi) * ((r) * (r))))

Square-based Pyramid
(((2) * ((b) * (l))) + ((b) * (l)))

Torus
(((4) * ((pi) * (pi))) * ((R) * (r)))



Note that this formula is just the product of the circumferences of two circles with radii R and r.

Triangle
There are numerous ways to calculate the area of a triangle:

The most common formula is Area = (base/2)*height (see below) where base is any side and height is the length of a line segment perpendicular to the base, ending at the vertex opposite the base. In Scratch, this translates to:

(((base) / (2)) * (height))

If two side lengths are known (a and b) and one angle (C), the following formula may be used to find the area: (((a) * (b)) * (([sin v] of (C)) / (2)))

If one side length is known (c) and two angles (A and B), the following formula may be used to find the area: ((((c) * (c)) * (([sin v] of (A)) * ([sin v] of (B)))) / ((-2) * ([sin v] of ((A) + (B)))))

If 3 side lengths are known (a, b, c), the following formula, known as Heron's formula, may be used to find the area: set [s v] to ((((a) + (b)) + (c)) / (2)) //s is called the semiperimeter; it is half the perimeter set [area v] to ([sqrt v] of ((((s) * ((s) - (a))) * ((s) - (b))) * ((s) - (c))))

If the triangle's vertices have integer coordinates, it is best to use Pick's theorem or Heron's formula (above) (using the #Distance between two points to find the lengths of the triangle's sides).

If one knows the radius of the triangle's incircle and its semiperimeter (half the perimeter), we can use this formula:

((radius) * (semiperimeter))

Cone
(((pi) * (((r) * (r)) * (h))) / (3))



Cylinder
((pi) * ((r) * ((r) * (h))))



Frustum
((((pi) * (h)) / (3)) * (((r of bottom circle) * (r of bottom circle)) + (((r of bottom circle) * (r of top circle)) + ((r of top circle) * (r of top circle)))))



Pyramid
(((b) * (h)) / (3))



Regular Tetrahedron
Here, "b" is the length of each edge:

((([sqrt v] of (2)) / (12)) * (((b) * (b)) * (b)))



Sphere
(((4) / (3)) * ((pi) * ((r) * ((r) * (r)))))



Torus
(((2) * ((pi) * (pi))) * ((R) * ((r) * (r))))



Note that this formula is just the product of the area of a circle with radius r and the circumference of a circle with radius R. It is only correct when R ≥ r.

Sides
This will give an answer for side "a":

(((b) * ( [sin v] of (A))) / ( [sin v] of (B)))

Angles
This will give an answer for angle "A":

( [asin v] of (((a) * ( [sin v] of (B))) / (b)))

Sides
This will give an answer for side "c": ( [sqrt v] of ((((a) * (a)) + ((b) * (b))) - ((2) * ((a) * ((b) * ( [cos v] of (C)))))))

Angles
This will give an answer for angle "C": ( [acos v] of ((((a) * (a)) + (((b) * (b)) - ((c) * (c)))) / ((2) * ((a) * (b)))))

Hyperbolic Functions
There are six main hyperbolic functions:


 * sinhx (the hyperbolic sine)
 * coshx (the hyperbolic cosine)
 * tanhx (the hyperbolic tangent)
 * cothx (the hyperbolic cotangent)
 * sechx (the hyperbolic secant)
 * cschx (the hyperbolic cosecant), also, cosechx

sinh and cosh
Just as in normal trigonometry, the sinh and cosh functions are the fundamental units. They can be replicated with

((([e^ v] of (x)) / (2)) - ((1) / ((2) * ([e^ v] of ((0) - (x))))))

and

((([e^ v] of (x)) / (2)) + ((1) / ((2) * ([e^ v] of ((0) - (x))))))

respectively.

sech and csch
In normal trigonometry, the secant and cosecant are given by 1/cosx and 1/sinx, respectively. The hyperbolic secant and cosecant can be expressed in the same way: sechx = 1/coshx, or:

((2) / (([e^ v] of (x)) + ([e^ v] of ((0) - (x)))))

and cschx = 1/sinhx:

((2) / (([e^ v] of (x)) - ([e^ v] of ((0) - (x)))))

tanh and coth
The tangent function is expressed by sinx/cosx. Similarly, the hyperbolic tangent is expressed by sinhx/coshx. In Scratch, that is:

((([e^ v] of (x)) - ([e^ v] of ((0) - (x)))) / (([e^ v] of (x)) + ([e^ v] of ((0) - (x)))))

Similarly, the cotangent is 1/tanx, so the hyperbolic cotangent is:

((([e^ v] of (x)) + ([e^ v] of ((0) - (x)))) / (([e^ v] of (x)) - ([e^ v] of ((0) - (x)))))

Pythagorean Theorem


This will give the length of the hypotenuse: ( [sqrt v] of (((a) * (a)) + ((b) * (b))))

And these will give the length of sides "a" and "b" (assuming the hypotenuse is "c"): ( [sqrt v] of (((c) * (c)) + ((a) * (a)))) ( [sqrt v] of (((c) * (c)) + ((b) * (b))))

Distance between two Points
The distance between two points can be calculated by using the Distance Formula which is derived from the Pythagorean Theorem, The following is a ScratchBlocks representation of the distance formula. It has been broken into three lines. The distance formula is as follows: $$ set [a v] to ( ((x2) - (x1) ) * ( (x2) - (x1) )) set [b v] to (((y2) - (y1)) * ((y2) - (y1))) set [distance v] to ([sqrt v] of ((a) + (b)))

The distance formula in one line is: <(d) = ([sqrt v] of ((( (x2) - (x1)) * ((x2) - (x1) )) + (( (y2) - (y1)) * ((y2) - (y1) )))>

Where d = distance, x2 = larger x value, x1 = smaller x value, y2 = larger y value, y1 = smaller y value

Midpoint between two Points
The coordinate of the midpoint of a line is found using the midpoint formula, which is as follows (the equation gives a (x,y) paired coordinate): $$ set [x v] to (((x2) + (x1)) / (2)) set [y v] to (((y2) + (y1)) / (2))

Linear Equations
A linear equation is an algebraic equation in which each term is either a constant or the product of a constant and a single variable.

Here is an example of a linear equation: 2x+4=14, for which in standard form would look like this: ((((a) * (x)) + (b)) = (c))

In scratch, we could solve for x using the following script: (((c) - (b)) / (a))

Inputting the values of a, b and c scratch could solve the equation with ease.

Quadratic Formula


These will give the two possible values of "x": ((((b) * (-1)) + ( [sqrt v] of (((b) * (b)) - ((4) * ((a) * (c)))))) / ((2) * (a))) ((((b) * (-1)) - ( [sqrt v] of (((b) * (b)) - ((4) * ((a) * (c)))))) / ((2) * (a)))

In this case these will give you the two possible values of "x":

(join (((b) * (-1)) / ( (2) * (a))) (join (join [+] (([sqrt v] of ((((b) * (b)) - ((4) * ((a) * (c)))) * (-1))) / ((2) * (a)))) [i]))

(join (((b) * (-1)) / ( (2) * (a))) (join (join [-] (([sqrt v] of ((((b) * (b)) - ((4) * ((a) * (c)))) * (-1))) / ((2) * (a)))) [i]))

a≠0. If you plug in a=0, you will receive an invalid solution. As a rule in math, the "a" coefficient in Quadratic equations should not have a value of 0.

Cubic Formula
This will give the answer to the equation:



The analogous formula for this is:



In Scratch this translates to this (scroll the equation to see more):

((([10 ^ v] of (((1) / (3)) * ([log v] of ((((((0) - (((b) * (b)) * (b))) / ((27) * (((a) * (a)) * (a)))) + (((b) * (c)) / ((6) * ((a) * (a))))) - ((d) / ((2) * (a)))) + ([sqrt v] of (((((((0) - (((b) * (b)) * (b))) / ((27) * (((a) * (a)) * (a)))) + (((b) * (c)) / ((6) * ((a) * (a))))) - ((d) / ((2) * (a)))) * (((((0) - (((b) * (b)) * (b))) / ((27) * (((a) * (a)) * (a)))) + (((b) * (c)) / ((6) * ((a) * (a))))) - ((d) / ((2) * (a))))) + ((((c) / ((3) * (a))) - (((b) * (b)) / ((9) * ((a) * (a))))) * ((((c) / ((3) * (a))) - (((b) * (b)) / ((9) * ((a) * (a))))) * (((c) / ((3) * (a))) - (((b) * (b)) / ((9) * ((a) * (a))))))))))))) + ([10 ^ v] of (((1) / (3)) * ([log v] of ((((((0) - (((b) * (b)) * (b))) / ((27) * (((a) * (a)) * (a)))) + (((b) * (c)) / ((6) * ((a) * (a))))) - ((d) / ((2) * (a)))) - ([sqrt v] of (((((((0) - (((b) * (b)) * (b))) / ((27) * (((a) * (a)) * (a)))) + (((b) * (c)) / ((6) * ((a) * (a))))) - ((d) / ((2) * (a)))) * (((((0) - (((b) * (b)) * (b))) / ((27) * (((a) * (a)) * (a)))) + (((b) * (c)) / ((6) * ((a) * (a))))) - ((d) / ((2) * (a))))) + ((((c) / ((3) * (a))) - (((b) * (b)) / ((9) * ((a) * (a))))) * ((((c) / ((3) * (a))) - (((b) * (b)) / ((9) * ((a) * (a))))) * (((c) / ((3) * (a))) - (((b) * (b)) / ((9) * ((a) * (a)))))))))))))) - ((b) / ((3) * (a)))

There are ways to work around Scratch's incapability of calculating complex roots with the aid of the Trigonometric Form of Solutions.

Tetration
Tetration is iterated exponentiation. It is written as ba, a^^b, or a[4]b, where a is the base and b is the height. Tetration is computed by the following procedure: ba=aa ⋰ a, where there are b a's So 42 is 22 2 2  , which is 65536. It can be written in Scratch as:

repeat ((b) - (1)) repeat (a) set [a^^b v] to ((a^^b) * (a)) end end

Here, "a^^b" is your answer. This method only works for whole heights, however, but there is no known algorithm for calculating the value for non-integral heights.

xth root
The xth root of a number n is number that must be multiplied x times to get n. For example, the cube root (3rd root) of 2 (written ∛2) is about 1.2599, because 1.2599*1.2599*1.2599≈2.

A universal formula for finding the xth root of a number can be found using logarithms. To find the x root of n, use the following formula: ([e ^ v] of (([ln v] of (n)) / (x)))

This is based on a method of using exponents and logarithms, which Scratch supports, to find powers, which Scratch does not directly support (see Solving Exponents#Logarithmic Method).

Fourth root, Eighth root, etc.
The fourth root of a number is the number that, when squared twice, gives the original number. The fourth root of 81, for example, is 3. Therefore, it can be replicated in Scratch with this script:

([sqrt v] of ([sqrt v] of (a)))//a is the input number

Similarly, the eighth root of a number is the number, when squared three times, gives the original number. The eighth root of 256, for example, is 2. It can be replicated with this script:

([sqrt v] of ([sqrt v] of ([sqrt v] of (a))))

In general, to get the 2nth root of a number, nest n of  (Operators block) blocks together, and then enter the desired value, or insert a variable.

Physics
This section is for physical constants and equations.

Pick's Theorem
Pick's theorem says that the area of a polygon with integer coordinates can be determined by:

$$

In the equation, a is the number of integer coordinates on the perimeter of the shape, and b is the number of coordinates inside the figure. In Scratch this translates to:

((((a) / (2)) + (b)) - (1))