MathGroup Archive 2007

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

Search the Archive

Re: Symbolic vector handling

> Hello group,
> this is most probably a very simple question but still ...
> Consider a set of vectors vA, vB, vC, ... and scalars a, b, c, ...
> What I want to do is a symbolic handling of expressions like vA.(b vB +
> vC)
> which should be expanded to
> (1)    expr = vA.(b vB + vC) -> b vA.vB + vA.vC
> i.e. I want Mathematica to apply the distributive law and the
> extraction of scalars.
> I don't want to use any coordinate representation.
> The first thing that comes into mind would be to define a type "vector"
> and another type "scalar" and then define the usual rules.
> I'd like to execute a comand like
>     FunctionExpand[ expr , Assumptions->{{vA, vB, vC} "elem" vectors,
> {a,b,c} "elem" scalars}]
> Here's an example of a simple problem in which my question arises:
> Let the vectors vR1 and vR2 be defined in terms of four other vectors
> vA1, vA2, vN1, vN2 and two scalars a and b as follows:
> vR1 = vA1 + a vN1
> vR2 = vA2 + b vN2
> and consider the function
> U = (vR1 - vR2).(vR1 - vR2)
> The task is to find the minimum of U in terms of a combination of
> scalar product of the vectors vA1, vA2, vN1, vN2 and of the optimizing
> parameters a and b.
> Any help is greatly appreciated.
> Regards,
> Wolfgang

There are probably a few reasonable ways to go about this. One is to use a
special vector "head" and define rules for handling distribution involving
Plus, Times, and whatever else might be of relevance. I encapsulate your
vectors with vec[].

I find it convenient to move to a new function, myDot, for purposes of
intermediate computation. This avoids placing new behavior on Dot itself.

myDot[a_] /; Head[a] =!= vec := a
myDot[x___, y_Plus, z___] := Map[myDot[x, #, z] &, y]
myDot[x___, y_Dot, z___] := myDot[x, Apply[Sequence, y], z]
myDot[x___, y_Times, z___] := myDot[x, Apply[Sequence, y], z]
myDot[x___, y_myDot, z___] := myDot[x, Apply[Sequence, y], z]
myDot[] = 1;
myDot[x___, y_, z___] /; Head[y] =!= vec := y*myDot[x, z]

DotExpand[expr_] := (expr /. Dot -> myDot) /. myDot -> Dot

In[54]:= DotExpand[vec[vA].(b*vec[vB] + vec[vC])]

Out[54]= b vec[vA].vec[vB] + vec[vA].vec[vC]

The above myDot is an alteration of some code I cribbed from the section
"Some noncommutative algebraic manipulation" in the 1998 conference
notebook at:

Daniel Lichtblau
Wolfram Research

  • Prev by Date: Re: memory release problem in mathematica6.0
  • Next by Date: Re: Basic Question about Mathematica
  • Previous by thread: Symbolic vector handling
  • Next by thread: Re: Symbolic vector handling