## VBA: Math

Calculating the integral of sin(x) from 0 to Pi * The integral of a mathematic function is another function to calculate the net surface of the first with regard to the x-axis. I'm just saying this in my own words (and still it might sound complicated) but the concept is simple.
Example. Say you have diagonal line that starts on the 0 point (where x-axis and y-axis cross) The corresponding function is: y = x
Now let's say we cut of the line when x=3 (upper limit), what is the surface under the line with regard to the x-asix? The answer is easy; its half of the square 3x3 so the answer is 4.5
The integral function of y = x is y(int) = 0.5x^2
If you enter 3 in the formula you'll see that you get 4.5 as the answer. We already figured that out of course but what if you have very complex functions? It would be hard, sometimes even impossible, to determine the integral function. In those situations we can revert to using iteration.
The concept of iteration is in beginning exactly the same as calculating the integral; we slice the the surface up into small rectangles that start on x with width dx (x+dx)and length y(=x). We then add up the surfaces of all rectangels to approximate the total surface .
Example, say we slice up the the above function into three rectangles. The first runs from 0 to 1 and has height 0 (height at the beginning of the width). The second rectangle runs from 1 to 2 and has height 1, the third runs from 2 to 3 and has height 2. Add it up: 0 + 1 + 2 = 3. Not even close to 4.5 but if you slice up the surface into more rectangles the answer will get closer to the real value. For example, if you used 6 rectangles you'd get 0 + 0.25 + 0.5 + 0.75 + 1 + 1.25 = 3.75. The more slices you make (=iterations) the better the result will be.
This article demonstrates the use of an iterating function.*

Counting how many times a sum of x draws from a collection of y values equals z * Imagine a range of y numbers on a worksheet. How many combinations of x draws are there where the sum of the draws equals a total of z? This function counts the occurrences.*

SINC function (sinus cardinalis also known as cardinal sine, interpolation function, filtering function or sampling function) * This is a very simple function to calculate a sinc of a number. It's used in signal analysis. *

Two functions to calculate a factorium (n!) * These are two functions to calculate a factorium. The first functions works with a loop, the second is a recursive function (calls itself). *

Calculate and display permutations * This sub calculates all permutations of a 3 number draw from a collection and writes them as text in the active worksheet.
*