Re: Help needed: defining a function of a vector variable
- To: mathgroup at smc.vnet.net
- Subject: [mg18072] Re: [mg18016] Help needed: defining a function of a vector variable
- From: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>
- Date: Tue, 15 Jun 1999 01:43:31 -0400
- Delivery-date: Tue Jun 15 05:15:11 1999
- Sender: owner-wri-mathgroup at wolfram.com
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
In[1]:=
functionarray[d_,n_] := Array[d,n]
Now, define a value for d (define it to be a function):
In[2]:=
d[x_]:=x^2
This creates a vector values function:
In[3]:=
functionarray[d,3]
Out[3]=
{1, 4, 9}
You can also assign values to individual components:
In[4]:=
d[2]=5;functionarray[d,3]
Out[4]=
{1, 5, 9}
--
Andrzej Kozlowski
Toyama International University
JAPAN
http://sigma.tuins.ac.jp
http://eri2.tuins.ac.jp
----------
>From: iaz at cs.umd.edu (Ilya Zavorine)
To: mathgroup at smc.vnet.net
>To: mathgroup at smc.vnet.net
>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
function
> 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
matrix
> 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