Re: Simple question
- To: mathgroup at smc.vnet.net
- Subject: [mg132205] Re: Simple question
- From: Ulrich Arndt <ulrich.arndt at data2knowledge.de>
- Date: Thu, 16 Jan 2014 01:54:44 -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: <20140115091656.DEBE169F0@smc.vnet.net>
Would something like this work for you?
exp = K11 Ue + (K12 - K21) Uexx +
K22 Uex + (K23 + K32) Uexy + (K13 - K31) Uey + K33 Ueyy;
findings =
StringTrim[
StringTake[ToString[exp],
StringPosition[ToString[exp],
x : Shortest["Ue" ~~ ___] ~~
" " | "+" | "(" | ")" | "-" | "/" | EndOfString]]]
Clear[genFun]
genFun[exp_String, pat_String] := Block[{b, c, s},
If[exp === pat,
StringTake[exp, 1] <> "[x,y,z,t]",
b = StringTake[exp, 1];
c = StringTake[exp, {StringLength[pat] + 1, StringLength[exp]}];
s = ToString[Characters[c]];
"D[" <> StringTake[exp, 1] <> "[x,y,z,t]," <>
If[StringLength[c] == 1, c, s] <> "]"
]
]
genFun["Uexy", "Ue"]
genFun["Uey", "Ue"]
genFun["Ue", "Ue"]
mapped = genFun[#, "Ue"] & /@ findings;
f = ToExpression[#, TraditionalForm] & /@ findings;
m = ToExpression[#, TraditionalForm] & /@ mapped;
ReplaceAll[exp, Apply[Rule, Transpose[{f, m}], 1]]
Am 15.01.2014 um 10:16 schrieb 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.
>
> HMQ
>
- References:
- Simple question
- From: KFUPM <hussain.alqahtani@gmail.com>
- Simple question