8.3.3 Defining algebraic functions
Defining a function from ℝp to ℝq.
If expr is an expression possibly involving a variable
x, use it to define a function f either by
f(x):=expr
or
f:=x->expr
(see Section 3.4.1).
Note that the expression after -> is not evaluated. You should use
unapply (see Section 8.2.2) if you expect the second
member to be evaluated before the function is defined.
Example
To define f(x)=xsin(x), input:
or:
Then:
You can similarly define a function of several variables, by replacing
x by a sequence (x1,…,xp)
or a list [x1,…,xp] of variables.
Example
To define f(x)=xsin(y), input:
or:
Then:
You can also define a function with values in ℝq by
replacing expr by a sequence
(expr1,…,exprq) or list
[expr1,…,exprq] of
expressions.
Examples
Define the function h(x,y)=(xcos(y),xsin(y)).
h(x,y):=(x*cos(y),x*sin(y)) |
Then:
Define the function h(x,y)=[xcos(y),xsin(y)].
h(x,y):=[x*cos(y),x*sin(y)]; |
or:
h:=(x,y)->[x*cos(y),x*sin(y)]; |
or:
h(x,y):={ [x*cos(y),x*sin(y)] }; |
or:
h:=(x,y)->return [x*cos(y),x*sin(y)]; |
or:
h(x,y):={ return [x*cos(y),x*sin(y)]; } |
Then:
Defining families of function from ℝp−1 to ℝq using a function from ℝp to ℝq.
Suppose that the function f: (x,y) → f(x,y) is defined,
and you want to define a family of functions g(t) such that
g(t)(y):=f(t,y) (i.e. t is viewed as a parameter). Since the
expression after -> (or :=) is not evaluated, you
should not define g(t) by g(t):=y->f(t,y); you have to use
the unapply command (see Section 8.2.2).
For example, to define f:(x,y)→ xsin(y) and
g(t):y→ f(t,y):
f(x,y):=x*sin(y); g(t):=unapply(f(t,y),y) |
then:
As another example, suppose that you want to define the function h:
(x,y) → [xcos(y),xsin(y)] and then you want to define
the family of functions k(t) having t as parameter such that
k(t)(y):=h(t,y). To define the function h(x,y):
h(x,y):=(x*cos(y),x*sin(y)) |
To define properly the function k(t):
then:
|
x↦ | ⎛
⎝ | x cos | ⎛
⎝ | 2 | ⎞
⎠ | ,x sin | ⎛
⎝ | 2 | ⎞
⎠ | ⎞
⎠ |
| | | | | | | | | | |
|