Content deleted Content added
m Automated conversion |
m added links, bolded 'x', other minor edits |
||
Line 1:
A variable is something that's subject to change. In computer and mathematic terms, it denotes a name that's used in place of an unknown value.
In [[mathematics]], variables are usually represented by letters of the [[Roman alphabet]], but also may be represented by letters of other [[alphabet]]s or any other unambiguous symbol. In [[computer programming]], variables are usually represented by single letters or by alphanumeric strings.
For instance, in the formula: x + 1 = 5, x is the variable since it's an unknown value.▼
▲For instance, in the formula: '''x''' + 1 = 5, '''x''' is the variable since it's an unknown value.
Variables are useful in mathematics and [[computer programming]] because they allow instructions to be specified in a general way. If one were forced to use actual values, then the instructions would only apply in those cases.
For instance, by using variables, we can specify a mathematical definition for finding the square of ANY number: square('''x''') = '''x''' * '''x'''.
Now, all we need to do to find the square of a number is replace '''x''' with any number we want. For example:
:square(1) = 1 * 1 = 1
Line 14 ⟶ 16:
etc...
In short, the variable '''x''' becomes a place holder for ANY number.▼
One important thing we're assuming is that the value of each occurrence of '''x''' is the same -- that '''x''' doesn't get a new value between the first '''x''' and the second '''x'''. In computer programming, this isn't always the case, which makes it difficult to reason about programs.▼
▲In short, the variable x becomes a place holder for ANY number.
▲One important thing we're assuming is that the value of each occurrence of x is the same -- that x doesn't get a new value between the first x and the second x. In computer programming, this isn't always the case which makes it difficult to reason about programs.
|