MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Help needed: defining a function of a vector variable

If I understad correctly what you would liketo happen then your last idea 
works fine except that you must use := and not = in your definition.

More explicitely, define the function functionarray by

functionarray[d_,n_] := Array[d,n]

Now, define a value for d (define it to be a function):


This creates a vector values function:

{1, 4, 9}

You can also assign values to individual components:

{1, 5, 9}

Andrzej Kozlowski
Toyama International University

>From: iaz at (Ilya Zavorine)
To: mathgroup at
>To: mathgroup at
>Subject: [mg18072] [mg18016] Help needed: defining a function of a vector variable
>Date: Sun, Jun 13, 1999, 4:52 AM

> Suppose I have an object (e.g. a matrix) which I want to consider as a
> of several variables. For instance, suppose the matrix is diagonal of size
> N and the
> variables are its diagonal elements. Logically I can also consider the same
> as a function of a single N-vector variable which would contain the
> diagonal elements.
> How should I define my matrix? Whatever the definition is, it has to satisfy 2
> requirements:
> (1) I need to be able to assign values both to specific variables and to the
> whole vector.
> (2) The definition should be the same for any N, i.e. if I want to go from
> N = 2 to N = 3
> or even to N = 10, I do not want to rewrite the whole thing from scratch.
> One way of defining a matrix would be something like this:
> M[d1_,d2_,d3_] = DiagonalMatrix[{d1,d2,d3}];
> Clearly, this type of definition does not really satisfy either requirement
> since it is
> difficult to assign a value to the vector {d1,d2,d3} as a whole. Also, this
> definition
> has to be rewritten every time I change N.
> I've also tried doing something like this:
> Size = 3;
> M[d_] = Array[d,Size];
> This satisfies (2) but not (1). In fact Mathematica does not seem to relate
> the variable d
> in the left-hand side of the definition to the variable d inside Array.
> Is there a better way of doind this?
> Thanks for any help,
> Ilya

  • Prev by Date: Re: Mathematical question: Exponetial function
  • Next by Date: Re: Formatting of Equations
  • Previous by thread: Re: Mathematical question: Exponetial function
  • Next by thread: Re: Help needed: defining a function of a vector variable