MathGroup Archive 1999

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

Search the Archive

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

  • To: mathgroup at smc.vnet.net
  • Subject: [mg18056] Re: Help needed: defining a function of a vector variable
  • From: Brian Higgins <bghiggins at ucdavis.edu>
  • Date: Tue, 15 Jun 1999 01:43:18 -0400
  • Delivery-date: Tue Jun 15 10:26:55 1999
  • Organization: Deja.com - Share what you know. Learn what you don't.
  • References: <7jub1a$56u@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

In article <7jub1a$56u at smc.vnet.net>,
  iaz at cs.umd.edu (Ilya Zavorine) wrote:
> 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
>
>

Ilya,

Try this:

M2[d_List]:=DiagonalMatrix[d]

Here is the result for  alist of 2  elements

In[11]:=M2[{a,b}]

Out[11]={{a,0},{0,b}}

and her for  3 elements

In[12]:=M2[{a,b,c}]

Out[12]={{a,0,0},{0,b,0},{0,0,c}}

Ch


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.

  • Prev by Date: Re: A little problem with positive numbers
  • Next by Date: Re: Tips for 4.0 !!
  • Previous by thread: Re: Help needed: defining a function of a vector variable
  • Next by thread: Re: Formatting of Equations