Sponsored links: Algebra eBooks
 

Help Index

A

B

C

D

E

F

G

H

I

J

K

L

M

N

O

P

Q

R

S

T

U

V

W

X

Y

Z

The Maxima on-line user's manual

Algebra Calculator

Search:

Define Calculator

Define

Function: define (<f>(<x_1>, ..., <x_n>), <expr>)

define(f(x), (x^3+x-13)/(5*x^3));
float(f(-6));

Function: define (<f>[<x_1>, ..., <x_n>], <expr>)

Function: define (funmake (<f>, [<x_1>, ..., <x_n>]), <expr>)

Function: define (arraymake (<f>, [<x_1>, ..., <x_n>]), <expr>)

Function: define (ev (<expr_1>), <expr_2>) Defines a function named <f> with arguments <x_1>, ..., <x_n> and function body <expr>. define always evaluates its second argument (unless explicitly quoted). The function so defined may be an ordinary Maxima function (with arguments enclosed in parentheses) or an array function (with arguments enclosed in square brackets).

When the last or only function argument <x_n> is a list of one element, the function defined by define accepts a variable number of arguments. Actual arguments are assigned one-to-one to formal arguments <x_1>, ..., <x_(n - 1)>, and any further actual arguments, if present, are assigned to <x_n> as a list.

When the first argument of define is an expression of the form <f>(<x_1>, ..., <x_n>) or <f>[<x_1>, ..., <x_n>], the function arguments are evaluated but <f> is not evaluated, even if there is already a function or variable by that name.

When the first argument is an expression with operator funmake, arraymake, or ev, the first argument is evaluated; this allows for the function name to be computed, as well as the body.

All function definitions appear in the same namespace; defining a function f within another function g does not automatically limit the scope of f to g. However, local(f) makes the definition of function f effective only within the block or other compound expression in which local appears.

If some formal argument <x_k> is a quoted symbol (after evaluation), the function defined by define does not evaluate the corresponding actual argument. Otherwise all actual arguments are evaluated.

See also := and ::=.

Examples:

define always evaluates its second argument (unless explicitly quoted).

          (%i1) expr : cos(y) - sin(x);
          (%o1)                    cos(y) - sin(x)
          (%i2) define (F1 (x, y), expr);
          (%o2)              F1(x, y) := cos(y) - sin(x)
          (%i3) F1 (a, b);
          (%o3)                    cos(b) - sin(a)
          (%i4) F2 (x, y) := expr;
          (%o4)                   F2(x, y) := expr
          (%i5) F2 (a, b);
          (%o5)                    cos(y) - sin(x)

The function defined by define may be an ordinary Maxima function or an array function.

          (%i1) define (G1 (x, y), x.y - y.x);
          (%o1)               G1(x, y) := x . y - y . x
          (%i2) define (G2 [x, y], x.y - y.x);
          (%o2)                G2     := x . y - y . x
                                 x, y

When the last or only function argument <x_n> is a list of one element, the function defined by define accepts a variable number of arguments.

          (%i1) define (H ([L]), (apply ("+", L)));
          (%o1)                H([L]) := apply("+", L)
          (%i2) H (a, b, c);
          (%o2)                       c + b + a

When the first argument is an expression with operator funmake, arraymake, or ev, the first argument is evaluated.

          (%i1) [F : I, u : x];
          (%o1)                        [I, x]
          (%i2) funmake (F, [u]);
          (%o2)                         I(x)
          (%i3) define (funmake (F, [u]), cos(u) + 1);
          (%o3)                  I(x) := cos(x) + 1
          (%i4) define (arraymake (F, [u]), cos(u) + 1);
          (%o4)                   I  := cos(x) + 1
                                   x
          (%i5) define (foo (x, y), bar (y, x));
          (%o5)                foo(x, y) := bar(y, x)
          (%i6) define (ev (foo (x, y)), sin(x) - cos(y));
          (%o6)             bar(y, x) := sin(x) - cos(y)

There are also some inexact matches for define. Try ?? define to see them.

(%o1)                                true
(%i2) 

Define Example

Related Examples

define-diff-expand-float-realroots-rhs

define(c(x),60-3*x);

define(B(x),expand(x^...

define(Bp(x),diff(B(x...

Calculate

define-plot2d
plot2d(r(x), [x, -5, 5]);

define(n(x), x^3 + 3*...

define(d(x), x^3 + 13);

define(r(x), n(x)/d(x));

Calculate

define-float-pi-plot2d
plot2d(r(x), [x,-5,5], [y,-10,10]);

define(f(x), x^3 + 3*...

define(g(x), x^3 + 13);

define(r(x), f(x)/g(x));

Calculate

define-float

define(r(x), (x^3 - 5...

a: 0;

b: 1;

Calculate

define-float-realroots

define (n(x), (x^3+2*...

define (d(x), (x^4- 4...

c: realroots (n(x)=0);

Calculate

define

define(f(x), (4*x^2+7...

Calculate

define-diff-expand-float-plot2d-realroots
plot2d(f(x),[x,-10,10], [y,-10,10]);

define(f(x), (x^3 + x...

float(f(-6));

plot2d(f(x),[x,-10,10...

Calculate

define-load-matrix-sqrt

load(vect);

m1:matrix([0],[1],[1]);

define(magn(a),sqrt(a...

Calculate

define-float-pi-realroots

define(n(x), x^3+3*x^...

define (d(x), x^3+13);

define (r(x), n(x)/d(...

Calculate

define-exp-quad_qag

define(F(s),(mu-x*s)/...

quad_qag(f(0.01+%i*s)...

Calculate