Mathematica Asked by Ying Zhang on March 29, 2021
I know that this seems to be unnecessary, but here I have a bunch of assignments, like around 50, and I want to create rules for all these to have the freedom to apply these rules only on certain expressions. However I can’t find an efficient way to do this. Please help.
Here’s an example:
I want to turn the following assignment expressions:
a = Cosh[ξ0];
b = Sinh[ξ0];
d = Coth[ξ0];
c = 1/((Sinh[ξ0])^2*Cosh[ξ0])^(1/3);
...
into a rule:
subabcd = {
a -> Cosh[ξ0],
b -> Sinh[ξ0],
d -> Coth[ξ0],
c -> 1/((Sinh[ξ0])^2*Cosh[ξ0])^(1/3)
};
Problem is I got more then 50 of the definitions..
Clear
is also not efficient because I have to put in all those names of the variables.
How about:
torulelist =
Function[a, Unevaluated[a] /. {Set -> Rule, CompoundExpression -> List}, HoldAll];
torulelist[
a = Cosh[ξ0];
b = Sinh[ξ0];
d = Coth[ξ0];
c = 1/((Sinh[ξ0])^2*Cosh[ξ0])^(1/3)]
(*
{a -> Cosh[ξ0], b -> Sinh[ξ0], d -> Coth[ξ0],
c -> 1/(Cosh[ξ0] Sinh[ξ0]^2)^(1/3)}
*)
Correct answer by xzczd on March 29, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP