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: [mg105844] Re: vector and matrix valued functions
  • From: dh <dh at metrohm.com>
  • Date: Mon, 21 Dec 2009 06:54:42 -0500 (EST)
  • References: <hgfom4$g3q$1@smc.vnet.net>


Hi Daniel,

  Cross[a,{1,2,3}] Cross gives an error message but leaves the 

expression unevaluated as you require. Well, you may eliminate the 

message by e.g. using Quiet or you may define your own Cross that only 

evaluates for vector arguments:

Cross[x1_?VectorQ, x2_?VectorQ] := Cross[x1, x2]

Note that if you have n dimensions, Cross needs n-1 arguments!



You may also define your own symbolic gradient that only evaluates if 

you give an explicite vector:



myGrad[f_[x_?VectorQ]] := Table[Derivative[i] f[x], {i, Length[x]}]



Daniel (Huber)







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

> 




  • Prev by Date: Re: Marbles.nb [was Re: CellChangeTimes?]
  • Next by Date: Twitter.m (Twittering With Mathematica) broken?
  • Previous by thread: vector and matrix valued functions
  • Next by thread: Re: vector and matrix valued functions