Update
This commit is contained in:
parent
d6459bcdb0
commit
b9e84b9011
12 changed files with 101 additions and 40 deletions
|
@ -1,6 +1,8 @@
|
|||
# Function
|
||||
|
||||
Function is a very basic term in [mathematics](math.md) and [programming](programming.md) with a slightly different meanings in each: mathematical function maps numbers to other numbers, a function in programming is a subprogram to which we divide a bigger program. Well, that's pretty simplified but those are the basic ideas. A more detailed explanation will follow.
|
||||
Function is a very basic term in [mathematics](math.md) and [programming](programming.md) with a slightly different meanings in each, also depending on exact context: mathematical function basically maps [numbers](number.md) to other numbers, a function in programming is similar but is rather seen as a subprogram to which we divide a bigger program. Well, that's pretty simplified but those are the very rough ideas. A more detailed explanation will follow.
|
||||
|
||||
Yet another attempt at quick summary: imagine function as a tiny box. In mathematics you throw numbers (or similar object, for example [sets](set.md)) to the box and it spits out other numbers (or "objects"); the number that falls out always only depends on the number you throw in. So the box basically just transforms numbers into other numbers. In programming a function is similar, it is also a box to which you throw numbers and can behave like the mathematical function, but the limitations are relaxed so the box can also do additional things when you throw a number in it, it may for example light up a light bulb; it may also remember things and sometimes spit out a different number when you throw in the same number twice.
|
||||
|
||||
## Mathematical Functions
|
||||
|
||||
|
@ -10,8 +12,6 @@ In mathematics functions can be defined and viewed from different angles, but it
|
|||
|
||||
Here we call the function *f* and say it takes one [parameter](parameter.md) (the "input number") called *x*. The "output number" is defined by the right side of the equation, *x / 2*, i.e. the number output by the function will be half of the parameter (*x*). The domain of this function (the set of all possible numbers that can be taken as input) is the set of [real numbers](real_number.md) and the codomain is also the set of real numbers. This equation assigns each real number *x* another real number *x / 2*, therefore it is a function.
|
||||
|
||||
{ I always imagined functions as kind of little boxes into which we throw a number and another number falls out. ~drummyfish }
|
||||
|
||||
Now consider a function *f2(x) = 1 - 1 / x*. Note that in this case the domain is the set of real numbers minus [zero](zero.md); the function can't take zero as an input because we can't divide by zero. The codomain is the set of real numbers minus one because we can't ever get one as a result.
|
||||
|
||||
Another common example of a function is the [sine](sin.md) function that we write as *sin(x)*. It can be defined in several ways, commonly e.g. as follows: considering a [right triangle](right_triangle.md) with one of its angles equal to *x* [radians](radian.md), *sin(x)* is equal to the ratio of the side opposing this angle to the triangle [hypotenuse](hypotenuse.md). For example *sin(pi / 4) = sin(45 degrees) = 1 / sqrt(2) ~= 0.71*. The domain of sine function is again the set of real number but its codomain is only the set of real numbers between -1 and 1 because the ratio of said triangle sides can never be negative or greater than 1, i.e. sine function will never yield a number outside the interval <-1,1>.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue