[Date Index]
[Thread Index]
[Author Index]
Re: Function Doesn't Evaluate Local Variables?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg124676] Re: Function Doesn't Evaluate Local Variables?
*From*: Brentt <brenttnewman at gmail.com>
*Date*: Tue, 31 Jan 2012 05:35:28 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*References*: <CAFJC7Xr9ACFiAvBapMcyxMzXgpwRymVc_XMTKkXFeu=MbQi3rw@mail.gmail.com>
Sorry this
ReplacePart[#1, n -> p #1[[n]] + q #1[[m]]&
should be this
ReplacePart[#1, n -> p #1[[n]] + q #1[[m]]]&
On Mon, Jan 30, 2012 at 10:37 AM, Brentt <brenttnewman at gmail.com> wrote:
> Hello, this result is puzzling me.
> I'm trying to make a function that outputs a pure function.
>
> The inputs are two expressions of the form
>
> input1: p r[n] + q r[m]
> input2: r[n]
>
> And the output should be a pure function of the form:
> ReplacePart[#1, n -> p #1[[n]] + q #1[[m]]&
>
>
> This was my attempt:
>
> row[n_] := Hold[Part[Slot[1], n]];
> rpl[old_, new_] := Block[{index, newrow},
> index = new[[1]];
> newrow = old /. r -> row;
> ReplacePart[#1, index -> newrow] &
> ];
>
> But when using rpl, for some reason doesn't evaluate index and newexp,
> and just gives me this
>
> In[1]:= rpl[2 r[1] + 3 r[2] , r[1]]
> Out[1]= ReplacePart[#1, index -> newrow] &
>
> Why did it not give the appropriate expressions for "new row" and "index"
> but instead just output the names of the variables?
>
> In case you are curious, I'm trying to write a program that takes a list
> of elementary row opeartion, specified by a list of the form
> operationSequence ={
> 1 r[1] + 2 r[2] -> r[1],
> r[1] <-> r[2],
> 2 r[1] -> r[1]
> }
> and transforms each row operation in the list into a function, and uses
> compose list to output a nicely formatted sequence of row operations to
> Latex. Any pointers for a more elegant way to do this would be most
> welcome.
>
>
>
Prev by Date:
**Re: Unrelated variable affects rsolve result**
Next by Date:
**Re: GramSchmidt function**
Previous by thread:
**Function Doesn't Evaluate Local Variables?**
Next by thread:
**Re: Function Doesn't Evaluate Local Variables?**
| |