Difference between revisions of "If Command"
From GeoGebra Manual
(one more example) |
|||
Line 8: | Line 8: | ||
The ''If'' command can be used to create conditional functions. Such conditional functions may be used as arguments in any command that takes a function argument, such as [[Derivative Command|Derivative]], [[Integral Command|Integral]], and [[Intersect Command|Intersect]]. | The ''If'' command can be used to create conditional functions. Such conditional functions may be used as arguments in any command that takes a function argument, such as [[Derivative Command|Derivative]], [[Integral Command|Integral]], and [[Intersect Command|Intersect]]. | ||
− | {{Example| | + | {{Example| |
− | * <code>f(x) = If[x < 3, sin(x), x^2]</code> yields a function that equals ''sin(x)'' for ''x < 3'' and ''x<sup>2</sup>'' for ''x ≥ 3'' | + | * <code>f(x) {{=}} If[x < 3, sin(x), x^2]</code> yields a function that equals ''sin(x)'' for ''x < 3'' and ''x<sup>2</sup>'' for ''x ≥ 3'' |
− | * <code>f(x) = If[x < 3 ∧ x>0, x^3]</code> yields a function that equals ''sin(x)'' for x between 0 and 3 and undefined for for ''x ≥ 3'' or ''0 ≥ x''.}} | + | * <code>f(x) {{=}} If[x < 3 ∧ x>0, x^3]</code> yields a function that equals ''sin(x)'' for x between 0 and 3 and undefined for for ''x ≥ 3'' or ''0 ≥ x''.}} |
{{note|See section: [[Boolean values]] for the symbols used in conditional statements.}} | {{note|See section: [[Boolean values]] for the symbols used in conditional statements.}} |
Revision as of 14:41, 27 February 2011
- If[Condition, Object]
- Yields a copy of the object if the condition evaluates to true, and an undefined object if it evaluates to false.
- If[Condition, Object a, Object b]
- Yields a copy of object a if the condition evaluates to true, and a copy of object b if it evaluates to false.
Warning: | Both objects must be of the same type. |
Conditional Functions
The If command can be used to create conditional functions. Such conditional functions may be used as arguments in any command that takes a function argument, such as Derivative, Integral, and Intersect.
Example:
f(x) = If[x < 3, sin(x), x^2]
yields a function that equals sin(x) for x < 3 and x2 for x ≥ 3f(x) = If[x < 3 ∧ x>0, x^3]
yields a function that equals sin(x) for x between 0 and 3 and undefined for for x ≥ 3 or 0 ≥ x.
Note: See section: Boolean values for the symbols used in conditional statements.