Defining algebraic functions

### 5.16.3 Defining algebraic functions

#### Defining a function from ℝp to ℝq

If expr is an expression possibly involving a variable x, you can use it to define a function f either by
f(x):=expr
or f := x->expr
(see Section 4.5.1).

Warning!!!
The expression after -> is not evaluated. You should use unapply (see Section 5.15.2) if you expect the second member to be evaluated before the function is defined.

#### Example.

To define f:(x)→ x*sin(x),
Input:

f(x):=x*sin(x)

or:

f:=x->x*sin(x)

then:

f(pi/4)

Output:

π | √ |
2
8

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.

Input:

f(x,y):=x*sin(y)

or:

f:=(x,y)->x*sin(y)

then:

f(2,pi/6)

Output:

1

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)→ (x*cos(y),x*sin(y)).
  Input:
  h(x,y):=(x*cos(y),x*sin(y))
  then:
  h(2,pi/4)
  Output:

  √ |
  2
  | , | √ |
  2

- Define the function h (x,y)→ [x*cos(y),x*sin(y)].
  Input:
  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:
  h(2,pi/4)
  Output:

  ⎡ ⎢ ⎣ | √ |
  2
  | , | √ |
  2
  | ⎤ ⎥ ⎦

#### 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 5.15.2).

For example, to define f:(x,y)→ xsin(y) and g(t):y→ f(t,y):
Input:

f(x,y):=x*sin(y);g(t):=unapply(f(t,y),y)

then:

g(2)

Output:

y↦ 2 siny

Input:

g(2)(1)

Output:

2 sin | ⎛ ⎝ | 1 | ⎞ ⎠

For another example, suppose that you want to define the function h: (x,y) → [x*cos(y),x*sin(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)
Input:

h(x,y):=(x*cos(y),x*sin(y))

To define properly the function k(t): Input:

k(t):=unapply(h(x,t),x)

then:

k(2)

Output:

x↦ | ⎛ ⎝ | x cos | ⎛ ⎝ | 2 | ⎞ ⎠ | ,x sin | ⎛ ⎝ | 2 | ⎞ ⎠ | ⎞ ⎠

(x)->(x*cos(2),x*sin(2))

Input:

k(2)(1)

Output:

cos | ⎛ ⎝ | 2 | ⎞ ⎠ | ,sin | ⎛ ⎝ | 2 | ⎞ ⎠