Why do Replace and ReplaceAll give different results even when only one rule and one expression is used?

前端 未结 2 523
南旧
南旧 2021-02-08 02:06

Maybe someone can explain to me why Replace gives a different answer than ReplaceAll, even though I am using one rule, and, I think, I have one express

2条回答
  •  予麋鹿
    予麋鹿 (楼主)
    2021-02-08 02:36

    I think the relevant bit of the documentation for Replace is: "applies a rule or list of rules in an attempt to transform the entire expression expr. " i.e., to transform the entire expression. Thus,

    Replace[z, z -> Exp[I*w]]
    

    would transform z to Exp[I*w], but your example fails because the rule does not match the entire expression.

    Note that Replace takes an argument level spec; so to operate on the end leaves of your tree, try

    Replace[hz, z -> Exp[I*w], -1]
    

    giving

    E^(I w)/(0.5 -1.4 E^(I w)+E^(2 I w))
    

提交回复
热议问题