| Line 1: |
Line 1: |
| | A '''function''' f is a rule for taking one item x, as an input, and producing another item f(x) as an output. Frequently this will involve numbers, so for example the [[polynomial]] <math>f(x) = x^2</math> takes numbers as inputs, and outputs their squares. So in this case, if 1 is input, 1 is output, whilst if 2 is input, 4 is output. However, there are functions that take other objects as inputs. For example, rotation can be thought of as a function that takes a shape as an input, and outputs that shape rotated by a certain number of degrees. | | A '''function''' f is a rule for taking one item x, as an input, and producing another item f(x) as an output. Frequently this will involve numbers, so for example the [[polynomial]] <math>f(x) = x^2</math> takes numbers as inputs, and outputs their squares. So in this case, if 1 is input, 1 is output, whilst if 2 is input, 4 is output. However, there are functions that take other objects as inputs. For example, rotation can be thought of as a function that takes a shape as an input, and outputs that shape rotated by a certain number of degrees. |
| | | | |
| − | Usually, a function will be written with a formula for the output, in terms of the input. For example, in the case of f above, the formula is <math>f(x) = x^2</math>. When we want to input a particular value, we insert in in the place of x. So <math>f(1) = 1^2 = 1*1 = 1</math>. | + | Usually, a function will be written with a formula for the output, in terms of the input. For example, in the case of f above, the formula is <math>f(x) = x^2</math>. When we want to input a particular value, we insert it in the place of x. So <math>f(1) = 1^2 = 1*1 = 1</math>. |
| | | | |
| | ==Examples== | | ==Examples== |
| Line 11: |
Line 11: |
| | Some functions do not have numbers as outputs. For example, we can define a function pres that takes a number n, and returns the name of the nth [[President_of_the_United_States_of_America| American President]]. So, pres(1) = [[George Washington]] (the first president), pres(2) = [[John Adams]] (the second president), and so on. | | Some functions do not have numbers as outputs. For example, we can define a function pres that takes a number n, and returns the name of the nth [[President_of_the_United_States_of_America| American President]]. So, pres(1) = [[George Washington]] (the first president), pres(2) = [[John Adams]] (the second president), and so on. |
| | | | |
| − | Similarly, not all functions take numbers as inputs. For example, we can define a function pres2 that takes the name of an American President (the nth in sequence), and outputs n. Thus pres2(George Washington) = 1, pres2(John Adams) = 2. This is the reverse of pres defined above. | + | Similarly, not all functions take numbers as inputs. For example, we can define a function pres2 that takes the name of an American President (the nth in sequence), and outputs n. Thus pres2(George Washington) = 1, pres2(John Adams) = 2. This is the inverse of pres defined above. |
| | | | |
| | ==Composition== | | ==Composition== |