[Date Index]
[Thread Index]
[Author Index]
Function Doesn't Evaluate Local Variables?
*To*: mathgroup at smc.vnet.net
*Subject*: [mg124675] Function Doesn't Evaluate Local Variables?
*From*: Brentt <brenttnewman at gmail.com>
*Date*: Tue, 31 Jan 2012 05:35:07 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
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: Executing function on Mathematica 8**
Next by Date:
**large lists with variable and if condition (vrs. 8.0.4)**
Previous by thread:
**Making an Installed Stylesheet Permanent**
Next by thread:
**Re: Function Doesn't Evaluate Local Variables?**
| |