MathGroup Archive 2009

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

Search the Archive

Re: vector and matrix valued functions

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105849] Re: vector and matrix valued functions
  • From: David Bailey <dave at removedbailey.co.uk>
  • Date: Mon, 21 Dec 2009 06:57:18 -0500 (EST)
  • References: <hgfom4$g3q$1@smc.vnet.net>

Daniel wrote:
> Hello,
> 
> I am working with functions that have vector and matrix valued
> arguments. I'd like to postpone going to a component representation as
> late as possible, but that is not easy because some vectors are
> already in the component form and this gives me error messages from
> cross and times.
> 
> One example: I have several vector valued quantities x,y,z  (let's say
> 100 dimensional).
> I'd like to write all expressions in the form
> f[x_,y_]:=x.y
>  instead of
> f[x1_,x2_,...,_x100,y1_,...]:=...
> 
> The problem is, that in the first case the system does not know it is
> dealing with 100 dimensional vectors.
> 
> g[x_] :=5  x
> Cross[g[a] , {1, 0, 0}]
> should give me  something like g[a] x {1,0,0}, e.g. stay unevaluated
> or alternatively be evaluated in component form {0, 5 a3, - 5 a2}.
> 
> Instead I get an error message:
> Cross::nonn1: The arguments are expected to be vectors of equal
> length, and the number of arguments is expected to be 1 less than
> their length
> 
> In addition, I'd like to write the gradient of a function with one or
> several vector arguments, i.e. something like
> gradient_y f,
> which should be a vector with the components df/dy_i, i.e. D[f[x,y],
> {{y1,y2,y3,...y100}}]. This does not work either, because the system
> does not now that y is in reality {y1,..,y100}
> 
> 
> How can I deal naturally with vectors, e.g. have vector valued
> variables as function arguments and return values, use the usual
> vector functions (cross, dot, grad, div, rot), and diff with respect
> to a vector.
> 
> Many thanks
> 
> 
> Dan
> 

Really, you are asking how to do abstract algebra using Mathematica.

The best way to do work like that, is to use some of the unassigned 
operators - such as \[CircleTimes] to represent operators such as Cross. 
These are inert, but you can give them the attributes that you require 
(SetAttributes) - say to make them associative - and you can write 
definitions that describe what they should do. You can also define 
(usually recursive) functions that act on expressions of this sort.

When the time comes that you want to go to a fully component 
representation and evaluate the result, you can simply replace 
\[CicleTimes] by Cross (say).

Likewise, I would define your own differentiation operator - say DD - so 
you can define exactly what it does, and then switch to standard 
Mathematica differentiation when everything has been reduced to components.

Of course, there may well be packages out there that do all this for the 
sorts of problems you are interested in.

David Bailey
http://www.dbaileyconsultancy.co.uk


  • Prev by Date: Re: MathematicaMark7 compare with AMD 3.2 GHz
  • Next by Date: intersection of two circles
  • Previous by thread: Re: vector and matrix valued functions
  • Next by thread: What's up with the order of Eigenvalues