If 指令
来自GeoGebra Manual
Pegasusroe(讨论 | 贡献)2012年9月16日 (日) 18:03的版本
本頁為官方文件,一般使用者無法修改,若有任何誤謬,請與官方聯絡。如欲編輯,請至本頁的開放版。
- If[ <Condition>, <Then> ]
- If[ <Condition>, <Then>, <Else> ]
CAS 視窗
- If[ <Condition>, <Then> ]
- If[ <Condition>, <Then>, <Else> ]
- 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.
注意: | Both objects must be of the same type. |
條件式函數
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.
範例:
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 x ≥ 3 or x ≤ 0.
備註: See section: 真假值 for the symbols used in conditional statements.
備註: Derivative of If[condition, f(x), g(x)] gives If[condition, f'(x), g'(x)]. It does not do any evaluation of limits at the critical points.
同時限制函數的定義域與值域
範例:
f(x) =If[ 0<x^2<3,x^2]
將值域限制在 0 與 3 之間。f(x) = If[ -2<x<3∧-4<tan(x)<4,tan(x)]
將定義域限制在 -2 到 3,值域限制在 -4 到 4 之間。
If Command in Scripting
In many programming languages if is has the meaning "If condition holds, do something; otherwise do something else". In GeoGebra, arguments of If are not commands, but values, one of which becomes the value of the result. Therefore
if you want to e.g. set value of b to 2 provided a > 2, correct way to do this is SetValue[b,If[a>2,2,b]]
. The other way of nesting SetValue and If is incorrect.
Comments
同時限制函數的定義域與值域[编辑]
- 範例:
f(x) = If[ 0<x^2<3,x^2]
將值域限制在 0 與 3 之間。f(x) = If[ -2<x<3∧-4<tan(x)<4,tan(x)]
將定義域限制在 -2 到 3,值域限制在 -4 到 4 之間。