Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2006
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2006

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

Search the Archive

Re: Symbolic vectors possible?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg65967] Re: [mg65946] Symbolic vectors possible?
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Tue, 25 Apr 2006 05:18:35 -0400 (EDT)
  • References: <200604241001.GAA08929@smc.vnet.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 24 Apr 2006, at 19:01, Vladimir wrote:

> Colleagues,
>
> Is it possible to create functions in Mathematica
> for manipulating expressions with symbolic vectors?
> Just like we do on paper, without representing them with lists.
> Something like the following for Dot and similar for Cross:
>
> In[] := vectors = { v, u, w }; (* these symbols should be treated as
> vectors *)
>
> In[] := VectorExpand[(a v + b u) . w]
> Out[] = a v.w + b u.w
>
> In[] := VectorFactor[a v.w + b u.w]
> Out[] = (a v + b u) . w
>
> In[] := VectorSimplify[v.v + 2 v.u + u.u]
> Out[] = (v + u) . (v + u)
>
> To get the above results, simple replacement rules would suffice,
> but the real challenge is to make it work for any expression.
> Do you have any ideas?
>
> --
> Vladimir
>

One possible way is to use an idea which I have already described in  
several postings. Namely: you specify your symbolic scalars and make  
everything else a vector (you could also specify vectors, as you seem  
to prefer, but I think specifying the scalars works more nicely). To  
specify the symbolic scalars I like to use the predicate NumericQ,  
which has some nice undocumented properties, which I have also  
written about before.

So, we make a general rule like this:

VectorExpand[(a_?NumericQ v_ + b_?NumericQ *u_) . w_] := a v.w + b u.w

Which of course means that, for example:

In[8]:=
VectorExpand[(2 v+ 3  w).x]

Out[8]=
2 v.x+3 w.x

but, we can also specify the symbols a and by to be scalars by;

NumericQ[a] = True; NumericQ[b] = True;


VectorExpand[(a v+ b  w).x]


a v.x+b w.x

As a bonus you get things like:


VectorExpand[(a^2*v + b^2*w) . x]

a^2*v . x + b^2*w . x

which makes use of one of those "nice properties" of NumericQ. You  
can deal with the other rules in the same way.

The alternative approach would be to define your own predicate  
vectorQ (note that VectorQ is already taken) and define rules for  
vectorQ of the form

vectorQ[a_ v_ + b_ w_]/;vectorQ[v]&&vectorQ[w] := True

and then make the rules for Dot product work with symbols for which  
vectorQ returns True and any with anything else treated as scalars.    
Or you could require  (I think this is probably the best approach)  
both symbolic vectors to satisfy vectorQ == True  and symbolic  
scalars to satisfy NumericQ = True, with everything else leaving the  
rules undefined.

Andrzej Kozlowski

Tokyo, Japan







  • Prev by Date: Re: Troubles in NonlinearFit-Why always failed?
  • Next by Date: Re: Width of plots
  • Previous by thread: Symbolic vectors possible?
  • Next by thread: Re: Symbolic vectors possible?