如何在mma中替换n-1->n
我已经定义了
Subscript[S,n]=Subscript[X,n]+Subscript[S,n-1]
For 表达式:
3*n^2 – 6* n* Subscript[S, -1 + n] ^2
我想做 n-1->n
,但似乎
3*n^2 – 6* n* Subscript[S, -1 + n] ^2/. {n-1->n}
我得到的这种方式
3 n^2 - 6 n (Subscript[S, -1 + n] + Subscript[X, n])^2
并没有做我想做的事情。我希望使用 n-1
将 3*n^2
重写为等效项,在本例中为 3*(n-1)^2+ 6*(n-1)+3
,然后进行替换得到 3*n^2+6*n+3
总的来说,我想要:
3*n^2+6*n+3+6*n*Subscript[S, n] ^2+6* Subscript[S, n] ^2
即我也没有希望 mma 在最终结果中展开Subscript[S, n]
。
如何在 mma 中自动执行此操作?
多谢。
I have defined
Subscript[S,n]=Subscript[X,n]+Subscript[S,n-1]
For the expression:
3*n^2 – 6* n* Subscript[S, -1 + n] ^2
I want to do n-1->n
, but it seems
3*n^2 – 6* n* Subscript[S, -1 + n] ^2/. {n-1->n}
This way I got
3 n^2 - 6 n (Subscript[S, -1 + n] + Subscript[X, n])^2
does not do what I want. I want 3*n^2
be re-written as an equivalent using n-1
, in this case, 3*(n-1)^2+6*(n-1)+3
, then do the substitution to get 3*n^2+6*n+3
Overall, I want to have:
3*n^2+6*n+3+6*n*Subscript[S, n] ^2+6* Subscript[S, n] ^2
i.e. I also do not want mma to expand Subscript[S, n]
in the final result.
How to do this in mma automatically?
Thanks a lot.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我不确定你为什么有最初的定义...
看起来你想要的结果(除了一些标志之外)遵循简单的
至于不扩展最终结果中的下标项,也许你想要类似的东西
I'm not sure why you have the initial definition...
It looks like the result that you want (apart from some signs) follows from the simple
As for not expanding out the Subscript terms in the final result, maybe you want something like