Re: replace one rule in a list of rules
- To: mathgroup at smc.vnet.net
- Subject: [mg125592] Re: replace one rule in a list of rules
- From: Christoph Lhotka <christoph.lhotka at fundp.ac.be>
- Date: Tue, 20 Mar 2012 02:22:17 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
- References: <jk1fv4$515$1@smc.vnet.net> <jk44fj$e40$1@smc.vnet.net> <201203190957.EAA00933@smc.vnet.net>
Dear Alan,
if your simple examples below are what you need I would avoid to replace
rules
in a list but rather define the rules (which are needed to be changed) using
parameters or patterns:
Clear[a, b, c]
Table[{a -> 0.1, b -> i/10., c -> 0.1}, {i, 0, 10}]
For example if the rules are controlled by an external parameter,
you could define a rule depending on i as:
rul[i_]:={a -> 0.1, b -> i/10., c -> 0.1}
etc...
and use it in the following way in your expressions:
Table[{a,b,c}/.rul[i],{i,0,10}]
If the rule depends on the lhs of the above (the rule depends
on the expression it will be used with) I would use patterns
instead:
Clear[rul]
rul={a->0.1,b:>b/10, c->0.1}
{a,b,c}/. rul
Hope that helps,
Best,
Christoph
On 03/19/2012 10:57 AM, Alan wrote:
> Using Murray's approach I end up with (for example):
>
> Clear[a, b, c]
> rules = Thread[{a, b, c} -> {0.1, 0.1, 0.1}]
> Table[rules /. ((b -> _) -> (b -> i/10.)), {i, 0, 10}]
>
> Using Peter's approach I end up with (for example):
>
> Clear[a, b, c]
> rules = Thread[{a, b, c} -> {0.1, 0.1, 0.1}]
> Table[(rules /. HoldPattern[b -> _] :> b -> i/10.), {i, 0, 10}]
>
> Both appear to meet my needs. I'm not sure what the real
> difference between the two is.
>
> Thanks,
> Alan
>
>
> Thanks!
> Alan
>
- References:
- Re: replace one rule in a list of rules
- From: Alan <alan.isaac@gmail.com>
- Re: replace one rule in a list of rules