Mathematica 9 is now available

ReplacePart

Usage

ReplacePart[expr, new, n] 得到一个表达式,且在该表达式中expr的第n个部分由new替换.
ReplacePart[expr, new,  i, j, ...  ] 替换 i, j, ...  位置上的部分.
ReplacePart[expr, new,    ,  , ...  ,   ,  , ...  , ...  ]new替换几个位置上的部分.
ReplacePart[expr, new, pos, npos]newnpos位置上的部分替换exprpos位置上的部分.


Notes

• 例如: ReplacePart[ a, b, c, d , x, 3]LongRightArrow .
ReplacePart 所使用的位置列表与函数Position所返回的具有相同形式.
ReplacePart[expr, Hold[new], pos, 1] 可以用来替换一个不对它进行计算的部分.
• 如果 posnpos 都指定多个部分, pos 中的每个部分用npos中相应的部分替换.
• 参见 Mathematica 全书: 1.8.6节 和 2.1.4节.
Further Examples

This puts x into the third part of the expression.

In[1]:=  

Out[1]=

A powerful application of ReplacePart is in the partial evaluation of a held expression. Here's a function that takes an expression and a list of positions, and evaluates in place the parts at the specified positions.

In[2]:=  

In this case, {1,2} specifies the second element of the held list, and {1,-1,1} the first part of the last element.

In[3]:=  

Out[3]=

In[4]:=  



Any questions about topics on this page? Click here to get an individual response.Buy NowMore Information
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE DOCUMENTATION CENTER FOR THE LATEST INFORMATION.