The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Notice: We are no longer accepting new posts, but the forums will continue to be readable.

Topic: Simple question
Replies: 1   Last Post: Jan 16, 2014 1:50 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View  
David Park

Posts: 1,560
Registered: 5/19/07
Re: Simple question
Posted: Jan 16, 2014 1:50 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply

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,
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 @@ #] &) /@
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

From: KFUPM []

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.


Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2018. All Rights Reserved.