Re: vector pattern?

*To*: mathgroup at smc.vnet.net*Subject*: [mg20277] Re: [mg20258] vector pattern?*From*: "Andrzej Kozlowski" <andrzej at tuins.ac.jp>*Date*: Mon, 11 Oct 1999 02:19:52 -0400*Sender*: owner-wri-mathgroup at wolfram.com

This can't be done in exactly the way you want. If you give a symbol an OwnValue (which is what you are doing when setting v={x,y}) that own value will be evaluated before any other rules which you attach to v. There are various ways in which you can achieve something that comes close to what you want. I will just give a couple that come to my mind, I am sure youwill get more suggestions. One simple way is to set In[1]:= v = {x, y}; and simply write Through[v[t]] rather than v[t] In[2]:= Through[v[t]] Out[2]= {x[t], y[t]} Another possible way is to "cheat". You can format v to "look like" {x,y}: In[3]:= Clear[v] In[4]:= Format[v] := {x, y} In[5]:= v[t_] := {x[t], y[t]} Now indeed everything will look just as you wanted: In[6]:= v Out[6]= {x, y} In[7]:= v[t] Out[7]= {x[t], y[t]} but of course v isn't really a vector now: In[8]:= v + {1, 1} Out[8]= {1 + {x, y}, 1 + {x, y}} Andrzej Kozlowski Toyama International University JAPAN http://sigma.tuins.ac.jp http://eri2.tuins.ac.jp ---------- >From: Susan Hovde <hovde at al.noaa.gov> To: mathgroup at smc.vnet.net >To: mathgroup at smc.vnet.net >Subject: [mg20277] [mg20258] vector pattern? >Date: Sun, 10 Oct 1999 00:04:08 -0400 > > I'd like to define a pattern for a 2D vector v such that > > v = {x,y} and > > v[t] = {x[t],y[t]}. > > I tried > > v[t___] := If[Count[{t},s_]==0,{x,y},{x[t],y[t]}] > > and this gets me _almost_ what I want. I get v[t] = {x[t], y[t]} and > v[] = {x,y}, but when I ask for v, I just get v back. > > I then tried adding > > v := {x,y} > > but then when I ask for v[t] I get {x,y}[t] instead of {x[t],y[t]}. (I > also tried v := v[] with the same result.) I have tried various Hold > functions to try to get v not to be evluated too early, to no avail. > Can someone help me out? > > Susan Hovde > NOAA Aeronomy Lab > Boulder, Colorado > hovde at al.noaa.gov > >