MathGroup Archive 2014

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

Search the Archive

Re: Simple question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg132204] Re: Simple question
  • From: "djmpark" <djmpark at comcast.net>
  • Date: Thu, 16 Jan 2014 01:54:24 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Delivered-to: l-mathgroup@wolfram.com
  • Delivered-to: mathgroup-outx@smc.vnet.net
  • Delivered-to: mathgroup-newsendx@smc.vnet.net
  • References: <732260.3114.1389777827422.JavaMail.root@m03>

You could use a set of rules which you could write by hand, but here is a
method to automatically generate them.

generateRules[symbol_Symbol, vars : {_Symbol ..}] :=
 Module[{base = SymbolName[symbol], onestrings = ToString /@ vars, 
   twostrings, twotuples, fstring, fname, ffunc, zerorule, onerules, 
   tworules},
  fstring = StringTake[base, 1];
  fname = Symbol[fstring];
  ffunc = fname @@ vars;
  zerorule = Symbol[base] -> ffunc;
  onestrings = base <> # & /@ onestrings;
  onerules = 
   Symbol[#] -> D[ffunc, Symbol[StringTake[#, -1]]] & /@ onestrings;
  twotuples = Tuples[vars, 2];
  twostrings = 
   StringJoin[base, ##] & @@@ Map[ToString, twotuples, {-1}];
  tworules = 
   Thread[Symbol /@ twostrings -> (D[ffunc, Sequence @@ #] &) /@ 
      twotuples];
  Flatten[{zerorule, onerules, tworules}]
  ]

caseRules = generateRules[Ue, {x, y, z, t}];

For the replacement:

K11 Ue + (K12 - K21) Uex +  K22 Uexx + (K23 + K32) Uexy + (K13 - K31) Uey +
K33 Ueyy /.  caseRules


David Park
djmpark at comcast.net 
http://home.comcast.net/~djmpark/index.html 




From: KFUPM [mailto:hussain.alqahtani at gmail.com] 


Dear  All

I have a long expression. Below is just a short part of it:

K11 Ue + (K12 - K21) Uex +
 K22 Uexx + (K23 + K32) Uexy + (K13 - K31) Uey + K33 Ueyy

I want to replace Ue->U[x,y,z,t]. and Uex->D[U[x,y,z,t],x] and
Uexy->D[U[x,y,z,t],{x,y}] and so on. I want to make a command to scan the
expression and do the conversion autmatically. I don't want to use Replace
or ReplaceAll commands, because as I said, the command is very long and I
have so many functions to deal with.

Many thanks in advance for your help.

HMQ




  • Prev by Date: Re: Vertices of a polyhedron
  • Next by Date: Re: Simple question
  • Previous by thread: Re: Simple question
  • Next by thread: Re: Simple question